From: Kelly Dean <kellydeanch@yahoo.com>
To: emacs-devel@gnu.org
Subject: [PATCH] Unify fn and var help to make learning elisp a little easier
Date: Thu, 6 Dec 2012 10:59:36 -0800 (PST) [thread overview]
Message-ID: <1354820376.62901.YahooMailClassic@web141102.mail.bf1.yahoo.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1305 bytes --]
A new user will often not remember whether a symbol he has in mind is a function or variable, so he doesn't know whether to use C-h f or C-h v to get help for it. For example do I use mark or (mark)? C-h v mark TAB TAB, it's not there, C-g C-h f mark TAB TAB, there it is. Later I'm looking for mark-active and try C-h f first, and again have to cancel and switch. Also, when a symbol is used as both a function and a variable, a new user would want to know about this, but he's not going to find out by using C-h f or C-h v unless he manually tries both every time he looks up something new, which is inconvenient.
A help command which provides completion on both functions and variables, and if a symbol is used as both, shows the help pages for both, solves both problems. The attached patch is a simple union of describe-function and describe-variable to do this. It triggers bug# 13105, but I sent a fix for that.
BTW am I supposed to send little things like this to emacs-devel, or to bug-gnu-emacs, or just post on the wiki? It isn't a bug, but some of the docs say the bug list is also for new features and patches so they can be tracked by bug number, but they also say if a patch needs discussion then it should go to the devel list. Maybe it's superfluous, not worth cluttering Emacs with it.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: descfunorvar.patch --]
[-- Type: text/x-diff; name="descfunorvar.patch", Size: 3385 bytes --]
--- emacs-24.2/lisp/help-fns.el
+++ emacs-24.2/lisp/help-fns.el
@@ -897,6 +897,37 @@
;;;###autoload
+(defun describe-function-or-variable (symbol &optional buffer frame)
+ "Display the full documentation of the function or variable SYMBOL.
+If SYMBOL is a variable and has a buffer-local value in BUFFER or FRAME
+\(default to the current buffer and current frame), it is displayed along
+with the global value."
+ (interactive
+ (let* ((v-or-f (variable-at-point))
+ (found (symbolp v-or-f))
+ (v-or-f (if found v-or-f (function-called-at-point)))
+ (found (or found v-or-f))
+ (enable-recursive-minibuffers t)
+ val)
+ (setq val (completing-read (if found
+ (format
+ "Describe function or variable (default %s): " v-or-f)
+ "Describe function or variable: ")
+ obarray
+ (lambda (vv)
+ (or (fboundp vv)
+ (get vv 'variable-documentation)
+ (and (boundp vv) (not (keywordp vv)))))
+ t nil nil
+ (if found (symbol-name v-or-f))))
+ (list (if (equal val "")
+ v-or-f (intern val)))))
+ (if (not (symbolp symbol)) (message "You didn't specify a function or variable")
+ (unless (buffer-live-p buffer) (setq buffer (current-buffer)))
+ (unless (frame-live-p frame) (setq frame (selected-frame)))
+ (help-xref-interned symbol buffer frame)))
+
+;;;###autoload
(defun describe-syntax (&optional buffer)
"Describe the syntax specifications in the syntax table of BUFFER.
The descriptions are inserted in a help buffer, which is then displayed.
--- emacs-24.2/lisp/help-mode.el
+++ emacs-24.2/lisp/help-mode.el
@@ -627,10 +627,13 @@
\f
;; Additional functions for (re-)creating types of help buffers.
-(defun help-xref-interned (symbol)
+
+;;;###autoload
+(defun help-xref-interned (symbol &optional buffer frame)
"Follow a hyperlink which appeared to be an arbitrary interned SYMBOL.
Both variable, function and face documentation are extracted into a single
-help buffer."
+help buffer. If SYMBOL is a variable, include buffer-local value for optional
+BUFFER or FRAME."
(with-current-buffer (help-buffer)
;; Push the previous item on the stack before clobbering the output buffer.
(help-setup-xref nil nil)
@@ -646,7 +649,7 @@
(get symbol 'variable-documentation))
;; Don't record the current entry in the stack.
(setq help-xref-stack-item nil)
- (describe-variable symbol))))
+ (describe-variable symbol buffer frame))))
(cond
(sdoc
;; We now have a help buffer on the variable.
--- emacs-24.2/lisp/help.el
+++ emacs-24.2/lisp/help.el
@@ -90,6 +90,7 @@
(define-key map "k" 'describe-key)
(define-key map "l" 'view-lossage)
(define-key map "m" 'describe-mode)
+ (define-key map "o" 'describe-function-or-variable)
(define-key map "n" 'view-emacs-news)
(define-key map "p" 'finder-by-keyword)
(define-key map "P" 'describe-package)
@@ -215,6 +216,7 @@
m Display documentation of current minor modes and current major mode,
including their special commands.
n Display news of recent Emacs changes.
+o SYMBOL Display the given function or variable's documentation and value.
p TOPIC Find packages matching a given topic keyword.
r Display the Emacs manual in Info mode.
s Display contents of current syntax table, plus explanations.
next reply other threads:[~2012-12-06 18:59 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-06 18:59 Kelly Dean [this message]
2012-12-07 2:09 ` [PATCH] Unify fn and var help to make learning elisp a little easier Stefan Monnier
2012-12-07 18:12 ` Kelly Dean
2012-12-07 18:30 ` chad
2012-12-07 18:50 ` Stefan Monnier
2012-12-07 19:32 ` [PATCH] Unify fn and var help to make learning elisp a littleeasier Drew Adams
-- strict thread matches above, loose matches on Subject: below --
2012-12-08 19:19 [PATCH] Unify fn and var help to make learning elisp a little easier Kelly Dean
2012-12-22 21:20 ` Dmitry Gutov
2012-12-22 21:43 ` Glenn Morris
2012-12-23 14:35 ` Stefan Monnier
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=1354820376.62901.YahooMailClassic@web141102.mail.bf1.yahoo.com \
--to=kellydeanch@yahoo.com \
--cc=emacs-devel@gnu.org \
/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.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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).