0

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?

Background:

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 yank.

Although not essential to this question, it sure would be nice to know an example where (1- arg) could be useful.


P.S.

The issue is now resolved, but I wanted to add the explanation of (1- arg) within the function yank. (1- arg) is the nth entry in the kill-ring, which can be accessed when the arg is not a list or -. 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.

2

Use C-uC-y to to interactively pass a listp arg to yank.

yank uses (interactive "P") which means the prefix argument is passed in raw form.

When a prefix arg is supplied via one or more C-u presses (only), the raw form of the argument is a list: (4) or (16) or (64), etc...

(And similarly for the - argument, which is also tested for explicitly in this function.)

See C-hig (elisp) Prefix Command Arguments RET

Hence the varied behaviour described by the function's docstring:

With just C-u as argument, put point at beginning, and mark at end.
With argument N, reinsert the Nth most recent kill.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.