Evil numbered register behavior vis-a-vis vim

Currell Berry currellberry at gmail.com
Tue Feb 4 17:38:22 CET 2014


Frank Fischer <frank-fischer <at> shadow-soft.de> writes:

> 
> Am 03.02.2014 18:27, schrieb Kari Oikarinen:
> > 
> > Currell Berry <currellberry <at> gmail.com> writes:
> 
> >> One feature I use a lot in vim is, use 'yy' to yank a line, perform some
> >> arbitrary editing, possibly including deletions, trusting that vim will
> >> hold onto the yanked text in the 0 register until I yank another text, and
> >> then, finally, pasting the text back with '"0p'.  Evil doesn't implement
> >> the same behavior here.
> > 
> > There's a bug report about this at
> > https://bitbucket.org/lyro/evil/issue/339/zero-register-0-has-odd-behavior
> > 
> > I'm not sure if it was done on purpose, but I think it was just an
> > oversight. Perhaps an evil developer will confirm that. I also don't
> > think it would be hard to implement but I don't really know elisp and
> > haven't actually gotten around to trying to do it.
> 
> I can't really remember who implemented number registers and when, but I
> think the current implementation is how it is because it was ... easy.
> No special case concerning yank/delete ;).
> 
> I'm not sure how difficult it is to implement the desired behaviour. The
> evil function that is responsible for yanking is `evil-yank`, so it
> could be modified to put text in the 0 register (which would not be
> mapped to the kill-ring anymore). However, it is also called by
> `evil-delete` as a subroutine (because deleting is, well, yanking the
> text followed by wiping it out of the buffer). There are also a few
> other yank functions, but they all should call `evil-yank`. Furthermore,
> there are also some non-Evil functions (e.g. `kill-ring-save` typically
> bound to M-w), which also put text onto the kill-ring but do not delete
> it from the buffer. Handling all of them appropriately might not be so easy.
> 
> So, implementing the 0-register correctly is certainly possible but not
> completely trivial (unless there is some support by pre-existing Emacs
> functions that I'm not aware of).
> 
> If somebody wants to try implementing it, I'll be glad to provide any
> help I can ;)
> 
> Best regards,
> Frank
> 

Ok, thanks for the responses everyone.  I'll give it a shot myself when I
get a window of free time.  I will need to read up on emacs kill-ring
behavior and vim buffer behavior, and pick up some elisp along the way.  

Just to confirm: the goal with these types of features is to emulate vim
behavior as closely as possible, no?

Just from glancing over the evil code, it looks like most of the vim
"special register" behaviors are already implemented.  
"evil-set-register" within evil-common.el does register type checking, and
implements special features depending on the register involved.

A lot of functions TAKE IN various arguments (including register) but atm I
can't figure out where the calls to these functions (with the register
number) are actually happening.  For example here's the signature for the
function "evil-delete-line" in evil-commands.el.

(evil-define-operator evil-delete-line (beg end type register yank-handler)
  "Delete to end of line."

and here's where the key mapping to it is set in evil-maps.el

(define-key evil-normal-state-map "D" 'evil-delete-line)

.
Where do the arguments to evil-delete-line actually get specified?  Sorry if
this is a stupid question, I am new to elisp.

--Currell




More information about the implementations-list mailing list