I am trying to write a small code snippet in Elisp.
Basically, I want to create a function so that the content of the whole buffer is copied and, then, copied to the kill ring.
I can achieve this by the execution of command M-x
mark-whole-buffer
and M-x copy-region-as-kill
. It works.
Hence, I decided to translate it to Elisp code. After opening a tiny Elisp evaluator with M-x eval-expression
I inserted:
(copy-region-as-kill (mark-whole-buffer))
The mark-whole-buffer
part seems to work. However, copy-region-as-kill
does not work. Emacs echoes the following error message:
eval: Wrong number of arguments: (2 . 3), 0
The documentation indicates:
copy-region-as-kill is an interactive compiled Lisp function in
‘simple.el’.
(copy-region-as-kill BEG END &optional REGION)
Save the region as if killed, but don’t kill it.
In Transient Mark mode, deactivate the mark.
If ‘interprogram-cut-function’ is non-nil, also save the text for a window
system cut and paste.
The copied text is filtered by ‘filter-buffer-substring’ before it is
saved in the kill ring, so the actual saved text might be different
from what was in the buffer.
When called from Lisp, save in the kill ring the stretch of text
between BEG and END, unless the optional argument REGION is
non-nil, in which case ignore BEG and END, and save the current
region instead.
I thought I was sending the region
optional argument.
What is wrong with my approach? How can I fix it?
Obs.: I am building this as an intermediary step for this problem.