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

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

Re: How to define minor-mode keybindings conditional on buffer's major-m


From: Thorsten Jolitz
Subject: Re: How to define minor-mode keybindings conditional on buffer's major-mode?
Date: Fri, 04 Oct 2013 17:28:09 +0200
User-agent: Gnus/5.130002 (Ma Gnus v0.2) Emacs/24.3 (gnu/linux)

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




reply via email to

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