* How to define minor-mode keybindings conditional on buffer's major-mode?
@ 2013-10-04 14:02 Thorsten Jolitz
2013-10-04 14:13 ` Thorsten Jolitz
0 siblings, 1 reply; 6+ messages in thread
From: Thorsten Jolitz @ 2013-10-04 14:02 UTC (permalink / raw)
To: help-gnu-emacs
Hi List,
assume in a program in minor-mode is activated for a buffer that can
have one of two different major-mode, and different keybindings are
needed for each major-mode to avoid conflicts.
Here is a kind of "emacs lisp pseudocode" that shows the logic, but
can't work of course:
,----------------------------------------------------------
| (define-key minor-mode-map
| (if (eq major-mode 'xyz-mode) "<<key-binding1>>" "<<key-binding1>>" )
| 'minor-mode-command)
`----------------------------------------------------------
How can this be achieved?
--
cheers,
Thorsten
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to define minor-mode keybindings conditional on buffer's major-mode?
2013-10-04 14:02 How to define minor-mode keybindings conditional on buffer's major-mode? Thorsten Jolitz
@ 2013-10-04 14:13 ` Thorsten Jolitz
2013-10-04 14:27 ` Stefan Monnier
0 siblings, 1 reply; 6+ messages in thread
From: Thorsten Jolitz @ 2013-10-04 14:13 UTC (permalink / raw)
To: help-gnu-emacs
Thorsten Jolitz <tjolitz@gmail.com> writes:
ok, sometimes spellchecking would not hurt: this should be more readable
than the first version:
"assume in a program a minor-mode is activated for a buffer that can
have one of two different major-mode, and different keybindings are
needed for each major-mode to avoid conflicts.
Here is a kind of "emacs lisp pseudocode" that shows the logic, but
can't work of course:
,----------------------------------------------------------
| (define-key minor-mode-map
| (if (eq major-mode 'xyz-mode) "<<key-binding1>>" "<<key-binding2>>" )
| 'minor-mode-command)
`----------------------------------------------------------
How can this be achieved?"
--
cheers,
Thorsten
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to define minor-mode keybindings conditional on buffer's major-mode?
2013-10-04 14:13 ` Thorsten Jolitz
@ 2013-10-04 14:27 ` Stefan Monnier
2013-10-04 15:28 ` Thorsten Jolitz
0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2013-10-04 14:27 UTC (permalink / raw)
To: help-gnu-emacs
> How can this be achieved?"
You can define two keymaps (probably inheriting from a third one that
contains the shared stuff), and then in the minor-mode function, setup
minor-mode-overriding-map-alist to use the right one.
Or you can do truly evil things like
(define-key minor-mode-map
"<<key-binding1>>"
`(menu-item "" minor-mode-command
:filter ,(lambda (cmd) (if (eq major-mode 'xyz-mode) cmd))))
(define-key minor-mode-map
"<<key-binding2>>"
`(menu-item "" minor-mode-command
:filter ,(lambda (cmd) (if (not (eq major-mode 'xyz-mode)) cmd))))
-- Stefan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to define minor-mode keybindings conditional on buffer's major-mode?
2013-10-04 14:27 ` Stefan Monnier
@ 2013-10-04 15:28 ` Thorsten Jolitz
2013-10-04 22:26 ` Stefan Monnier
0 siblings, 1 reply; 6+ messages in thread
From: Thorsten Jolitz @ 2013-10-04 15:28 UTC (permalink / raw)
To: help-gnu-emacs
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> How can this be achieved?"
>
> You can define two keymaps (probably inheriting from a third one that
> contains the shared stuff), and then in the minor-mode function, setup
> minor-mode-overriding-map-alist to use the right one.
That is the way I want to go - but I don't get it, unfortunatly
I find examples like this on the web:
,---------------------------------------------------------------------------------------
| (defun ergoemacs-minibuffer-setup-hook ()
| "Hook for minibuffer to move through history with previous-line and next-line keys."
|
| (defvar ergoemacs-minibuffer-keymap (copy-keymap ergoemacs-keymap))
|
| (define-key ergoemacs-minibuffer-keymap ergoemacs-previous-line-key
| 'previous-history-element)
|
| [...]
| (add-to-list 'minor-mode-overriding-map-alist (cons 'ergoemacs-mode
| ergoemacs-minibuffer-keymap)) )
`---------------------------------------------------------------------------------------
so, is it as simple as putting something like this
,----------------------------------------------
| (progn
| (add-to-list 'minor-mode-overriding-map-alist
| (cons 'major-mode-A A-specific-keymap))
| (add-to-list 'minor-mode-overriding-map-alist
| (cons 'major-mode-B B-specific-keymap)) )
`----------------------------------------------
at the end of this definition
,-----------------------------------------------------------
| (defun w3m-form-input-textarea-mode (&optional arg)
| "\\<w3m-form-input-textarea-map>
| Minor mode to edit form textareas of w3m.
|
| \\[w3m-form-input-textarea-set]\
| Set the value and exit from this textarea.
| \\[w3m-form-input-textarea-exit]\
| Exit from this textarea without setting the value.
| \\[w3m-form-input-textarea-save]\
| Save editing data in this textarea.
| "
| (interactive "P")
| (when (setq w3m-form-input-textarea-mode
| (if arg
| (> (prefix-numeric-value arg) 0)
| (not w3m-form-input-textarea-mode)))
| (run-hooks 'w3m-form-input-textarea-mode-hook)))
`-----------------------------------------------------------
?
> Or you can do truly evil things like
>
> (define-key minor-mode-map
> "<<key-binding1>>"
> `(menu-item "" minor-mode-command
> :filter ,(lambda (cmd) (if (eq major-mode 'xyz-mode) cmd))))
> (define-key minor-mode-map
> "<<key-binding2>>"
> `(menu-item "" minor-mode-command
> :filter ,(lambda (cmd) (if (not (eq major-mode 'xyz-mode)) cmd))))
I rather try not to be evil in this case ...
--
cheers,
Thorsten
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to define minor-mode keybindings conditional on buffer's major-mode?
2013-10-04 15:28 ` Thorsten Jolitz
@ 2013-10-04 22:26 ` Stefan Monnier
2013-10-05 8:03 ` Thorsten Jolitz
0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2013-10-04 22:26 UTC (permalink / raw)
To: help-gnu-emacs
> so, is it as simple as putting something like this
> ,----------------------------------------------
> | (progn
> | (add-to-list 'minor-mode-overriding-map-alist
> | (cons 'major-mode-A A-specific-keymap))
> | (add-to-list 'minor-mode-overriding-map-alist
> | (cons 'major-mode-B B-specific-keymap)) )
> `----------------------------------------------
No, you'd put
(add-to-list 'minor-mode-overriding-map-alist
(cons 'my-minor-mode (if (eq major-mode 'xyz-mode)
xyz-specific-map
other-minor-map)))
in your minor mode function. Or
(when (eq major-mode 'xyz-mode)
(add-to-list 'minor-mode-overriding-map-alist
(cons 'my-minor-mode xyz-specific-map)))
-- Stefan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to define minor-mode keybindings conditional on buffer's major-mode?
2013-10-04 22:26 ` Stefan Monnier
@ 2013-10-05 8:03 ` Thorsten Jolitz
0 siblings, 0 replies; 6+ messages in thread
From: Thorsten Jolitz @ 2013-10-05 8:03 UTC (permalink / raw)
To: help-gnu-emacs
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> so, is it as simple as putting something like this
>
>> ,----------------------------------------------
>> | (progn
>> | (add-to-list 'minor-mode-overriding-map-alist
>> | (cons 'major-mode-A A-specific-keymap))
>> | (add-to-list 'minor-mode-overriding-map-alist
>> | (cons 'major-mode-B B-specific-keymap)) )
>> `----------------------------------------------
>
> No, you'd put
>
> (add-to-list 'minor-mode-overriding-map-alist
> (cons 'my-minor-mode (if (eq major-mode 'xyz-mode)
> xyz-specific-map
> other-minor-map)))
>
> in your minor mode function. Or
>
> (when (eq major-mode 'xyz-mode)
> (add-to-list 'minor-mode-overriding-map-alist
> (cons 'my-minor-mode xyz-specific-map)))
Thanks, that works - the doc for 'minor-mode-overriding-map-alist' is
actually a bit sparse (or I'm a bit thick ;)
BTW - I just sent a patch (not yet accepted and applied at the time of
this writing) to the emacs-w3m maintainer that adds functionality to the
textarea section of w3m-form.el - which opens a dedicated, minimal size
text-mode edit buffer for the content of a html textarea by default -
for editing textareas containing text in Org-mode syntax in a
(full-size) Org-mode edit buffer.
You can use `w3m-form-textarea-toggle-major-mode' to toggle between
'text-mode and 'org-mode as major modes for the edit buffer. Since the
original keybindings for 'text-mode clash with important Org-mode
keybindings, a specialised keymap is activated for the 'org-mode case.
This makes emacs-w3m a very good Emacs UI for interactive web apps based
on Org-mode markup syntax - to be announced soon, I hope.
--
cheers,
Thorsten
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-10-05 8:03 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-04 14:02 How to define minor-mode keybindings conditional on buffer's major-mode? Thorsten Jolitz
2013-10-04 14:13 ` Thorsten Jolitz
2013-10-04 14:27 ` Stefan Monnier
2013-10-04 15:28 ` Thorsten Jolitz
2013-10-04 22:26 ` Stefan Monnier
2013-10-05 8:03 ` Thorsten Jolitz
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.