Update modules/completion/ivy
This commit is contained in:
parent
2b027c0052
commit
5c13f2eced
4 changed files with 59 additions and 46 deletions
34
modules/completion/ivy/autoload/evil.el
Normal file
34
modules/completion/ivy/autoload/evil.el
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
;;; completion/ivy/autoload/evil.el
|
||||||
|
|
||||||
|
(defvar +ivy--ag-last-search nil)
|
||||||
|
|
||||||
|
;;;###autoload (autoload '+ivy:ag-search "completion/ivy/autoload/evil" nil t)
|
||||||
|
(evil-define-operator +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 ((search (or search
|
||||||
|
(and (evil-visual-state-p)
|
||||||
|
(and beg end
|
||||||
|
(let ((str (buffer-substring-no-properties beg end)))
|
||||||
|
(if regex-p (rxt-quote-pcre str) str))))
|
||||||
|
+ivy--ag-last-search)))
|
||||||
|
(setq +ivy--ag-last-search search)
|
||||||
|
(counsel-ag search (or dir (doom-project-root))
|
||||||
|
(concat "--nocolor --nogroup" (if regex-p " -Q")))))
|
||||||
|
|
||||||
|
;;;###autoload (autoload '+ivy:ag-search-cwd "completion/ivy/autoload/evil" nil t)
|
||||||
|
(evil-define-operator +ivy:ag-search-cwd (beg end search regex-p)
|
||||||
|
:type inclusive :repeat nil
|
||||||
|
(interactive "<r><a><!>")
|
||||||
|
(+ivy:ag-search beg end search regex-p default-directory))
|
||||||
|
|
||||||
|
;;;###autoload (autoload '+ivy:swiper "completion/ivy/autoload/evil" nil t)
|
||||||
|
(evil-define-command +ivy:swiper (&optional search)
|
||||||
|
"Invoke `swiper' with SEARCH, otherwise with the symbol at point."
|
||||||
|
(interactive "<a>")
|
||||||
|
(swiper (or search (thing-at-point 'symbol))))
|
|
@ -1,8 +1,8 @@
|
||||||
;;; completion/ivy/packages.el
|
;;; completion/ivy/autoload/ivy.el
|
||||||
|
|
||||||
;; Show more information in ivy-switch-buffer; and only display
|
;; Show more information in ivy-switch-buffer; and only display
|
||||||
;; project/workgroup-relevant buffers.
|
;; project/workgroup-relevant buffers.
|
||||||
(defun +ivy-get-buffers (&optional buffer-list)
|
(defun +ivy--get-buffers (&optional buffer-list)
|
||||||
(let ((min-name 5)
|
(let ((min-name 5)
|
||||||
(min-mode 5)
|
(min-mode 5)
|
||||||
(proot (doom-project-root)))
|
(proot (doom-project-root)))
|
||||||
|
@ -32,8 +32,8 @@
|
||||||
(propertize "[+]" 'face 'doom-modeline-buffer-modified)))
|
(propertize "[+]" 'face 'doom-modeline-buffer-modified)))
|
||||||
(propertize mode-name 'face 'font-lock-constant-face)
|
(propertize mode-name 'face 'font-lock-constant-face)
|
||||||
(when buffer-file-name
|
(when buffer-file-name
|
||||||
(f-slash (abbreviate-file-name (f-dirname buffer-file-name))))))))
|
(abbreviate-file-name (file-name-directory buffer-file-name)))))))
|
||||||
(or buffer-list (doom/get-buffers t))))))
|
(or buffer-list (doom-buffer-list t))))))
|
||||||
|
|
||||||
(defun +ivy--select-buffer-action (buffer)
|
(defun +ivy--select-buffer-action (buffer)
|
||||||
(ivy--switch-buffer-action
|
(ivy--switch-buffer-action
|
||||||
|
@ -47,7 +47,7 @@
|
||||||
all open buffers."
|
all open buffers."
|
||||||
(interactive)
|
(interactive)
|
||||||
(ivy-read (format "%s buffers: " (if all-p "All" "Project"))
|
(ivy-read (format "%s buffers: " (if all-p "All" "Project"))
|
||||||
(+ivy-get-buffers (if all-p (buffer-list)))
|
(+ivy--get-buffers (if all-p (buffer-list)))
|
||||||
:matcher #'ivy--switch-buffer-matcher
|
:matcher #'ivy--switch-buffer-matcher
|
||||||
:action #'+ivy--select-buffer-action
|
:action #'+ivy--select-buffer-action
|
||||||
:keymap ivy-switch-buffer-map
|
:keymap ivy-switch-buffer-map
|
||||||
|
@ -62,14 +62,16 @@ all open buffers."
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +ivy/kill-ring ()
|
(defun +ivy/kill-ring ()
|
||||||
(interactive)
|
(interactive)
|
||||||
(ivy-read "Kill ring:" (--filter (not (or (< (length it) 3)
|
(ivy-read "Kill ring:"
|
||||||
(string-match-p "\\`[\n[:blank:]]+\\'" it)))
|
(cl-remove-if (lambda (it)
|
||||||
(cl-remove-duplicates kill-ring :test 'equal))))
|
(or (< (length it) 3)
|
||||||
|
(string-match-p "\\`[\n[:blank:]]+\\'" it)))
|
||||||
|
(cl-remove-duplicates kill-ring :test 'equal))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +ivy/tasks ()
|
(defun +ivy/tasks ()
|
||||||
(interactive)
|
(interactive)
|
||||||
;; TODO Something a little nicer
|
;; TODO Make nicer
|
||||||
(counsel-ag " (TODO|FIXME|NOTE) " (doom-project-root)))
|
(counsel-ag " (TODO|FIXME|NOTE) " (doom-project-root)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
|
@ -103,37 +105,3 @@ interferes with my custom :ag ex command `+ivy:ag-search'."
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +ivy-yas-prompt (prompt choices &optional display-fn)
|
(defun +ivy-yas-prompt (prompt choices &optional display-fn)
|
||||||
(yas-completing-prompt prompt choices display-fn #'ivy-completing-read))
|
(yas-completing-prompt prompt choices display-fn #'ivy-completing-read))
|
||||||
|
|
||||||
|
|
||||||
;;;###autoload (autoload '+ivy:ag-search "completion/ivy/autoload" nil t)
|
|
||||||
;;;###autoload (autoload '+ivy:ag-search-cwd "completion/ivy/autoload" nil t)
|
|
||||||
;;;###autoload (autoload '+ivy:swiper "completion/ivy/autoload" nil t)
|
|
||||||
(@after evil
|
|
||||||
(defvar +ivy--ag-last-search nil)
|
|
||||||
|
|
||||||
(evil-define-operator +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 ((search (or search
|
|
||||||
(and (evil-visual-state-p)
|
|
||||||
(and beg end (rxt-quote-pcre (buffer-substring-no-properties beg end))))
|
|
||||||
+ivy--ag-last-search)))
|
|
||||||
(setq +ivy--ag-last-search search)
|
|
||||||
(counsel-ag search (or dir (f-slash (doom-project-root)))
|
|
||||||
(concat "--nocolor --nogroup" (if regex-p " -Q")))))
|
|
||||||
|
|
||||||
(evil-define-operator +ivy:ag-search-cwd (beg end search regex-p)
|
|
||||||
:type inclusive :repeat nil
|
|
||||||
(interactive "<r><a><!>")
|
|
||||||
(+ivy:ag-search beg end search regex-p default-directory))
|
|
||||||
|
|
||||||
(evil-define-command +ivy:swiper (&optional search)
|
|
||||||
"Invoke `swiper' with SEARCH, otherwise with the symbol at point."
|
|
||||||
(interactive "<a>")
|
|
||||||
(swiper (or search (thing-at-point 'symbol)))))
|
|
||||||
|
|
|
@ -49,10 +49,12 @@
|
||||||
"C-b" 'backward-word
|
"C-b" 'backward-word
|
||||||
"C-f" 'forward-word)
|
"C-f" 'forward-word)
|
||||||
|
|
||||||
;; Occasionally, when ivy closes, it causes display artifacting between
|
;; Occasionally, when ivy closes, it causes display artifacting
|
||||||
;; horizontal splits. This fixes it, though may cause flickering on some OSes.
|
;; between horizontal splits. This fixes it, though may cause
|
||||||
(defun doom|redisplay (&rest _) (redisplay))
|
;; flickering on some OSes.
|
||||||
|
(defun doom|redisplay (&rest _) (force-mode-line-update))
|
||||||
(advice-add 'ivy-read :after 'doom|redisplay)
|
(advice-add 'ivy-read :after 'doom|redisplay)
|
||||||
|
(add-hook 'projectile-find-file-hook 'doom|redisplay)
|
||||||
|
|
||||||
(@after magit (setq magit-completing-read-function 'ivy-completing-read))
|
(@after magit (setq magit-completing-read-function 'ivy-completing-read))
|
||||||
(@after yasnippet (push '+ivy-yas-prompt yas-prompt-functions))
|
(@after yasnippet (push '+ivy-yas-prompt yas-prompt-functions))
|
||||||
|
@ -95,3 +97,11 @@
|
||||||
"C-SPC" 'counsel-git-grep-recenter ; preview
|
"C-SPC" 'counsel-git-grep-recenter ; preview
|
||||||
"M-RET" '+ivy/counsel-ag-open-in-other-window))
|
"M-RET" '+ivy/counsel-ag-open-in-other-window))
|
||||||
|
|
||||||
|
|
||||||
|
;; 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))
|
||||||
|
|
||||||
|
|
|
@ -4,3 +4,4 @@
|
||||||
(@package ivy)
|
(@package ivy)
|
||||||
(@package counsel)
|
(@package counsel)
|
||||||
(@package counsel-projectile)
|
(@package counsel-projectile)
|
||||||
|
(@package smex)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue