completion/ivy: minor refactor
This commit is contained in:
parent
875225cdd9
commit
ace4c4c782
1 changed files with 87 additions and 81 deletions
|
@ -48,7 +48,6 @@ immediately runs it on the current candidate (ending the ivy session)."
|
|||
;;; Packages
|
||||
|
||||
(use-package! ivy
|
||||
:defer 1
|
||||
:after-call pre-command-hook
|
||||
:init
|
||||
(setq ivy-re-builders-alist
|
||||
|
@ -60,18 +59,10 @@ immediately runs it on the current candidate (ending the ivy session)."
|
|||
;; Ignore order for non-fuzzy searches by default
|
||||
(t . ivy--regex-ignore-order)))
|
||||
:config
|
||||
;; Counsel has a history of modifying ivy's variables in a way that is very
|
||||
;; difficult to predict. This makes changing its defaults (without changing
|
||||
;; any possible user customizations of those defaults) very difficult. It's
|
||||
;; easiest to load counsel immediately.
|
||||
(require 'counsel nil t)
|
||||
|
||||
(setq ivy-height 15
|
||||
ivy-wrap t
|
||||
ivy-fixed-height-minibuffer t
|
||||
projectile-completion-system 'ivy
|
||||
;; Don't use ^ as initial input
|
||||
ivy-initial-inputs-alist nil
|
||||
;; disable magic slash on non-match
|
||||
ivy-magic-slash-non-match-action nil
|
||||
;; don't show recent files in switch-buffer
|
||||
|
@ -86,32 +77,8 @@ immediately runs it on the current candidate (ending the ivy session)."
|
|||
(setf (alist-get 't ivy-format-functions-alist)
|
||||
#'ivy-format-function-line)
|
||||
|
||||
;; REVIEW Move this somewhere else and perhaps generalize this so both
|
||||
;; ivy/helm users can enjoy it.
|
||||
(defadvice! +ivy--counsel-file-jump-use-fd-rg-a (args)
|
||||
"Change `counsel-file-jump' to use fd or ripgrep, if they are available."
|
||||
:override #'counsel--find-return-list
|
||||
(cl-destructuring-bind (find-program . args)
|
||||
(cond ((executable-find "fd")
|
||||
(cons "fd" (list "-t" "f" "-E" ".git")))
|
||||
((executable-find "rg")
|
||||
(cons "rg" (list "--files" "--hidden" "--no-messages")))
|
||||
((cons find-program args)))
|
||||
(unless (listp args)
|
||||
(user-error "`counsel-file-jump-args' is a list now, please customize accordingly."))
|
||||
(counsel--call
|
||||
(cons find-program args)
|
||||
(lambda ()
|
||||
(goto-char (point-min))
|
||||
(let ((offset (if (member find-program '("fd" "rg")) 0 2))
|
||||
files)
|
||||
(while (< (point) (point-max))
|
||||
(push (buffer-substring
|
||||
(+ offset (line-beginning-position)) (line-end-position)) files)
|
||||
(forward-line 1))
|
||||
(nreverse files))))))
|
||||
|
||||
;; Ensure a jump point is registered before jumping to new locations with ivy
|
||||
;; 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
|
||||
|
@ -131,7 +98,7 @@ immediately runs it on the current candidate (ending the ivy session)."
|
|||
(after! yasnippet
|
||||
(add-hook 'yas-prompt-functions #'+ivy-yas-prompt))
|
||||
|
||||
(defadvice! +ivy--inhibit-in-evil-ex-a (orig-fn &rest args)
|
||||
(defadvice! +ivy--inhibit-completion-in-region-a (orig-fn &rest args)
|
||||
"`ivy-completion-in-region' struggles with completing certain
|
||||
evil-ex-specific constructs, so we disable it solely in evil-ex."
|
||||
:around #'evil-ex
|
||||
|
@ -167,13 +134,12 @@ evil-ex-specific constructs, so we disable it solely in evil-ex."
|
|||
'ivy-switch-buffer))))
|
||||
|
||||
;; Include variable value in `counsel-describe-variable'
|
||||
(setq ivy-rich-display-transformers-list
|
||||
(plist-put ivy-rich-display-transformers-list
|
||||
(plist-put! ivy-rich-display-transformers-list
|
||||
'counsel-describe-variable
|
||||
'(:columns
|
||||
((counsel-describe-variable-transformer (:width 40)) ; the original transformer
|
||||
(+ivy-rich-describe-variable-transformer (:width 50))
|
||||
(ivy-rich-counsel-variable-docstring (:face font-lock-doc-face))))))
|
||||
(ivy-rich-counsel-variable-docstring (:face font-lock-doc-face)))))
|
||||
|
||||
;; Remove built-in coloring of buffer list; we do our own
|
||||
(setq ivy-switch-buffer-faces-alist nil)
|
||||
|
@ -187,12 +153,10 @@ evil-ex-specific constructs, so we disable it solely in evil-ex."
|
|||
(setcar switch-buffer-alist '+ivy-rich-buffer-name)))
|
||||
|
||||
;; Apply switch buffer transformers to `counsel-projectile-switch-to-buffer' as well
|
||||
(setq ivy-rich-display-transformers-list
|
||||
(plist-put ivy-rich-display-transformers-list
|
||||
(plist-put! ivy-rich-display-transformers-list
|
||||
'counsel-projectile-switch-to-buffer
|
||||
(plist-get ivy-rich-display-transformers-list 'ivy-switch-buffer)))
|
||||
(plist-get ivy-rich-display-transformers-list 'ivy-switch-buffer))
|
||||
|
||||
;; Reload ivy which so changes to `ivy-rich-display-transformers-list' work
|
||||
(ivy-rich-mode +1))
|
||||
|
||||
|
||||
|
@ -215,7 +179,8 @@ evil-ex-specific constructs, so we disable it solely in evil-ex."
|
|||
(use-package! counsel
|
||||
:commands counsel-describe-face
|
||||
:init
|
||||
(map! [remap apropos] #'counsel-apropos
|
||||
(define-key!
|
||||
[remap apropos] #'counsel-apropos
|
||||
[remap bookmark-jump] #'counsel-bookmark
|
||||
[remap describe-face] #'counsel-faces
|
||||
[remap describe-function] #'counsel-describe-function
|
||||
|
@ -238,21 +203,52 @@ evil-ex-specific constructs, so we disable it solely in evil-ex."
|
|||
:config
|
||||
(set-popup-rule! "^\\*ivy-occur" :size 0.35 :ttl 0 :quit nil)
|
||||
|
||||
;; Don't use ^ as initial input. Set this here because `counsel' defines more
|
||||
;; of its own, on top of the defaults.
|
||||
(setq ivy-initial-inputs-alist nil)
|
||||
|
||||
;; REVIEW Move this somewhere else and perhaps generalize this so both
|
||||
;; ivy/helm users can enjoy it.
|
||||
(defadvice! +ivy--counsel-file-jump-use-fd-rg-a (args)
|
||||
"Change `counsel-file-jump' to use fd or ripgrep, if they are available."
|
||||
:override #'counsel--find-return-list
|
||||
(cl-destructuring-bind (find-program . args)
|
||||
(cond ((executable-find "fd")
|
||||
(cons "fd" (list "-t" "f" "-E" ".git")))
|
||||
((executable-find "rg")
|
||||
(cons "rg" (list "--files" "--hidden" "--no-messages")))
|
||||
((cons find-program args)))
|
||||
(unless (listp args)
|
||||
(user-error "`counsel-file-jump-args' is a list now, please customize accordingly."))
|
||||
(counsel--call
|
||||
(cons find-program args)
|
||||
(lambda ()
|
||||
(goto-char (point-min))
|
||||
(let ((offset (if (member find-program '("fd" "rg")) 0 2))
|
||||
files)
|
||||
(while (< (point) (point-max))
|
||||
(push (buffer-substring
|
||||
(+ offset (line-beginning-position)) (line-end-position)) files)
|
||||
(forward-line 1))
|
||||
(nreverse files))))))
|
||||
|
||||
;; Integrate with `helpful'
|
||||
(setq counsel-describe-function-function #'helpful-callable
|
||||
counsel-describe-variable-function #'helpful-variable)
|
||||
|
||||
;; Make `counsel-compile' projectile-aware (if you prefer it over
|
||||
;; `+ivy/compile' and `+ivy/project-compile')
|
||||
(add-to-list 'counsel-compile-root-functions #'projectile-project-root)
|
||||
|
||||
(after! savehist
|
||||
;; Persist `counsel-compile' history
|
||||
(add-to-list 'savehist-additional-variables 'counsel-compile-history))
|
||||
|
||||
;; Use spotlight on mac for `counsel-locate' by default
|
||||
(when IS-MAC
|
||||
(setq counsel-locate-cmd #'counsel-locate-cmd-mdfind))
|
||||
(setq counsel-find-file-ignore-regexp "\\(?:^[#.]\\)\\|\\(?:[#~]$\\)\\|\\(?:^Icon?\\)"
|
||||
counsel-describe-function-function #'helpful-callable
|
||||
counsel-describe-variable-function #'helpful-variable)
|
||||
|
||||
(add-to-list 'swiper-font-lock-exclude #'+doom-dashboard-mode nil #'eq)
|
||||
;; Don't mess with font-locking on the dashboard; it causes breakages
|
||||
(add-to-list 'swiper-font-lock-exclude #'+doom-dashboard-mode)
|
||||
|
||||
;; Record in jumplist when opening files via counsel-{ag,rg,pt,git-grep}
|
||||
(add-hook 'counsel-grep-post-action-hook #'better-jumper-set-jump)
|
||||
|
@ -270,6 +266,8 @@ evil-ex-specific constructs, so we disable it solely in evil-ex."
|
|||
(funcall cmd source target 1))))
|
||||
|
||||
;; Configure `counsel-find-file'
|
||||
(setq counsel-find-file-at-point t
|
||||
counsel-find-file-ignore-regexp "\\(?:^[#.]\\)\\|\\(?:[#~]$\\)\\|\\(?:^Icon?\\)")
|
||||
(ivy-add-actions
|
||||
'counsel-find-file
|
||||
`(("b" counsel-find-file-cd-bookmark-action "cd bookmark")
|
||||
|
@ -296,13 +294,21 @@ evil-ex-specific constructs, so we disable it solely in evil-ex."
|
|||
(use-package! counsel-projectile
|
||||
:defer t
|
||||
:init
|
||||
(map! [remap projectile-find-file] #'+ivy/projectile-find-file
|
||||
(define-key!
|
||||
[remap projectile-find-file] #'+ivy/projectile-find-file
|
||||
[remap projectile-find-dir] #'counsel-projectile-find-dir
|
||||
[remap projectile-switch-to-buffer] #'counsel-projectile-switch-to-buffer
|
||||
[remap projectile-grep] #'counsel-projectile-grep
|
||||
[remap projectile-ag] #'counsel-projectile-ag
|
||||
[remap projectile-switch-project] #'counsel-projectile-switch-project)
|
||||
:config
|
||||
;; A more sensible `counsel-projectile-find-file' that reverts to
|
||||
;; `counsel-find-file' if invoked from $HOME, `counsel-file-jump' if invoked
|
||||
;; from a non-project, `projectile-find-file' if in a big project (more than
|
||||
;; `ivy-sort-max-size' files), or `counsel-projectile-find-file' otherwise.
|
||||
(setf (alist-get 'projectile-find-file counsel-projectile-key-bindings)
|
||||
#'+ivy/projectile-find-file)
|
||||
|
||||
;; no highlighting visited files; slows down the filtering
|
||||
(ivy-set-display-transformer #'counsel-projectile-find-file nil))
|
||||
|
||||
|
@ -333,8 +339,8 @@ evil-ex-specific constructs, so we disable it solely in evil-ex."
|
|||
|
||||
|
||||
(use-package! flx
|
||||
:when (and (featurep! +fuzzy)
|
||||
(not (featurep! +prescient)))
|
||||
:when (featurep! +fuzzy)
|
||||
:unless (featurep! +prescient)
|
||||
:defer t ; is loaded by ivy
|
||||
:init
|
||||
(setf (alist-get 't ivy-re-builders-alist) #'ivy--regex-fuzzy)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue