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 [solved]T


From: Tim Johnson
Subject: Re: Trapping prefixes with universal argument component [solved]T
Date: Sun, 22 Aug 2021 10:14:43 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0

See bottom:

On 8/22/21 12:13 AM, Yuri Khan wrote:
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)
Dang Dude! You nailed it. Those assignments all work.
Thanks very much. I'm marking this solved and ripping off the duct tape.

Thanks also to Drew, Emanuel and all else who chimed in.
Good work. :)

(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.
This is a mechanical keypad but it is not programmable. I've used xmodmap
a lot in the past but from inspecting xev output, I'm afraid that any reassignment
through xmodmap might also effect the keyboard too.
cheers ...

--
Tim
tj49.com




reply via email to

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