From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stephen Leake Newsgroups: gmane.emacs.devel Subject: Re: invoke a keyboard menu map from lisp? Date: Wed, 26 Aug 2015 22:18:40 -0500 Message-ID: <86wpwhiflb.fsf@stephe-leake.org> References: <86egipk9tu.fsf@stephe-leake.org> <878u8xbhev.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1440645562 8288 80.91.229.3 (27 Aug 2015 03:19:22 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 27 Aug 2015 03:19:22 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Aug 27 05:19:10 2015 Return-path: Envelope-to: ged-emacs-devel@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 1ZUniX-00015z-EK for ged-emacs-devel@m.gmane.org; Thu, 27 Aug 2015 05:19:09 +0200 Original-Received: from localhost ([::1]:51652 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUniW-0003jo-PZ for ged-emacs-devel@m.gmane.org; Wed, 26 Aug 2015 23:19:08 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53583) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUniF-0003jK-UT for emacs-devel@gnu.org; Wed, 26 Aug 2015 23:18:52 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZUniC-0000ox-Ol for emacs-devel@gnu.org; Wed, 26 Aug 2015 23:18:51 -0400 Original-Received: from gproxy10-pub.mail.unifiedlayer.com ([69.89.20.226]:39504) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1ZUniC-0000og-In for emacs-devel@gnu.org; Wed, 26 Aug 2015 23:18:48 -0400 Original-Received: (qmail 23682 invoked by uid 0); 27 Aug 2015 03:18:47 -0000 Original-Received: from unknown (HELO CMOut01) (10.0.90.82) by gproxy10.mail.unifiedlayer.com with SMTP; 27 Aug 2015 03:18:47 -0000 Original-Received: from host114.hostmonster.com ([74.220.207.114]) by CMOut01 with id 9fJj1r0092UdiVW01fJmlD; Wed, 26 Aug 2015 21:18:46 -0600 X-Authority-Analysis: v=2.1 cv=EbVbHpWC c=1 sm=1 tr=0 a=CQdxDb2CKd3SRg4I0/XZPQ==:117 a=CQdxDb2CKd3SRg4I0/XZPQ==:17 a=DsvgjBjRAAAA:8 a=f5113yIGAAAA:8 a=9i_RQKNPAAAA:8 a=y7kgw_RnJtkA:10 a=IkcTkHD0fZMA:10 a=hEr_IkYJT6EA:10 a=x_XPkuGwIRMA:10 a=uRRa74qj2VoA:10 a=pGLkceISAAAA:8 a=drMCGqYuufiPiAPvuQEA:9 a=IiZM3cB7sUgz_xYS:21 a=FVYufUk9b1Haqllh:21 a=QEXdDO2ut3YA:10 Original-Received: from [76.218.37.33] (port=58472 helo=TAKVER2) by host114.hostmonster.com with esmtpa (Exim 4.84) (envelope-from ) id 1ZUni7-0002Xm-Tk for emacs-devel@gnu.org; Wed, 26 Aug 2015 21:18:44 -0600 In-Reply-To: <878u8xbhev.fsf@gmail.com> (Alexis's message of "Thu, 27 Aug 2015 12:21:12 +1000") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (windows-nt) X-Identified-User: {2442:host114.hostmonster.com:stephele:stephe-leake.org} {sentby:smtp auth 76.218.37.33 authed with stephen_leake@stephe-leake.org} X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 69.89.20.226 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:189211 Archived-At: Alexis writes: > Stephen Leake writes: > >> I'm trying to build a keyboard menu keymap on the fly, and then >> invoke it. I've gotten this far: >> >> (defun dvc-offer-choices (comment choices) "Present user with a >> choice of actions, labeled by COMMENT. CHOICES is a list of pairs >> containing (function description)." ;; Build a keyboard menu >> keymap (let ((i 0) (map (make-sparse-keymap "actions")) choice) >> (unless (< (length choices) 10) (error "=E2=80=98dvc-offer-choices= =E2=80=99 >> only supports up to 10 choices")) >> >> (while choices (setq choice (pop choices)) (define-key map >> (int-to-string i) (list menu-item (format "%d) %s" i >> (cadr choice)) (car choice)))) ;; FIXME: invoke the map )) >> >> But I can't find the function that executes the keymap. > > Is setting the value of `overriding-local-map` perhaps what you want? (now set-transient-map) Close. This emulates a menu keymap: (defun dvc-offer-choices (comment choices) "Execute a keyboard menu built from COMMENT, CHOICES. CHOICES is a list of pairs (function description)." ;; I can't find the code that executes a real keyboard menu; this is ;; close. (popup-menu map) works, but is not a keyboard menu (let ((i 0) (msg (if comment comment "")) (map (make-sparse-keymap)) choice) (unless (< (length choices) 10) (error "=E2=80=98dvc-offer-choices=E2=80=99 only supports up to 10 ch= oices")) (while choices (setq choice (pop choices)) (setq msg (concat msg (format "%d) %s " i (cadr choice)))) (define-key map (int-to-string i) (car choice)) (setq i (1+ i))) (message msg) (set-transient-map map) )) Good enough for my use cases, which all have only a few choices. --=20 -- Stephe