0

Is it possible to treat typed numbers similar to universal argument C-u 10 C-n, but make it so that there is no need to type C-u in a minor mode? So only 10 C-n would be needed to move 10 lines down and C-n to move 1 line down.

  • Not an answer to your question, but you can also use C-1, C-2, ..., instead of typing C-u NUM ... E.g. C-4 C-n for four lines down. – lawlist Oct 10 at 0:00
  • ...which is essentially a solution: such sequences are all bound to C-h f digit-argument, so your minor mode map would simply bind the un-modified number keys to that as well. – phils Oct 10 at 0:43
  • Note that M-0 to M-9 are the reliable variants in a terminal (C-0 to C-9 may also work for GUI frames). Both sets can be useful depending on what you are intending to type next, if you like to avoid switching between modifier keys. Note also that for multi-digit numbers you only need the modifier key for the first digit -- after the first one, it's as if you'd used C-u. e.g. M-1 0 0 M-f would move forward 100 words (as would M-1 M-0 M-0 M-f). – phils Oct 10 at 0:50
0

Of course. The canonical way to do that is to use suppress-keymap on your mode's keymap. E.g.

(defvar my-mode-map
  (let ((map (make-keymap)))
    (suppress-keymap map)
    ...
    map))

In the unlikely case that you want to keep the self-inserting behavior of non-digits, then you should instead manually bind each digit to digit-argument as you apparently discovered in the mean time.

  • this is how I did it (define-minor-mode nav-mode "Toggle Nav Mode" :init-value nil :lighter " Nav" :group 'nav :keymap (let ((map (make-sparse-keymap))) (suppress-keymap map) (define-key map (kbd "1") (kbd "C-u 1")) map)) – phoxd Oct 12 at 0:38
  • I recommend you define the keymap in a separate (defvar nav-mode-map ....) instead of using the :keymap argument, but if it worked for you then it's all that matters. – Stefan Oct 12 at 12:49

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.