diff options
| -rw-r--r-- | lisp/help-fns.el | 54 |
1 files changed, 22 insertions, 32 deletions
diff --git a/lisp/help-fns.el b/lisp/help-fns.el index 8f5510c01a9..245bbd0e8d0 100644 --- a/lisp/help-fns.el +++ b/lisp/help-fns.el | |||
| @@ -42,30 +42,13 @@ | |||
| 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"))) |
| @@ -182,18 +165,25 @@ DEF is the function whose usage we're looking for in DOC." | |||
| 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. |