From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "Stefan Monnier" Newsgroups: gmane.emacs.devel Subject: Re: |PATCH| describe-minor-mode and describe-minor-mode-from-indicator Date: Mon, 31 Mar 2003 10:51:01 -0500 Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <200303311551.h2VFp1xQ016968@rum.cs.yale.edu> References: <20030330.165124.126582929.jet@gyve.org> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1049126120 29821 80.91.224.249 (31 Mar 2003 15:55:20 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Mon, 31 Mar 2003 15:55:20 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Mon Mar 31 17:55:18 2003 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1901cL-0007iP-00 for ; Mon, 31 Mar 2003 17:54:37 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 1901gE-0005w5-00 for ; Mon, 31 Mar 2003 17:58:38 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 1901ah-0007jQ-00 for emacs-devel@quimby.gnus.org; Mon, 31 Mar 2003 10:52:55 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10.13) id 1901Zt-0007BJ-00 for emacs-devel@gnu.org; Mon, 31 Mar 2003 10:52:05 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10.13) id 1901ZH-0005I7-00 for emacs-devel@gnu.org; Mon, 31 Mar 2003 10:51:31 -0500 Original-Received: from rum.cs.yale.edu ([128.36.229.169]) by monty-python.gnu.org with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.10.13) id 1901Yw-0004o3-00; Mon, 31 Mar 2003 10:51:07 -0500 Original-Received: from rum.cs.yale.edu (localhost [127.0.0.1]) by rum.cs.yale.edu (8.12.8/8.12.8) with ESMTP id h2VFp6Pe016970; Mon, 31 Mar 2003 10:51:06 -0500 Original-Received: (from monnier@localhost) by rum.cs.yale.edu (8.12.8/8.12.8/Submit) id h2VFp1xQ016968; Mon, 31 Mar 2003 10:51:01 -0500 X-Mailer: exmh version 2.4 06/23/2000 with nmh-1.0.4 Original-To: Masatake YAMATO Original-cc: rms@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Emacs development discussions. List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:12763 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:12763 > +(defun describe-minor-mode (minor-mode) > + "Display documentation of a minor mode given as MINOR-MODE." > + (interactive (list (intern (completing-read > + "Minor mode: " > + (delete nil (mapcar > + (function (lambda (x) `function' is not necessary, and it forces too much indendation here. > + (if (eval (car x)) > + (symbol-name (car x))))) I generally believe that `eval' should be avoided. This is especially true here since you call `symbol-name' so you already assume that (car x) is a symbol, so you could just call `symbol-value' instead of `eval'. But note also that nothing guarantees you that (car x) is bound. Finally, I think it's perfectly OK (if not preferable) to list all the minor modes rather than just the currently active ones, so I'd just use (delq nil (mapcar (lambda (x) (symbol-name (car x))) minor-mode-alist)) > +(defun describe-minor-mode-from-indicator (indicator) > + "Display documentation of a minor mode specified by INDICATOR." > + (interactive (list > + (completing-read > + "Minor mode indicator: " > + (delete nil > + (mapcar > + #'(lambda (x) > + (if (eval (car x)) > + (let ((i (expand-minor-mode-indicator-object (cadr x)))) > + (if (and (< 0 (length i)) > + (string= " " (substring i 0 1))) > + (substring i 1) > + i)))) > + minor-mode-alist))))) How about (delq nil (mapcar (lambda (x) (let ((i (format-mode-line x))) (if (> (length i) 0) (if (eq (aref i 0) ?\ ) (substring i 1) i)))) minor-mode-alist)) ? > +(defun lookup-minor-mode-from-indicator (indicator) > + "Return a minor mode symbol from its indicator on the modeline." > + (if (and (< 0 (length indicator)) > + (not (string= " " (substring indicator 0 1)))) > + (setq indicator (concat " " indicator))) I'd rather not assume that indicators start with a space. > +cdr part of a `minor-mode-alist' element(indicator object) is the > +indicator of minor mode that is in car part. Normally indicator > +object is a string. However, in some case it is more compound object > +like cons cell. Actually, minor-mode-alist is a mode-line-spec. So we can simply use `formal-mode-line' to interpret it. > (defvar mode-line-minor-mode-keymap nil "\ > -Keymap to display on major and minor modes.") > +Keymap to display on minor modes.") > + > +(let ((map (make-sparse-keymap))) > + (define-key map [mode-line mouse-2] 'describe-mode) > + (setq mode-line-major-mode-keymap map)) I recommend the use of (defvar foo-map (let ((map (...) (define-key ...) ... map)) I think that the coding cnvention also recommend it. Admittedly, a lot of Emacs code doesn't use it :-( In any case, it seems that your patch removes the "mouse-3 on major mode" behavior that allowed to turn on minor modes by clicking mouse-3 on the major-mode name. I think this is important since it can often happen that there is no active minor-mode on which to click mouse-3. Stefan