First of all, if your goal is to translate something from a .vimrc
, it's as simple as (define-key evil-normal-state-map (kbd ...) "d$")
. If you want to write new commands to use from Evil, it's better to construct these from Emacs primitives and wrap them as needed with Evil macros. But if you're just interested in how Evil works, then read on...
As you've noticed already, if you're calling an operator like evil-delete
interactively, it will read in its arguments as specified by its interactive
spec. Reading evil-commands.el
reveals that evil-delete
is defined with the evil-define-operator
macro which turns the rather unusual looking "<R><x><y>"
spec into something Emacs can deal with, a list evaluating to the desired values!
evil-types.el
has a listing of these codes. <x>
is evil-this-register
, <y>
is (evil-yank-handler)
. Since you haven't expressed interest in any of those (and the usage of evil-delete
as displayed by F1 f evil-delete
suggests they are optional anyways), let's take a closer look at <R>
which is using (evil-operator-range t)
to evaluate to a list looking like (BEG END TYPE)
. evil-operator-range
reads in a motion, checks up on its properties (like, its type), then executes it to determine where the motion did begin and where it does end. A motion in Evil is just an Emacs command taking point somewhere else after all...
So, considering our type isn't line
or block
and evil-delete
doesn't care what other value it is, we'll go with t
for TYPE
. BEG
is going to be (point)
because we're deleting from where we are at, END
is set with (move-end-of-line COUNT)
in evil-end-of-line
and can be determined by wrapping it into save-excursion
:
(evil-delete (point) (save-excursion (move-end-of-line 1) (point)) t)
This can probably be simplified to:
(evil-delete (point) (line-end-position) t)
Or if you don't need to do this with Evil (because you're writing a new command and don't actually need to repurpose it):
(delete-region (point) (line-end-position))
end-of-line
and no further example code that would explain the rest.