Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion modes/grep/README.org
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@

Evil bindings for [[https://www.gnu.org/software/emacs/manual/html_node/emacs/Grep-Searching.html][grep]].

** Key bindings
** grep-mode-map key bindings

| Command | Original | Evil |
|----------------------------+----------+-------|
| =evil-search-next= | n/a | =n= |
| =next-error-no-select= | =n= | =C-j= |
| =previous-error-no-select= | =p= | =C-k= |

** grep-edit-mode-map key bindings
| Command | Original | Evil |
|--------------------------+-----------+------------|
| =grep-edit-save-changes= | =C-c C-c= | =ZZ=, =:w= |

** Integrations

- wgrep: =i= → =wgrep-change-to-wgrep-mode= when =wgrep= is available.
- grep-edit: =i= → =grep-change-to-grep-edit-mode= when =wgrep= is not available and Emacs is newer than 31
18 changes: 14 additions & 4 deletions modes/grep/evil-collection-grep.el
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
(require 'evil-collection)
(require 'grep)

(defconst evil-collection-grep-maps '(grep-mode-map))
(defvar grep-edit-mode-map) ;; might be missing if it's older Emacs

(defconst evil-collection-grep-maps '(grep-mode-map
grep-edit-mode-map))

;;;###autoload
(defun evil-collection-grep-setup ()
Expand All @@ -40,10 +43,17 @@
"\C-j" 'next-error-no-select
"\C-k" 'previous-error-no-select)

;; `wgrep' integration
(when (fboundp 'wgrep-setup)
(cond

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to use both wgrep and grep-edit-mode in the same emacs session?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically yes, they implement a similar grep-mode <-> editable grep-mode behavior. But I believe the reason most people installed wgrep is for this editing grep result feature, which precedes grep-edit-mode by far (as it implements atomic updates, could be reverted, etc). The most benefit of grep-edit-mode is that it's built-in, so I consider it as a fallback as for now.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets split them then. I use wgrep most with dired, not grep.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets split them then. I use wgrep most with dired, not grep.

Maybe you're using wdired-mode

;; prefer `wgrep' integration
((fboundp 'wgrep-setup)
(evil-collection-define-key 'normal 'grep-mode-map
"i" 'wgrep-change-to-wgrep-mode))
;; fallback to built-in grep-edit
((>= emacs-major-version 31)
(evil-collection-define-key 'normal 'grep-mode-map
"i" 'wgrep-change-to-wgrep-mode)))
"i" 'grep-change-to-grep-edit-mode)
(evil-collection-bind 'grep-edit-mode-map
'quit-save 'grep-edit-save-changes))))

(provide 'evil-collection-grep)
;;; evil-collection-grep.el ends here
Loading