From fe36bbca1f396167de0733dc7793c1a5f1432ff3 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Mon, 20 May 2019 21:06:06 -0400 Subject: [PATCH] Standardize C-c C-e for ivy wgrep Removes backtab in favor of standardizing C-c C-e. Already used by helm, wgrep and dired. --- modules/completion/ivy/autoload/ivy.el | 43 ++++++++++++----------- modules/completion/ivy/config.el | 6 ++++ modules/config/default/+emacs-bindings.el | 2 -- modules/config/default/+evil-bindings.el | 10 +----- 4 files changed, 30 insertions(+), 31 deletions(-) diff --git a/modules/completion/ivy/autoload/ivy.el b/modules/completion/ivy/autoload/ivy.el index 1be5108dc..3810a8df2 100644 --- a/modules/completion/ivy/autoload/ivy.el +++ b/modules/completion/ivy/autoload/ivy.el @@ -229,30 +229,33 @@ search current file. See `+ivy-task-tags' to customize what this searches for." :caller '+ivy/tasks)) ;;;###autoload -(defun +ivy/wgrep-occur () - "Invoke the search+replace wgrep buffer on the current ag/rg search results." +(defun +ivy/woccur () + "Invoke a wgrep buffer on the current ivy results, if supported." (interactive) (unless (window-minibuffer-p) (user-error "No completion session is active")) (require 'wgrep) - (let* ((caller (ivy-state-caller ivy-last)) - (occur-fn (plist-get ivy--occurs-list caller)) - (buffer - (generate-new-buffer - (format "*ivy-occur%s \"%s\"*" - (if caller (concat " " (prin1-to-string caller)) "") - ivy-text)))) - (with-current-buffer buffer - (let ((inhibit-read-only t)) - (erase-buffer) - (funcall occur-fn)) - (setf (ivy-state-text ivy-last) ivy-text) - (setq ivy-occur-last ivy-last) - (setq-local ivy--directory ivy--directory)) - (ivy-exit-with-action - `(lambda (_) - (pop-to-buffer ,buffer) - (ivy-wgrep-change-to-wgrep-mode))))) + (let ((caller (ivy-state-caller ivy-last))) + (if-let* ((occur-fn (plist-get +ivy-edit-functions caller))) + (ivy-exit-with-action + (lambda (_) (funcall occur-fn))) + (if-let* ((occur-fn (plist-get ivy--occurs-list caller))) + (let ((buffer (generate-new-buffer + (format "*ivy-occur%s \"%s\"*" + (if caller (concat " " (prin1-to-string caller)) "") + ivy-text)))) + (with-current-buffer buffer + (let ((inhibit-read-only t)) + (erase-buffer) + (funcall occur-fn)) + (setf (ivy-state-text ivy-last) ivy-text) + (setq ivy-occur-last ivy-last) + (setq-local ivy--directory ivy--directory)) + (ivy-exit-with-action + `(lambda (_) + (pop-to-buffer ,buffer) + (ivy-wgrep-change-to-wgrep-mode)))) + (user-error "%S doesn't support wgrep" caller))))) ;;;###autoload (defun +ivy-yas-prompt (prompt choices &optional display-fn) diff --git a/modules/completion/ivy/config.el b/modules/completion/ivy/config.el index edd3a8b1d..032943a3d 100644 --- a/modules/completion/ivy/config.el +++ b/modules/completion/ivy/config.el @@ -26,6 +26,10 @@ If you want to already use git-grep or grep, set this to nil.") (defvar +ivy-buffer-unreal-face 'font-lock-comment-face "The face for unreal buffers in `ivy-switch-to-buffer'.") +(defvar +ivy-edit-functions nil + "A plist mapping ivy/counsel commands to commands that generate an editable +results buffer.") + (defmacro +ivy-do-action! (action) "Returns an interactive lambda that sets the current ivy action and immediately runs it on the current candidate (ending the ivy session)." @@ -86,6 +90,8 @@ immediately runs it on the current candidate (ending the ivy session)." [remap switch-to-buffer-other-window] #'+ivy/switch-buffer-other-window [remap persp-switch-to-buffer] #'+ivy/switch-workspace-buffer) + (define-key ivy-minibuffer-map (kbd "C-c C-e") #'+ivy/woccur) + (ivy-mode +1) (def-package! ivy-hydra diff --git a/modules/config/default/+emacs-bindings.el b/modules/config/default/+emacs-bindings.el index adc5fb47b..968be1718 100644 --- a/modules/config/default/+emacs-bindings.el +++ b/modules/config/default/+emacs-bindings.el @@ -322,8 +322,6 @@ "C-g" #'keyboard-escape-quit) (:after counsel :map counsel-ag-map - "C-c C-e" #'+ivy/wgrep-occur ; search/replace on results - [backtab] #'+ivy/wgrep-occur ; search/replace on results "C-SPC" #'ivy-call-and-recenter ; preview "M-RET" (+ivy-do-action! #'+ivy-git-grep-other-window-action)) "C-M-y" #'counsel-yank-pop) diff --git a/modules/config/default/+evil-bindings.el b/modules/config/default/+evil-bindings.el index 3dc457c08..e1fc341be 100644 --- a/modules/config/default/+evil-bindings.el +++ b/modules/config/default/+evil-bindings.el @@ -220,12 +220,7 @@ :map counsel-ag-map "C-SPC" #'ivy-call-and-recenter ; preview "C-l" #'ivy-done - "C-c C-e" #'+ivy/wgrep-occur ; search/replace on results - [backtab] #'+ivy/wgrep-occur ; search/replace on results - [C-return] (+ivy-do-action! #'+ivy-git-grep-other-window-action)) - (:after swiper - :map swiper-map - [backtab] #'+ivy/wgrep-occur)) + [C-return] (+ivy-do-action! #'+ivy-git-grep-other-window-action))) (:when (featurep! :completion helm) (:after helm @@ -249,13 +244,10 @@ "TAB" #'helm-execute-persistent-action [tab] #'helm-execute-persistent-action "C-z" #'helm-select-action) - (:after swiper-helm - :map swiper-helm-keymap [backtab] #'helm-ag-edit) (:after helm-ag :map helm-ag-map "C--" #'+helm-do-ag-decrease-context "C-=" #'+helm-do-ag-increase-context - [backtab] #'helm-ag-edit [left] nil [right] nil) (:after helm-files