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

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

Re: Gud keybindings


From: Emanuel Berg
Subject: Re: Gud keybindings
Date: Thu, 14 Aug 2014 23:13:02 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Yuri Khan <address@hidden> writes:

> That would work but is inelegant. Here in C++ world,
> we don't pay for what we don't use — having each
> keypress of "s" check if Gud is active runs very much
> counter to that principle.

I think it is very fast both to setup and to use. Try
it yourself. Here, I've set it up globally - it would
be better to have it but for the desired modes. And
that can be automatized as well: you setup a defun to
do the changes, and then you send that defun a keymap
argument to specify what mode should be affected. Put a
bunch of those in a list and iterate it, sending the
elements to the defun one by one.

(defvar some-mode nil)
(setq some-mode t)

(global-set-key
 "s"
 (lambda () (interactive) (if some-mode (message "do mode thing")
                            (insert ?s) )))

(global-set-key "s" 'self-insert-command) ; reset

>> If it is, you can write a defun, we-are-debugging
>> which rebinds the keys, and correspondingly
>> no-bugs-left to reset. You can automatize this
>> second part like, if a non-debug key is pressed, it
>> is not only self-inserted, it also disables the
>> debugging keys.
>
> This equates to a global minor mode, doesn’t it?

The example I provided is a minor mode, yes, but you
don't need to do it like that. You can have a defun
that changes the keys (using the current map) and then
another defun that resets them. But - why not make it a
minor mode to get a lighter, proper documentation, and
all?

-- 
underground experts united


reply via email to

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