2017-06-08 11:47:56 +02:00
|
|
|
;;; completion/ivy/config.el -*- lexical-binding: t; -*-
|
2017-02-13 04:54:12 -05:00
|
|
|
|
2017-08-21 21:54:04 +02:00
|
|
|
(defvar +ivy-buffer-icons nil
|
|
|
|
"If non-nil, show buffer mode icons in `ivy-switch-buffer' and the like.")
|
|
|
|
|
2017-06-08 11:47:56 +02:00
|
|
|
(defvar +ivy-task-tags
|
|
|
|
'(("TODO" . warning)
|
|
|
|
("FIXME" . error))
|
2017-05-10 06:13:14 +02:00
|
|
|
"An alist of tags for `+ivy/tasks' to include in its search, whose CDR is the
|
|
|
|
face to render it with.")
|
|
|
|
|
2018-07-23 00:06:47 +02:00
|
|
|
(defvar +ivy-project-search-engines '(rg ag pt)
|
|
|
|
"What search tools for `+ivy/project-search' (and `+ivy-file-search' when no
|
|
|
|
ENGINE is specified) to try, and in what order.
|
|
|
|
|
|
|
|
To disable a particular tool, remove it from this list. To prioritize a tool
|
|
|
|
over others, move it to the front of the list. Later duplicates in this list are
|
|
|
|
silently ignored.
|
|
|
|
|
|
|
|
If you want to already use git-grep or grep, set this to nil.")
|
|
|
|
|
2017-05-10 08:38:32 +02:00
|
|
|
(defmacro +ivy-do-action! (action)
|
2017-09-15 14:35:18 +02:00
|
|
|
"Returns an interactive lambda that sets the current ivy action and
|
|
|
|
immediately runs it on the current candidate (ending the ivy session)."
|
2017-05-10 05:20:54 +02:00
|
|
|
`(lambda ()
|
2017-02-13 04:54:12 -05:00
|
|
|
(interactive)
|
2017-05-10 05:20:54 +02:00
|
|
|
(ivy-set-action ,action)
|
2017-02-13 04:54:12 -05:00
|
|
|
(setq ivy-exit 'done)
|
|
|
|
(exit-minibuffer)))
|
|
|
|
|
2017-02-13 21:11:54 -05:00
|
|
|
|
|
|
|
;;
|
|
|
|
;; Packages
|
|
|
|
;;
|
|
|
|
|
2017-06-08 11:47:56 +02:00
|
|
|
(def-package! ivy
|
2018-05-25 00:46:11 +02:00
|
|
|
:defer 1
|
|
|
|
:after-call pre-command-hook
|
2017-02-22 04:27:23 -05:00
|
|
|
:config
|
2018-05-25 00:50:33 +02:00
|
|
|
(setq ivy-height 15
|
2017-02-13 04:54:12 -05:00
|
|
|
ivy-wrap t
|
|
|
|
ivy-fixed-height-minibuffer t
|
2017-02-22 04:27:23 -05:00
|
|
|
projectile-completion-system 'ivy
|
|
|
|
smex-completion-method 'ivy
|
2017-03-08 21:34:52 -05:00
|
|
|
;; Don't use ^ as initial input
|
|
|
|
ivy-initial-inputs-alist nil
|
2017-02-22 04:27:23 -05:00
|
|
|
;; highlight til EOL
|
2017-05-19 05:45:11 -04:00
|
|
|
ivy-format-function #'ivy-format-function-line
|
|
|
|
;; disable magic slash on non-match
|
2018-01-08 14:41:41 -05:00
|
|
|
ivy-magic-slash-non-match-action nil
|
|
|
|
;; don't show recent files in switch-buffer
|
|
|
|
ivy-use-virtual-buffers nil
|
|
|
|
;; ...but if that ever changes, show their full path
|
2018-03-23 02:23:57 -04:00
|
|
|
ivy-virtual-abbreviate 'full
|
|
|
|
;; don't quit minibuffer on delete-error
|
2018-05-14 20:03:36 +02:00
|
|
|
ivy-on-del-error-function nil
|
|
|
|
;; enable ability to select prompt (alternative to `ivy-immediate-done')
|
|
|
|
ivy-use-selectable-prompt t)
|
2017-02-13 04:54:12 -05:00
|
|
|
|
2018-08-02 00:29:26 +02:00
|
|
|
(when (featurep! +fuzzy)
|
|
|
|
(setq ivy-re-builders-alist
|
|
|
|
'((counsel-ag . ivy--regex-plus)
|
|
|
|
(counsel-grep . ivy--regex-plus)
|
|
|
|
(swiper . ivy--regex-plus)
|
|
|
|
(t . ivy--regex-fuzzy))
|
|
|
|
ivy-initial-inputs-alist nil))
|
|
|
|
|
2018-08-03 16:12:27 +02:00
|
|
|
;; make projectile-find-file faster
|
|
|
|
(add-to-list 'ivy-sort-functions-alist '(projectile-find-file))
|
|
|
|
|
2018-07-28 12:33:27 +02:00
|
|
|
(after! yasnippet
|
|
|
|
(add-to-list 'yas-prompt-functions #'+ivy-yas-prompt nil #'eq))
|
2017-02-22 04:27:23 -05:00
|
|
|
|
2018-06-03 15:46:00 +02:00
|
|
|
(define-key! 'global
|
|
|
|
[remap switch-to-buffer] #'ivy-switch-buffer
|
|
|
|
[remap persp-switch-to-buffer] #'+ivy/switch-workspace-buffer
|
|
|
|
[remap imenu-anywhere] #'ivy-imenu-anywhere)
|
2017-02-22 04:27:23 -05:00
|
|
|
|
2018-08-03 16:12:27 +02:00
|
|
|
(ivy-mode +1)
|
2017-02-13 04:54:12 -05:00
|
|
|
|
2018-08-03 16:12:27 +02:00
|
|
|
;; Show more buffer information in switch-buffer commands
|
|
|
|
(after! ivy-rich
|
|
|
|
(dolist (cmd '(ivy-switch-buffer +ivy/switch-workspace-buffer
|
|
|
|
counsel-projectile-switch-to-buffer))
|
|
|
|
(ivy-set-display-transformer cmd '+ivy-buffer-transformer)))
|
2017-02-13 04:54:12 -05:00
|
|
|
|
2018-08-03 16:12:27 +02:00
|
|
|
(def-package! ivy-hydra
|
|
|
|
:commands (ivy-dispatching-done-hydra ivy--matcher-desc)
|
|
|
|
:init
|
|
|
|
(define-key! ivy-minibuffer-map
|
|
|
|
"\C-o" #'+ivy-coo-hydra/body
|
|
|
|
(kbd "M-o") #'ivy-dispatching-done-hydra)))
|
2018-01-08 14:41:41 -05:00
|
|
|
|
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(def-package! counsel
|
2018-05-30 13:28:22 +02:00
|
|
|
:commands counsel-describe-face
|
2018-01-27 20:57:02 -05:00
|
|
|
:init
|
2018-06-03 15:46:00 +02:00
|
|
|
(define-key! 'global
|
|
|
|
[remap apropos] #'counsel-apropos
|
|
|
|
[remap bookmark-jump] #'counsel-bookmark
|
|
|
|
[remap describe-face] #'counsel-describe-face
|
|
|
|
[remap describe-function] #'counsel-describe-function
|
|
|
|
[remap describe-variable] #'counsel-describe-variable
|
|
|
|
[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 org-capture] #'counsel-org-capture
|
|
|
|
[remap swiper] #'counsel-grep-or-swiper)
|
|
|
|
|
2017-02-13 21:11:54 -05:00
|
|
|
:config
|
2018-06-18 02:26:05 +02:00
|
|
|
(set-popup-rule! "^\\*ivy-occur" :size 0.35 :ttl 0 :quit nil)
|
2018-01-28 22:24:45 -05:00
|
|
|
|
2018-05-17 16:59:55 +02:00
|
|
|
(setq counsel-find-file-ignore-regexp "\\(?:^[#.]\\)\\|\\(?:[#~]$\\)\\|\\(?:^Icon?\\)"
|
2018-05-18 01:21:09 +02:00
|
|
|
;; Add smart-casing and compressed archive searching (-zS) to default
|
|
|
|
;; command arguments:
|
2018-05-17 16:59:55 +02:00
|
|
|
counsel-rg-base-command "rg -zS --no-heading --line-number --color never %s ."
|
|
|
|
counsel-ag-base-command "ag -zS --nocolor --nogroup %s"
|
|
|
|
counsel-pt-base-command "pt -zS --nocolor --nogroup -e %s")
|
2017-02-13 04:54:12 -05:00
|
|
|
|
2018-01-27 20:57:02 -05:00
|
|
|
;; Dim recentf entries that are not in the current project.
|
|
|
|
(ivy-set-display-transformer #'counsel-recentf #'+ivy-recentf-transformer)
|
|
|
|
|
2018-07-05 14:05:09 +02:00
|
|
|
;; Factories
|
|
|
|
(defun +ivy-action-reloading (cmd)
|
|
|
|
(lambda (x)
|
|
|
|
(funcall cmd x)
|
|
|
|
(ivy--reset-state ivy-last)))
|
|
|
|
|
|
|
|
(defun +ivy-action-given-file (cmd prompt)
|
|
|
|
(lambda (source)
|
|
|
|
(let* ((enable-recursive-minibuffers t)
|
|
|
|
(target (read-file-name (format "%s %s to:" prompt source))))
|
|
|
|
(funcall cmd source target 1))))
|
|
|
|
|
2018-07-04 23:59:18 +08:00
|
|
|
;; Configure `counsel-find-file'
|
|
|
|
(ivy-add-actions
|
|
|
|
'counsel-find-file
|
2018-07-05 00:38:41 +08:00
|
|
|
`(("b" counsel-find-file-cd-bookmark-action "cd bookmark")
|
|
|
|
("s" counsel-find-file-as-root "open as root")
|
|
|
|
("m" counsel-find-file-mkdir-action "mkdir")
|
2018-07-05 14:05:09 +02:00
|
|
|
("c" ,(+ivy-action-given-file #'copy-file "Copy file") "copy file")
|
|
|
|
("d" ,(+ivy-action-reloading #'+ivy-confirm-delete-file) "delete")
|
2018-07-05 00:38:41 +08:00
|
|
|
("r" (lambda (path) (rename-file path (read-string "New name: "))) "rename")
|
2018-07-05 14:05:09 +02:00
|
|
|
("R" ,(+ivy-action-reloading (+ivy-action-given-file #'rename-file "Move")) "move")
|
2018-07-04 23:59:18 +08:00
|
|
|
("f" find-file-other-window "other window")
|
2018-07-05 00:38:41 +08:00
|
|
|
("F" find-file-other-frame "other frame")
|
|
|
|
("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")
|
2018-07-04 23:59:18 +08:00
|
|
|
("l" (lambda (path) "Insert org-link with relative path"
|
2018-07-05 00:38:41 +08:00
|
|
|
(with-ivy-window (insert (format "[[./%s]]" (file-relative-name path default-directory))))) "insert org-link (rel. path)")
|
2018-07-04 23:59:18 +08:00
|
|
|
("L" (lambda (path) "Insert org-link with absolute path"
|
2018-07-05 00:38:41 +08:00
|
|
|
(with-ivy-window (insert (format "[[%s]]" path)))) "insert org-link (abs. path)")))
|
2018-07-04 23:59:18 +08:00
|
|
|
|
2018-08-03 16:12:27 +02:00
|
|
|
(ivy-add-actions
|
|
|
|
'counsel-ag ; also applies to `counsel-rg' & `counsel-pt'
|
|
|
|
'(("O" +ivy-git-grep-other-window-action "open in other window"))))
|
2017-02-13 04:54:12 -05:00
|
|
|
|
2017-02-19 18:41:37 -05:00
|
|
|
|
2018-01-27 20:57:02 -05:00
|
|
|
(def-package! counsel-projectile
|
|
|
|
:commands (counsel-projectile-find-file counsel-projectile-find-dir counsel-projectile-switch-to-buffer
|
2018-01-28 03:34:18 -05:00
|
|
|
counsel-projectile-grep counsel-projectile-ag counsel-projectile-switch-project)
|
2018-01-27 20:57:02 -05:00
|
|
|
:init
|
2018-06-03 15:46:00 +02:00
|
|
|
(define-key! 'global
|
2018-08-03 16:10:20 +02:00
|
|
|
[remap projectile-find-file] #'+ivy/projectile-find-file
|
2018-06-03 15:46:00 +02:00
|
|
|
[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)
|
2018-01-27 20:57:02 -05:00
|
|
|
:config
|
2018-08-03 16:12:27 +02:00
|
|
|
;; Highlight entries that have been visited; opposite of default
|
2018-01-27 20:57:02 -05:00
|
|
|
(ivy-set-display-transformer #'counsel-projectile-find-file #'+ivy-projectile-find-file-transformer))
|
|
|
|
|
|
|
|
|
2018-08-03 16:12:27 +02:00
|
|
|
(def-package! ivy-prescient
|
|
|
|
:after ivy
|
2017-09-23 16:26:30 +02:00
|
|
|
:init
|
2018-08-03 16:12:27 +02:00
|
|
|
(if (featurep! +fuzzy)
|
|
|
|
(setq prescient-filter-method 'fuzzy)
|
|
|
|
(setq prescient-filter-method 'regexp
|
|
|
|
ivy-prescient-retain-classic-highlighting t))
|
|
|
|
:config
|
|
|
|
(setq prescient-save-file (concat doom-cache-dir "presclient-save.el"))
|
|
|
|
|
|
|
|
;; `ivy-prescient' is too slow for fuzzy projectile-find-file and
|
|
|
|
;; counsel-file-jump, so ensure they're ignored
|
|
|
|
(when (featurep! +fuzzy)
|
|
|
|
(add-to-list 'ivy-re-builders-alist '(counsel-file-jump . +ivy--regex-fuzzy))
|
|
|
|
(add-to-list 'ivy-re-builders-alist '(projectile-find-file . +ivy--regex-fuzzy)))
|
|
|
|
(add-to-list 'ivy-prescient-excluded-commands 'counsel-find-jump nil #'eq)
|
|
|
|
(add-to-list 'ivy-prescient-excluded-commands 'projectile-find-file nil #'eq)
|
|
|
|
|
|
|
|
(prescient-persist-mode +1)
|
|
|
|
(ivy-prescient-mode +1))
|
2018-01-14 02:04:30 -05:00
|
|
|
|
|
|
|
|
|
|
|
(def-package! wgrep
|
2018-05-25 00:46:11 +02:00
|
|
|
:commands wgrep-change-to-wgrep-mode
|
2018-01-14 02:04:30 -05:00
|
|
|
:config (setq wgrep-auto-save-buffer t))
|
2018-05-08 21:47:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
(def-package! ivy-posframe
|
2018-05-18 01:21:09 +02:00
|
|
|
:when (and EMACS26+ (featurep! +childframe))
|
2018-05-08 21:47:40 +02:00
|
|
|
:hook (ivy-mode . ivy-posframe-enable)
|
|
|
|
:preface
|
|
|
|
;; This function searches the entire `obarray' just to populate
|
|
|
|
;; `ivy-display-functions-props'. There are 15k entries in mine! This is
|
|
|
|
;; wasteful, so...
|
|
|
|
(advice-add #'ivy-posframe-setup :override #'ignore)
|
|
|
|
:config
|
2018-06-05 11:20:39 +02:00
|
|
|
(setq ivy-fixed-height-minibuffer nil
|
2018-06-26 01:47:32 +02:00
|
|
|
ivy-posframe-parameters
|
|
|
|
`((min-width . 90)
|
|
|
|
(min-height . ,ivy-height)
|
|
|
|
(internal-border-width . 10)))
|
2018-05-18 01:21:09 +02:00
|
|
|
|
2018-06-26 01:47:32 +02:00
|
|
|
;; ... let's do it manually instead
|
2018-06-23 16:48:58 +02:00
|
|
|
(unless (assq 'ivy-posframe-display-at-frame-bottom-left ivy-display-functions-props)
|
|
|
|
(dolist (fn (list 'ivy-posframe-display-at-frame-bottom-left
|
|
|
|
'ivy-posframe-display-at-frame-center
|
|
|
|
'ivy-posframe-display-at-point
|
|
|
|
'ivy-posframe-display-at-frame-bottom-window-center
|
|
|
|
'ivy-posframe-display
|
|
|
|
'ivy-posframe-display-at-window-bottom-left
|
|
|
|
'ivy-posframe-display-at-window-center
|
|
|
|
'+ivy-display-at-frame-center-near-bottom))
|
2018-06-25 14:48:30 +02:00
|
|
|
(push (cons fn '(:cleanup ivy-posframe-cleanup)) ivy-display-functions-props)))
|
|
|
|
;; default to posframe display function
|
|
|
|
(setf (alist-get t ivy-display-functions-alist) #'+ivy-display-at-frame-center-near-bottom)
|
2018-05-08 21:47:40 +02:00
|
|
|
|
|
|
|
;; posframe doesn't work well with async sources
|
|
|
|
(dolist (fn '(swiper counsel-rg counsel-ag counsel-pt counsel-grep counsel-git-grep))
|
2018-07-14 04:08:17 +02:00
|
|
|
(setf (alist-get fn ivy-display-functions-alist) #'ivy-display-function-fallback)))
|
2018-05-30 11:25:41 +02:00
|
|
|
|
|
|
|
|
2018-06-20 18:37:13 +02:00
|
|
|
;; Used by `counsel-M-x'
|
2018-07-12 16:45:57 +02:00
|
|
|
(setq amx-save-file (concat doom-cache-dir "amx-items"))
|
2018-06-20 18:37:13 +02:00
|
|
|
|
|
|
|
|
2018-05-31 11:41:33 +02:00
|
|
|
;;
|
|
|
|
;; Evil key fixes
|
|
|
|
;;
|
|
|
|
|
|
|
|
(map! :when (featurep! :feature evil +everywhere)
|
|
|
|
:after ivy
|
|
|
|
:map ivy-occur-mode-map
|
|
|
|
:n [mouse-1] #'ivy-occur-click
|
|
|
|
:n "<return>" #'ivy-occur-press-and-switch
|
|
|
|
:m "j" #'ivy-occur-next-line
|
|
|
|
:m "k" #'ivy-occur-previous-line
|
|
|
|
:m "h" #'evil-backward-char
|
|
|
|
:m "l" #'evil-forward-char
|
|
|
|
:m "g" nil
|
|
|
|
:m "gg" #'evil-goto-first-line
|
|
|
|
:n "gf" #'ivy-occur-press
|
|
|
|
:n "ga" #'ivy-occur-read-action
|
|
|
|
:n "go" #'ivy-occur-dispatch
|
|
|
|
:n "gc" #'ivy-occur-toggle-calling
|
|
|
|
:n "gr" #'ivy-occur-revert-buffer
|
|
|
|
:n "q" #'quit-window
|
|
|
|
|
|
|
|
:map ivy-occur-grep-mode-map
|
|
|
|
:v "j" #'evil-next-line
|
|
|
|
:v "k" #'evil-previous-line
|
|
|
|
:n "D" #'ivy-occur-delete-candidate
|
|
|
|
:n "C-d" #'evil-scroll-down
|
|
|
|
:n "d" #'ivy-occur-delete-candidate
|
|
|
|
:n "C-x C-q" #'ivy-wgrep-change-to-wgrep-mode
|
|
|
|
:n "i" #'ivy-wgrep-change-to-wgrep-mode
|
|
|
|
:n "gd" #'ivy-occur-delete-candidate
|
|
|
|
:n [mouse-1] #'ivy-occur-click
|
|
|
|
:n "<return>" #'ivy-occur-press-and-switch
|
|
|
|
:m "j" #'ivy-occur-next-line
|
|
|
|
:m "k" #'ivy-occur-previous-line
|
|
|
|
:m "h" #'evil-backward-char
|
|
|
|
:m "l" #'evil-forward-char
|
|
|
|
:m "g" nil
|
|
|
|
:m "gg" #'evil-goto-first-line
|
|
|
|
:n "gf" #'ivy-occur-press
|
|
|
|
:n "gr" #'ivy-occur-revert-buffer
|
|
|
|
:n "ga" #'ivy-occur-read-action
|
|
|
|
:n "go" #'ivy-occur-dispatch
|
|
|
|
:n "gc" #'ivy-occur-toggle-calling
|
|
|
|
;; quit
|
2018-06-01 02:18:46 +02:00
|
|
|
:n "q" #'quit-window)
|