From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.help Subject: RE: List of major modes? // "switch-to-mode"?? Date: Fri, 11 Nov 2005 09:00:18 -0800 Message-ID: References: <87728210-D02C-4129-886F-C2D02891BC06@gmail.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1131728724 29054 80.91.229.2 (11 Nov 2005 17:05:24 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 11 Nov 2005 17:05:24 +0000 (UTC) Cc: David Reitter Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Nov 11 18:05:20 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1EacIk-0000Cd-5A for geh-help-gnu-emacs@m.gmane.org; Fri, 11 Nov 2005 18:02:58 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EacIj-0006Ev-Ep for geh-help-gnu-emacs@m.gmane.org; Fri, 11 Nov 2005 12:02:57 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1EacGN-0005sb-U8 for help-gnu-emacs@gnu.org; Fri, 11 Nov 2005 12:00:32 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1EacGM-0005s5-Ce for Help-gnu-emacs@gnu.org; Fri, 11 Nov 2005 12:00:30 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EacGL-0005rt-J3 for Help-gnu-emacs@gnu.org; Fri, 11 Nov 2005 12:00:29 -0500 Original-Received: from [148.87.122.30] (helo=rgminet01.oracle.com) by monty-python.gnu.org with esmtp (TLS-1.0:DHE_RSA_3DES_EDE_CBC_SHA:24) (Exim 4.34) id 1EacGJ-0002yY-PS for Help-gnu-emacs@gnu.org; Fri, 11 Nov 2005 12:00:29 -0500 Original-Received: from rgmsgw300.us.oracle.com (rgmsgw300.us.oracle.com [138.1.186.49]) by rgminet01.oracle.com (Switch-3.1.6/Switch-3.1.6) with ESMTP id jABH0LHs015069; Fri, 11 Nov 2005 10:00:22 -0700 Original-Received: from rgmsgw300.us.oracle.com (localhost [127.0.0.1]) by rgmsgw300.us.oracle.com (Switch-3.1.7/Switch-3.1.7) with ESMTP id jABH0Lf5023977; Fri, 11 Nov 2005 10:00:21 -0700 Original-Received: from dradamslap (dradams-lap.us.oracle.com [130.35.177.126]) by rgmsgw300.us.oracle.com (Switch-3.1.7/Switch-3.1.7) with SMTP id jABH0ISS023952 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO); Fri, 11 Nov 2005 10:00:18 -0700 Original-To: "Emacs help" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.6604 (9.0.2911.0) X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506 Importance: Normal In-Reply-To: <87728210-D02C-4129-886F-C2D02891BC06@gmail.com> X-Brightmail-Tracker: AAAAAQAAAAI= X-Whitelist: TRUE X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:30990 Archived-At: I'd like to come up with a function switch-to-buffer that could be used interactively instead of M-x, with the advantage that completion would only complete mode names, and it would be able to display a list of modes (together with the first lines of their documentation strings) . Has anyone already written something like this? (or is there an Emacs function that I don't know of...?) I don't really understand what you said about switch-to-buffer or M-x (did you maybe mean `switch-to-mode'?). But, IIUC, the following is close to the rest of what you describe. Users will need library `icicles.el': http://www.emacswiki.org/cgi-bin/emacs/icicles.el. It provides pretty much what you're asking for, out of the box (you need only one line of code). Here's the user interaction: M-x help-on-major-modes prompts you for a mode name. Anything you type is matched against (only) major-mode names. Matching can be literal prefix matching (like normal Emacs completion) or regexp matching. Use `TAB' for the former, `S-TAB' for the latter. That is, hit `S-TAB' or `TAB' at any time to complete your minibuffer input and display the names of all major modes that match it. If the minibuffer is empty (no input) when you do this, then _all_ major-mode names are displayed. The mode names are displayed as completion candidates in buffer *Completions*. You can use the up and down (arrow) keys or the next and prior keys (Page Up/Down) to cycle among the mode names in *Completions*. Up and down use the normal, prefix-completion matching; next and prior use regexp matching. What you're interested in is this: Use `C-o' to display the help on the current candidate (as determined by completion or cycling). That is, use up, down, next, or prior to cycle among the mode names; then use `C-o' to display the help for the mode-name currently highlighted in the list. Or type part of a name, complete it with `TAB' or `S-TAB', and then use `C-o' to display its help. Or, just use `C-up', `C-down', `C-next', or `C-prior' to cycle among the mode names that match your input, showing the help for each one, in turn. For example, press and hold Control while using the down arrow, to display the help for each mode, in turn. If you are interested only in modes whose names contain "font" (anywhere in the name), then type "font" in the minibuffer and hit `S-TAB' (then cycle among the modes with `C-down'). This is similar to the name-matching that `apropos' does, so I call this "apropos completion". If you are interested only in modes whose names start with "toggle", then type "tog" and hit `TAB'. This is the standard, literal prefix completion of Emacs. You asked for just the first line of doc. The code below gives the entire doc for the mode (in buffer *Help*) - but that's close. You can use Icicles to define a command that gives you only the first line of help, if you really need that, but the whole help is available out of the box. If you had not needed to filter the function names to just major-mode names, _no coding at all_ would have been needed. Just use `C-h f', and then cycle among the doc strings of all functions, as described above. To cycle among the functions with "-mode" in their name, just use `C-h f', type "-mode" (or "-mode$", if you want a match only at the end), then `S-TAB', then cycle with `C-down'. The code below just adds your major-mode filter predicate to `completing-read'. Note that command `help-on-major-modes' doesn't do anything interesting with the mode name it reads via `completing-read' - it just shows its help. You can make it do something more interesting, such as activate that mode, and still get the show-help functionality described above. That is, the `C-o' and `C-down' show-help-on-mode-names is independent of what you finally do if the user hits `RET' to choose a mode name. Replace `describe-function' by `funcall' in the code below, and the chosen mode will be activated. For more info on Icicles: http://www.emacswiki.org/cgi-bin/wiki/Icicles. For info on the show-help functionality described here: http://www.emacswiki.org/cgi-bin/wiki/Icicles#HelpOnCandidates. HTH, Drew --------8<----------- ;; Your filter predicate ;; (defun major-mode-p (fn) (and (commandp fn) (string-match "-mode\\'" (symbol-name fn)) (not (string-match "\\`turn-\\(on\\|off\\)-" (symbol-name fn))) (not (assq fn minor-mode-alist)))) ;; One-liner command - it just calls `completing-read' with your filter. ;; (defun help-on-major-modes () "Show help on major modes. `S-TAB' to see all modes matching input. Input-candidate completion and cycling are available. While cycling, these keys show help on the current candidate mode name: `C-o' - Show help on current candidate mode name only `C-down' - Show current, then move to next (prefix-completion) `C-up' - Show current, then move to previous (prefix-completion) `C-next' - Show current, then move to next (apropos-completion) `C-prior' - Show current, then move to previous (apropos-completion) Use `RET' or `C-g' to quit." (interactive) (describe-function (intern (completing-read "Mode: " obarray 'major-mode-p))))