emacs-evil / evil

The extensible vi layer for Emacs.
GNU General Public License v3.0
3.34k stars 282 forks source link

Advising evil-delete breaks evil-surround-delete #1326

Open romandecker opened 4 years ago

romandecker commented 4 years ago

Wasn't sure if I should file this issue over at the evil-surround repo, but I think this is not an evil-surround problem but rather a problem on how I'm trying to advise evil-delete.

Issue type

Environment

Emacs version: GNU Emacs 26.1 (build 1, x86_64-apple-darwin14.5.0, NS appkit-1348.17 Version 10.10.5 (Build 14F2511)) of 2018-05-31 Operating System: macOS Catalina (10.15.5) Evil version: 1.14.0 Evil installation type: manual Graphical/Terminal: both Tested in a make emacs session (see CONTRIBUTING.md): Yes

Reproduction steps

;; simple advice that should send all deletes to black-hole register (defun evil-delete-advice (orig-fn beg end type register &rest args) (apply orig-fn beg end type ?_ args))

(advice-add 'evil-delete :around #'evil-delete-advice)



- `M-x eval-buffer`
- Place cursor somewhere between `()` and type `d s (`

# Expected behavior
Only the parentheses are deleted.

# Actual behavior
Instead of deleting just the parenthesis, everything between the opening parentheses and point is deleted too.

# Further notes
When the advice is removed, everything works as expected. How do I correctly advise `evil-delete` without breaking `evil-surround`?
romandecker commented 4 years ago

in case anybody has similar problems, I was able to work around the issue by not advising evil-delete and instead defining a new operator and making sure it works with evil-surround:

(after! evil
  (evil-define-operator evil-destroy (beg end type)
    "Delete text from BEG to END with TYPE. Just like evil-delete but always
deletes to black-hole"
    (evil-delete beg end type ?_ nil))

  (map! :n "d" #'evil-destroy)
  (map! :n "m" #'evil-delete))

(after! evil-surround
  (add-to-list 'evil-surround-operator-alist '(evil-destroy . delete)))

I actually like this solution better than what I originally intended, but the problem that advising evil-delete breaks evil-surround still persists.