doomemacs/modules/completion/ivy/config.el

107 lines
3.6 KiB
EmacsLisp
Raw Normal View History

2017-02-13 04:54:12 -05:00
;;; completion/ivy/packages.el
;; 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)))
;;
;; Packages
;;
2017-02-13 04:54:12 -05:00
(@def-package ivy :demand t
:init
(setq ivy-height 14
ivy-do-completion-in-region nil
ivy-wrap t
ivy-fixed-height-minibuffer t
ivy-format-function 'ivy-format-function-line) ;; highlight til EOL
:config
(setq projectile-completion-system 'ivy
smex-completion-method 'ivy)
(@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-19 18:41:37 -05:00
;; Occasionally, when ivy closes, it causes display artifacting
;; between horizontal splits. This fixes it, though may cause
;; flickering on some OSes.
(defun doom|redisplay (&rest _) (force-mode-line-update))
2017-02-13 04:54:12 -05:00
(advice-add 'ivy-read :after 'doom|redisplay)
2017-02-19 18:41:37 -05:00
(add-hook 'projectile-find-file-hook 'doom|redisplay)
2017-02-13 04:54:12 -05:00
(@after magit (setq magit-completing-read-function 'ivy-completing-read))
(@after yasnippet (push '+ivy-yas-prompt yas-prompt-functions))
2017-02-13 04:54:12 -05:00
(ivy-mode +1)
(@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
[remap execute-extended-command] 'counsel-M-x))
2017-02-13 04:54:12 -05:00
(@def-package counsel
:after ivy
:config
2017-02-13 04:54:12 -05:00
(setq counsel-find-file-ignore-regexp "\\(?:^[#.]\\)\\|\\(?:[#~]$\\)\\|\\(?:^Icon?\\)")
2017-02-20 20:43:08 -05:00
(@set :popup "^\\*ivy-occur counsel-ag" :size 25 :select t :regexp t)
2017-02-13 04:54:12 -05:00
(require 'counsel-projectile)
(@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))
(line-number (match-string-no-properties 2 x)))
(with-ivy-window
(find-file-other-window (expand-file-name file-name counsel--git-grep-dir))
(forward-line (1- (string-to-number line-number)))
(re-search-forward (ivy--regex ivy-text t) (line-end-position) t)
(swiper--ensure-visible)
(run-hooks 'counsel-grep-post-action-hook)
(unless (eq ivy-exit 'done)
(swiper--cleanup)
(swiper--add-overlays (ivy--regex ivy-text))))))))
(@def-counsel-action open-in-other-window
(lambda (x) (with-ivy-window (find-file-other-window x))))
(@add-hook doom-popup-mode
(when (eq major-mode 'ivy-occur-grep-mode)
(ivy-wgrep-change-to-wgrep-mode)))
(advice-add 'counsel-ag-function :override '+ivy*counsel-ag-function)
(@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))