Goodbye Helm, hello Ivy

This commit is contained in:
Henrik Lissner
2016-06-04 22:47:20 -04:00
parent e8344945f5
commit bc33e39823
14 changed files with 191 additions and 83 deletions

View File

@@ -253,6 +253,8 @@
(sp-with-modes '(xml-mode nxml-mode php-mode)
(sp-local-pair "<!--" "-->" :post-handlers '(("| " "SPC")))))
(use-package swiper :commands (swiper swiper-all))
;;
;; Keybinding fixes

View File

@@ -15,8 +15,7 @@
quickrun-with-arg
quickrun-shell
quickrun-compile-only
quickrun-replace-region
helm-quickrun)
quickrun-replace-region)
:init (add-hook 'quickrun/mode-hook 'linum-mode)
:config
(setq quickrun-focus-p nil)

35
core/core-ivy.el Normal file
View File

@@ -0,0 +1,35 @@
;;; core-ivy.el
;; see defuns/defuns-ivy.el
(use-package ivy
:init
(setq projectile-completion-system 'ivy
ivy-height 15
ivy-do-completion-in-region nil)
:config
(ivy-mode +1)
(map! :map ivy-minibuffer-map
[escape] 'keyboard-escape-quit
"C-w" 'backward-kill-word
"C-u" 'backward-kill-sentence
"C-b" 'backward-word
"C-f" 'forward-word)
(require 'counsel)
(defun counsel-ag-function (string)
"Grep in the current directory for STRING."
(if (< (length string) 1)
(counsel-more-chars 1)
(let ((default-directory counsel--git-grep-dir)
(regex (counsel-unquote-regex-parens
(setq ivy--old-re
(ivy--regex string)))))
(counsel--async-command
(format counsel-ag-base-command (shell-quote-argument regex)))
nil))))
(use-package counsel-projectile :after projectile)
(provide 'core-ivy)
;;; core-ivy.el ends here

View File

@@ -141,37 +141,37 @@
(message "Unable to find location in file"))))
'help-echo (purecopy "mouse-2, RET: find face's definition")))
(after! helm
;; This is a good alternative to either popwin or shackle, specifically for
;; helm. If either fail me (for the last time), this is where I'll turn.
;;(add-to-list 'display-buffer-alist
;; `(,(rx bos "*helm" (* not-newline) "*" eos)
;; (display-buffer-in-side-window)
;; (inhibit-same-window . t)
;; (window-height . 0.4)))
;; (after! helm
;; ;; This is a good alternative to either popwin or shackle, specifically for
;; ;; helm. If either fail me (for the last time), this is where I'll turn.
;; ;;(add-to-list 'display-buffer-alist
;; ;; `(,(rx bos "*helm" (* not-newline) "*" eos)
;; ;; (display-buffer-in-side-window)
;; ;; (inhibit-same-window . t)
;; ;; (window-height . 0.4)))
;; Helm tries to clean up after itself, but shackle has already done this.
;; This fixes that. To reproduce, add a helm rule in `shackle-rules', open two
;; splits side-by-side, move to the buffer on the right and invoke helm. It
;; will close all but the left-most buffer.
(setq-default helm-reuse-last-window-split-state t
helm-split-window-in-side-p t))
;; ;; Helm tries to clean up after itself, but shackle has already done this.
;; ;; This fixes that. To reproduce, add a helm rule in `shackle-rules', open two
;; ;; splits side-by-side, move to the buffer on the right and invoke helm. It
;; ;; will close all but the left-most buffer.
;; (setq-default helm-reuse-last-window-split-state t
;; helm-split-window-in-side-p t))
(after! helm-swoop
(setq helm-swoop-split-window-function (lambda (b) (doom/popup-buffer b))))
;; (after! helm-swoop
;; (setq helm-swoop-split-window-function (lambda (b) (doom/popup-buffer b))))
(after! helm-ag
;; This prevents helm-ag from switching between windows and buffers.
(defadvice helm-ag--edit-abort (around helm-ag-edit-abort-popup-compat activate)
(cl-letf (((symbol-function 'select-window) 'ignore)) ad-do-it)
(doom/popup-close nil t t))
(defadvice helm-ag--edit-commit (around helm-ag-edit-commit-popup-compat activate)
(cl-letf (((symbol-function 'select-window) 'ignore)) ad-do-it)
(doom/popup-close nil t t))
(defadvice helm-ag--edit (around helm-ag-edit-popup-compat activate)
(cl-letf (((symbol-function 'other-window) 'ignore)
((symbol-function 'switch-to-buffer) 'doom/popup-buffer))
ad-do-it)))
;; (after! helm-ag
;; ;; This prevents helm-ag from switching between windows and buffers.
;; (defadvice helm-ag--edit-abort (around helm-ag-edit-abort-popup-compat activate)
;; (cl-letf (((symbol-function 'select-window) 'ignore)) ad-do-it)
;; (doom/popup-close nil t t))
;; (defadvice helm-ag--edit-commit (around helm-ag-edit-commit-popup-compat activate)
;; (cl-letf (((symbol-function 'select-window) 'ignore)) ad-do-it)
;; (doom/popup-close nil t t))
;; (defadvice helm-ag--edit (around helm-ag-edit-popup-compat activate)
;; (cl-letf (((symbol-function 'other-window) 'ignore)
;; ((symbol-function 'switch-to-buffer) 'doom/popup-buffer))
;; ad-do-it)))
(after! quickrun
;; This allows us to rerun code from inside a quickrun buffer.

View File

@@ -13,8 +13,7 @@
(setq yas-verbosity 0
yas-indent-line 'auto
yas-also-auto-indent-first-line t
yas-wrap-around-region nil
yas-prompt-functions '(yas-ido-prompt yas-no-prompt)
yas-prompt-functions '(doom/yas-ivy-prompt yas-ido-prompt yas-no-prompt)
;; Only load personal snippets
yas-snippet-dirs (list (concat doom-private-dir "/snippets")
(concat doom-private-dir "/templates")))

View File

@@ -159,6 +159,13 @@
:commands (describe-buffer describe-command describe-file
describe-keymap describe-option describe-option-of-type))
(use-package smex
:commands (smex smex-major-mode-commands)
:config
(setq smex-completion-method 'ivy
smex-save-file (concat doom-temp-dir "/smex-items"))
(smex-initialize))
;;
;; Automatic minor modes

57
core/defuns/defuns-ivy.el Normal file
View File

@@ -0,0 +1,57 @@
;;; defuns-ivy.el
;;;###autoload
(defun doom/ivy-switch-buffer (&optional all-p)
"Displays open buffers in current project. If ALL-P, then show all open
buffers."
(interactive)
(let ((this-command 'ivy-switch-buffer))
(ivy-read "Switch to buffer: " (doom/get-buffer-names (not all-p))
:matcher #'ivy--switch-buffer-matcher
:preselect (buffer-name (other-buffer (current-buffer)))
:action #'ivy--switch-buffer-action
:keymap ivy-switch-buffer-map
:caller 'doom/ivy-switch-buffer)))
;;;###autoload
(defun doom/ivy-kill-ring ()
(interactive)
(ivy-read "Kill ring:" (--filter (not (or (< (length it) 3)
(string-match-p "\\`[\n[:blank:]]+\\'" it)))
(remove-duplicates kill-ring :test' equal))))
;;;###autoload (autoload 'doom:ivy-recentf "defuns-ivy" nil t)
(evil-define-command doom:ivy-recentf (&optional bang)
"Ex-mode interface for `ivy-recentf' and `projectile-recentf'."
:repeat nil
(interactive "<!>")
(if bang (ivy-recentf) (projectile-recentf)))
;;;###autoload (autoload 'doom:ivy-swipe "defuns-ivy" nil t)
(evil-define-command doom:ivy-swiper (&optional search)
(interactive "<a>")
(swiper (or search (thing-at-point 'symbol))))
;;;###autoload (autoload 'doom:ivy-ag-search "defuns-ivy" nil t)
(evil-define-operator doom:ivy-ag-search (beg end search regex-p &optional dir)
"Preform a counsel search with SEARCH. If SEARCH is nil and in visual mode,
use the selection, otherwise activate live ag searching in helm.
If REGEX-P is non-nil, SEARCH will be treated as a regular expression.
DIR specifies the default-directory from which ag is run."
:type inclusive :repeat nil
(interactive "<r><a><!>")
(let ((counsel-ag-base-command
(format "ag --nocolor --nogroup %s %%s -- ."
(if regex-p "-Q" "")))
(search (or search (and beg end (buffer-substring-no-properties beg end)))))
(counsel-ag search (or dir (f-slash (doom/project-root))))))
;;;###autoload (autoload 'doom:ivy-ag-search-cwd "defuns-ivy" nil t)
(evil-define-operator doom:ivy-ag-search-cwd (beg end search regex-p)
:type inclusive :repeat nil
(interactive "<r><a><!>")
(doom:ivy-ag-search beg end search regex-p default-directory))
(provide 'defuns-ivy)
;;; defuns-ivy.el ends here

View File

@@ -92,9 +92,12 @@ normal mode if there are no fields."
;;;###autoload
(defun doom/yas-find-file ()
"Browse through snippets folder"
;; FIXME
(interactive)
(doom/ido-find-file (car doom-snippet-dirs)))
(projectile-find-file-in-directory (car yas-snippet-dirs)))
;;;###autoload
(defun doom/yas-ivy-prompt (prompt choices &optional display-fn)
(yas-completing-prompt prompt choices display-fn #'ivy-completing-read))
(provide 'defuns-yasnippet)
;;; nlinum-defuns.el ends here