How to advice `evil-delete'

Frank Fischer frank.fischer at mathematik.tu-chemnitz.de
Mon Oct 3 12:11:38 CEST 2011


Am Sun, 2 Oct 2011 23:16:06 -0400
schrieb York Zhao <gtdplatform at gmail.com>:

> Hi,
> 
> I've been straggling with this for the entire afternoon and am really
> really frustrated. What I want is that when deleting an empty line, I
> don't want it to be yanked, just delete.
> 
> So I adviced `evil-delete' like this and it worked as I expected.
> 
> (defadvice evil-delete
>   (around around-delete (beg end type register yank-handler) activate)
>   (if (eq type 'line)
> 	  (let (here)
> 		(save-excursion
> 		  (goto-char beg)
> 		  (skip-chars-forward " \n\t" end)
> 		  (setq here (point)))
> 		(if (eq here end)
> 			(flet ((evil-yank (&rest args) t))
> 			  ad-do-it)
> 		  ad-do-it))
> 	ad-do-it))
> 
> However, as soon as I add another advice on `evil-yank', things
> stopped working correctly, even thougt the yank advice is empty like
> the following, things still not working properly.
> 	
> (defadvice evil-yank
>   (around around-yank (beg end type register yank-handler) activate)
>   ad-do-it)
> 
> The problem is that after I deleted an empty line, I could no longer
> yank anything, whenever I yank I get the errer:
> 
> Debugger entered--Lisp error:
> (wrong-type-argument commandp evil-yank)
> call-interactively(evil-yank nil nil)

I do not know if this is indeed the solution, but `evil-yank' is in the
end a usual Emacs command, i.e., it has an interactive-form. Your
redefinition does not have an interactive form and is therefore not
regarded as a command. Changing your code to

...
  (flet ((evil-yank (&rest args) (interactive) t)) ...

may work. But I haven't tested it.

Furthermore it may be easier to just call `delete-region' to remove
those lines instead of redefining `evil-yank'. In fact, this is what
`evil-delete' does.

Frank



More information about the implementations-list mailing list