From 5c13f2eced23b8fb8077b53dab7970b0ceb9b84e Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 19 Feb 2017 18:41:37 -0500 Subject: [PATCH] Update modules/completion/ivy --- modules/completion/ivy/autoload/evil.el | 34 ++++++++++++ .../ivy/{autoload.el => autoload/ivy.el} | 54 ++++--------------- modules/completion/ivy/config.el | 16 ++++-- modules/completion/ivy/packages.el | 1 + 4 files changed, 59 insertions(+), 46 deletions(-) create mode 100644 modules/completion/ivy/autoload/evil.el rename modules/completion/ivy/{autoload.el => autoload/ivy.el} (64%) diff --git a/modules/completion/ivy/autoload/evil.el b/modules/completion/ivy/autoload/evil.el new file mode 100644 index 000000000..4f62d0b5f --- /dev/null +++ b/modules/completion/ivy/autoload/evil.el @@ -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 "") + (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 "") + (+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 "") + (swiper (or search (thing-at-point 'symbol)))) diff --git a/modules/completion/ivy/autoload.el b/modules/completion/ivy/autoload/ivy.el similarity index 64% rename from modules/completion/ivy/autoload.el rename to modules/completion/ivy/autoload/ivy.el index 569e5f11e..cd5d582ee 100644 --- a/modules/completion/ivy/autoload.el +++ b/modules/completion/ivy/autoload/ivy.el @@ -1,8 +1,8 @@ -;;; completion/ivy/packages.el +;;; completion/ivy/autoload/ivy.el ;; Show more information in ivy-switch-buffer; and only display ;; project/workgroup-relevant buffers. -(defun +ivy-get-buffers (&optional buffer-list) +(defun +ivy--get-buffers (&optional buffer-list) (let ((min-name 5) (min-mode 5) (proot (doom-project-root))) @@ -32,8 +32,8 @@ (propertize "[+]" 'face 'doom-modeline-buffer-modified))) (propertize mode-name 'face 'font-lock-constant-face) (when buffer-file-name - (f-slash (abbreviate-file-name (f-dirname buffer-file-name)))))))) - (or buffer-list (doom/get-buffers t)))))) + (abbreviate-file-name (file-name-directory buffer-file-name))))))) + (or buffer-list (doom-buffer-list t)))))) (defun +ivy--select-buffer-action (buffer) (ivy--switch-buffer-action @@ -47,7 +47,7 @@ all open buffers." (interactive) (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 :action #'+ivy--select-buffer-action :keymap ivy-switch-buffer-map @@ -62,14 +62,16 @@ all open buffers." ;;;###autoload (defun +ivy/kill-ring () (interactive) - (ivy-read "Kill ring:" (--filter (not (or (< (length it) 3) - (string-match-p "\\`[\n[:blank:]]+\\'" it))) - (cl-remove-duplicates kill-ring :test 'equal)))) + (ivy-read "Kill ring:" + (cl-remove-if (lambda (it) + (or (< (length it) 3) + (string-match-p "\\`[\n[:blank:]]+\\'" it))) + (cl-remove-duplicates kill-ring :test 'equal)))) ;;;###autoload (defun +ivy/tasks () (interactive) - ;; TODO Something a little nicer + ;; TODO Make nicer (counsel-ag " (TODO|FIXME|NOTE) " (doom-project-root))) ;;;###autoload @@ -103,37 +105,3 @@ interferes with my custom :ag ex command `+ivy:ag-search'." ;;;###autoload (defun +ivy-yas-prompt (prompt choices &optional display-fn) (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 "") - (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 "") - (+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 "") - (swiper (or search (thing-at-point 'symbol))))) - diff --git a/modules/completion/ivy/config.el b/modules/completion/ivy/config.el index da242bc1c..de8b84946 100644 --- a/modules/completion/ivy/config.el +++ b/modules/completion/ivy/config.el @@ -49,10 +49,12 @@ "C-b" 'backward-word "C-f" 'forward-word) - ;; 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 _) (redisplay)) + ;; 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)) (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 yasnippet (push '+ivy-yas-prompt yas-prompt-functions)) @@ -95,3 +97,11 @@ "C-SPC" 'counsel-git-grep-recenter ; preview "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)) + diff --git a/modules/completion/ivy/packages.el b/modules/completion/ivy/packages.el index b9d6c7a72..37d1bd9d2 100644 --- a/modules/completion/ivy/packages.el +++ b/modules/completion/ivy/packages.el @@ -4,3 +4,4 @@ (@package ivy) (@package counsel) (@package counsel-projectile) +(@package smex)