2017-02-13 04:54:12 -05:00
|
|
|
;;; completion/ivy/packages.el
|
|
|
|
|
2017-02-21 03:45:24 -05:00
|
|
|
;; Ivy is my completion backend of choice. With counsel's help, I get:
|
|
|
|
;;
|
|
|
|
;; + Project-wide search with `counsel-ag' (or `+ivy:ag-search')
|
|
|
|
;; + Project-wide replace if you press <backtab> in the ag occur buffer.
|
|
|
|
;; + An Atom/Sublime-Text Command-T implementation with `counsel-find-file' and
|
|
|
|
;; `counsel-projectile-find-file'.
|
|
|
|
;; + Ido-like completion for a slew of functions, like `counsel-M-x' and
|
|
|
|
;; `counsel-imenu'.
|
|
|
|
|
2017-02-13 04:54:12 -05:00
|
|
|
;; TODO Make this a setting
|
|
|
|
(defmacro @def-counsel-action (name &rest forms)
|
|
|
|
`(defun ,(intern (format "+ivy/counsel-%s" (symbol-name name))) ()
|
|
|
|
(interactive)
|
|
|
|
(ivy-set-action ',@forms)
|
|
|
|
(setq ivy-exit 'done)
|
|
|
|
(exit-minibuffer)))
|
|
|
|
|
2017-02-13 21:11:54 -05:00
|
|
|
|
|
|
|
;;
|
|
|
|
;; Packages
|
|
|
|
;;
|
|
|
|
|
2017-02-13 04:54:12 -05:00
|
|
|
(@def-package ivy :demand t
|
2017-02-22 04:27:23 -05:00
|
|
|
:config
|
2017-02-13 04:54:12 -05:00
|
|
|
(setq ivy-height 14
|
|
|
|
ivy-do-completion-in-region nil
|
|
|
|
ivy-wrap t
|
|
|
|
ivy-fixed-height-minibuffer t
|
2017-02-22 04:27:23 -05:00
|
|
|
projectile-completion-system 'ivy
|
|
|
|
smex-completion-method 'ivy
|
|
|
|
;; highlight til EOL
|
|
|
|
ivy-format-function 'ivy-format-function-line)
|
2017-02-13 04:54:12 -05:00
|
|
|
|
2017-02-22 04:27:23 -05:00
|
|
|
(@after magit (setq magit-completing-read-function 'ivy-completing-read))
|
|
|
|
(@after yasnippet (push '+ivy-yas-prompt yas-prompt-functions))
|
|
|
|
|
|
|
|
(ivy-mode +1)
|
2017-02-13 21:11:54 -05:00
|
|
|
|
2017-02-21 00:45:50 -05:00
|
|
|
(@map :map ivy-minibuffer-map
|
2017-02-13 04:54:12 -05:00
|
|
|
[escape] 'keyboard-escape-quit
|
|
|
|
"C-r" 'evil-paste-from-register
|
|
|
|
"M-v" 'clipboard-yank
|
|
|
|
"C-w" 'backward-kill-word
|
|
|
|
"C-u" 'backward-kill-sentence
|
|
|
|
"C-b" 'backward-word
|
|
|
|
"C-f" 'forward-word)
|
|
|
|
|
2017-02-21 00:45:50 -05:00
|
|
|
(@map :map ivy-mode-map
|
|
|
|
[remap find-file] 'counsel-find-file
|
|
|
|
[remap switch-to-buffer] '+ivy/switch-buffer
|
|
|
|
[remap persp-switch-to-buffer] '+ivy/switch-workspace-buffer
|
|
|
|
[remap recentf] 'counsel-recentf
|
|
|
|
[remap imenu] 'counsel-imenu
|
|
|
|
[remap bookmark-jump] 'counsel-bookmark
|
|
|
|
[remap projectile-switch-project] 'counsel-projectile-switch-project
|
|
|
|
[remap projectile-find-file] 'counsel-projectile-find-file
|
|
|
|
[remap imenu-anywhere] 'ivy-imenu-anywhere
|
2017-02-22 04:27:23 -05:00
|
|
|
[remap execute-extended-command] 'counsel-M-x)
|
|
|
|
|
|
|
|
(when (@featurep :feature workspaces)
|
|
|
|
(nconc ivy-sort-functions-alist
|
|
|
|
'((persp-kill-buffer . nil)
|
|
|
|
(persp-remove-buffer . nil)
|
|
|
|
(persp-add-buffer . nil)
|
|
|
|
(persp-switch . nil)
|
|
|
|
(persp-window-switch . nil)
|
|
|
|
(persp-frame-switch . nil)
|
|
|
|
(+workspace/switch-to . nil)
|
|
|
|
(+workspace/delete . nil)))))
|
2017-02-13 04:54:12 -05:00
|
|
|
|
|
|
|
|
2017-02-21 16:03:44 -05:00
|
|
|
(@def-package swiper :commands (swiper swiper-all))
|
|
|
|
|
|
|
|
|
2017-02-13 04:54:12 -05:00
|
|
|
(@def-package counsel
|
|
|
|
:after ivy
|
2017-02-13 21:11:54 -05:00
|
|
|
:config
|
2017-02-13 04:54:12 -05:00
|
|
|
(setq counsel-find-file-ignore-regexp "\\(?:^[#.]\\)\\|\\(?:[#~]$\\)\\|\\(?:^Icon?\\)")
|
|
|
|
|
2017-02-21 01:08:57 -05:00
|
|
|
(@set :popup "^\\*ivy-occur counsel-ag" :size 25 :regexp t :autokill t)
|
2017-02-20 20:43:08 -05:00
|
|
|
|
2017-02-13 04:54:12 -05:00
|
|
|
(require 'counsel-projectile)
|
|
|
|
|
2017-02-21 03:45:24 -05:00
|
|
|
;; FIXME Messy workaround, refactor this
|
2017-02-13 04:54:12 -05:00
|
|
|
(@def-counsel-action ag-open-in-other-window
|
|
|
|
(lambda (x)
|
|
|
|
(when (string-match "\\`\\(.*?\\):\\([0-9]+\\):\\(.*\\)\\'" x)
|
|
|
|
(let ((file-name (match-string-no-properties 1 x))
|
2017-02-22 17:18:04 -05:00
|
|
|
(line-number (match-string-no-properties 2 x))
|
|
|
|
dest-win)
|
2017-02-13 04:54:12 -05:00
|
|
|
(with-ivy-window
|
|
|
|
(find-file-other-window (expand-file-name file-name counsel--git-grep-dir))
|
2017-02-22 17:18:04 -05:00
|
|
|
(setq dest-win (selected-window))
|
2017-02-13 04:54:12 -05:00
|
|
|
(forward-line (1- (string-to-number line-number)))
|
|
|
|
(re-search-forward (ivy--regex ivy-text t) (line-end-position) t)
|
2017-02-22 17:18:04 -05:00
|
|
|
(recenter)
|
2017-02-13 04:54:12 -05:00
|
|
|
(swiper--ensure-visible)
|
|
|
|
(run-hooks 'counsel-grep-post-action-hook)
|
|
|
|
(unless (eq ivy-exit 'done)
|
|
|
|
(swiper--cleanup)
|
2017-02-22 17:18:04 -05:00
|
|
|
(swiper--add-overlays (ivy--regex ivy-text))))
|
|
|
|
(when dest-win
|
|
|
|
(select-window dest-win))))))
|
2017-02-13 04:54:12 -05:00
|
|
|
|
2017-02-22 17:18:04 -05:00
|
|
|
(@add-hook 'doom-popup-mode-hook
|
2017-02-13 04:54:12 -05:00
|
|
|
(when (eq major-mode 'ivy-occur-grep-mode)
|
|
|
|
(ivy-wgrep-change-to-wgrep-mode)))
|
|
|
|
|
2017-02-21 00:53:00 -05:00
|
|
|
(defun +ivy*recenter (&rest _) (recenter))
|
2017-02-13 04:54:12 -05:00
|
|
|
(advice-add 'counsel-ag-function :override '+ivy*counsel-ag-function)
|
2017-02-21 00:53:00 -05:00
|
|
|
(advice-add 'imenu :after '+ivy*recenter)
|
2017-02-13 04:54:12 -05:00
|
|
|
(@map :map counsel-ag-map
|
|
|
|
[backtab] '+ivy/counsel-ag-occur ; search/replace on results
|
|
|
|
"C-SPC" 'counsel-git-grep-recenter ; preview
|
|
|
|
"M-RET" '+ivy/counsel-ag-open-in-other-window))
|
|
|
|
|
2017-02-19 18:41:37 -05:00
|
|
|
|
|
|
|
;; Used by `counsel-M-x'
|
|
|
|
(@def-package smex
|
|
|
|
:commands (smex smex-major-mode-commands)
|
|
|
|
:config
|
|
|
|
(setq smex-save-file (concat doom-cache-dir "/smex-items"))
|
|
|
|
(smex-initialize))
|
|
|
|
|