Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Disabling M-q

14 views
Skip to first unread message

Cecil Westerhof

unread,
May 15, 2013, 11:31:31 AM5/15/13
to
A friend asked how to disable M-q. My first thought was:
(local-unset-key (kbd "\M-q"))
or
(local-set-key (kbd "M-q") nil)

But both did not work. I am now using:
(local-set-key (kbd "M-q") "")

and this works. Is this the best way, or is there a better way?

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Yuri Khan

unread,
May 15, 2013, 10:59:26 PM5/15/13
to Cecil Westerhof, help-gn...@gnu.org
On Wed, May 15, 2013 at 10:31 PM, Cecil Westerhof <Ce...@decebal.nl> wrote:
> A friend asked how to disable M-q. My first thought was:
> (local-unset-key (kbd "\M-q"))
> or
> (local-set-key (kbd "M-q") nil)

You need to unset the key in the map that sets it, or override it with
another function in a higher-priority map (as you do below with the
empty string, which is not a proper function).

> But both did not work. I am now using:
> (local-set-key (kbd "M-q") "")
>
> and this works. Is this the best way, or is there a better way?

You could bind the `ignore' function discussed recently on this list.

B. T. Raven

unread,
May 18, 2013, 12:43:46 AM5/18/13
to

> A friend asked how to disable M-q. My first thought was:
> (local-unset-key (kbd "\M-q"))
> or
> (local-set-key (kbd "M-q") nil)
>
> But both did not work. I am now using:
> (local-set-key (kbd "M-q") "")
>
> and this works. Is this the best way, or is there a better way?
>

How about either

(global-unset-key [(meta q)]

or

(local-unset-key [(meta q)]

??

Emanuel Berg

unread,
May 18, 2013, 6:26:07 AM5/18/13
to
I wrote a couple of lines you can experiment with. Use `C-h w' for the
functions and `C-x C-e' to change keybinding.

The local binding will shadow the global. If the global is shadowed,
it won't report any key on `C-h w'. But, as soon as you unset the
local, or set it to the nils, the global is back on. When the local is
set to the empty string, the shadow is on (i.e., the global is off)
only this "shadow" doesn't do anything.

Like I said, play around with it.

(defun test-message-local () (interactive) (message "local check"))
(defun test-message-global () (interactive) (message "global check"))
(global-unset-key (kbd "C-M-w")) ; either unset both
(local-unset-key (kbd "C-M-w"))
(global-set-key (kbd "C-M-w") 'test-message-global) ; test C-h w here
(local-set-key (kbd "C-M-w") 'test-message-local) ; shadows global
(local-set-key (kbd "C-M-w") nil) ; these four - global *on*
(local-set-key (kbd "C-M-w") 'nil)
(local-set-key (kbd "C-M-w") ())
(local-set-key (kbd "C-M-w") '())
(local-set-key (kbd "C-M-w") "") ; this - local "nothing" shadow

--
Emanuel Berg - programmer (hire me! CV below)
computer projects: http://user.it.uu.se/~embe8573
internet activity: http://home.student.uu.se/embe8573

B. T. Raven

unread,
May 18, 2013, 1:44:13 PM5/18/13
to


> "B. T. Raven" <btr...@nihilo.net> writes:
>
>>> A friend asked how to disable M-q. My first thought was:
>>> (local-unset-key (kbd "\M-q"))

This was the original question. Should M be escaped in a string here?
Did you try the vector description of "M-q"? I notice that (kbd <key>...
returns a specific vector but the vector [(meta q)] just evaluates to
itself. Have you tried:

(define-key (current-local-map) [(meta q)] nil)

??

Cecil Westerhof

unread,
May 21, 2013, 4:21:08 AM5/21/13
to
Op zaterdag 18 mei 2013 19:44 CEST schreef B. T. Raven:

> This was the original question. Should M be escaped in a string
> here? Did you try the vector description of "M-q"? I notice that
> (kbd <key>... returns a specific vector but the vector [(meta q)]
> just evaluates to itself. Have you tried:
>
> (define-key (current-local-map) [(meta q)] nil)

Does not work either, but
(local-set-key (kbd "M-q") 'ignore)
does.

Cecil Westerhof

unread,
May 21, 2013, 4:13:22 AM5/21/13
to
Op donderdag 16 mei 2013 04:59 CEST schreef Yuri Khan:
I have tried (I am not using it):
(local-set-key (kbd "M-q") 'ignore)

and it works. I send the improved solution to my friend.

Drew Adams

unread,
May 21, 2013, 12:44:16 PM5/21/13
to Cecil Westerhof, help-gn...@gnu.org
> (define-key (current-local-map) [(meta q)] nil) Does not work either

You must use [(meta ?q)], not [(meta q)].

B. T. Raven

unread,
May 21, 2013, 12:57:10 PM5/21/13
to

> Op zaterdag 18 mei 2013 19:44 CEST schreef B. T. Raven:
>
>> This was the original question. Should M be escaped in a string
>> here? Did you try the vector description of "M-q"? I notice that
>> (kbd <key>... returns a specific vector but the vector [(meta q)]
>> just evaluates to itself. Have you tried:
>>
>> (define-key (current-local-map) [(meta q)] nil)
>
> Does not work either, but
> (local-set-key (kbd "M-q") 'ignore)
> does.
>

It's weird that both you and the third party are having the same
problem. If one of you tries the same experiments on an emacs -Q
invocation, does the problem disappear?

Ed


Cecil Westerhof

unread,
May 21, 2013, 2:35:14 PM5/21/13
to
Op dinsdag 21 mei 2013 18:44 CEST schreef Drew Adams:

>> (define-key (current-local-map) [(meta q)] nil) Does not work
>> either
>
> You must use [(meta ?q)], not [(meta q)].

Does not work either. I'll try with -Q as in the other post.
On the other hand I do not find
(local-set-key (kbd "M-q") 'ignore)

less clear. I even think it is more clear. Or is there a reason to
prefer this solution above the ignore solution?

B. T. Raven

unread,
May 21, 2013, 4:44:37 PM5/21/13
to

>> (define-key (current-local-map) [(meta q)] nil) Does not work either
>
> You must use [(meta ?q)], not [(meta q)].
>


I've seen that in the docs but it doesn't seem to matter (with ver.
23.3). In my .emacs (together with a couple of dozen other similar
forms) I have:

(global-set-key [(meta super s)] 'search-forward-regexp)

This works and C-hf search-forward-regexp shows this:

"
search-forward-regexp is an interactive built-in function in
`subr.el'.

It is bound to M-s-s.

(search-forward-regexp REGEXP &optional BOUND NOERROR COUNT)
"

But maybe I've just been lucky not to have something masking the ?q
interpretation of q. Anyway it seems to work without specifying that q
is a char.


Ed

Drew Adams

unread,
May 22, 2013, 10:59:04 AM5/22/13
to B. T. Raven, help-gn...@gnu.org
> > You must use [(meta ?q)], not [(meta q)].
>
> I've seen that in the docs but it doesn't seem to matter (with ver. 23.3).

I guess you're right. That seems to be the case from at least Emacs 22 on (perhaps earlier too). I wasn't aware of that (or forgot it).

0 new messages