changeset 47663:e9121795960f

(help-with-tutorial): Use minibuffer-completion-help. (help-split-fundoc): Don't support old syntax any more. (help-add-fundoc-usage): New fun.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Fri, 27 Sep 2002 22:59:41 +0000
parents a6d932b28650
children a0d27828cf39
files lisp/help-fns.el
diffstat 1 files changed, 22 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/help-fns.el	Fri Sep 27 22:32:48 2002 +0000
+++ b/lisp/help-fns.el	Fri Sep 27 22:59:41 2002 +0000
@@ -42,30 +42,13 @@
 If there is a tutorial version written in the language
 of the selected language environment, that version is used.
 If there's no tutorial in that language, `TUTORIAL' is selected.
-With arg, you are asked to choose which language."
+With ARG, you are asked to choose which language."
   (interactive "P")
   (let ((lang (if arg
-		  (let (completion-buffer)
-		    ;; Display a completion list right away
-		    ;; to guide the user.
-		    (with-output-to-temp-buffer "*Completions*"
-		      (display-completion-list
-		       (all-completions "" language-info-alist
-					(lambda (elm)
-					  (and (listp elm) (assq 'tutorial elm)))))
-		      (setq completion-buffer standard-output))
-		    ;; Arrange to set completion-reference-buffer
-		    ;; in *Completions* to point to the minibuffer,
-		    ;; after entering the minibuffer.
 		    (let ((minibuffer-setup-hook minibuffer-setup-hook))
 		      (add-hook 'minibuffer-setup-hook
-				(lambda ()
-				  (let ((mini (current-buffer)))
-				    (with-current-buffer completion-buffer
-				      (make-local-variable 'completion-reference-buffer)
-				      (setq completion-reference-buffer 
-					    mini)))))
-		      (read-language-name 'tutorial "Language: " "English")))
+				'minibuffer-completion-help)
+		      (read-language-name 'tutorial "Language: " "English"))
 		(if (get-language-info current-language-environment 'tutorial)
 		    current-language-environment
 		  "English")))
@@ -182,18 +165,25 @@
   ;; In cases where `function' has been fset to a subr we can't search for
   ;; function's name in the doc string so we use `fn' as the anonymous
   ;; function name instead.
-  (when doc
-    (let* ((rep (prin1-to-string (indirect-function def)))
-	   (name (if (string-match " \\([^ ]+\\)>$" rep)
-		     (match-string 1 rep) (prin1-to-string def))))
-      (if (string-match (format "\n\n(\\(fn\\|%s\\)\\(\\( .*\\)?)\\)\\'"
-				(regexp-quote name))
-			doc)
-	  (cons (format "(%s%s"
-			;; Replace `fn' with the actual function name.
-			(if (consp def) "anonymous" def)
-			(match-string 2 doc))
-		(substring doc 0 (match-beginning 0)))))))
+  (when (and doc (string-match "\n\n(fn\\(\\( .*\\)?)\\)\\'" doc))
+    (cons (format "(%s%s"
+		  ;; Replace `fn' with the actual function name.
+		  (if (consp def) "anonymous" def)
+		  (match-string 1 doc))
+	  (substring doc 0 (match-beginning 0)))))
+
+(defun help-add-fundoc-usage (doc arglist)
+  "Add the usage info to the docstring DOC.
+If DOC already has a usage info, then just return DOC unchanged.
+The usage info is built from ARGLIST.  DOC can be nil."
+  (unless (stringp doc) (setq doc "Not documented"))
+  (if (string-match "\n\n(fn\\(\\( .*\\)?)\\)\\'" doc)
+      doc
+    (format "%s%s%s" doc
+	    (if (string-match "\n?\n\\'" doc)
+		(if (< (- (match-end 0) (match-beginning 0)) 2) "\n")
+	      "\n\n")
+	    (help-make-usage 'fn arglist))))
 
 (defun help-function-arglist (def)
   ;; Handle symbols aliased to other symbols.