help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trapping prefixes with universal argument component


From: Yuri Khan
Subject: Re: Trapping prefixes with universal argument component
Date: Sun, 22 Aug 2021 15:13:47 +0700

On Sun, 22 Aug 2021 at 06:30, Emanuel Berg via Users list for the GNU
Emacs text editor <help-gnu-emacs@gnu.org> wrote:

> Try this then ... should work
>
>   (global-set-key [M-kp-0] nil)

Binding the offending key to nil isn’t going to help because when
Emacs sees this (lack of) binding it will just proceed to key
translation. And kp-0 translates to 0 and M-0 is bound to
universal-argument.

Instead:

    (global-set-key (kbd "<M-kp-0>") 'ignore)
    (global-set-key (kbd "<M-kp-1>") 'ignore)
    (global-set-key (kbd "<M-kp-4>") 'ignore)
    (global-set-key (kbd "<M-kp-6>") 'ignore)

Alternatively:

    (defun my-insert-open-paren ()
      (interactive)
      (let ((last-command-event ?\())
        (call-interactively 'self-insert-command)))
    (defun my-insert-close-paren ()
      (interactive)
      (let ((last-command-event ?\)))
        (call-interactively 'self-insert-command)))
    (defun my-insert-equal ()
      (interactive)
      (let ((last-command-event ?=))
        (call-interactively 'self-insert-command)))

    (global-set-key (kbd "<M-kp-0> <M-kp-4> <M-kp-0>") 'my-insert-open-paren)
    (global-set-key (kbd "<M-kp-0> <M-kp-4> <M-kp-1>") 'my-insert-close-paren)
    (global-set-key (kbd "<M-kp-0> <M-kp-6> <M-kp-1>") 'my-insert-equal)

(Why not (insert "(")? Because self-insert-command also handles the
numeric prefix argument, is affected by overwrite-mode, expands
abbreviations, and does a lot of other things.)


The “correct” solution, of course, would be to reprogram the keypad so
it sends different key codes, such as Shift+9, Shift+0, and = (or
whatever is appropriate for one’s national keyboard layout), or if the
device does not allow reprogramming, then harvest key switches and
build one that does ;) Plenty of macropad kits on the market right
now, some based on Free firmwares such as TMK or QMK.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]