unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Reporting when keymapping stomped... best approach
@ 2014-06-10 19:15 Grant Rettke
  2014-06-10 19:24 ` Stefan Monnier
  2014-06-12  6:50 ` Kevin Rodgers
  0 siblings, 2 replies; 5+ messages in thread
From: Grant Rettke @ 2014-06-10 19:15 UTC (permalink / raw)
  To: Emacs Help

Good afternoon,

My goal is to issue a warning whenever a keymapping is stomped on my
myself or anyone else. For example, say I replace self-insert for 1
like this:

(global-set-key (kbd "1") 'scheme-mode)

Then I want to look up in the global keymap space whether the desired
key already exists, and if it does, then I want to warn the user what
function was rebound to that keymap. Eg:

(defadvice global-set-key (before check-keymapping activate)
  (let ((key (ad-get-arg 0))
        (command (ad-get-arg 1)))
    (when command
      (warn (concat "Just stomped on a global keymapping bound to: "
command)))))


The only problem is that this doesn't work, as global-undo-tree starts
complaining and I'm not sure where to start looking . Setting
debug-on-error to true doesn't even reveal anything useful.

Where might I start debugging further?

Kind regards,

Grant Rettke | AAAS, ACM, ASA, FSF, IEEE, SIAM, Sigma Xi
gcr@wisdomandwonder.com | http://www.wisdomandwonder.com/
“Wisdom begins in wonder.” --Socrates
((λ (x) (x x)) (λ (x) (x x)))
“Life has become immeasurably better since I have been forced to stop
taking it seriously.” --Thompson



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Reporting when keymapping stomped... best approach
  2014-06-10 19:15 Reporting when keymapping stomped... best approach Grant Rettke
@ 2014-06-10 19:24 ` Stefan Monnier
  2014-06-10 23:56   ` Grant Rettke
  2014-06-12  6:50 ` Kevin Rodgers
  1 sibling, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2014-06-10 19:24 UTC (permalink / raw)
  To: help-gnu-emacs

> (defadvice global-set-key (before check-keymapping activate)
>   (let ((key (ad-get-arg 0))
>         (command (ad-get-arg 1)))
>     (when command
>       (warn (concat "Just stomped on a global keymapping bound to: "
> command)))))

This doesn't check whether the key was already bound.
You'll probably prefer something like

   (defadvice global-set-key (before check-keymapping activate)
     (let* ((key (ad-get-arg 0))
            (command (ad-get-arg 1))
            (old (lookup-key global-map key)))
       (when old
         (message "Replacing %S with %S in global-map"
                  old command))))

and you'll probably also want to advise `define-key' similarly.


        Stefan




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Reporting when keymapping stomped... best approach
  2014-06-10 19:24 ` Stefan Monnier
@ 2014-06-10 23:56   ` Grant Rettke
  0 siblings, 0 replies; 5+ messages in thread
From: Grant Rettke @ 2014-06-10 23:56 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Emacs Help

Thanks so much.

I'll check also if there is something good for a "local-set-key" check.
Grant Rettke | AAAS, ACM, ASA, FSF, IEEE, SIAM, Sigma Xi
gcr@wisdomandwonder.com | http://www.wisdomandwonder.com/
“Wisdom begins in wonder.” --Socrates
((λ (x) (x x)) (λ (x) (x x)))
“Life has become immeasurably better since I have been forced to stop
taking it seriously.” --Thompson


On Tue, Jun 10, 2014 at 2:24 PM, Stefan Monnier
<monnier@iro.umontreal.ca> wrote:
>> (defadvice global-set-key (before check-keymapping activate)
>>   (let ((key (ad-get-arg 0))
>>         (command (ad-get-arg 1)))
>>     (when command
>>       (warn (concat "Just stomped on a global keymapping bound to: "
>> command)))))
>
> This doesn't check whether the key was already bound.
> You'll probably prefer something like
>
>    (defadvice global-set-key (before check-keymapping activate)
>      (let* ((key (ad-get-arg 0))
>             (command (ad-get-arg 1))
>             (old (lookup-key global-map key)))
>        (when old
>          (message "Replacing %S with %S in global-map"
>                   old command))))
>
> and you'll probably also want to advise `define-key' similarly.
>
>
>         Stefan
>
>



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Reporting when keymapping stomped... best approach
  2014-06-10 19:15 Reporting when keymapping stomped... best approach Grant Rettke
  2014-06-10 19:24 ` Stefan Monnier
@ 2014-06-12  6:50 ` Kevin Rodgers
  2014-06-12 17:18   ` Grant Rettke
  1 sibling, 1 reply; 5+ messages in thread
From: Kevin Rodgers @ 2014-06-12  6:50 UTC (permalink / raw)
  To: help-gnu-emacs

On 6/10/14 1:15 PM, Grant Rettke wrote:
> My goal is to issue a warning whenever a keymapping is stomped on my
> myself or anyone else. For example, say I replace self-insert for 1
> like this:
>
> (global-set-key (kbd "1") 'scheme-mode)
>
> Then I want to look up in the global keymap space whether the desired
> key already exists, and if it does, then I want to warn the user what
> function was rebound to that keymap. Eg:
>
> (defadvice global-set-key (before check-keymapping activate)
>    (let ((key (ad-get-arg 0))
>          (command (ad-get-arg 1)))
>      (when command
>        (warn (concat "Just stomped on a global keymapping bound to: "
> command)))))
>
>
> The only problem is that this doesn't work, as global-undo-tree starts
> complaining and I'm not sure where to start looking . Setting
> debug-on-error to true doesn't even reveal anything useful.
>
> Where might I start debugging further?

Stefan already provided the solution, but FYI I think the problem with your 
original attempt is that you try to concat `command' (which is a symbol in most 
cases) to a string.  His solution works because he uses the %S format specifier.

