emacs-devel
[Top][All Lists]
Advanced

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

Re: Improved help from minibuffer prompts


From: Juanma Barranquero
Subject: Re: Improved help from minibuffer prompts
Date: Sat, 01 May 2004 00:20:21 +0200

On 30 Apr 2004 17:50:38 +0200, address@hidden (Kim F. Storm) wrote:

> the bracketed (optional) args are not recognized.

I forgot about them. It's just a matter of fixing the regexp.

New iteration attached.

Thanks a lot for testing.

                                                           /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 -r1.40 help-fns.el
--- help-fns.el 29 Apr 2004 18:46:13 -0000      1.40
+++ help-fns.el 30 Apr 2004 22:15:08 -0000
@@ -131,4 +131,33 @@
 ;; Functions
 
+(defun help-highlight-arguments (fun &rest args)
+  (save-excursion
+    (goto-char (point-min))
+    (let* ((case-fold-search nil)
+           (next (and (not args)
+                      (re-search-forward (concat "(" (symbol-name fun)) nil 
t))))
+      (save-restriction
+        (narrow-to-region (point) (re-search-forward ")\n" nil t))
+        (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 all found arguments anywhere in the *Help* buffer
+      (while args
+        (let* ((arg (car args))
+               (solo (concat "\\<\\(" arg "\\)e?s?\\>"))
+               (high (propertize arg 'face 'font-lock-variable-name-face)))
+          (setq args (cdr args))
+          (goto-char (point-min))
+          (while (re-search-forward solo nil t)
+            (replace-match high nil t nil 1)))))))
+
 ;;;###autoload
 (defun describe-function (function)
@@ -156,4 +185,6 @@
        (print-help-return-message)
        (with-current-buffer standard-output
+          ;; highlight argument names
+          (help-highlight-arguments function)
          ;; Return the text we displayed.
          (buffer-string))))))





reply via email to

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