Is it possible to interactively pass an argument that matches
listp to the function
yank so that
current-kill receives an argument of
0? If so, how please can that be achieved?
I am using
multiple-cursors ( https://github.com/magnars/multiple-cursors.el ) and frequently find the need to block and copy information from another Emacs buffer while
multiple-cursors remains active. Then, I switch back to the buffer where
multiple-cursors is active, and I try to paste the same information to every cursor. Unless
current-kill (within the
yank function) receives an argument of
0, the first cursor receives the paste and then an error message is generated by
current-kill -- i.e.,
The kill-ring is empty. The error message is caused due to the failure of passing a
listp arg to
yank when interactively using same -- i.e., from a kebboard shortcut. The default argument within
yank (when no argument is given) is
(1- arg) -- and that is what causes the error message. If
yank had been called with a
listp arg, then
current-kill would have received a
0 and everything would have worked as expected.
I do not understand when the default of
(1- arg) would be helpful, but changing that to
0 (i.e., hacking
yank) avoids the error message and achieves the desired effect. If possible, I would prefer to avoid hacking
Although not essential to this question, it sure would be nice to know an example where
(1- arg) could be useful.
The issue is now resolved, but I wanted to add the explanation of
(1- arg) within the function
(1- arg) is the nth entry in the kill-ring, which can be accessed when the
arg is not a
-. There is an apparent bug in the
yank function in the October 1, 2014 build of Emacs Trunk (which may be present in other versions) -- i.e., at the outset of
yank, there should be
(unless arg (setq arg 1)) [which is missing]. I'll make a note on my todo-list to check a current version of Emacs Trunk and then file a bug-report if it is missing in the latest build also.
With respect to copying and pasting the same entry at multiple active cursors, additional code is needed when copying from within Emacs versus copying from an external program. The author of multiple-cursors has already included a revision of
current-kill through an
advice for the external kill-ring -- similar code is needed for copying from within Emacs -- however, that is beyond the scope of this particular question.