AdrieanKhisbe
AdrieanKhisbe

Reputation: 4058

Emacs: Prefix Command Arguments with numeric Keypad

Using a french keybord where regular digit are not accessible without holding shift, I would like to use the numpad to be able to send prefix/numeric arguments along with emacs commands. For instance M-4 C-b, M-6 C-k, and so on....

Natively, if i try to do so hitting the keypad I get <M-kp-2> is undefined.

How can I make it works, either with emacs config, or system settings (using LinuxMint15)?

(I have been through emacs docs, but I didn't found any lead)

Upvotes: 2

Views: 655

Answers (2)

giordano
giordano

Reputation: 8344

Add the following code to your init file (solution taken from Nicolas Richard message here https://lists.gnu.org/archive/html/bug-gnu-emacs/2013-05/msg00365.html):

(dotimes (i 10)                         ; for all keys
  (dolist (prefix (list "M" "C"))       ; for both modifiers
    (global-set-key
     (read (format "[%s-kp-%s]" prefix i))
     'digit-argument)
    (put 
     (read (format "%s-kp-%s" prefix i))
     'ascii-character
     (+ ?0 i))))

This maps both C-<kp-num> and M-<kp-num> to the corresponding key bindings with the standard numeric keys.

Upvotes: 1

Drew
Drew

Reputation: 30708

It's a good question. Keys such as <kp-2> are all bound correctly in universal-argument-map to digit-argument. And <kp-subtract> is bound to universal-argument-minus, etc. But the Meta modifier is not taught to handle them wrt universal-argument-map.

I think this is the way to go, but I'm not sure it is the best approach:

 (define-key local-function-key-map [M-kp-2] [?\C-2])

That works, and it seems parallel to other keypad key bindings in local-function-key-map.

BTW, doing this is not enough:

 (define-key universal-argument-map (kbd "<M-kp-2>") 'digit-argument)

Looking forward to other answers. (FWIW, a workaround is to just use ESC <kp-3> instead of <M-kp-3> etc.)

Upvotes: 3

Related Questions