From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kevin Rodgers Newsgroups: gmane.emacs.help Subject: Re: List of major modes? // "switch-to-mode"?? Date: Fri, 11 Nov 2005 12:30:51 -0700 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=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1131737664 25304 80.91.229.2 (11 Nov 2005 19:34:24 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 11 Nov 2005 19:34:24 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Nov 11 20:34:22 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1Eaedx-00073A-Is for geh-help-gnu-emacs@m.gmane.org; Fri, 11 Nov 2005 20:33:01 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Eaedw-00040v-V1 for geh-help-gnu-emacs@m.gmane.org; Fri, 11 Nov 2005 14:33:01 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1EaedT-0003yF-2U for help-gnu-emacs@gnu.org; Fri, 11 Nov 2005 14:32:31 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1EaedS-0003x3-93 for help-gnu-emacs@gnu.org; Fri, 11 Nov 2005 14:32:30 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EaedR-0003wN-W4 for help-gnu-emacs@gnu.org; Fri, 11 Nov 2005 14:32:30 -0500 Original-Received: from [80.91.229.2] (helo=ciao.gmane.org) by monty-python.gnu.org with esmtp (TLS-1.0:RSA_AES_128_CBC_SHA:16) (Exim 4.34) id 1EaedR-0005Ey-NP for help-gnu-emacs@gnu.org; Fri, 11 Nov 2005 14:32:30 -0500 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1EaecR-0005xb-PR for help-gnu-emacs@gnu.org; Fri, 11 Nov 2005 20:31:27 +0100 Original-Received: from 207.167.42.60 ([207.167.42.60]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 11 Nov 2005 20:31:27 +0100 Original-Received: from ihs_4664 by 207.167.42.60 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 11 Nov 2005 20:31:27 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-To: help-gnu-emacs@gnu.org Original-Lines: 84 Original-X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: 207.167.42.60 User-Agent: Mozilla Thunderbird 0.9 (X11/20041105) X-Accept-Language: en-us, en In-Reply-To: <87728210-D02C-4129-886F-C2D02891BC06@gmail.com> 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:30999 Archived-At: David Reitter wrote: > Thanks for your help with this. > > Here is my fusion of your code, not using the documentation strings, > but using apropos-internal to speed things up: > > (apropos-internal > "-mode\\'" > (lambda (mode) > (and (commandp mode) > (not (string-match "\\`turn-\\(on\\|off\\)-" > (symbol-name mode))) > (not (assq mode minor-mode-alist))))) > > Here's why I wanted this: > > 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) . In what way is "used interactively" different from `M-x'? What does switch-to-buffer have to do with major modes? You can modify the interactive behavior of any command like this: (defadvice some-command (before weird-interaction activate) "Read arguments with `weird-interaction'." (interactive (weird-interaction))) > Has anyone already written something like this? (or is there an Emacs > function that I don't know of...?) If you want to display the documentation in the *Completions* buffer, it will be returned along with the mode name. But you could then select just the mode name from that: (let* ((major-modes (apropos-internal "-mode\\'" (lambda (mode) (and (commandp mode) (string-match "\\`Major mode\\>" (documentation mode)))))) (completions (mapcar (lambda (mode) (let* ((doc-string (documentation mode)) (text (format "%s (%s)" mode (substring doc-string 0 (string-match "\n" doc-string))))) (list text))) major-modes)) (completed-string (completing-read "Major mode (w/docstring): " completions))) (substring completed-string 0 (string-match " " completed-string))) It would be better if you could associate the docstring as a tool tip over the mode name in the *Completions* buffer, but text properties seem to get removed when the completions are inserted into the buffer: (let* ((major-modes (apropos-internal "-mode\\'" (lambda (mode) (and (commandp mode) (string-match "\\`Major mode\\>" (documentation mode)))))) (completions (mapcar (lambda (mode) (let* ((doc-string (documentation mode)) (tooltip (substring doc-string 0 (string-match "\n" doc-string))) (mode-name (copy-sequence (symbol-name mode)))) (put-text-property 0 (1- (length mode-name)) 'help-echo mode-name) (list mode-name))) major-modes))) (completing-read "Major mode (w/docstring): " completions)) -- Kevin Rodgers