Evil numbered register behavior vis-a-vis vim
Frank Fischer
frank-fischer at shadow-soft.de
Wed Feb 5 07:00:57 CET 2014
Am 04.02.2014 17:38, schrieb Currell Berry:
> 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?
Yes, if it is possible with reasonable effort. For instances, buffers
are handled in different ways in Vim and Emacs (e.g. Vim buffers are
numbered, Emacs buffers are not), but there is probably no real
advantage in enforcing Vim-like buffer handling.
> 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.
Evil commands are Emacs interactive commands. An interactive command is
a function with an (interactive ...) directive right at the beginning of
the function body. If a function is called, well, interactively, i.e.
using a key-sequence, the actual values for the parameters are not
passed explicitly (as there is no way in specifying those values with a
key-sequence) but are determined by investigating the interactive directive.
If you have function like this
```
(defun myfunc (x)
(interactive (list 42))
(message "%s" x))
(global-set-key (kbd "C-c t") 'myfunc)
```
then calling `myfunc` by pressing C-c t will pass 42 as value of x. More
information about the interactive directive can be found in the elisp
manual.
Evil extends standard interactive directives to support special codes.
The interactive directive of `evil-delete-line` is
```
(interactive "<R><x>")
```
The first code <R> means the Evil should pass the current visual
selection (if any) in the first three parameters `beg end type` (or nil
if Evil is not in visual state). The second code <x> causes Evil to pass
the selected register-name (i.e. the one selected by a preceding `"x`
key-sequence, where x is the character of the register) in the next (the
fourth) argument (or nil). The fifth argument of the function
`yank-handler` is always nil, it is only needed when `evil-delete-line`
is called as a function from other elisp code.
I hope this helps. Note that interactive codes are a Emacs feature and
nothing special to Evil.
Best regards,
Frank
More information about the implementations-list
mailing list