* Strange behavior with major mode specific key bindings
@ 2020-04-24 22:20 Tim Johnson
2020-04-24 22:36 ` Emanuel Berg via Users list for the GNU Emacs text editor
0 siblings, 1 reply; 6+ messages in thread
From: Tim Johnson @ 2020-04-24 22:20 UTC (permalink / raw)
To: MLEmacs
I have customized a key binding for jinja2 mode.
;; In my init.el I have the following
(require 'jinja2-mode)
(require 'tj-mode-custom)
(add-to-list 'auto-mode-alist '("\\.html$" . jinja2-mode))
(add-hook 'jinja2-mode-hook 'tj-jinja2-mode-keys)
;; In tj-mode-custom the following
(defun tj-jinja2-mode-keys ()
"Bindings and for jinja2"
(define-prefix-command 'jinja2-mode-map)
(local-set-key (kbd "C-c") 'jinja2-mode-map)
(define-key jinja2-mode-map "a" 'jinja2-close-tag))
If an .html file is loaded at emacs startup, the following key sequence:
C-c a
invokes jinja2-close-tag
BUT if I open an .html file that is on disk but not preloaded at
startup, OR if I create a new .html file, the single character "a" will
execute the same function.
In other words, now both "C-c a" and "a" are bound to 'jinja2-close-tag,
clobbering 'insert-char
I can observe that the newly opened files are in jinja2 mode.
I do not have similar issues with elpy mode
I am using GNU Emacs 26.3 (build 1, x86_64-pc-linux-gnu, GTK+ Version
2.24.30)
On ubuntu 16.04
thanks
--
Tim
tj49.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Strange behavior with major mode specific key bindings
2020-04-24 22:20 Strange behavior with major mode specific key bindings Tim Johnson
@ 2020-04-24 22:36 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-04-24 22:57 ` Tim Johnson
0 siblings, 1 reply; 6+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2020-04-24 22:36 UTC (permalink / raw)
To: help-gnu-emacs
Tim Johnson wrote:
> (defun tj-jinja2-mode-keys ()
> "Bindings and for jinja2"
> (define-prefix-command 'jinja2-mode-map)
> (local-set-key (kbd "C-c") 'jinja2-mode-map)
> (define-key jinja2-mode-map "a" 'jinja2-close-tag))
... why is it called the same thing? :O
And why set locally for a mode?
And isnt' C-c already a prefix command?
???
This works for me. Just change the Gnus map for the
real, intended, unquoted keymap, and change
the function.
Doesn't that work, no hook needed?
(define-key gnus-group-mode-map "\C-ca" #'gnus-group-unsubscribe-current-group)
--
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Strange behavior with major mode specific key bindings
2020-04-24 22:36 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2020-04-24 22:57 ` Tim Johnson
2020-04-24 23:07 ` Emanuel Berg via Users list for the GNU Emacs text editor
0 siblings, 1 reply; 6+ messages in thread
From: Tim Johnson @ 2020-04-24 22:57 UTC (permalink / raw)
To: help-gnu-emacs
On 4/24/20 2:36 PM, Emanuel Berg via Users list for the GNU Emacs text
editor wrote:
> Tim Johnson wrote:
>
>> (defun tj-jinja2-mode-keys ()
>> "Bindings and for jinja2"
>> (define-prefix-command 'jinja2-mode-map)
>> (local-set-key (kbd "C-c") 'jinja2-mode-map)
>> (define-key jinja2-mode-map "a" 'jinja2-close-tag))
> ... why is it called the same thing? :O
>
> And why set locally for a mode?
>
> And isnt' C-c already a prefix command?
>
> ???
>
> This works for me. Just change the Gnus map for the
> real, intended, unquoted keymap, and change
> the function.
I followed your pattern and it works. Thank you very much.
> Doesn't that work, no hook needed?
Hook **is** needed, else another function is executed with "c-c a"
>
> (define-key gnus-group-mode-map "\C-ca" #'gnus-group-unsubscribe-current-group)
Good work, quick reply. Much gratitude.
cheers
>
--
Tim
tj49.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Strange behavior with major mode specific key bindings
2020-04-24 22:57 ` Tim Johnson
@ 2020-04-24 23:07 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-04-24 23:46 ` Tim Johnson
0 siblings, 1 reply; 6+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2020-04-24 23:07 UTC (permalink / raw)
To: help-gnu-emacs
Tim Johnson wrote:
> I followed your pattern and it works. Thank you
np :)
> Hook **is** needed, else another function is executed
> with "c-c a"
Wierd. Maybe another hook resets it :)
--
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Strange behavior with major mode specific key bindings
2020-04-24 23:07 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2020-04-24 23:46 ` Tim Johnson
2020-04-24 23:48 ` Emanuel Berg via Users list for the GNU Emacs text editor
0 siblings, 1 reply; 6+ messages in thread
From: Tim Johnson @ 2020-04-24 23:46 UTC (permalink / raw)
To: help-gnu-emacs
On 4/24/20 3:07 PM, Emanuel Berg via Users list for the GNU Emacs text
editor wrote:
> Tim Johnson wrote:
>
>> I followed your pattern and it works. Thank you
> np :)
>
>> Hook **is** needed, else another function is executed
>> with "c-c a"
> Wierd. Maybe another hook resets it :)
>
Its org-agenda (found in global-map),
--
Tim
tj49.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Strange behavior with major mode specific key bindings
2020-04-24 23:46 ` Tim Johnson
@ 2020-04-24 23:48 ` Emanuel Berg via Users list for the GNU Emacs text editor
0 siblings, 0 replies; 6+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2020-04-24 23:48 UTC (permalink / raw)
To: help-gnu-emacs
Tim Johnson wrote:
>>> Hook **is** needed, else another function is
>>> executed with "c-c a"
>>
>> Wierd. Maybe another hook resets it :)
>>
>
> Its org-agenda (found in global-map),
Case closed :)
--
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-04-24 23:48 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-24 22:20 Strange behavior with major mode specific key bindings Tim Johnson
2020-04-24 22:36 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-04-24 22:57 ` Tim Johnson
2020-04-24 23:07 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-04-24 23:46 ` Tim Johnson
2020-04-24 23:48 ` Emanuel Berg via Users list for the GNU Emacs text editor
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).