4

How can I use a number in a register after C-u ?

For example my register looks like 1: 24, and I want to do C-u 24 x.

1

This should do the trick.

(defun reg-as-pref-arg (register)
  "Use numeric register as prefix arg for next command
You are prompted for the register, showing preview of registers."
  (interactive (list (register-read-with-preview "Increment register: ")))
  (let ((reg-val (get-register register)))
    (when (numberp reg-val)
      (setq prefix-arg  reg-val))))

E.g.:

C-u 42 C-x r n a         ; Put 42 in register `a'

M-x reg-as-pref-arg a X  ; Use 42 as prefix arg for command to insert `X': 42 X's

Bind it to a key.

(global-set-key (kbd "C-o") #'reg-as-pref-arg)

Then use it.

C-o a X                  ; Insert 42 X's.
C-o a C-M-f              ; Move forward 42 words.

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.