From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: bizarre problem with minor mode defined using define-minor-mode Date: Sun, 16 Jan 2011 01:46:44 -0500 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1295160422 30295 80.91.229.12 (16 Jan 2011 06:47:02 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 16 Jan 2011 06:47:02 +0000 (UTC) Cc: emacs-devel@gnu.org To: ken manheimer Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Jan 16 07:46:58 2011 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PeMO9-0000S9-Rv for ged-emacs-devel@m.gmane.org; Sun, 16 Jan 2011 07:46:58 +0100 Original-Received: from localhost ([127.0.0.1]:49492 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PeMO9-0001pI-52 for ged-emacs-devel@m.gmane.org; Sun, 16 Jan 2011 01:46:57 -0500 Original-Received: from [140.186.70.92] (port=44316 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PeMO1-0001mi-8L for emacs-devel@gnu.org; Sun, 16 Jan 2011 01:46:50 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PeMNz-0001fV-Nq for emacs-devel@gnu.org; Sun, 16 Jan 2011 01:46:49 -0500 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.183]:34589 helo=ironport2-out.pppoe.ca) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PeMNz-0001fG-If for emacs-devel@gnu.org; Sun, 16 Jan 2011 01:46:47 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvsEAPciMk1FxKhC/2dsb2JhbACkaHS8a4VQBIRwjjY X-IronPort-AV: E=Sophos;i="4.60,328,1291611600"; d="scan'208";a="88196266" Original-Received: from 69-196-168-66.dsl.teksavvy.com (HELO pastel.home) ([69.196.168.66]) by ironport2-out.pppoe.ca with ESMTP/TLS/ADH-AES256-SHA; 16 Jan 2011 01:46:45 -0500 Original-Received: by pastel.home (Postfix, from userid 20848) id BBBCB590FC; Sun, 16 Jan 2011 01:46:44 -0500 (EST) In-Reply-To: (ken manheimer's message of "Sun, 16 Jan 2011 01:15:33 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:134594 Archived-At: >> I really can't understand who it could be effective. =A0My reading of the >> code tells me that function binding is never used. > (elisp)Format of Keymaps: "A symbol whose function definition is a > keymap is also a keymap." > minor-mode-map-alist entries of the form `(allout-mode . > allout-mode-map)' apparently tells the emacs key resolution facility > to look in the function value of the symbol in the cdr. that's why > the fset i do works. I'm talking about my reading of the allout.el code: nowhere does your code use the function cell of that variable, AFAICT. I know you *intend* to use it, and I see you set it, but I don't see where it's used (i.e. where you use the symbol as a keymap). >>> in fact, removing the fset leads to the same problems with the >>> regular, defun'ed allout-mode that i have been seeing with the >>> byte-compiled define-minor-mode defined allout mode. >> That's what I would expect, since I think this fset is a no-op. > it's not a no-op! as i said before, removing the fset changed > behavior. as i describe above, there's an explanation. Then, I'm lost. >>> the problem with switching to define-minor-mode is that >>> define-minor-mode apparently associates the mode name with the keymap >>> value, itself, on minor-mode-map-alist. >>=20 >> That's because that's what you told it: >>=20 >> =A0:keymap >>=20 >> says to use the value of as the keymap, so ":keymap >> allout-mode-map" says to use the value of the variable as the keymap. >> If you want to use a symbol, then you need to quote it. > alas, that's apparently not so: Indeed, I misremembered: the :keymap argument is not an expression, it's a funny thing, described in the docstring as: Optional KEYMAP is the default keymap bound to the mode keymap. If non-nil, it should be a variable name (whose value is a keymap), a keymap, or a list of arguments for `easy-mmode-define-keymap'. If KEYMAP is a keymap or list, this also defines the variable MODE-map. And it's not clear at all when/if that thing is evaluated (i.e. if it can be an expression). So if you use `allout-mode-map', it will use the value of that variable, and if you use something else, it will turn it into a keymap, set it as default value of allout-mode-map, and then use the value of allout-mode-map. Since the allout-mode-map is already defined before, this ends up having no effect. Here's a relevant sample of IELM session: ELISP> (macroexpand '(define-minor-mode allout-mode "doc" :keymap 'blabla)) (defvar allout-mode-map (let ((m #1=3D'blabla)) (cond ((keymapp m) m) ((listp m) (easy-mmode-define-keymap m)) (t (error "Invalid keymap %S" #1#)))) "Keymap for `allout-mode'.") (with-no-warnings (add-minor-mode 'allout-mode 'nil allout-mode-map nil n= il))) I suggest to stay away from the :keymap argument. Instead, do it this way: (defvar allout-mode--map ) (defalias 'allout-mode-map allout-mode--map) (defvar allout-mode-map 'allout-mode-map) >> This said, you can modify a keymap after the fact: as long as you don't >> do a (setq allout-mode-map ), you can modify allout-mode-map on >> the fly and those changes will take effect immediately without having to >> use an indirection through the allout-mode-map symbol. > are you suggesting doing a rplacd on the minor-mode-map-alist cell? No, I'm really talking about modifying the keymap itself directly rather than modifying various variables that point to it. E.g. I'm suggesting doing a bunch of define-key only. But if some of your changes involve adding/moving bindings it's more difficult, so you could instead use (setcdr allout-mode-map (cdr newmap)), but that would be ugly. But the above (defvar allout-mode-map 'allout-mode-map) should work much more cleanly. Stefan