I don't know why setting debug-on-error didn't work as expected.

-- 
Kevin Rodgers
Denver, Colorado, USA




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Reporting when keymapping stomped... best approach
  2014-06-12  6:50 ` Kevin Rodgers
@ 2014-06-12 17:18   ` Grant Rettke
  0 siblings, 0 replies; 5+ messages in thread
From: Grant Rettke @ 2014-06-12 17:18 UTC (permalink / raw)
  To: Kevin Rodgers; +Cc: Emacs Help

Understood, thanks for explaining.
Grant Rettke | AAAS, ACM, ASA, FSF, IEEE, SIAM, Sigma Xi
gcr@wisdomandwonder.com | http://www.wisdomandwonder.com/
“Wisdom begins in wonder.” --Socrates
((λ (x) (x x)) (λ (x) (x x)))
“Life has become immeasurably better since I have been forced to stop
taking it seriously.” --Thompson


On Thu, Jun 12, 2014 at 1:50 AM, Kevin Rodgers
<kevin.d.rodgers@gmail.com> wrote:
> On 6/10/14 1:15 PM, Grant Rettke wrote:
>>
>> My goal is to issue a warning whenever a keymapping is stomped on my
>> myself or anyone else. For example, say I replace self-insert for 1
>> like this:
>>
>> (global-set-key (kbd "1") 'scheme-mode)
>>
>> Then I want to look up in the global keymap space whether the desired
>> key already exists, and if it does, then I want to warn the user what
>> function was rebound to that keymap. Eg:
>>
>> (defadvice global-set-key (before check-keymapping activate)
>>    (let ((key (ad-get-arg 0))
>>          (command (ad-get-arg 1)))
>>      (when command
>>        (warn (concat "Just stomped on a global keymapping bound to: "
>> command)))))
>>
>>
>> The only problem is that this doesn't work, as global-undo-tree starts
>> complaining and I'm not sure where to start looking . Setting
>> debug-on-error to true doesn't even reveal anything useful.
>>
>> Where might I start debugging further?
>
>
> Stefan already provided the solution, but FYI I think the problem with your
> original attempt is that you try to concat `command' (which is a symbol in
> most cases) to a string.  His solution works because he uses the %S format
> specifier.
>
> I don't know why setting debug-on-error didn't work as expected.
>
> --
> Kevin Rodgers
> Denver, Colorado, USA
>
>



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-06-12 17:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-10 19:15 Reporting when keymapping stomped... best approach Grant Rettke
2014-06-10 19:24 ` Stefan Monnier
2014-06-10 23:56   ` Grant Rettke
2014-06-12  6:50 ` Kevin Rodgers
2014-06-12 17:18   ` Grant Rettke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).