From: Kevin Rodgers <ihs_4664@yahoo.com>
Subject: Re: List of major modes? // "switch-to-mode"??
Date: Fri, 11 Nov 2005 12:30:51 -0700 [thread overview]
Message-ID: <dl2rhg$o4r$1@sea.gmane.org> (raw)
In-Reply-To: <87728210-D02C-4129-886F-C2D02891BC06@gmail.com>
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
next prev parent reply other threads:[~2005-11-11 19:30 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-11-11 12:27 List of major modes? // "switch-to-mode"?? David Reitter
2005-11-11 17:00 ` Drew Adams
2005-11-11 18:45 ` David Reitter
2005-11-11 19:04 ` Drew Adams
2005-11-11 19:30 ` Kevin Rodgers [this message]
-- strict thread matches above, loose matches on Subject: below --
2005-11-12 2:09 David Reitter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='dl2rhg$o4r$1@sea.gmane.org' \
--to=ihs_4664@yahoo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).