0

I have function like this:

(defun swap-region-ring ()
  "replace selected text with the one from kill ring"
  (interactive)
  (backward-delete-char (- (point) (mark)))
  (yank))

(global-set-key (kbd "C-c y") 'swap-region-ring)

How can I rewrite that function to call yank with argument and have also optional argument so it act the same as yank? So I can call C-u 2 C-c y

1 Answer 1

1

yank happens to accept a "raw prefix argument" as its argument, so you can pick it up and forward it:

(defun swap-region-ring (&optional arg)
  "replace selected text with the one from kill ring"
  (interactive "*P")
  (backward-delete-char (- (point) (mark)))
  (yank arg))

Type C-h f interactive for more information about the interactive spec.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.