Given a definer, for example:

(general-create-definer test-def
  :states '(normal insert motion emacs)
  :keymaps 'override
  :prefix "SPC")
(test-def "" nil
          "f" 'find-file

I would like to press u to get the behaviour of pressing the C-u prefix.

For example, the following pairs of keypresses should work equivalently:

  • SPC u f same as C-u SPC f
  • SPC u u f same as C-u C-u SPC f

This solution should work for all the keys in the definer.

Solution attempt:

If I set

(test-def "u" 'universal-argument)
(general-def universal-argument-map "u" 'universal-argument-more)

then to get behaviour equivalent to C-u C-u SPC f I have to press SPC u u SPC f. I don't want to have to press SPC the second time.

2 Answers 2


A reasonably satisfactory approach

;; change prefix argument, and activate transient keymap 'map'
(defun tap/prefix-map-add-numeric-prefix (map)
  (universal-argument-more (list (prefix-numeric-value prefix-arg)))
  (set-transient-map map))

(general-create-definer space-def
  :states '(normal insert motion emacs)
  :keymaps 'override
  :prefix-map 'space-def-map
  :prefix "SPC"
  :non-normal-prefix "M-SPC")
(space-def "" nil) ;; makes this an incomplete prefix

;; change prefix argument, and activate transient keymap space-def-map 
(space-def "u" '((lambda () (interactive) (tap/prefix-map-add-numeric-prefix space-def-map)) :which-key "add C-u"))


(defun prefixval (arg)
  (interactive "P")
  (message (format "%d" (prefix-numeric-value current-prefix-arg))))
(space-def "p" 'prefixval)

;; SPC p (1)
;; SPC u p (4)
;; SPC u u p (16)
;; etc.

NB: After pressing SPC u, which-key completions will no longer be visible. It is possible to try to include them, but I am happy enough without them, because if I forget the keys, I can just press SPC instead of SPC u, and find the key.

 :states '(normal insert motion emacs)
 :keymaps 'override
 :prefix-map 'tyrant-map
 :prefix "SPC"
 :non-normal-prefix "M-SPC")

(general-create-definer tyrant-def :keymaps 'tyrant-map)
(tyrant-def "" nil)
(general-def universal-argument-map
  "u" 'universal-argument-more)
  "SPC"     '("M-x" . execute-extended-command)
  "u"       '("universal arg" . universal-argument))
  • Using this, I still have to press SPC the second time. Therefore, I don't see what it improves over my initial solution attempt. Please explain in what way it is different.
    – user615536
    Dec 18, 2023 at 13:55
  • The key is (general-def universal-argument-map "u" 'universal-argument-more), and I can press SPC u u to get C-u C-u on my side. Dec 18, 2023 at 14:06
  • Yes, I can press SPC u u to get C-u C-u (but I was already able to do that). The problem is, in your example, to run execute-extended-command with two prefix arguments, I need to press SPC u u SPC SPC, but I want to just be able to press SPC u u SPC. i.e. I don't want to have to press the SPC prefix command twice. In my original question I have given other examples. Thanks
    – user615536
    Dec 18, 2023 at 14:37
  • I suppose you could try changing the SPC prefix-map to universal-argument-map but that would cause the binding SPC digit to override the C-u digit function. Dec 21, 2023 at 2:51
  • I want the solution to generalise well. For example, I may have many definers with different prefixes: SPC, DEL, etc. Setting all of their prefix-maps to universal-argument-map would dump all the bindings from SPC, DEL, etc. into the same map. My posted answer below achieves roughly the desired behaviour
    – user615536
    Dec 22, 2023 at 17:10

Your Answer

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

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