mirror of
https://gitlab.com/dwt1/dotfiles.git
synced 2026-04-24 12:00:24 +10:00
Updating Doom Emacs.
This commit is contained in:
@@ -14,33 +14,31 @@ When 'everything, also preview virtual buffers")
|
||||
"A plist mapping ivy/counsel commands to commands that generate an editable
|
||||
results buffer.")
|
||||
|
||||
(defvar +ivy-standard-search-fn
|
||||
(if (featurep! +prescient)
|
||||
#'+ivy-prescient-non-fuzzy
|
||||
#'ivy--regex-plus)
|
||||
"Function to use for non-fuzzy search commands.
|
||||
This uses the standard search algorithm ivy uses (or a variant of it).")
|
||||
|
||||
(defvar +ivy-alternative-search-fn
|
||||
(cond ((featurep! +prescient) #'ivy-prescient-re-builder)
|
||||
((featurep! +fuzzy) #'ivy--regex-fuzzy)
|
||||
;; Ignore order for non-fuzzy searches by default
|
||||
(#'ivy--regex-ignore-order))
|
||||
"Function to use for fuzzy search commands.
|
||||
This uses a search algorithm other than ivy's default.")
|
||||
|
||||
|
||||
;;
|
||||
;;; Packages
|
||||
|
||||
(use-package! ivy
|
||||
:after-call pre-command-hook
|
||||
:hook (doom-first-input . ivy-mode)
|
||||
:init
|
||||
(setq ivy-re-builders-alist
|
||||
`((counsel-rg . +ivy-standard-search)
|
||||
(swiper . +ivy-standard-search)
|
||||
(swiper-isearch . +ivy-standard-search)
|
||||
(t . +ivy-alternative-search)))
|
||||
(let ((standard-search-fn
|
||||
(if (featurep! +prescient)
|
||||
#'+ivy-prescient-non-fuzzy
|
||||
#'ivy--regex-plus))
|
||||
(alt-search-fn
|
||||
(if (featurep! +fuzzy)
|
||||
#'ivy--regex-fuzzy
|
||||
;; Ignore order for non-fuzzy searches by default
|
||||
#'ivy--regex-ignore-order)))
|
||||
(setq ivy-re-builders-alist
|
||||
`((counsel-rg . ,standard-search-fn)
|
||||
(swiper . ,standard-search-fn)
|
||||
(swiper-isearch . ,standard-search-fn)
|
||||
(t . ,alt-search-fn))
|
||||
ivy-more-chars-alist
|
||||
'((counsel-rg . 1)
|
||||
(counsel-search . 2)
|
||||
(t . 3))))
|
||||
|
||||
(define-key!
|
||||
[remap switch-to-buffer] #'+ivy/switch-buffer
|
||||
@@ -90,7 +88,7 @@ This uses a search algorithm other than ivy's default.")
|
||||
(setq +ivy--origin nil)))
|
||||
|
||||
(after! yasnippet
|
||||
(add-hook 'yas-prompt-functions #'+ivy-yas-prompt))
|
||||
(add-hook 'yas-prompt-functions #'+ivy-yas-prompt-fn))
|
||||
|
||||
(defadvice! +ivy--inhibit-completion-in-region-a (orig-fn &rest args)
|
||||
"`ivy-completion-in-region' struggles with completing certain
|
||||
@@ -99,19 +97,11 @@ 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-minibuffer-map (kbd "C-c C-e") #'+ivy/woccur)
|
||||
|
||||
(ivy-mode +1)
|
||||
|
||||
(use-package! ivy-hydra
|
||||
:commands (ivy-dispatching-done ivy--matcher-desc ivy-hydra/body)
|
||||
:init
|
||||
(define-key! ivy-minibuffer-map
|
||||
"C-o" #'ivy-dispatching-done
|
||||
"M-o" #'hydra-ivy/body)
|
||||
:config
|
||||
;; ivy-hydra rebinds this, so we have to do so again
|
||||
(define-key ivy-minibuffer-map (kbd "M-o") #'hydra-ivy/body)))
|
||||
(define-key! ivy-minibuffer-map
|
||||
[remap doom/delete-backward-word] #'ivy-backward-kill-word
|
||||
"C-c C-e" #'+ivy/woccur
|
||||
"C-o" #'ivy-dispatching-done
|
||||
"M-o" #'hydra-ivy/body))
|
||||
|
||||
|
||||
(use-package! ivy-rich
|
||||
@@ -122,15 +112,27 @@ evil-ex-specific constructs, so we disable it solely in evil-ex."
|
||||
(when (featurep! +icons)
|
||||
(cl-pushnew '(+ivy-rich-buffer-icon)
|
||||
(cadr (plist-get ivy-rich-display-transformers-list
|
||||
'ivy-switch-buffer))))
|
||||
'ivy-switch-buffer))
|
||||
:test #'equal))
|
||||
|
||||
;; Include variable value in `counsel-describe-variable'
|
||||
;; Enahnce the appearance of a couple counsel commands
|
||||
(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-describe-variable-transformer (:width 50)) ; display variable value
|
||||
(ivy-rich-counsel-variable-docstring (:face font-lock-doc-face))))
|
||||
'counsel-M-x
|
||||
'(:columns
|
||||
((counsel-M-x-transformer (:width 60))
|
||||
(ivy-rich-counsel-function-docstring (:face font-lock-doc-face))))
|
||||
;; Apply switch buffer transformers to `counsel-projectile-switch-to-buffer' as well
|
||||
'counsel-projectile-switch-to-buffer
|
||||
(plist-get ivy-rich-display-transformers-list 'ivy-switch-buffer)
|
||||
'counsel-bookmark
|
||||
'(:columns
|
||||
((ivy-rich-candidate (:width 0.5))
|
||||
(ivy-rich-bookmark-filename (:width 60)))))
|
||||
|
||||
;; Remove built-in coloring of buffer list; we do our own
|
||||
(setq ivy-switch-buffer-faces-alist nil)
|
||||
@@ -138,15 +140,9 @@ evil-ex-specific constructs, so we disable it solely in evil-ex."
|
||||
|
||||
;; Highlight buffers differently based on whether they're in the same project
|
||||
;; as the current project or not.
|
||||
(let* ((plist (plist-get ivy-rich-display-transformers-list 'ivy-switch-buffer))
|
||||
(switch-buffer-alist (assq 'ivy-rich-candidate (plist-get plist :columns))))
|
||||
(when switch-buffer-alist
|
||||
(setcar switch-buffer-alist '+ivy-rich-buffer-name)))
|
||||
|
||||
;; Apply switch buffer transformers to `counsel-projectile-switch-to-buffer' as well
|
||||
(plist-put! ivy-rich-display-transformers-list
|
||||
'counsel-projectile-switch-to-buffer
|
||||
(plist-get ivy-rich-display-transformers-list 'ivy-switch-buffer))
|
||||
(when-let* ((plist (plist-get ivy-rich-display-transformers-list 'ivy-switch-buffer))
|
||||
(switch-buffer-alist (assq 'ivy-rich-candidate (plist-get plist :columns))))
|
||||
(setcar switch-buffer-alist '+ivy-rich-buffer-name))
|
||||
|
||||
(ivy-rich-mode +1))
|
||||
|
||||
@@ -161,9 +157,10 @@ evil-ex-specific constructs, so we disable it solely in evil-ex."
|
||||
|
||||
(all-the-icons-ivy-setup)
|
||||
(after! counsel-projectile
|
||||
(let ((all-the-icons-ivy-file-commands '(counsel-projectile
|
||||
counsel-projectile-find-file
|
||||
counsel-projectile-find-dir)))
|
||||
(let ((all-the-icons-ivy-file-commands
|
||||
'(counsel-projectile
|
||||
counsel-projectile-find-file
|
||||
counsel-projectile-find-dir)))
|
||||
(all-the-icons-ivy-setup))))
|
||||
|
||||
|
||||
@@ -173,62 +170,69 @@ evil-ex-specific constructs, so we disable it solely in evil-ex."
|
||||
(define-key!
|
||||
[remap apropos] #'counsel-apropos
|
||||
[remap bookmark-jump] #'counsel-bookmark
|
||||
[remap compile] #'+ivy/compile
|
||||
[remap describe-bindings] #'counsel-descbinds
|
||||
[remap describe-face] #'counsel-faces
|
||||
[remap describe-function] #'counsel-describe-function
|
||||
[remap describe-variable] #'counsel-describe-variable
|
||||
[remap describe-bindings] #'counsel-descbinds
|
||||
[remap set-variable] #'counsel-set-variable
|
||||
[remap evil-ex-registers] #'counsel-evil-registers
|
||||
[remap evil-show-marks] #'counsel-mark-ring
|
||||
[remap execute-extended-command] #'counsel-M-x
|
||||
[remap find-file] #'counsel-find-file
|
||||
[remap find-library] #'counsel-find-library
|
||||
[remap info-lookup-symbol] #'counsel-info-lookup-symbol
|
||||
[remap imenu] #'counsel-imenu
|
||||
[remap recentf-open-files] #'counsel-recentf
|
||||
[remap swiper] #'counsel-grep-or-swiper
|
||||
[remap evil-ex-registers] #'counsel-evil-registers
|
||||
[remap evil-show-marks] #'counsel-mark-ring
|
||||
[remap yank-pop] #'counsel-yank-pop
|
||||
[remap info-lookup-symbol] #'counsel-info-lookup-symbol
|
||||
[remap load-theme] #'counsel-load-theme
|
||||
[remap locate] #'counsel-locate
|
||||
[remap org-goto] #'counsel-org-goto
|
||||
[remap org-set-tags-command] #'counsel-org-tag
|
||||
[remap projectile-compile-project] #'+ivy/project-compile
|
||||
[remap recentf-open-files] #'counsel-recentf
|
||||
[remap set-variable] #'counsel-set-variable
|
||||
[remap swiper] #'counsel-grep-or-swiper
|
||||
[remap unicode-chars-list-chars] #'counsel-unicode-char
|
||||
[remap compile] #'+ivy/compile
|
||||
[remap projectile-compile-project] #'+ivy/project-compile)
|
||||
[remap yank-pop] #'counsel-yank-pop)
|
||||
:config
|
||||
(set-popup-rule! "^\\*ivy-occur" :size 0.35 :ttl 0 :quit nil)
|
||||
|
||||
;; HACK Fix an issue where `counsel-projectile-find-file-action' would try to
|
||||
;; open a candidate in an occur buffer relative to the wrong buffer,
|
||||
;; causing it to fail to find the file we want.
|
||||
(defadvice! +ivy--run-from-ivy-directory-a (orig-fn &rest args)
|
||||
:around #'counsel-projectile-find-file-action
|
||||
(let ((default-directory (ivy-state-directory ivy-last)))
|
||||
(apply orig-fn args)))
|
||||
|
||||
;; 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))))))
|
||||
;; REVIEW Counsel allows `counsel-rg-base-command' to be a string or list.
|
||||
;; This backwards compatibility complicates things for Doom. Simpler to
|
||||
;; just force it to always be a list.
|
||||
(when (stringp counsel-rg-base-command)
|
||||
(setq counsel-rg-base-command (split-string counsel-rg-base-command)))
|
||||
|
||||
;; REVIEW Fix #3215: prevents mingw on Windows throwing an error trying to
|
||||
;; expand / to an absolute path. Remove this when it is fixed upstream
|
||||
;; in counsel.
|
||||
(when (and (memq system-type '(windows-nt ms-dos))
|
||||
(listp counsel-rg-base-command)
|
||||
(member "--path-separator" counsel-rg-base-command))
|
||||
(setf (cadr (member "--path-separator" counsel-rg-base-command))
|
||||
"//"))
|
||||
|
||||
;; Integrate with `helpful'
|
||||
(setq counsel-describe-function-function #'helpful-callable
|
||||
counsel-describe-variable-function #'helpful-variable)
|
||||
|
||||
;; Record in jumplist when opening files via counsel-{ag,rg,pt,git-grep}
|
||||
(add-hook 'counsel-grep-post-action-hook #'better-jumper-set-jump)
|
||||
(add-hook 'counsel-grep-post-action-hook #'recenter)
|
||||
(ivy-add-actions
|
||||
'counsel-rg ; also applies to `counsel-rg'
|
||||
'(("O" +ivy-git-grep-other-window-action "open in other window")))
|
||||
|
||||
;; 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)
|
||||
@@ -236,33 +240,69 @@ evil-ex-specific constructs, so we disable it solely in evil-ex."
|
||||
;; Persist `counsel-compile' history
|
||||
(add-to-list 'savehist-additional-variables 'counsel-compile-history))
|
||||
|
||||
;; Use spotlight on mac for `counsel-locate' by default, since it doesn't need
|
||||
;; any additional setup.
|
||||
;; `counsel-imenu' -- no sorting for imenu. Sort it by appearance in page.
|
||||
(add-to-list 'ivy-sort-functions-alist '(counsel-imenu))
|
||||
|
||||
;; `counsel-locate'
|
||||
(when IS-MAC
|
||||
;; Use spotlight on mac by default since it doesn't need any additional setup
|
||||
(setq counsel-locate-cmd #'counsel-locate-cmd-mdfind))
|
||||
|
||||
;; `swiper'
|
||||
;; 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)
|
||||
|
||||
;; Configure `counsel-find-file'
|
||||
;; `counsel-find-file'
|
||||
(setq counsel-find-file-ignore-regexp "\\(?:^[#.]\\)\\|\\(?:[#~]$\\)\\|\\(?:^Icon?\\)")
|
||||
(ivy-add-actions
|
||||
'counsel-find-file
|
||||
'(("p" (lambda (path) (with-ivy-window (insert (file-relative-name path default-directory))))
|
||||
"insert relative path")
|
||||
("P" (lambda (path) (with-ivy-window (insert path)))
|
||||
"insert absolute path")
|
||||
("l" (lambda (path) (with-ivy-window (insert (format "[[./%s]]" (file-relative-name path default-directory)))))
|
||||
"insert relative org-link")
|
||||
("L" (lambda (path) (with-ivy-window (insert (format "[[%s]]" path))))
|
||||
"Insert absolute org-link")))
|
||||
(dolist (fn '(counsel-rg counsel-find-file))
|
||||
(ivy-add-actions
|
||||
fn '(("p" (lambda (path) (with-ivy-window (insert (file-relative-name path default-directory))))
|
||||
"insert relative path")
|
||||
("P" (lambda (path) (with-ivy-window (insert path)))
|
||||
"insert absolute path")
|
||||
("l" (lambda (path) (with-ivy-window (insert (format "[[./%s]]" (file-relative-name path default-directory)))))
|
||||
"insert relative org-link")
|
||||
("L" (lambda (path) (with-ivy-window (insert (format "[[%s]]" path))))
|
||||
"Insert absolute org-link"))))
|
||||
|
||||
(ivy-add-actions
|
||||
'counsel-ag ; also applies to `counsel-rg'
|
||||
'(("O" +ivy-git-grep-other-window-action "open in other window"))))
|
||||
(ivy-add-actions 'counsel-file-jump (plist-get ivy--actions-list 'counsel-find-file))
|
||||
|
||||
;; `counsel-search': use normal page for displaying results, so that we see
|
||||
;; custom ddg themes (if one is set).
|
||||
(setf (nth 1 (alist-get 'ddg counsel-search-engines-alist))
|
||||
"https://duckduckgo.com/?q=")
|
||||
|
||||
;; 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 doom-projectile-fd-binary)
|
||||
(append (list doom-projectile-fd-binary
|
||||
"--color=never" "-E" ".git"
|
||||
"--type" "file" "--type" "symlink" "--follow")
|
||||
(if IS-WINDOWS '("--path-separator=/"))))
|
||||
((executable-find "rg")
|
||||
(append (list "rg" "--files" "--follow" "--color=never" "--hidden" "--no-messages")
|
||||
(cl-loop for dir in projectile-globally-ignored-directories
|
||||
collect "--glob"
|
||||
collect (concat "!" dir))
|
||||
(if IS-WINDOWS (list "--path-separator" "/"))))
|
||||
((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 (list "rg" doom-projectile-fd-binary)) 0 2))
|
||||
files)
|
||||
(while (< (point) (point-max))
|
||||
(push (buffer-substring (+ offset (line-beginning-position)) (line-end-position))
|
||||
files)
|
||||
(forward-line 1))
|
||||
(nreverse files)))))))
|
||||
|
||||
|
||||
(use-package! counsel-projectile
|
||||
@@ -284,7 +324,10 @@ evil-ex-specific constructs, so we disable it solely in evil-ex."
|
||||
#'+ivy/projectile-find-file)
|
||||
|
||||
;; no highlighting visited files; slows down the filtering
|
||||
(ivy-set-display-transformer #'counsel-projectile-find-file nil))
|
||||
(ivy-set-display-transformer #'counsel-projectile-find-file nil)
|
||||
|
||||
(when (featurep! +prescient)
|
||||
(setq counsel-projectile-sort-files t)))
|
||||
|
||||
|
||||
(use-package! wgrep
|
||||
@@ -311,7 +354,9 @@ evil-ex-specific constructs, so we disable it solely in evil-ex."
|
||||
;; posframe.
|
||||
(dolist (fn '(swiper counsel-rg counsel-grep counsel-git-grep))
|
||||
(setf (alist-get fn ivy-posframe-display-functions-alist)
|
||||
#'ivy-display-function-fallback)))
|
||||
#'ivy-display-function-fallback))
|
||||
|
||||
(add-hook 'doom-reload-hook #'posframe-delete-all))
|
||||
|
||||
|
||||
(use-package! flx
|
||||
@@ -322,24 +367,26 @@ evil-ex-specific constructs, so we disable it solely in evil-ex."
|
||||
|
||||
|
||||
(use-package! ivy-prescient
|
||||
:hook (ivy-mode . ivy-prescient-mode)
|
||||
:when (featurep! +prescient)
|
||||
:hook (ivy-mode . ivy-prescient-mode)
|
||||
:hook (ivy-prescient-mode . prescient-persist-mode)
|
||||
:init
|
||||
(setq prescient-filter-method
|
||||
(if (featurep! +fuzzy)
|
||||
'(literal regexp initialism fuzzy)
|
||||
'(literal regexp initialism))
|
||||
ivy-prescient-enable-filtering nil ; we do this ourselves
|
||||
ivy-prescient-retain-classic-highlighting t)
|
||||
|
||||
'(literal regexp initialism)))
|
||||
:config
|
||||
(setq ivy-prescient-sort-commands
|
||||
'(:not swiper swiper-isearch ivy-switch-buffer counsel-grep
|
||||
counsel-git-grep counsel-ag counsel-rg counsel-imenu
|
||||
counsel-yank-pop counsel-recentf counsel-buffer-or-recentf)
|
||||
ivy-prescient-retain-classic-highlighting t)
|
||||
(defun +ivy-prescient-non-fuzzy (str)
|
||||
(let ((prescient-filter-method '(literal regexp)))
|
||||
(ivy-prescient-re-builder str)))
|
||||
|
||||
;; NOTE prescient config duplicated with `company'
|
||||
(setq prescient-save-file (concat doom-cache-dir "prescient-save.el"))
|
||||
(prescient-persist-mode +1))
|
||||
(setq prescient-save-file (concat doom-cache-dir "prescient-save.el")))
|
||||
|
||||
|
||||
;;;###package swiper
|
||||
|
||||
Reference in New Issue
Block a user