From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thorsten Jolitz Newsgroups: gmane.emacs.help Subject: Re: How to define minor-mode keybindings conditional on buffer's major-mode? Date: Fri, 04 Oct 2013 17:28:09 +0200 Message-ID: <87li293vjq.fsf@gmail.com> References: <87txgx3zj9.fsf@gmail.com> <87pprl3z07.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1380900528 24017 80.91.229.3 (4 Oct 2013 15:28:48 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 4 Oct 2013 15:28:48 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Oct 04 17:28:50 2013 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1VS7JB-00013X-S0 for geh-help-gnu-emacs@m.gmane.org; Fri, 04 Oct 2013 17:28:49 +0200 Original-Received: from localhost ([::1]:48521 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VS7JB-0001qp-Fz for geh-help-gnu-emacs@m.gmane.org; Fri, 04 Oct 2013 11:28:49 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60712) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VS7Iv-0001qf-Ql for help-gnu-emacs@gnu.org; Fri, 04 Oct 2013 11:28:39 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VS7Ip-0006Mg-QT for help-gnu-emacs@gnu.org; Fri, 04 Oct 2013 11:28:33 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:54497) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VS7Ip-0006MZ-K8 for help-gnu-emacs@gnu.org; Fri, 04 Oct 2013 11:28:27 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1VS7Im-0000jG-VL for help-gnu-emacs@gnu.org; Fri, 04 Oct 2013 17:28:24 +0200 Original-Received: from e178190177.adsl.alicedsl.de ([85.178.190.177]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 04 Oct 2013 17:28:24 +0200 Original-Received: from tjolitz by e178190177.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 04 Oct 2013 17:28:24 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 77 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: e178190177.adsl.alicedsl.de User-Agent: Gnus/5.130002 (Ma Gnus v0.2) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:PzcbqdmwhRHcMJupVWkiJT/diZs= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:93836 Archived-At: Stefan Monnier 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) | "\\ | 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 > "<>" > `(menu-item "" minor-mode-command > :filter ,(lambda (cmd) (if (eq major-mode 'xyz-mode) cmd)))) > (define-key minor-mode-map > "<>" > `(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