diff --git a/modules/completion/ivy/autoload/ivy.el b/modules/completion/ivy/autoload/ivy.el index 414b887b1..c264f8337 100644 --- a/modules/completion/ivy/autoload/ivy.el +++ b/modules/completion/ivy/autoload/ivy.el @@ -488,7 +488,6 @@ If ALL-FILES-P, search compressed and hidden files as well." (interactive) (counsel-compile (projectile-project-root))) - ;;;###autoload (defun +ivy/jump-list () "Go to an entry in evil's (or better-jumper's) jumplist." @@ -529,3 +528,11 @@ If ALL-FILES-P, search compressed and hidden files as well." (goto-char (marker-position mark))))) :caller '+ivy/jump-list) (mapc #'kill-buffer buffers)))) + +;;;###autoload +(defun +ivy/git-grep-other-window-action () + "Open the current counsel-{ag,rg,git-grep} candidate in other-window." + (interactive) + (ivy-set-action #'+ivy-git-grep-other-window-action) + (setq ivy-exit 'done) + (exit-minibuffer)) diff --git a/modules/completion/ivy/config.el b/modules/completion/ivy/config.el index e27bfa34a..a5fbd9b2c 100644 --- a/modules/completion/ivy/config.el +++ b/modules/completion/ivy/config.el @@ -34,14 +34,17 @@ If you want to already use git-grep or grep, set this to nil.") "A plist mapping ivy/counsel commands to commands that generate an editable results buffer.") -(defmacro +ivy-do-action! (action) - "Returns an interactive lambda that sets the current ivy action and -immediately runs it on the current candidate (ending the ivy session)." - `(lambda () - (interactive) - (ivy-set-action ,action) - (setq ivy-exit 'done) - (exit-minibuffer))) +(defvar +ivy-standard-search-fn + (if (featurep! +prescient) + #'+ivy-prescient-non-fuzzy + #'ivy--regex-plus) + "Function to use for non-fuzzy search commands.") + +(defvar +ivy-alternative-search-fn + (cond ((featurep! +prescient) #'ivy-prescient-re-builder) + ((featurep! +fuzzy) #'ivy--regex-fuzzy) + (#'ivy--regex-ignore-order)) + "Function to use for fuzzy search commands.") ;; @@ -51,13 +54,20 @@ immediately runs it on the current candidate (ending the ivy session)." :after-call pre-command-hook :init (setq ivy-re-builders-alist - '((counsel-ag . ivy--regex-plus) - (counsel-rg . ivy--regex-plus) - (counsel-grep . ivy--regex-plus) - (swiper . ivy--regex-plus) - (swiper-isearch . ivy--regex-plus) + `(,@(cl-loop for cmd in '(counsel-ag + counsel-rg + counsel-grep + swiper + swiper-isearch) + collect (cons cmd +ivy-standard-search-fn)) ;; Ignore order for non-fuzzy searches by default - (t . ivy--regex-ignore-order))) + (t . ,+ivy-alternative-search-fn))) + + (define-key! + [remap switch-to-buffer] #'+ivy/switch-buffer + [remap switch-to-buffer-other-window] #'+ivy/switch-buffer-other-window + [remap persp-switch-to-buffer] #'+ivy/switch-workspace-buffer + [remap evil-show-jumps] #'+ivy/jump-list) :config (setq ivy-height 15 ivy-wrap t @@ -74,26 +84,26 @@ immediately runs it on the current candidate (ending the ivy session)." ;; enable ability to select prompt (alternative to `ivy-immediate-done') ivy-use-selectable-prompt t) + ;; Highlight each ivy candidate including the following newline, so that it + ;; extends to the right edge of the window (setf (alist-get 't ivy-format-functions-alist) #'ivy-format-function-line) ;; Integrate `ivy' with `better-jumper'; ensure a jump point is registered ;; before jumping to new locations with ivy - (defvar +ivy--origin nil) - (defun +ivy--record-position-maybe-fn () - (with-ivy-window - (setq +ivy--origin (point-marker)))) - (setq ivy-hooks-alist '((t . +ivy--record-position-maybe-fn))) + (setf (alist-get 't ivy-hooks-alist) + (lambda () + (with-ivy-window + (setq +ivy--origin (point-marker))))) (add-hook! 'minibuffer-exit-hook (defun +ivy--set-jump-point-maybe-h () - (with-demoted-errors "Ivy error: %s" - (when (and (markerp +ivy--origin) - (not (equal (with-ivy-window (point-marker)) - +ivy--origin))) - (with-current-buffer (marker-buffer +ivy--origin) - (better-jumper-set-jump +ivy--origin))) - (setq +ivy--origin nil)))) + (and (markerp (bound-and-true-p +ivy--origin)) + (not (equal (ignore-errors (with-ivy-window (point-marker))) + +ivy--origin)) + (with-current-buffer (marker-buffer +ivy--origin) + (better-jumper-set-jump +ivy--origin))) + (setq +ivy--origin nil))) (after! yasnippet (add-hook 'yas-prompt-functions #'+ivy-yas-prompt)) @@ -105,12 +115,6 @@ evil-ex-specific constructs, so we disable it solely in evil-ex." (let ((completion-in-region-function #'completion--in-region)) (apply orig-fn args))) - (define-key! ivy-mode-map - [remap switch-to-buffer] #'+ivy/switch-buffer - [remap switch-to-buffer-other-window] #'+ivy/switch-buffer-other-window - [remap persp-switch-to-buffer] #'+ivy/switch-workspace-buffer - [remap evil-show-jumps] #'+ivy/jump-list) - (define-key ivy-minibuffer-map (kbd "C-c C-e") #'+ivy/woccur) (ivy-mode +1) @@ -343,10 +347,7 @@ evil-ex-specific constructs, so we disable it solely in evil-ex." :when (featurep! +fuzzy) :unless (featurep! +prescient) :defer t ; is loaded by ivy - :init - (setf (alist-get 't ivy-re-builders-alist) #'ivy--regex-fuzzy) - (setq ivy-initial-inputs-alist nil - ivy-flx-limit 10000)) + :init (setq ivy-flx-limit 10000)) (use-package! ivy-prescient @@ -358,15 +359,7 @@ evil-ex-specific constructs, so we disable it solely in evil-ex." '(literal regexp initialism fuzzy) '(literal regexp initialism)) ivy-prescient-enable-filtering nil ; we do this ourselves - ivy-prescient-retain-classic-highlighting t - ivy-initial-inputs-alist nil - ivy-re-builders-alist - '((counsel-ag . +ivy-prescient-non-fuzzy) - (counsel-rg . +ivy-prescient-non-fuzzy) - (counsel-grep . +ivy-prescient-non-fuzzy) - (swiper . +ivy-prescient-non-fuzzy) - (swiper-isearch . +ivy-prescient-non-fuzzy) - (t . ivy-prescient-re-builder))) + ivy-prescient-retain-classic-highlighting t) :config (defun +ivy-prescient-non-fuzzy (str) diff --git a/modules/config/default/+emacs-bindings.el b/modules/config/default/+emacs-bindings.el index 0756fc427..4b6bf75af 100644 --- a/modules/config/default/+emacs-bindings.el +++ b/modules/config/default/+emacs-bindings.el @@ -337,36 +337,36 @@ (:when (featurep! :completion ivy) (:after ivy :map ivy-minibuffer-map - "TAB" #'ivy-alt-done - "C-g" #'keyboard-escape-quit) + "TAB" #'ivy-alt-done + "C-g" #'keyboard-escape-quit) (:after counsel :map counsel-ag-map - "C-SPC" #'ivy-call-and-recenter ; preview - "M-RET" (+ivy-do-action! #'+ivy-git-grep-other-window-action)) - "C-M-y" #'counsel-yank-pop) + "C-SPC" #'ivy-call-and-recenter ; preview + "M-RET" #'+ivy/git-grep-other-window-action) + "C-M-y" #'counsel-yank-pop) ;;; neotree (:when (featurep! :ui neotree) - "" #'+neotree/open - "" #'+neotree/find-this-file + "" #'+neotree/open + "" #'+neotree/find-this-file (:after neotree :map neotree-mode-map - "q" #'neotree-hide - "RET" #'neotree-enter - "SPC" #'neotree-quick-look - "v" #'neotree-enter-vertical-split - "s" #'neotree-enter-horizontal-split - "c" #'neotree-create-node - "D" #'neotree-delete-node - "g" #'neotree-refresh - "r" #'neotree-rename-node - "R" #'neotree-refresh - "h" #'+neotree/collapse-or-up - "l" #'+neotree/expand-or-open - "n" #'neotree-next-line - "p" #'neotree-previous-line - "N" #'neotree-select-next-sibling-node - "P" #'neotree-select-previous-sibling-node)) + "q" #'neotree-hide + "RET" #'neotree-enter + "SPC" #'neotree-quick-look + "v" #'neotree-enter-vertical-split + "s" #'neotree-enter-horizontal-split + "c" #'neotree-create-node + "D" #'neotree-delete-node + "g" #'neotree-refresh + "r" #'neotree-rename-node + "R" #'neotree-refresh + "h" #'+neotree/collapse-or-up + "l" #'+neotree/expand-or-open + "n" #'neotree-next-line + "p" #'neotree-previous-line + "N" #'neotree-select-next-sibling-node + "P" #'neotree-select-previous-sibling-node)) ;;; popups (:when (featurep! :ui popup) diff --git a/modules/config/default/+evil-bindings.el b/modules/config/default/+evil-bindings.el index 31588b509..125c6042b 100644 --- a/modules/config/default/+evil-bindings.el +++ b/modules/config/default/+evil-bindings.el @@ -248,7 +248,7 @@ :map counsel-ag-map "C-SPC" #'ivy-call-and-recenter ; preview "C-l" #'ivy-done - [C-return] (+ivy-do-action! #'+ivy-git-grep-other-window-action))) + [C-return] #'+ivy/git-grep-other-window-action)) (:when (featurep! :completion helm) (:after helm