help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: describe-mode "some-mode"?


From: Drew Adams
Subject: RE: describe-mode "some-mode"?
Date: Sat, 23 Aug 2014 08:29:48 -0700 (PDT)

> >> is there a function like describe-key which describes a mode specified
> >> by the user?
> >>
> >> The docstring of describe-mode says it either describes the mode of the
> >> current buffer or of the buffer given.  How can I get a description of a
> >> mode without enabling the mode in a buffer?
> >
> > Something like this will get you started. For more info (e.g. to include
> > minor-mode info) see the definition of `describe-mode'.  You could also
> > improve the interactive spec, to use completion against major modes or
> > something.
> >
> > (defun my-describe-mode (mode)
> >   (interactive (list (intern (read-string "Mode: "))))
> >   (with-help-window (help-buffer)
> >     (with-current-buffer (help-buffer)
> >       (insert (help-documentation mode nil 'ADD-HELP-BUTTONS)))))
> 
> Warning: the function `help-documentation' is not known to be defined.

My bad.  Sometimes I forget what is provided from emacs -Q and what
is from my code (I should have tested it with emacs -Q).

`help-documentation' is defined in `help-fns+.el'
(http://www.emacswiki.org/emacs-en/download/help-fns%2b.el).  It is
like the vanilla function `documentation', but it uses
`help-substitute-command-keys' so that keys mentioned in the help
become links to their doc.

Using only vanilla functions:

(defun my-describe-mode (mode)
  (interactive (list (intern (read-string "Mode: "))))
  (with-help-window (help-buffer)
    (with-current-buffer (help-buffer)
      (insert (substitute-command-keys (documentation mode))))))

> > On the other hand, it is OK and simple to instead create a temporary
> > buffer, put it in the mode, and use `describe-mode' there.
> 
> Yes, I thought about writing a function to do just that and thought it
> shouldn't be necessary to create a dummy-buffer to see the docstring for
> a particular mode.  Emacs is self-documenting :)
> 
> It seems I'd have to do just that for now ...

(defun my-describe-mode2 (mode)
  (interactive (list (intern (read-string "Mode: "))))
  (with-temp-buffer
    (funcall mode)
    (describe-mode)))

M-x my-describe-mode2 RET emacs-lisp-mode RET



reply via email to

[Prev in Thread] Current Thread [Next in Thread]