From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.bugs Subject: bug#25505: 24.5; doc of `define-minor-mode': incorrect for :keymap Date: Mon, 23 Jan 2017 09:12:00 -0800 (PST) Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1485191600 18512 195.159.176.226 (23 Jan 2017 17:13:20 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 23 Jan 2017 17:13:20 +0000 (UTC) To: 25505@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Jan 23 18:13:15 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cViB5-00043n-7f for geb-bug-gnu-emacs@m.gmane.org; Mon, 23 Jan 2017 18:13:11 +0100 Original-Received: from localhost ([::1]:43386 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cViBA-0000aE-DY for geb-bug-gnu-emacs@m.gmane.org; Mon, 23 Jan 2017 12:13:16 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57491) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cViB0-0000YR-5I for bug-gnu-emacs@gnu.org; Mon, 23 Jan 2017 12:13:10 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cViAw-0003VG-Um for bug-gnu-emacs@gnu.org; Mon, 23 Jan 2017 12:13:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:41121) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cViAw-0003VC-RE for bug-gnu-emacs@gnu.org; Mon, 23 Jan 2017 12:13:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cViAw-0003WI-D0 for bug-gnu-emacs@gnu.org; Mon, 23 Jan 2017 12:13:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Drew Adams Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 23 Jan 2017 17:13:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 25505 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 25505-submit@debbugs.gnu.org id=B25505.148519153013470 (code B ref 25505); Mon, 23 Jan 2017 17:13:02 +0000 Original-Received: (at 25505) by debbugs.gnu.org; 23 Jan 2017 17:12:10 +0000 Original-Received: from localhost ([127.0.0.1]:39319 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cViA6-0003VC-6e for submit@debbugs.gnu.org; Mon, 23 Jan 2017 12:12:10 -0500 Original-Received: from aserp1040.oracle.com ([141.146.126.69]:26075) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cViA4-0003Uz-46 for 25505@debbugs.gnu.org; Mon, 23 Jan 2017 12:12:08 -0500 Original-Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v0NHC1Cl007252 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for <25505@debbugs.gnu.org>; Mon, 23 Jan 2017 17:12:02 GMT Original-Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id v0NHC1Uo026109 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for <25505@debbugs.gnu.org>; Mon, 23 Jan 2017 17:12:01 GMT Original-Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id v0NHC1GL002335 for <25505@debbugs.gnu.org>; Mon, 23 Jan 2017 17:12:01 GMT In-Reply-To: X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 12.0.6753.5000 (x86)] X-Source-IP: userv0022.oracle.com [156.151.31.74] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:128331 Archived-At: Consider this code. Evaluate the defvar, and then try to evaluate each of the define-minor-mode sexps, in turn. The only difference among the mode-defining sexps is whether the :group and :keymap values are quoted or unquoted symbols. (defvar foo-map (let ((map (make-sparse-keymap))) =09=09 (define-key map "q" 'forward-char) =09=09 map) "...") (define-minor-mode foo-mode "..." :global t :group 'convenience :init-value nil :keymap 'foo-map) Debugger entered--Lisp error: (error "Invalid keymap foo-map") signal(error ("Invalid keymap foo-map")) error("Invalid keymap %S" foo-map) (define-minor-mode foo-mode "..." :global t :group convenience :init-value nil :keymap foo-map) Debugger entered--Lisp error: (void-variable convenience) (custom-declare-variable (quote foo-mode) (quote nil) "Non-nil if Foo mod= e is enabled.\nSee the `foo-mode' command\nfor a description of this minor = mode." :set (function custom-set-minor-mode) :initialize (quote custom-init= ialize-default) :group convenience :type (quote boolean)) (define-minor-mode foo-mode "..." :global t :group convenience :init-value nil :keymap 'foo-map) Same error as previous. (define-minor-mode foo-mode "..." :global t :group 'convenience :init-value nil :keymap foo-map) Whew! Success, finally. But it does not correspond to the doc. And the behavior is not consistent. ------ How does Emacs's own Lisp code deal with this? In different ways. Here is allout.el, for example. It DOES use a quoted map-variable (and it jumps through a few hoops). (defvar allout-mode-map 'allout-mode-map "Keybindings place-holder for (allout) outline minor mode. Do NOT set the value of this variable. Instead, customize `allout-command-prefix', `allout-prefixed-keybindings', and `allout-unprefixed-keybindings'.") (defvar allout-mode-map-value nil "Keymap for allout outline minor mode. Do NOT set the value of this variable. Instead, customize `allout-command-prefix', `allout-prefixed-keybindings', and `allout-unprefixed-keybindings'.") ;;;_ =3D make allout-mode-map-value an alias for allout-mode-map: ;; this needs to be revised when the value is changed, sigh. (defalias 'allout-mode-map allout-mode-map-value) (defun allout-institute-keymap (map) "Associate allout-mode bindings with allout as a minor mode." ;; Architecture: ;; allout-mode-map var is a keymap by virtue of being a defalias for ;; allout-mode-map-value, which has the actual keymap value. ;; allout-mode-map's symbol value is just 'allout-mode-map, so it can be ;; used in minor-mode-map-alist to indirect to the actual ;; allout-mode-map-var value, which can be adjusted and reassigned. ;; allout-mode-map-value for keymap reference in various places: (setq allout-mode-map-value map) ;; the function value keymap of allout-mode-map is used in ;; minor-mode-map-alist - update it: (fset allout-mode-map allout-mode-map-value)) (define-minor-mode allout-mode "..." :lighter " Allout" :keymap 'allout-mode-map ...) Next up: autoarg-mode. This uses an UNquoted map variable. (defvar autoarg-mode-map (let ((map (make-sparse-keymap))) ... (define-key map " " 'autoarg-terminate) map) "Keymap for Autoarg mode.") (define-minor-mode autoarg-mode "..." nil " Aarg" autoarg-mode-map :global t :group 'keyboard) Those are only the first two grep hits for `define-minor-mode'. Isn't this more than a doc bug? Why should the :group value be evaluated but not the :keymap value? At any rate, none of the current behavior in this regard is documented. Users need to experiment to find out what the real story is. Am I missing something? `define-minor-mode' has been around since at least Emacs 22. Has this behavior inconsistency and missing doc never been noticed before?