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: Commands with more than one keybinding in menus Date: Wed, 14 Aug 2013 15:25:50 +0200 Message-ID: <87bo50jtep.fsf@gmail.com> References: <87ob91i99x.fsf@gmail.com> <871u5wh2jx.fsf@web.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1376486789 18594 80.91.229.3 (14 Aug 2013 13:26:29 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 14 Aug 2013 13:26:29 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Aug 14 15:26:31 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 1V9b5q-0006sA-QF for geh-help-gnu-emacs@m.gmane.org; Wed, 14 Aug 2013 15:26:31 +0200 Original-Received: from localhost ([::1]:51991 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V9b5q-00037m-2g for geh-help-gnu-emacs@m.gmane.org; Wed, 14 Aug 2013 09:26:30 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44707) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V9b5Y-0002wZ-Mz for help-gnu-emacs@gnu.org; Wed, 14 Aug 2013 09:26:18 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V9b5S-0007ew-PW for help-gnu-emacs@gnu.org; Wed, 14 Aug 2013 09:26:12 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:50557) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V9b5S-0007ek-Fw for help-gnu-emacs@gnu.org; Wed, 14 Aug 2013 09:26:06 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1V9b5N-0006XE-Fm for help-gnu-emacs@gnu.org; Wed, 14 Aug 2013 15:26:01 +0200 Original-Received: from g231226251.adsl.alicedsl.de ([92.231.226.251]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 14 Aug 2013 15:26:01 +0200 Original-Received: from tjolitz by g231226251.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 14 Aug 2013 15:26:01 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 157 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: g231226251.adsl.alicedsl.de User-Agent: Gnus/5.130002 (Ma Gnus v0.2) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:6gkldQYUdzGvZF1ku5rvJKkwCrg= 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:92878 Archived-At: Michael Heerdegen writes: > Thorsten Jolitz writes: > >> Its looks good so far, but I could not make easy-menu to show the >> advertised keybindings. The whole thing looks like this: >> >> ,----------------------------------------------------------------------- >> | ;; ** Menus >> | ;; *** Advertise Bindings >> | >> | (put 'outline-cycle :advertised-binding [TAB]) >> | (put 'outshine-cycle-buffer :advertised-binding [BACKTAB]) >> | (put 'outline-promote :advertised-binding [M-S-left]) >> | (put 'outline-demote :advertised-binding [M-S-right]) >> | [...snip...] >> | (put 'outline-up-heading :advertised-binding [M-\# M-u]) >> | (put 'outorg-edit-as-org :advertised-binding [M-\# M-\#]) >> | >> | ;; *** Define Menu >> | >> | (easy-menu-define outshine-menu outline-minor-mode-map "Outshine menu" >> | '("Outshine" >> | ["Cycle Subtree" outline-cycle >> | :active (outline-on-heading-p)] >> | [...snip...] >> | ["Up Heading" outline-up-heading t] >> | "--" >> | ["Edit As Org" outorg-edit-as-org t])) >> | >> | ;; add "Outshine" menu item >> | (easy-menu-add outshine-menu outline-minor-mode-map) >> | ;; get rid of "Outline" menu item >> | (define-key outline-minor-mode-map [menu-bar outline] 'undefined) >> `----------------------------------------------------------------------- >> >> but the advertised bindings don't appear in the menu, either the >> alternative bindings or no bindings at all show up. > > Looks ok to me. But presumably Emacs doesn't match your actual bindings > with the advertised bindings. > > I wonder how the actual bindings are compared with the > :advertised-binding property - equal? (Stefan?) > >> I should mention that I use a specialised macro to define keybindings >> conditional on point position, in order to not mess with user setting >> (this is a minor-mode). > > Please post the according code. Here is the macro (everything that follows is from [[https://github.com/tj64/outshine/blob/master/outshine.el][outshine.el]]): #+begin_src emacs-lisp (defmacro outshine-define-key-with-fallback (keymap key def condition &optional mode) "Define key with fallback. Binds KEY to definition DEF in keymap KEYMAP, the binding is active when the CONDITION is true. Otherwise turns MODE off and re-enables previous definition for KEY. If MODE is nil, tries to recover it by stripping off \"-map\" from KEYMAP name." `(define-key ,keymap ,key (lambda (&optional arg) (interactive "P") (if ,condition ,def (let* ((,(if mode mode (let* ((keymap-str (symbol-name keymap)) (mode-name-end (- (string-width keymap-str) 4))) (if (string= "-map" (substring keymap-str mode-name-end)) (intern (substring keymap-str 0 mode-name-end)) (message "Could not deduce mode name from keymap name") (intern "dummy-sym")) )) nil) (original-func (key-binding ,key))) (condition-case nil (call-interactively original-func) (error nil))))))) #+end_src Here are the principal keybindings (those I want to advertise): #+begin_src emacs-lisp (let ((map outline-minor-mode-map)) ;; Visibility Cycling (outshine-define-key-with-fallback map (kbd "TAB") (outline-cycle arg) (outline-on-heading-p)) (define-key map (kbd "") 'outshine-cycle-buffer) (outshine-define-key-with-fallback map (kbd "M-") (outline-hide-more) (outline-on-heading-p)) (outshine-define-key-with-fallback map (kbd "M-") (outline-show-more) (outline-on-heading-p)) ;; Headline Insertion (outshine-define-key-with-fallback map (kbd "M-RET") (outshine-insert-heading) (outline-on-heading-p)) ;; Structure Editing (outshine-define-key-with-fallback map (kbd "M-S-") (outline-promote) (outline-on-heading-p)) (outshine-define-key-with-fallback map (kbd "M-S-") (outline-demote) (outline-on-heading-p)) (outshine-define-key-with-fallback map (kbd "M-S-") (outline-move-subtree-up) (outline-on-heading-p)) (outshine-define-key-with-fallback map (kbd "M-S-") (outline-move-subtree-down) (outline-on-heading-p)) ;; Motion (define-key map (kbd "M-") 'outline-previous-visible-heading) (define-key map (kbd "M-") 'outline-next-visible-heading)) #+end_src and here an excerpt from the 'alternative' keybindings: #+begin_src emacs-lisp ;; Set the outline-minor-mode-prefix key in your init-file ;; before loading outline-mode (let ((map (lookup-key outline-minor-mode-map outline-minor-mode-prefix))) [...] (define-key map (kbd "I") 'outline-previous-visible-heading) (define-key map (kbd "K") 'outline-next-visible-heading) ;; for use with 'C-c' prefix (define-key map "\C-t" 'hide-body) (define-key map "\C-a" 'show-all) [...] ;; for use with 'M-#' prefix (define-key map "\M-t" 'hide-body) (define-key map "\M-a" 'show-all) [...] #+end_src I don't know how to copy the actual appearance of the "Outshine" menu item, but it looks like this (with 'M-#' being my `outline-minor-mode-prefix' set in my init file): ,---------------------------------- | Previous Visible Heading M-# I | Next Visible Heading M-# K `---------------------------------- and should look somehow like this when advertising works: ,---------------------------------- | Previous Visible Heading M- | Next Visible Heading M- `---------------------------------- -- cheers, Thorsten