From: Juanma Barranquero <lektu@mi.madritel.es>
Cc: Stefan Monnier <monnier@iro.umontreal.ca>
Subject: Re: Improved help from minibuffer prompts
Date: Sat, 01 May 2004 04:17:46 +0200 [thread overview]
Message-ID: <20040501034809.AEC7.LEKTU@mi.madritel.es> (raw)
In-Reply-To: <jwvhdv13wz0.fsf-monnier+emacs@gnu.org>
On 30 Apr 2004 18:49:42 -0400, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
> Instead, you could hook into describe-function-1 at the place where the
> corresponding text is inserted, at which point you know exactly where that
> text is, without needing any heuristic.
I agree, in principle, and as I said that's what I first tried.
The problem is, describe-function-1 is a big hairy function with a
complex program flow. For starters, there's not a single place where
help-split-fundoc is called inside describe-function-1, but two. There's
also a call to help-make-usage, which, to add fun, does not return a
string but a list which must be first converted. Additionally,
describe-function-1 uses princ to output data to the current buffer,
which must be changed to (with-current-buffer standard-output (insert...))
or otherwise the text attributes are lost...
All in all, I really doubt the result is easier to understand or
maintain. For example, there's a case I've been unable to test, the one
corresponding to ((stringp arglist) arglist) in the cond, because I
don't know of any such function.
AFAICS, the benefits from doing it your way are small:
- No heuristics to determine what's a usage doc and what's simply doc.
OK, but the format of docs is something we control so we can be
reasonably sure it's working, and we can always adapt
help-highlight-arguments if necessary.
- All functions that use describe-function-1 are automatically
highlighted.
The fact is that describe-function-1 is not a public function (it has
no docstring and it's not included on the Emacs Lisp reference
manual); it's only used in describe-function and describe-key. Adding
my initial implementation to both is a matter of adding one line to
describe-function and two lines to describe-key.
I've included below a patch doing it your style (it's a bit weird
because I've had to used diff -b to avoid the effects of a reindent of
some code). I honestly don't find it more robust or better that the
other implementation, but I'll be happy to pursue whatever one is deemed
more acceptable.
/L/e/k/t/u
Index: help-fns.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/help-fns.el,v
retrieving revision 1.40
diff -u -2 -b -r1.40 help-fns.el
--- help-fns.el 29 Apr 2004 18:46:13 -0000 1.40
+++ help-fns.el 1 May 2004 01:59:08 -0000
@@ -131,4 +131,39 @@
;; Functions
+(defun help-do-arg-highlight (doc args)
+ (while args
+ (let ((arg (car args)))
+ (setq args (cdr args))
+ (setq doc (replace-regexp-in-string (concat "\\<\\(" arg "\\)e?s?\\>")
+ (propertize arg 'face 'font-lock-variable-name-face)
+ doc))))
+ doc)
+
+(defun help-highlight-arguments (usage &rest args)
+ (when usage
+ (let* ((case-fold-search nil)
+ (use (car usage))
+ (doc (cdr usage))
+ (next (not args)))
+ ;; Make a list of all arguments
+ (with-temp-buffer
+ (insert use)
+ (goto-char (point-min))
+ ;; Make a list of all arguments
+ (while next
+ (if (not (re-search-forward " \\([\\[(]?\\)\\([^] &)\.]+\\)" nil t))
+ (setq next nil)
+ (setq args (cons (match-string 2) args))
+ (when (string= (match-string 1) "(")
+ ;; A pesky CL-style optional argument with default value,
+ ;; so let's skip over it
+ (search-backward "(")
+ (goto-char (scan-sexps (point) 1)))))
+ ;; Highlight aguments in the USE string
+ (setq use (help-do-arg-highlight (buffer-string) args)))
+ ;; Highlight arguments in the DOC string
+ (setq doc (and doc (help-do-arg-highlight doc args)))
+ (cons use doc))))
+
;;;###autoload
(defun describe-function (function)
@@ -353,10 +390,14 @@
(let* ((arglist (help-function-arglist def))
(doc (documentation function))
- (usage (help-split-fundoc doc function)))
+ (usage (help-highlight-arguments (help-split-fundoc doc function))))
;; If definition is a keymap, skip arglist note.
(unless (keymapp def)
- (princ (cond
+ (with-current-buffer standard-output
+ (insert (cond
(usage (setq doc (cdr usage)) (car usage))
- ((listp arglist) (help-make-usage function arglist))
+ ((listp arglist)
+ (setq doc (help-highlight-arguments (cons (format "%s" (help-make-usage function arglist))
+ doc)))
+ (prog1 (car doc) (setq doc (cdr doc))))
((stringp arglist) arglist)
;; Maybe the arglist is in the docstring of the alias.
@@ -367,10 +408,10 @@
(documentation fun)
function)))))
- usage)
+ (setq usage (help-highlight-arguments usage)))
(car usage))
((or (stringp def)
(vectorp def))
(format "\nMacro: %s" (format-kbd-macro def)))
- (t "[Missing arglist. Please make a bug report.]")))
+ (t "[Missing arglist. Please make a bug report.]"))))
(terpri))
(let ((obsolete (and
@@ -387,5 +428,6 @@
(terpri)))
(terpri)
- (princ (or doc "Not documented.")))))
+ (with-current-buffer standard-output
+ (insert (or doc "Not documented."))))))
\f
next prev parent reply other threads:[~2004-05-01 2:17 UTC|newest]
Thread overview: 59+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-04-13 6:26 Improved help from minibuffer prompts Stefan Reichör
2004-04-13 6:57 ` Miles Bader
2004-04-13 10:48 ` Stefan Reichör
2004-04-14 1:22 ` Miles Bader
2004-04-14 5:35 ` Stefan Reichör
2004-04-14 6:49 ` Miles Bader
2004-04-14 10:04 ` Kim F. Storm
2004-04-14 10:39 ` Stefan Reichör
2004-04-15 16:44 ` Richard Stallman
2004-04-16 6:15 ` Stefan Reichör
2004-04-16 10:04 ` Kim F. Storm
2004-04-16 13:12 ` Kai Grossjohann
2004-04-14 22:53 ` Richard Stallman
2004-04-15 1:23 ` Kim F. Storm
2004-04-16 18:08 ` Richard Stallman
2004-04-14 3:43 ` Masatake YAMATO
2004-04-14 18:02 ` Richard Stallman
2004-04-14 18:02 ` Richard Stallman
2004-04-15 5:50 ` Stefan Reichör
2004-04-16 18:07 ` Richard Stallman
2004-04-16 21:55 ` Kim F. Storm
2004-04-17 19:47 ` Richard Stallman
2004-04-19 7:51 ` Stefan Reichör
2004-04-19 11:50 ` Kim F. Storm
2004-04-29 23:48 ` Juanma Barranquero
2004-04-30 5:32 ` Stefan Reichör
2004-04-30 9:07 ` Juanma Barranquero
2004-05-01 17:51 ` Richard Stallman
2004-05-01 18:33 ` Juanma Barranquero
2004-05-02 19:52 ` Richard Stallman
2004-05-02 22:45 ` Juanma Barranquero
2004-05-03 22:20 ` Richard Stallman
2004-05-06 1:08 ` Juanma Barranquero
2004-05-06 14:13 ` Stefan Monnier
2004-05-07 1:11 ` Juanma Barranquero
2004-05-09 2:03 ` Juanma Barranquero
2004-05-07 0:29 ` Richard Stallman
2004-04-30 10:08 ` Kim F. Storm
2004-04-30 13:39 ` Juanma Barranquero
2004-04-30 15:50 ` Kim F. Storm
2004-04-30 22:20 ` Juanma Barranquero
2004-04-30 15:57 ` Stefan Monnier
2004-04-30 21:28 ` Juanma Barranquero
2004-04-30 22:49 ` Stefan Monnier
2004-05-01 2:17 ` Juanma Barranquero [this message]
2004-05-01 20:23 ` Stefan Monnier
2004-05-02 1:52 ` Juanma Barranquero
2004-05-04 0:32 ` Juanma Barranquero
2004-05-04 20:07 ` Richard Stallman
2004-05-04 22:52 ` Juanma Barranquero
2004-04-19 17:32 ` Drew Adams
2004-04-20 20:47 ` Richard Stallman
2004-04-20 23:13 ` Drew Adams
2004-04-21 6:25 ` Eli Zaretskii
2004-04-19 18:20 ` Richard Stallman
2004-04-16 18:07 ` Richard Stallman
2004-04-15 11:42 ` Matthew Mundell
2004-04-16 6:05 ` Stefan Reichör
2004-04-18 21:47 ` Richard Stallman
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040501034809.AEC7.LEKTU@mi.madritel.es \
--to=lektu@mi.madritel.es \
--cc=monnier@iro.umontreal.ca \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.