comparison lisp/help-fns.el @ 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 debd2b1e4d08
children 2107f1adf452
comparison
equal deleted inserted replaced
47662:a6d932b28650 47663:e9121795960f
40 (defun help-with-tutorial (&optional arg) 40 (defun help-with-tutorial (&optional arg)
41 "Select the Emacs learn-by-doing tutorial. 41 "Select the Emacs learn-by-doing tutorial.
42 If there is a tutorial version written in the language 42 If there is a tutorial version written in the language
43 of the selected language environment, that version is used. 43 of the selected language environment, that version is used.
44 If there's no tutorial in that language, `TUTORIAL' is selected. 44 If there's no tutorial in that language, `TUTORIAL' is selected.
45 With arg, you are asked to choose which language." 45 With ARG, you are asked to choose which language."
46 (interactive "P") 46 (interactive "P")
47 (let ((lang (if arg 47 (let ((lang (if arg
48 (let (completion-buffer)
49 ;; Display a completion list right away
50 ;; to guide the user.
51 (with-output-to-temp-buffer "*Completions*"
52 (display-completion-list
53 (all-completions "" language-info-alist
54 (lambda (elm)
55 (and (listp elm) (assq 'tutorial elm)))))
56 (setq completion-buffer standard-output))
57 ;; Arrange to set completion-reference-buffer
58 ;; in *Completions* to point to the minibuffer,
59 ;; after entering the minibuffer.
60 (let ((minibuffer-setup-hook minibuffer-setup-hook)) 48 (let ((minibuffer-setup-hook minibuffer-setup-hook))
61 (add-hook 'minibuffer-setup-hook 49 (add-hook 'minibuffer-setup-hook
62 (lambda () 50 'minibuffer-completion-help)
63 (let ((mini (current-buffer))) 51 (read-language-name 'tutorial "Language: " "English"))
64 (with-current-buffer completion-buffer
65 (make-local-variable 'completion-reference-buffer)
66 (setq completion-reference-buffer
67 mini)))))
68 (read-language-name 'tutorial "Language: " "English")))
69 (if (get-language-info current-language-environment 'tutorial) 52 (if (get-language-info current-language-environment 'tutorial)
70 current-language-environment 53 current-language-environment
71 "English"))) 54 "English")))
72 file filename) 55 file filename)
73 (setq filename (get-language-info lang 'tutorial)) 56 (setq filename (get-language-info lang 'tutorial))
180 DEF is the function whose usage we're looking for in DOC." 163 DEF is the function whose usage we're looking for in DOC."
181 ;; Functions can get the calling sequence at the end of the doc string. 164 ;; Functions can get the calling sequence at the end of the doc string.
182 ;; In cases where `function' has been fset to a subr we can't search for 165 ;; In cases where `function' has been fset to a subr we can't search for
183 ;; function's name in the doc string so we use `fn' as the anonymous 166 ;; function's name in the doc string so we use `fn' as the anonymous
184 ;; function name instead. 167 ;; function name instead.
185 (when doc 168 (when (and doc (string-match "\n\n(fn\\(\\( .*\\)?)\\)\\'" doc))
186 (let* ((rep (prin1-to-string (indirect-function def))) 169 (cons (format "(%s%s"
187 (name (if (string-match " \\([^ ]+\\)>$" rep) 170 ;; Replace `fn' with the actual function name.
188 (match-string 1 rep) (prin1-to-string def)))) 171 (if (consp def) "anonymous" def)
189 (if (string-match (format "\n\n(\\(fn\\|%s\\)\\(\\( .*\\)?)\\)\\'" 172 (match-string 1 doc))
190 (regexp-quote name)) 173 (substring doc 0 (match-beginning 0)))))
191 doc) 174
192 (cons (format "(%s%s" 175 (defun help-add-fundoc-usage (doc arglist)
193 ;; Replace `fn' with the actual function name. 176 "Add the usage info to the docstring DOC.
194 (if (consp def) "anonymous" def) 177 If DOC already has a usage info, then just return DOC unchanged.
195 (match-string 2 doc)) 178 The usage info is built from ARGLIST. DOC can be nil."
196 (substring doc 0 (match-beginning 0))))))) 179 (unless (stringp doc) (setq doc "Not documented"))
180 (if (string-match "\n\n(fn\\(\\( .*\\)?)\\)\\'" doc)
181 doc
182 (format "%s%s%s" doc
183 (if (string-match "\n?\n\\'" doc)
184 (if (< (- (match-end 0) (match-beginning 0)) 2) "\n")
185 "\n\n")
186 (help-make-usage 'fn arglist))))
197 187
198 (defun help-function-arglist (def) 188 (defun help-function-arglist (def)
199 ;; Handle symbols aliased to other symbols. 189 ;; Handle symbols aliased to other symbols.
200 (if (and (symbolp def) (fboundp def)) (setq def (indirect-function def))) 190 (if (and (symbolp def) (fboundp def)) (setq def (indirect-function def)))
201 ;; If definition is a macro, find the function inside it. 191 ;; If definition is a macro, find the function inside it.