Mercurial > hg > xemacs-beta
annotate lisp/help.el @ 5940:c608d4b0b75e cygwin64 tip
rescue lost branch from 64bit.backup
author | Henry Thompson <ht@markup.co.uk> |
---|---|
date | Thu, 16 Dec 2021 18:48:58 +0000 |
parents | cf0201de66df |
children |
rev | line source |
---|---|
3368 | 1 ;; help.el --- help commands for XEmacs. |
428 | 2 |
5793
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
3 ;; Copyright (C) 1985, 1986, 1992-4, 1997, 2014 Free Software Foundation, Inc. |
5070
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
4 ;; Copyright (C) 2001, 2002, 2003, 2010 Ben Wing. |
428 | 5 |
6 ;; Maintainer: FSF | |
7 ;; Keywords: help, internal, dumped | |
8 | |
9 ;; This file is part of XEmacs. | |
10 | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5182
diff
changeset
|
11 ;; XEmacs is free software: you can redistribute it and/or modify it |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5182
diff
changeset
|
12 ;; under the terms of the GNU General Public License as published by the |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5182
diff
changeset
|
13 ;; Free Software Foundation, either version 3 of the License, or (at your |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5182
diff
changeset
|
14 ;; option) any later version. |
428 | 15 |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5182
diff
changeset
|
16 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5182
diff
changeset
|
17 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5182
diff
changeset
|
18 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5182
diff
changeset
|
19 ;; for more details. |
428 | 20 |
21 ;; You should have received a copy of the GNU General Public License | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5182
diff
changeset
|
22 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>. |
428 | 23 |
24 ;;; Synched up with: FSF 19.30. | |
25 | |
26 ;;; Commentary: | |
27 | |
28 ;; This file is dumped with XEmacs. | |
29 | |
30 ;; This code implements XEmacs's on-line help system, the one invoked by | |
31 ;;`M-x help-for-help'. | |
32 | |
33 ;; 06/11/1997 -- Converted to use char-after instead of broken | |
34 ;; following-char. -slb | |
35 | |
36 ;;; Code: | |
37 | |
38 ;; Get the macro make-help-screen when this is compiled, | |
39 ;; or run interpreted, but not when the compiled code is loaded. | |
40 (eval-when-compile (require 'help-macro)) | |
41 | |
3368 | 42 (require 'loadhist) ;; For symbol-file. |
43 | |
428 | 44 (defgroup help nil |
45 "Support for on-line help systems." | |
46 :group 'emacs) | |
47 | |
48 (defgroup help-appearance nil | |
49 "Appearance of help buffers." | |
50 :group 'help) | |
51 | |
52 (defvar help-map (let ((map (make-sparse-keymap))) | |
53 (set-keymap-name map 'help-map) | |
54 (set-keymap-prompt | |
444 | 55 map (gettext "(Type ? for further options)")) |
428 | 56 map) |
57 "Keymap for characters following the Help key.") | |
58 | |
5793
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
59 (defvar help-mode-link-positions nil) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
60 (make-variable-buffer-local 'help-mode-link-positions) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
61 |
428 | 62 ;; global-map definitions moved to keydefs.el |
63 (fset 'help-command help-map) | |
64 | |
65 (define-key help-map (vector help-char) 'help-for-help) | |
66 (define-key help-map "?" 'help-for-help) | |
67 (define-key help-map 'help 'help-for-help) | |
68 (define-key help-map '(f1) 'help-for-help) | |
69 | |
70 (define-key help-map "a" 'hyper-apropos) ; 'command-apropos in FSFmacs | |
502 | 71 (define-key help-map "A" 'command-hyper-apropos) |
72 ;; #### should be hyper-apropos-documentation, once that's written. | |
73 (define-key help-map "\C-a" 'apropos-documentation) | |
428 | 74 |
75 (define-key help-map "b" 'describe-bindings) | |
76 (define-key help-map "B" 'describe-beta) | |
77 | |
502 | 78 (define-key help-map "c" 'describe-key-briefly) |
428 | 79 (define-key help-map "C" 'customize) |
502 | 80 ;; FSFmacs has Info-goto-emacs-command-node on C-f, no binding |
81 ;; for Info-elisp-ref | |
82 (define-key help-map "\C-c" 'Info-goto-emacs-command-node) | |
428 | 83 |
84 (define-key help-map "d" 'describe-function) | |
502 | 85 (define-key help-map "\C-d" 'describe-distribution) |
86 | |
87 (define-key help-map "e" (if (fboundp 'view-last-error) 'view-last-error | |
88 'describe-last-error)) | |
89 | |
428 | 90 (define-key help-map "f" 'describe-function) |
502 | 91 ;; #### not a good interface. no way to specify that C-h is preferred |
92 ;; as a prefix and not BS. should instead be specified as part of | |
93 ;; `define-key'. | |
94 ;; (put 'describe-function 'preferred-key-sequence "\C-hf") | |
428 | 95 (define-key help-map "F" 'xemacs-local-faq) |
502 | 96 (define-key help-map "\C-f" 'Info-elisp-ref) |
428 | 97 |
98 (define-key help-map "i" 'info) | |
502 | 99 (define-key help-map "I" 'Info-search-index-in-xemacs-and-lispref) |
100 (define-key help-map "\C-i" 'Info-query) | |
101 | |
102 (define-key help-map "k" 'describe-key) | |
103 (define-key help-map "\C-k" 'Info-goto-emacs-key-command-node) | |
428 | 104 |
105 (define-key help-map "l" 'view-lossage) | |
502 | 106 (define-key help-map "\C-l" 'describe-copying) ; on \C-c in FSFmacs |
428 | 107 |
108 (define-key help-map "m" 'describe-mode) | |
109 | |
502 | 110 (define-key help-map "n" 'view-emacs-news) |
428 | 111 (define-key help-map "\C-n" 'view-emacs-news) |
112 | |
113 (define-key help-map "p" 'finder-by-keyword) | |
502 | 114 (define-key help-map "\C-p" 'describe-pointer) |
3074 | 115 (define-key help-map "P" 'view-xemacs-problems) |
502 | 116 |
117 (define-key help-map "q" 'help-quit) | |
428 | 118 |
119 ;; Do this right with an autoload cookie in finder.el. | |
120 ;;(autoload 'finder-by-keyword "finder" | |
121 ;; "Find packages matching a given keyword." t) | |
122 | |
123 (define-key help-map "s" 'describe-syntax) | |
502 | 124 (define-key help-map "S" 'view-sample-init-el) |
428 | 125 |
126 (define-key help-map "t" 'help-with-tutorial) | |
127 | |
128 (define-key help-map "v" 'describe-variable) | |
129 | |
502 | 130 (define-key help-map "w" 'where-is) |
131 (define-key help-map "\C-w" 'describe-no-warranty) | |
428 | 132 |
502 | 133 ;; #### It would be nice if the code below to add hyperlinks was |
134 ;; generalized. We would probably need a "hyperlink mode" from which | |
135 ;; help-mode is derived. This means we probably need multiple | |
136 ;; inheritance of modes! Thankfully this is not hard to implement; we | |
137 ;; already have the ability for a keymap to have multiple parents. | |
138 ;; However, we'd have to define any multiply-inherited-from modes using | |
139 ;; a standard `define-mode' construction instead of manually doing it, | |
140 ;; because we don't want each guy calling `kill-all-local-variables' and | |
141 ;; messing up the previous one. | |
428 | 142 |
143 (define-derived-mode help-mode view-major-mode "Help" | |
144 "Major mode for viewing help text. | |
145 Entry to this mode runs the normal hook `help-mode-hook'. | |
146 Commands: | |
147 \\{help-mode-map}" | |
5793
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
148 (help-mode-get-link-positions) |
428 | 149 ) |
150 | |
151 (define-key help-mode-map "q" 'help-mode-quit) | |
152 (define-key help-mode-map "Q" 'help-mode-bury) | |
153 (define-key help-mode-map "f" 'find-function-at-point) | |
154 (define-key help-mode-map "d" 'describe-function-at-point) | |
155 (define-key help-mode-map "v" 'describe-variable-at-point) | |
156 (define-key help-mode-map "i" 'Info-elisp-ref) | |
157 (define-key help-mode-map "c" 'customize-variable) | |
158 (define-key help-mode-map [tab] 'help-next-symbol) | |
5793
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
159 (define-key help-mode-map [iso-left-tab] 'help-prev-symbol) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
160 (define-key help-mode-map [backtab] 'help-prev-symbol) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
161 (define-key help-mode-map [return] 'help-activate-function-or-scroll-up) |
428 | 162 (define-key help-mode-map "n" 'help-next-section) |
163 (define-key help-mode-map "p" 'help-prev-section) | |
164 | |
1123 | 165 (define-derived-mode temp-buffer-mode view-major-mode "Temp" |
166 "Major mode for viewing temporary buffers. | |
167 Exit using \\<temp-buffer-mode-map>\\[help-mode-quit]. | |
168 | |
169 Entry to this mode runs the normal hook `temp-buffer-mode-hook'. | |
170 Commands: | |
171 \\{temp-buffer-mode-map}" | |
172 ) | |
173 | |
174 (define-key temp-buffer-mode-map "q" 'help-mode-quit) | |
175 (define-key temp-buffer-mode-map "Q" 'help-mode-bury) | |
176 | |
428 | 177 (defun describe-function-at-point () |
178 "Describe directly the function at point in the other window." | |
179 (interactive) | |
180 (let ((symb (function-at-point))) | |
181 (when symb | |
182 (describe-function symb)))) | |
183 | |
184 (defun describe-variable-at-point () | |
185 "Describe directly the variable at point in the other window." | |
186 (interactive) | |
187 (let ((symb (variable-at-point))) | |
188 (when symb | |
189 (describe-variable symb)))) | |
190 | |
191 (defun help-next-symbol () | |
5793
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
192 "Move point to the next link." |
428 | 193 (interactive) |
5793
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
194 (let ((p (point)) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
195 (positions help-mode-link-positions) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
196 (firstpos (car help-mode-link-positions))) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
197 (while (and positions (>= p (car positions))) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
198 (setq positions (cdr positions))) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
199 (if (or positions firstpos) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
200 (goto-char (or (car positions) firstpos))))) |
428 | 201 |
202 (defun help-prev-symbol () | |
5793
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
203 "Move point to the previous link." |
428 | 204 (interactive) |
5793
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
205 (let* ((p (point)) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
206 (positions (reverse help-mode-link-positions)) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
207 (lastpos (car positions))) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
208 (while (and positions (<= p (car positions))) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
209 (setq positions (cdr positions))) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
210 (if (or positions lastpos) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
211 (goto-char (or (car positions) lastpos))))) |
428 | 212 |
213 (defun help-next-section () | |
214 "Move point to the next quoted symbol." | |
215 (interactive) | |
216 (search-forward-regexp "^\\w+:" nil t)) | |
217 | |
218 (defun help-prev-section () | |
219 "Move point to the previous quoted symbol." | |
220 (interactive) | |
221 (search-backward-regexp "^\\w+:" nil t)) | |
222 | |
223 (defun help-mode-bury () | |
224 "Bury the help buffer, possibly restoring the previous window configuration." | |
225 (interactive) | |
226 (help-mode-quit t)) | |
227 | |
228 (defun help-mode-quit (&optional bury) | |
229 "Exit from help mode, possibly restoring the previous window configuration. | |
230 If the optional argument BURY is non-nil, the help buffer is buried, | |
231 otherwise it is killed." | |
232 (interactive) | |
233 (let ((buf (current-buffer))) | |
442 | 234 (cond (help-window-config |
235 (set-window-configuration help-window-config)) | |
428 | 236 ((not (one-window-p)) |
237 (delete-window))) | |
238 (if bury | |
239 (bury-buffer buf) | |
240 (kill-buffer buf)))) | |
241 | |
242 (defun help-quit () | |
243 (interactive) | |
244 nil) | |
245 | |
5793
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
246 (defun help-mode-get-link-positions () |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
247 "Get the positions of the links in the help buffer" |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
248 (let ((el (extent-list nil (point-min) (point-max) nil 'activate-function)) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
249 (positions nil)) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
250 (while el |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
251 (setq positions (append positions (list (extent-start-position (car el))))) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
252 (setq el (cdr el))) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
253 (setq help-mode-link-positions positions))) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
254 |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
255 |
771 | 256 (define-obsolete-function-alias 'deprecated-help-command 'help-for-help) |
428 | 257 |
258 ;;(define-key global-map 'backspace 'deprecated-help-command) | |
259 | |
771 | 260 (defconst tutorial-supported-languages |
261 '( | |
262 ("Croatian" hr iso-8859-2) | |
263 ("Czech" cs iso-8859-2) | |
264 ("Dutch" nl iso-8859-1) | |
265 ("English" nil raw-text) | |
266 ("French" fr iso-8859-1) | |
267 ("German" de iso-8859-1) | |
268 ("Norwegian" no iso-8859-1) | |
269 ("Polish" pl iso-8859-2) | |
270 ("Romanian" ro iso-8859-2) | |
271 ("Slovak" sk iso-8859-2) | |
272 ("Slovenian" sl iso-8859-2) | |
273 ("Spanish" es iso-8859-1) | |
274 ("Swedish" se iso-8859-1) | |
275 ) | |
276 "Alist of supported languages in TUTORIAL files. | |
277 Add languages here, as more are translated.") | |
278 | |
279 ;; TUTORIAL arg is XEmacs addition | |
280 (defun help-with-tutorial (&optional tutorial language) | |
281 "Select the XEmacs learn-by-doing tutorial. | |
282 Optional arg TUTORIAL specifies the tutorial file; if not specified or | |
283 if this command is invoked interactively, the tutorial appropriate to | |
284 the current language environment is used. If there is no tutorial | |
285 written in that language, or if this version of XEmacs has no | |
286 international (Mule) support, the English-language tutorial is used. | |
287 With a prefix argument, you are asked to select which language." | |
288 (interactive "i\nP") | |
289 (when (and language (consp language)) | |
290 (setq language | |
291 (if (featurep 'mule) | |
292 (or (declare-fboundp (read-language-name 'tutorial "Language: ")) | |
293 (error "No tutorial file of the specified language")) | |
294 (let ((completion-ignore-case t)) | |
295 (completing-read "Language: " | |
296 tutorial-supported-languages nil t))))) | |
297 (or language | |
298 (setq language | |
299 (if (featurep 'mule) (declare-boundp current-language-environment) | |
300 "English"))) | |
301 (or tutorial | |
302 (setq tutorial | |
303 (cond ((featurep 'mule) | |
304 (or (declare-fboundp (get-language-info language 'tutorial)) | |
305 "TUTORIAL")) | |
306 ((equal language "English") "TUTORIAL") | |
307 (t (format "TUTORIAL.%s" | |
308 (cadr (assoc language | |
309 tutorial-supported-languages))))))) | |
310 (let ((file (expand-file-name tutorial "~"))) | |
311 (delete-other-windows) | |
312 (let ((buffer (or (get-file-buffer file) | |
313 (create-file-buffer file))) | |
314 (window-configuration (current-window-configuration))) | |
315 (condition-case error-data | |
316 (progn | |
317 (switch-to-buffer buffer) | |
318 (setq buffer-file-name file) | |
319 (setq default-directory (expand-file-name "~/")) | |
320 (setq buffer-auto-save-file-name nil) | |
321 ;; Because of non-Mule users, TUTORIALs are not coded | |
322 ;; independently, so we must guess the coding according to | |
323 ;; the language. | |
324 (let ((coding-system-for-read | |
325 (if (featurep 'mule) | |
326 (with-fboundp 'get-language-info | |
327 (or (get-language-info language | |
328 'tutorial-coding-system) | |
329 (car (get-language-info language | |
330 'coding-system)))) | |
331 (nth 2 (assoc language tutorial-supported-languages))))) | |
332 (insert-file-contents (locate-data-file tutorial))) | |
333 (goto-char (point-min)) | |
334 ;; [The 'didactic' blank lines: possibly insert blank lines | |
335 ;; around <<nya nya nya>> and replace << >> with [ ].] No more | |
336 ;; didactic blank lines. It was just a bad idea, anyway. I | |
337 ;; rewrote the TUTORIAL so it doesn't need them. However, some | |
338 ;; tutorials in other languages haven't yet been updated. #### | |
339 ;; Delete this code when they're all updated. | |
340 (if (re-search-forward "^<<.+>>" nil t) | |
341 (let ((n (- (window-height (selected-window)) | |
342 (count-lines (point-min) (point-at-bol)) | |
343 6))) | |
344 (if (< n 12) | |
345 (progn (beginning-of-line) (kill-line)) | |
346 ;; Some people get confused by the large gap | |
347 (delete-backward-char 2) | |
348 (insert "]") | |
349 (beginning-of-line) | |
350 (save-excursion | |
351 (delete-char 2) | |
352 (insert "[")) | |
353 (newline (/ n 2)) | |
354 (next-line 1) | |
355 (newline (- n (/ n 2)))))) | |
356 (goto-char (point-min)) | |
357 (set-buffer-modified-p nil)) | |
358 ;; TUTORIAL was not found: kill the buffer and restore the | |
359 ;; window configuration. | |
360 (file-error (kill-buffer buffer) | |
361 (set-window-configuration window-configuration) | |
362 ;; Now, signal the error | |
363 (signal (car error-data) (cdr error-data))))))) | |
428 | 364 |
365 ;; used by describe-key, describe-key-briefly, insert-key-binding, etc. | |
366 (defun key-or-menu-binding (key &optional menu-flag) | |
367 "Return the command invoked by KEY. | |
368 Like `key-binding', but handles menu events and toolbar presses correctly. | |
369 KEY is any value returned by `next-command-event'. | |
370 MENU-FLAG is a symbol that should be set to t if KEY is a menu event, | |
444 | 371 or nil otherwise." |
428 | 372 (let (defn) |
373 (and menu-flag (set menu-flag nil)) | |
374 ;; If the key typed was really a menu selection, grab the form out | |
375 ;; of the event object and intuit the function that would be called, | |
376 ;; and describe that instead. | |
5366
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
377 (if (and (vectorp key) (eql 1 (length key)) |
428 | 378 (or (misc-user-event-p (aref key 0)) |
379 (eq (car-safe (aref key 0)) 'menu-selection))) | |
380 (let ((event (aref key 0))) | |
381 (setq defn (if (eventp event) | |
382 (list (event-function event) (event-object event)) | |
383 (cdr event))) | |
384 (and menu-flag (set menu-flag t)) | |
385 (when (eq (car defn) 'eval) | |
386 (setq defn (car (cdr defn)))) | |
387 (when (eq (car-safe defn) 'call-interactively) | |
388 (setq defn (car (cdr defn)))) | |
389 (when (and (consp defn) (null (cdr defn))) | |
390 (setq defn (car defn)))) | |
391 ;; else | |
392 (setq defn (key-binding key))) | |
393 ;; kludge: if a toolbar button was pressed on, try to find the | |
394 ;; binding of the toolbar button. | |
395 (if (and (eq defn 'press-toolbar-button) | |
396 (vectorp key) | |
397 (button-press-event-p (aref key (1- (length key))))) | |
398 ;; wait for the button release. We're on shaky ground here ... | |
399 (let ((event (next-command-event)) | |
400 button) | |
401 (if (and (button-release-event-p event) | |
402 (event-over-toolbar-p event) | |
403 (eq 'release-and-activate-toolbar-button | |
404 (key-binding (vector event))) | |
405 (setq button (event-toolbar-button event))) | |
406 (toolbar-button-callback button) | |
407 ;; if anything went wrong, try returning the binding of | |
408 ;; the button-up event, of the original binding | |
409 (or (key-or-menu-binding (vector event)) | |
410 defn))) | |
411 ;; no toolbar kludge | |
412 defn) | |
413 )) | |
414 | |
415 (defun describe-key-briefly (key &optional insert) | |
416 "Print the name of the function KEY invokes. KEY is a string. | |
417 If INSERT (the prefix arg) is non-nil, insert the message in the buffer." | |
418 (interactive "kDescribe key briefly: \nP") | |
419 (let ((standard-output (if insert (current-buffer) t)) | |
420 defn menup) | |
421 (setq defn (key-or-menu-binding key 'menup)) | |
422 (if (or (null defn) (integerp defn)) | |
423 (princ (format "%s is undefined" (key-description key))) | |
424 ;; If it's a keyboard macro which trivially invokes another command, | |
425 ;; document that instead. | |
426 (if (or (stringp defn) (vectorp defn)) | |
427 (setq defn (or (key-binding defn) | |
428 defn))) | |
429 (let ((last-event (and (vectorp key) | |
430 (aref key (1- (length key)))))) | |
431 (princ (format (cond (insert | |
432 "%s (%s)") | |
433 ((or (button-press-event-p last-event) | |
434 (button-release-event-p last-event)) | |
435 (gettext "%s at that spot runs the command %s")) | |
436 (t | |
437 (gettext "%s runs the command %s"))) | |
438 ;; This used to say 'This menu item' but it | |
439 ;; could also be a scrollbar event. We can't | |
440 ;; distinguish at the moment. | |
441 (if menup | |
442 (if insert "item" "This item") | |
443 (key-description key)) | |
444 (if (symbolp defn) defn (prin1-to-string defn)))))))) | |
445 | |
446 ;; #### this is a horrible piece of shit function that should | |
447 ;; not exist. In FSF 19.30 this function has gotten three times | |
448 ;; as long and has tons and tons of dumb shit checking | |
449 ;; special-display-buffer-names and such crap. I absolutely | |
450 ;; refuse to insert that Ebolification here. I wanted to delete | |
451 ;; this function entirely but Mly bitched. | |
452 ;; | |
453 ;; If your user-land code calls this function, rewrite it to | |
454 ;; call with-displaying-help-buffer. | |
455 | |
456 (defun print-help-return-message (&optional function) | |
457 "Display or return message saying how to restore windows after help command. | |
458 Computes a message and applies the optional argument FUNCTION to it. | |
459 If FUNCTION is nil, applies `message' to it, thus printing it." | |
460 (and (not (get-buffer-window standard-output)) | |
461 (funcall | |
462 (or function 'message) | |
463 (concat | |
464 (substitute-command-keys | |
465 (if (one-window-p t) | |
466 (if pop-up-windows | |
467 (gettext "Type \\[delete-other-windows] to remove help window.") | |
468 (gettext "Type \\[switch-to-buffer] RET to remove help window.")) | |
469 (gettext "Type \\[switch-to-buffer-other-window] RET to restore the other window."))) | |
470 (substitute-command-keys | |
471 (gettext " \\[scroll-other-window] to scroll the help.")))))) | |
472 | |
473 (defcustom help-selects-help-window t | |
474 "*If nil, use the \"old Emacs\" behavior for Help buffers. | |
475 This just displays the buffer in another window, rather than selecting | |
476 the window." | |
477 :type 'boolean | |
478 :group 'help-appearance) | |
479 | |
480 (defcustom help-max-help-buffers 10 | |
481 "*Maximum help buffers to allow before they start getting killed. | |
482 If this is a positive integer, before a help buffer is displayed | |
483 by `with-displaying-help-buffer', any excess help buffers which | |
484 are not being displayed are first killed. Otherwise, if it is | |
485 zero or nil, only one help buffer, \"*Help*\" is ever used." | |
486 :type '(choice integer (const :tag "None" nil)) | |
487 :group 'help-appearance) | |
488 | |
489 (defvar help-buffer-list nil | |
490 "List of help buffers used by `help-register-and-maybe-prune-excess'") | |
491 | |
492 (defun help-register-and-maybe-prune-excess (newbuf) | |
2030 | 493 "Register help buffer named NEWBUF and possibly kill excess ones." |
494 ;; don't let client code pass us bogus NEWBUF---if it gets in the list, | |
495 ;; help can become unusable | |
496 (unless (stringp newbuf) | |
497 (error 'wrong-type-argument "help buffer name must be string" newbuf)) | |
428 | 498 ;; remove new buffer from list |
499 (setq help-buffer-list (remove newbuf help-buffer-list)) | |
500 ;; maybe kill excess help buffers | |
501 (if (and (integerp help-max-help-buffers) | |
502 (> (length help-buffer-list) help-max-help-buffers)) | |
503 (let ((keep-list nil) | |
504 (num-kill (- (length help-buffer-list) | |
505 help-max-help-buffers))) | |
506 (while help-buffer-list | |
507 (let ((buf (car help-buffer-list))) | |
508 (if (and (or (equal buf newbuf) (get-buffer buf)) | |
509 (string-match "^*Help" buf) | |
510 (save-excursion (set-buffer buf) | |
511 (eq major-mode 'help-mode))) | |
512 (if (and (>= num-kill (length help-buffer-list)) | |
513 (not (get-buffer-window buf t t))) | |
514 (kill-buffer buf) | |
515 (setq keep-list (cons buf keep-list))))) | |
516 (setq help-buffer-list (cdr help-buffer-list))) | |
517 (setq help-buffer-list (nreverse keep-list)))) | |
518 ;; push new buffer | |
519 (setq help-buffer-list (cons newbuf help-buffer-list))) | |
520 | |
521 (defvar help-buffer-prefix-string "Help" | |
522 "Initial string to use in constructing help buffer names. | |
2030 | 523 You should never set this directly, only let-bind it.") |
428 | 524 |
525 (defun help-buffer-name (name) | |
526 "Return a name for a Help buffer using string NAME for context." | |
527 (if (and (integerp help-max-help-buffers) | |
528 (> help-max-help-buffers 0) | |
529 (stringp name)) | |
530 (if help-buffer-prefix-string | |
531 (format "*%s: %s*" help-buffer-prefix-string name) | |
532 (format "*%s*" name)) | |
533 (format "*%s*" help-buffer-prefix-string))) | |
534 | |
863 | 535 ;; with-displaying-help-buffer |
428 | 536 |
537 ;; #### Should really be a macro to eliminate the requirement of | |
538 ;; caller to code a lambda form in THUNK -- mrb | |
539 | |
540 ;; #### BEFORE you rush to make this a macro, think about backward | |
541 ;; compatibility. The right way would be to create a macro with | |
542 ;; another name (which is a shame, because w-d-h-b is a perfect name | |
543 ;; for a macro) that uses with-displaying-help-buffer internally. | |
544 | |
442 | 545 (defcustom mode-for-help 'help-mode |
546 "*Mode that help buffers are put into.") | |
547 | |
1123 | 548 (defcustom mode-for-temp-buffer 'temp-buffer-mode |
549 "*Mode that help buffers are put into.") | |
550 | |
442 | 551 (defvar help-sticky-window nil |
552 ;; Window into which help buffers will be displayed, rather than | |
553 ;; always searching for a new one. This is INTERNAL and liable to | |
554 ;; change its interface and/or name at any moment. It should be | |
555 ;; bound, not set. | |
556 ) | |
557 | |
558 (defvar help-window-config nil) | |
559 | |
560 (make-variable-buffer-local 'help-window-config) | |
561 (put 'help-window-config 'permanent-local t) | |
562 | |
1123 | 563 (defmacro with-displaying-temp-buffer (name &rest body) |
2030 | 564 "Make a help buffer with given NAME and evaluate BODY, sending stdout there. |
1123 | 565 |
566 Use this function for displaying information in temporary buffers, where the | |
567 user will typically view the information and then exit using | |
568 \\<temp-buffer-mode-map>\\[help-mode-quit]. | |
863 | 569 |
2030 | 570 On exit from this form, the buffer is put into the mode specified in |
571 `mode-for-temp-buffer' and displayed, typically in a popup window. Ie, | |
572 the buffer is a scratchpad which is displayed all at once in formatted | |
573 form. | |
574 | |
575 N.B. Write to this buffer with functions like `princ', not `insert'." | |
1123 | 576 `(let* ((winconfig (current-window-configuration)) |
577 (was-one-window (one-window-p)) | |
578 (buffer-name ,name) | |
579 (help-not-visible | |
580 (not (and (windows-of-buffer buffer-name) ;shortcut | |
581 (memq (selected-frame) | |
582 (mapcar 'window-frame | |
583 (windows-of-buffer buffer-name))))))) | |
428 | 584 (help-register-and-maybe-prune-excess buffer-name) |
442 | 585 ;; if help-sticky-window is bogus or deleted, get rid of it. |
586 (if (and help-sticky-window (or (not (windowp help-sticky-window)) | |
587 (not (window-live-p help-sticky-window)))) | |
588 (setq help-sticky-window nil)) | |
589 (prog1 | |
590 (let ((temp-buffer-show-function | |
591 (if help-sticky-window | |
592 #'(lambda (buffer) | |
593 (set-window-buffer help-sticky-window buffer)) | |
594 temp-buffer-show-function))) | |
595 (with-output-to-temp-buffer buffer-name | |
1123 | 596 (prog1 (progn ,@body) |
442 | 597 (save-excursion |
598 (set-buffer standard-output) | |
1123 | 599 (funcall mode-for-temp-buffer))))) |
428 | 600 (let ((helpwin (get-buffer-window buffer-name))) |
601 (when helpwin | |
1123 | 602 ;; If the temp buffer is already displayed on this |
442 | 603 ;; frame, don't override the previous configuration |
604 (when help-not-visible | |
605 (with-current-buffer (window-buffer helpwin) | |
606 (setq help-window-config winconfig))) | |
428 | 607 (when help-selects-help-window |
608 (select-window helpwin)) | |
609 (cond ((eq helpwin (selected-window)) | |
610 (display-message 'command | |
1123 | 611 (substitute-command-keys "Type \\[help-mode-quit] to remove window, \\[scroll-up] to scroll the text."))) |
428 | 612 (was-one-window |
613 (display-message 'command | |
1123 | 614 (substitute-command-keys "Type \\[delete-other-windows] to remove window, \\[scroll-other-window] to scroll the text."))) |
428 | 615 (t |
616 (display-message 'command | |
1123 | 617 (substitute-command-keys "Type \\[switch-to-buffer-other-window] to restore the other window, \\[scroll-other-window] to scroll the text."))))))))) |
618 | |
619 (put 'with-displaying-temp-buffer 'lisp-indent-function 1) | |
620 | |
621 (defun with-displaying-help-buffer (thunk &optional name) | |
622 "Form which makes a help buffer with given NAME and evaluates BODY there. | |
623 The actual name of the buffer is generated by the function `help-buffer-name'. | |
624 | |
625 Use this function for displaying help when C-h something is pressed or | |
626 in similar situations. Do *not* use it when you are displaying a help | |
627 message and then prompting for input in the minibuffer -- this macro | |
628 usually selects the help buffer, which is not what you want in those | |
629 situations." | |
630 (let ((mode-for-temp-buffer mode-for-help)) | |
631 (with-displaying-temp-buffer (help-buffer-name name) | |
632 (funcall thunk)))) | |
428 | 633 |
634 (defun describe-key (key) | |
635 "Display documentation of the function invoked by KEY. | |
636 KEY is a string, or vector of events. | |
637 When called interactively, KEY may also be a menu selection." | |
638 (interactive "kDescribe key: ") | |
639 (let ((defn (key-or-menu-binding key)) | |
640 (key-string (key-description key))) | |
641 (if (or (null defn) (integerp defn)) | |
642 (message "%s is undefined" key-string) | |
643 (with-displaying-help-buffer | |
644 (lambda () | |
645 (princ key-string) | |
646 (princ " runs ") | |
647 (if (symbolp defn) | |
648 (princ (format "`%s'" defn)) | |
649 (princ defn)) | |
650 (princ "\n\n") | |
651 (cond ((or (stringp defn) (vectorp defn)) | |
652 (let ((cmd (key-binding defn))) | |
653 (if (not cmd) | |
654 (princ "a keyboard macro") | |
655 (progn | |
656 (princ "a keyboard macro which runs the command ") | |
657 (princ cmd) | |
658 (princ ":\n\n") | |
659 (if (documentation cmd) (princ (documentation cmd))))))) | |
660 ((and (consp defn) (not (eq 'lambda (car-safe defn)))) | |
661 (let ((describe-function-show-arglist nil)) | |
662 (describe-function-1 (car defn)))) | |
663 ((symbolp defn) | |
664 (describe-function-1 defn)) | |
665 ((documentation defn) | |
666 (princ (documentation defn))) | |
667 (t | |
668 (princ "not documented")))) | |
669 (format "key `%s'" key-string))))) | |
670 | |
671 (defun describe-mode () | |
672 "Display documentation of current major mode and minor modes. | |
673 For this to work correctly for a minor mode, the mode's indicator variable | |
674 \(listed in `minor-mode-alist') must also be a function whose documentation | |
675 describes the minor mode." | |
676 (interactive) | |
677 (with-displaying-help-buffer | |
678 (lambda () | |
679 ;; XEmacs change: print the major-mode documentation before | |
680 ;; the minor modes. | |
681 (princ mode-name) | |
682 (princ " mode:\n") | |
683 (princ (documentation major-mode)) | |
684 (princ "\n\n----\n\n") | |
685 (let ((minor-modes minor-mode-alist)) | |
686 (while minor-modes | |
687 (let* ((minor-mode (car (car minor-modes))) | |
688 (indicator (car (cdr (car minor-modes))))) | |
689 ;; Document a minor mode if it is listed in minor-mode-alist, | |
690 ;; bound locally in this buffer, non-nil, and has a function | |
691 ;; definition. | |
692 (if (and (boundp minor-mode) | |
693 (symbol-value minor-mode) | |
694 (fboundp minor-mode)) | |
695 (let ((pretty-minor-mode minor-mode)) | |
696 (if (string-match "-mode\\'" (symbol-name minor-mode)) | |
697 (setq pretty-minor-mode | |
698 (capitalize | |
699 (substring (symbol-name minor-mode) | |
700 0 (match-beginning 0))))) | |
701 (while (and (consp indicator) (extentp (car indicator))) | |
702 (setq indicator (cdr indicator))) | |
703 (while (and indicator (symbolp indicator)) | |
704 (setq indicator (symbol-value indicator))) | |
732 | 705 (princ (format "%s minor mode (%s):\n" |
706 pretty-minor-mode | |
707 (if indicator | |
708 (format "indicator%s" indicator) | |
709 "no indicator"))) | |
428 | 710 (princ (documentation minor-mode)) |
711 (princ "\n\n----\n\n")))) | |
712 (setq minor-modes (cdr minor-modes))))) | |
713 (format "%s mode" mode-name))) | |
714 | |
715 ;; So keyboard macro definitions are documented correctly | |
716 (fset 'defining-kbd-macro (symbol-function 'start-kbd-macro)) | |
717 | |
462 | 718 ;; view a read-only file intelligently |
719 (defun Help-find-file (file) | |
720 (if (fboundp 'view-file) | |
721 (view-file file) | |
722 (find-file-read-only file) | |
723 (goto-char (point-min)))) | |
724 | |
428 | 725 (defun describe-distribution () |
726 "Display info on how to obtain the latest version of XEmacs." | |
727 (interactive) | |
2537 | 728 (save-window-excursion |
729 (info) | |
730 (Info-find-node "xemacs-faq" "Q1.1.1")) | |
731 (switch-to-buffer "*info*")) | |
428 | 732 |
733 (defun describe-beta () | |
734 "Display info on how to deal with Beta versions of XEmacs." | |
735 (interactive) | |
2537 | 736 (save-window-excursion |
737 (info "(beta)Top")) | |
738 (switch-to-buffer "*info*")) | |
428 | 739 |
740 (defun describe-copying () | |
741 "Display info on how you may redistribute copies of XEmacs." | |
742 (interactive) | |
462 | 743 (Help-find-file (locate-data-file "COPYING"))) |
428 | 744 |
745 (defun describe-pointer () | |
746 "Show a list of all defined mouse buttons, and their definitions." | |
747 (interactive) | |
748 (describe-bindings nil t)) | |
749 | |
750 (defun describe-no-warranty () | |
751 "Display info on all the kinds of warranty XEmacs does NOT have." | |
752 (interactive) | |
753 (describe-copying) | |
754 (let (case-fold-search) | |
755 (search-forward "NO WARRANTY") | |
756 (recenter 0))) | |
757 | |
758 (defun describe-bindings (&optional prefix mouse-only-p) | |
759 "Show a list of all defined keys, and their definitions. | |
760 The list is put in a buffer, which is displayed. | |
444 | 761 If optional first argument PREFIX is supplied, only commands |
762 which start with that sequence of keys are described. | |
763 If optional second argument MOUSE-ONLY-P (prefix arg, interactively) | |
764 is non-nil then only the mouse bindings are displayed." | |
428 | 765 (interactive (list nil current-prefix-arg)) |
766 (with-displaying-help-buffer | |
767 (lambda () | |
768 (describe-bindings-1 prefix mouse-only-p)) | |
769 (format "bindings for %s" major-mode))) | |
770 | |
771 (defun describe-bindings-1 (&optional prefix mouse-only-p) | |
772 (let ((heading (if mouse-only-p | |
773 (gettext "button binding\n------ -------\n") | |
774 (gettext "key binding\n--- -------\n"))) | |
775 (buffer (current-buffer)) | |
776 (minor minor-mode-map-alist) | |
430 | 777 (extent-maps (mapcar-extents |
778 'extent-keymap | |
779 nil (current-buffer) (point) (point) nil 'keymap)) | |
428 | 780 (local (current-local-map)) |
781 (shadow '())) | |
782 (set-buffer standard-output) | |
430 | 783 (while extent-maps |
784 (insert "Bindings for Text Region:\n" | |
785 heading) | |
786 (describe-bindings-internal | |
787 (car extent-maps) nil shadow prefix mouse-only-p) | |
788 (insert "\n") | |
789 (setq shadow (cons (car extent-maps) shadow) | |
790 extent-maps (cdr extent-maps))) | |
428 | 791 (while minor |
792 (let ((sym (car (car minor))) | |
793 (map (cdr (car minor)))) | |
794 (if (symbol-value-in-buffer sym buffer nil) | |
795 (progn | |
796 (insert (format "Minor Mode Bindings for `%s':\n" | |
797 sym) | |
798 heading) | |
799 (describe-bindings-internal map nil shadow prefix mouse-only-p) | |
800 (insert "\n") | |
801 (setq shadow (cons map shadow)))) | |
802 (setq minor (cdr minor)))) | |
803 (if local | |
804 (progn | |
805 (insert "Local Bindings:\n" heading) | |
806 (describe-bindings-internal local nil shadow prefix mouse-only-p) | |
807 (insert "\n") | |
808 (setq shadow (cons local shadow)))) | |
771 | 809 (if (console-on-window-system-p) |
810 (progn | |
811 (insert "Global Window-System-Only Bindings:\n" heading) | |
812 (describe-bindings-internal global-window-system-map nil | |
813 shadow prefix mouse-only-p) | |
814 (push global-window-system-map shadow)) | |
815 (insert "Global TTY-Only Bindings:\n" heading) | |
816 (describe-bindings-internal global-tty-map nil | |
817 shadow prefix mouse-only-p) | |
818 (push global-tty-map shadow)) | |
819 (insert "\nGlobal Bindings:\n" heading) | |
428 | 820 (describe-bindings-internal (current-global-map) |
821 nil shadow prefix mouse-only-p) | |
822 (when (and prefix function-key-map (not mouse-only-p)) | |
823 (insert "\nFunction key map translations:\n" heading) | |
824 (describe-bindings-internal function-key-map nil nil | |
825 prefix mouse-only-p)) | |
826 (set-buffer buffer) | |
827 standard-output)) | |
828 | |
829 (defun describe-prefix-bindings () | |
830 "Describe the bindings of the prefix used to reach this command. | |
831 The prefix described consists of all but the last event | |
832 of the key sequence that ran this command." | |
833 (interactive) | |
834 (let* ((key (this-command-keys)) | |
835 (prefix (make-vector (1- (length key)) nil)) | |
836 i) | |
837 (setq i 0) | |
838 (while (< i (length prefix)) | |
839 (aset prefix i (aref key i)) | |
840 (setq i (1+ i))) | |
841 (with-displaying-help-buffer | |
842 (lambda () | |
843 (princ "Key bindings starting with ") | |
844 (princ (key-description prefix)) | |
845 (princ ":\n\n") | |
846 (describe-bindings-1 prefix nil)) | |
847 (format "%s prefix" (key-description prefix))))) | |
848 | |
849 ;; Make C-h after a prefix, when not specifically bound, | |
850 ;; run describe-prefix-bindings. | |
851 (setq prefix-help-command 'describe-prefix-bindings) | |
852 | |
853 (defun describe-installation () | |
854 "Display a buffer showing information about this XEmacs was compiled." | |
855 (interactive) | |
4246 | 856 (if (and-boundp 'Installation-string |
857 (stringp Installation-string)) | |
428 | 858 (with-displaying-help-buffer |
859 (lambda () | |
4246 | 860 (princ Installation-string)) |
428 | 861 "Installation") |
4246 | 862 (error 'unimplemented "No Installation information available."))) |
428 | 863 |
864 (defun view-emacs-news () | |
865 "Display info on recent changes to XEmacs." | |
866 (interactive) | |
2986 | 867 (Help-find-file (expand-file-name "NEWS" data-directory))) |
428 | 868 |
3074 | 869 (defun view-xemacs-problems () |
870 "Display known problems with XEmacs." | |
871 (interactive) | |
872 (Help-find-file (expand-file-name "PROBLEMS" data-directory))) | |
873 | |
428 | 874 (defun xemacs-www-page () |
875 "Go to the XEmacs World Wide Web page." | |
876 (interactive) | |
776 | 877 (if-fboundp 'browse-url |
442 | 878 (browse-url "http://www.xemacs.org/") |
428 | 879 (error "xemacs-www-page requires browse-url"))) |
880 | |
881 (defun xemacs-www-faq () | |
882 "View the latest and greatest XEmacs FAQ using the World Wide Web." | |
883 (interactive) | |
776 | 884 (if-fboundp 'browse-url |
442 | 885 (browse-url "http://www.xemacs.org/faq/index.html") |
428 | 886 (error "xemacs-www-faq requires browse-url"))) |
887 | |
888 (defun xemacs-local-faq () | |
889 "View the local copy of the XEmacs FAQ. | |
890 If you have access to the World Wide Web, you should use `xemacs-www-faq' | |
891 instead, to ensure that you get the most up-to-date information." | |
892 (interactive) | |
893 (save-window-excursion | |
894 (info) | |
895 (Info-find-node "xemacs-faq" "Top")) | |
896 (switch-to-buffer "*info*")) | |
897 | |
462 | 898 (defun view-sample-init-el () |
899 "Display the sample init.el file." | |
900 (interactive) | |
901 (Help-find-file (locate-data-file "sample.init.el"))) | |
902 | |
428 | 903 (defcustom view-lossage-key-count 100 |
904 "*Number of keys `view-lossage' shows. | |
905 The maximum number of available keys is governed by `recent-keys-ring-size'." | |
906 :type 'integer | |
907 :group 'help) | |
908 | |
909 (defcustom view-lossage-message-count 100 | |
910 "*Number of minibuffer messages `view-lossage' shows." | |
911 :type 'integer | |
912 :group 'help) | |
913 | |
914 (defun print-recent-messages (n) | |
915 "Print N most recent messages to standard-output, most recent first. | |
916 If N is nil, all messages will be printed." | |
793 | 917 (clear-message) ;; make sure current message goes into log |
428 | 918 (save-excursion |
919 (let ((buffer (get-buffer-create " *Message-Log*")) | |
920 oldpoint extent) | |
921 (goto-char (point-max buffer) buffer) | |
922 (set-buffer standard-output) | |
923 (while (and (not (bobp buffer)) | |
924 (or (null n) (>= (decf n) 0))) | |
925 (setq oldpoint (point buffer)) | |
926 (setq extent (extent-at oldpoint buffer | |
927 'message-multiline nil 'before)) | |
928 ;; If the message was multiline, move all the way to the | |
929 ;; beginning. | |
930 (if extent | |
931 (goto-char (extent-start-position extent) buffer) | |
932 (forward-line -1 buffer)) | |
933 (insert-buffer-substring buffer (point buffer) oldpoint))))) | |
934 | |
793 | 935 (defun view-warnings () |
936 "Display warnings issued." | |
937 (interactive) | |
938 (with-displaying-help-buffer | |
939 (lambda () | |
940 (let ((buf (get-buffer "*Warnings*"))) | |
941 (when buf | |
942 (save-excursion | |
943 (set-buffer standard-output) | |
944 (map-extents | |
945 #'(lambda (extent arg) | |
946 (goto-char (point-min)) | |
947 (insert (extent-string extent))) | |
948 buf))))) | |
949 "warnings")) | |
950 | |
951 (defun view-lossage (&optional no-keys) | |
428 | 952 "Display recent input keystrokes and recent minibuffer messages. |
953 The number of keys shown is controlled by `view-lossage-key-count'. | |
1038 | 954 The number of messages shown is controlled by `view-lossage-message-count'. |
955 | |
956 If optional arg NO-KEYS (prefix arg, interactively) is non-nil, | |
957 then recent input keystrokes output is omitted." | |
958 (interactive "P") | |
428 | 959 (with-displaying-help-buffer |
960 (lambda () | |
793 | 961 (unless no-keys |
962 (princ (key-description (recent-keys view-lossage-key-count))) | |
963 (save-excursion | |
964 (set-buffer standard-output) | |
965 (goto-char (point-min)) | |
966 (insert "Recent keystrokes:\n\n") | |
967 (while (progn (move-to-column 50) (not (eobp))) | |
968 (search-forward " " nil t) | |
969 (insert "\n"))) | |
970 (princ "\n\n\n")) | |
971 ;; Copy the messages from " *Message-Log*", reversing their order and | |
972 ;; handling multiline messages correctly. | |
973 (princ "Recent minibuffer messages (most recent first):\n\n") | |
428 | 974 (print-recent-messages view-lossage-message-count)) |
975 "lossage")) | |
976 | |
977 (define-function 'help 'help-for-help) | |
978 | |
979 (make-help-screen help-for-help | |
980 "A B C F I K L M N P S T V W C-c C-d C-f C-i C-k C-n C-w; ? for more help:" | |
502 | 981 (concat |
982 "Type a Help option: | |
428 | 983 \(Use SPC or DEL to scroll through this text. Type \\<help-map>\\[help-quit] to exit the Help command.) |
984 | |
502 | 985 Help on key bindings: |
986 | |
987 \\[describe-bindings] Table of all key bindings. | |
988 \\[describe-key-briefly] Type a key sequence or select a menu item; | |
989 it displays the corresponding command name. | |
990 \\[describe-key] Type a key sequence or select a menu item; | |
991 it displays the documentation for the command bound to that key. | |
992 (Terser but more up-to-date than what's in the manual.) | |
993 \\[Info-goto-emacs-key-command-node] Type a key sequence or select a menu item; | |
994 it jumps to the full documentation in the XEmacs User's Manual | |
995 for the corresponding command. | |
996 \\[view-lossage] Recent input keystrokes and minibuffer messages. | |
997 \\[describe-mode] Documentation of current major and minor modes. | |
998 \\[describe-pointer] Table of all mouse-button bindings. | |
999 \\[where-is] Type a command name; it displays which keystrokes invoke that command. | |
1000 | |
1001 Help on functions and variables: | |
1002 | |
428 | 1003 \\[hyper-apropos] Type a substring; it shows a hypertext list of |
1004 functions and variables that contain that substring. | |
502 | 1005 \\[command-apropos] Older version of apropos; superseded by previous command. |
1006 \\[apropos-documentation] Type a substring; it shows a hypertext list of | |
1007 functions and variables containing that substring anywhere | |
1008 in their documentation. | |
1009 \\[Info-goto-emacs-command-node] Type a command name; it jumps to the full documentation | |
1010 in the XEmacs User's Manual. | |
1011 \\[describe-function] Type a command or function name; it shows its documentation. | |
1012 (Terser but more up-to-date than what's in the manual.) | |
1013 \\[Info-elisp-ref] Type a function name; it jumps to the full documentation | |
1014 in the XEmacs Lisp Reference Manual. | |
1015 \\[Info-search-index-in-xemacs-and-lispref] Type a substring; it looks it up in the indices of both | |
1016 the XEmacs User's Manual and the XEmacs Lisp Reference Manual. | |
1017 It jumps to the first match (preferring an exact match); you | |
1018 can use `\\<Info-mode-map>\\[Info-index-next]\\<help-map>' to successively visit other matches. | |
1019 \\[describe-variable] Type a variable name; it displays its documentation and value. | |
1020 | |
1021 Miscellaneous: | |
1022 | |
1023 " | |
1024 (if (string-match "beta" emacs-version) | |
1025 "\\[describe-beta] Special considerations about running a beta version of XEmacs. | |
1026 " | |
1027 "") | |
1028 " | |
3074 | 1029 \\[view-xemacs-problems] Known problems. |
428 | 1030 \\[customize] Customize Emacs options. |
502 | 1031 \\[describe-distribution] How to obtain XEmacs. |
1032 \\[describe-last-error] Information about the most recent error. | |
428 | 1033 \\[xemacs-local-faq] Local copy of the XEmacs FAQ. |
1034 \\[info] Info documentation reader. | |
1035 \\[Info-query] Type an Info file name; it displays it in Info reader. | |
502 | 1036 \\[describe-copying] XEmacs copying permission (General Public License). |
428 | 1037 \\[view-emacs-news] News of recent XEmacs changes. |
1038 \\[finder-by-keyword] Type a topic keyword; it finds matching packages. | |
1039 \\[describe-syntax] Contents of syntax table with explanations. | |
502 | 1040 \\[view-sample-init-el] View the sample init.el that comes with XEmacs. |
428 | 1041 \\[help-with-tutorial] XEmacs learn-by-doing tutorial. |
502 | 1042 \\[describe-no-warranty] Information on absence of warranty for XEmacs." |
1043 ) | |
428 | 1044 help-map) |
1045 | |
1046 (defun function-called-at-point () | |
1047 "Return the function which is called by the list containing point. | |
1048 If that gives no function, return the function whose name is around point. | |
1049 If that doesn't give a function, return nil." | |
1050 (or (ignore-errors | |
1051 (save-excursion | |
1052 (save-restriction | |
1053 (narrow-to-region (max (point-min) (- (point) 1000)) | |
1054 (point-max)) | |
1055 (backward-up-list 1) | |
1056 (forward-char 1) | |
1057 (let (obj) | |
1058 (setq obj (read (current-buffer))) | |
1059 (and (symbolp obj) (fboundp obj) obj))))) | |
1060 (ignore-errors | |
1061 (with-syntax-table emacs-lisp-mode-syntax-table | |
1062 (save-excursion | |
1063 (or (not (zerop (skip-syntax-backward "_w"))) | |
1064 (eq (char-syntax (char-after (point))) ?w) | |
1065 (eq (char-syntax (char-after (point))) ?_) | |
1066 (forward-sexp -1)) | |
1067 (skip-chars-forward "`'") | |
1068 (let ((obj (read (current-buffer)))) | |
1069 (and (symbolp obj) (fboundp obj) obj))))))) | |
1070 | |
1071 (defun function-at-point () | |
1072 "Return the function whose name is around point. | |
1073 If that gives no function, return the function which is called by the | |
1074 list containing point. If that doesn't give a function, return nil." | |
1075 (or (ignore-errors | |
1076 (with-syntax-table emacs-lisp-mode-syntax-table | |
1077 (save-excursion | |
1078 (or (not (zerop (skip-syntax-backward "_w"))) | |
1079 (eq (char-syntax (char-after (point))) ?w) | |
1080 (eq (char-syntax (char-after (point))) ?_) | |
1081 (forward-sexp -1)) | |
1082 (skip-chars-forward "`'") | |
1083 (let ((obj (read (current-buffer)))) | |
1084 (and (symbolp obj) (fboundp obj) obj))))) | |
1085 (ignore-errors | |
1086 (save-excursion | |
1087 (save-restriction | |
1088 (narrow-to-region (max (point-min) (- (point) 1000)) | |
1089 (point-max)) | |
1090 (backward-up-list 1) | |
1091 (forward-char 1) | |
1092 (let (obj) | |
1093 (setq obj (read (current-buffer))) | |
1094 (and (symbolp obj) (fboundp obj) obj))))))) | |
1095 | |
442 | 1096 (defun function-at-event (event) |
1097 "Return the function whose name is around the position of EVENT. | |
1098 EVENT should be a mouse event. When calling from a popup or context menu, | |
1099 use `last-popup-menu-event' to find out where the mouse was clicked. | |
1100 \(You cannot use (interactive \"e\"), unfortunately. This returns a | |
1101 misc-user event.) | |
1102 | |
1103 If the event contains no position, or the position is not over text, or | |
1104 there is no function around that point, nil is returned." | |
1105 (if (and event (event-buffer event) (event-point event)) | |
1106 (save-excursion | |
1107 (set-buffer (event-buffer event)) | |
1108 (goto-char (event-point event)) | |
1109 (function-at-point)))) | |
1110 | |
428 | 1111 ;; Default to nil for the non-hackers? Not until we find a way to |
1112 ;; distinguish hackers from non-hackers automatically! | |
1113 (defcustom describe-function-show-arglist t | |
4695
fee33ab25966
Add arglist info for autoloaded functions and macros.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4694
diff
changeset
|
1114 "*If non-nil, describe-function will show the function's arglist." |
428 | 1115 :type 'boolean |
1116 :group 'help-appearance) | |
1117 | |
3368 | 1118 (define-obsolete-function-alias |
1119 ;; Moved to using the version in loadhist.el | |
1120 'describe-function-find-symbol | |
1121 'symbol-file) | |
428 | 1122 |
1123 (define-obsolete-function-alias | |
1124 'describe-function-find-file | |
3368 | 1125 'symbol-file) |
428 | 1126 |
1127 (defun describe-function (function) | |
1128 "Display the full documentation of FUNCTION (a symbol). | |
1129 When run interactively, it defaults to any function found by | |
1130 `function-at-point'." | |
1131 (interactive | |
1132 (let* ((fn (function-at-point)) | |
1133 (val (let ((enable-recursive-minibuffers t)) | |
1134 (completing-read | |
1135 (if fn | |
1136 (format (gettext "Describe function (default %s): ") | |
1137 fn) | |
1138 (gettext "Describe function: ")) | |
430 | 1139 obarray 'fboundp t nil 'function-history |
1140 (symbol-name fn))))) | |
1141 (list (intern val)))) | |
428 | 1142 (with-displaying-help-buffer |
1143 (lambda () | |
1144 (describe-function-1 function) | |
1145 ;; Return the text we displayed. | |
1146 (buffer-string nil nil standard-output)) | |
1147 (format "function `%s'" function))) | |
1148 | |
1149 (defun function-obsolete-p (function) | |
1150 "Return non-nil if FUNCTION is obsolete." | |
1151 (not (null (get function 'byte-obsolete-info)))) | |
1152 | |
1153 (defun function-obsoleteness-doc (function) | |
1154 "If FUNCTION is obsolete, return a string describing this." | |
1155 (let ((obsolete (get function 'byte-obsolete-info))) | |
1156 (if obsolete | |
1157 (format "Obsolete; %s" | |
1158 (if (stringp (car obsolete)) | |
1159 (car obsolete) | |
1160 (format "use `%s' instead." (car obsolete))))))) | |
1161 | |
1162 (defun function-compatible-p (function) | |
1163 "Return non-nil if FUNCTION is present for Emacs compatibility." | |
1164 (not (null (get function 'byte-compatible-info)))) | |
1165 | |
1166 (defun function-compatibility-doc (function) | |
1167 "If FUNCTION is Emacs compatible, return a string describing this." | |
1168 (let ((compatible (get function 'byte-compatible-info))) | |
1169 (if compatible | |
1170 (format "Emacs Compatible; %s" | |
1171 (if (stringp (car compatible)) | |
1172 (car compatible) | |
1173 (format "use `%s' instead." (car compatible))))))) | |
1174 | |
1175 ;Here are all the possibilities below spelled out, for the benefit | |
1176 ;of the I18N3 snarfer. | |
1177 ; | |
1178 ;(gettext "a built-in function") | |
1179 ;(gettext "an interactive built-in function") | |
1180 ;(gettext "a built-in macro") | |
1181 ;(gettext "an interactive built-in macro") | |
1182 ;(gettext "a compiled Lisp function") | |
1183 ;(gettext "an interactive compiled Lisp function") | |
1184 ;(gettext "a compiled Lisp macro") | |
1185 ;(gettext "an interactive compiled Lisp macro") | |
1186 ;(gettext "a Lisp function") | |
1187 ;(gettext "an interactive Lisp function") | |
1188 ;(gettext "a Lisp macro") | |
1189 ;(gettext "an interactive Lisp macro") | |
1190 ;(gettext "an autoloaded Lisp function") | |
1191 ;(gettext "an interactive autoloaded Lisp function") | |
1192 ;(gettext "an autoloaded Lisp macro") | |
1193 ;(gettext "an interactive autoloaded Lisp macro") | |
1194 | |
1195 ;; taken out of `describe-function-1' | |
1196 (defun function-arglist (function) | |
1197 "Return a string giving the argument list of FUNCTION. | |
1198 For example: | |
1199 | |
1200 (function-arglist 'function-arglist) | |
4694
2ac296807b88
Don't needlessly intern symbols, #'function-arglist, #'cl-function-arglist
Aidan Kehoe <kehoea@parhasard.net>
parents:
4671
diff
changeset
|
1201 => \"(function-arglist FUNCTION)\" |
428 | 1202 |
1203 This function is used by `describe-function-1' to list function | |
1204 arguments in the standard Lisp style." | |
440 | 1205 (let* ((fnc (indirect-function function)) |
1206 (fndef (if (eq (car-safe fnc) 'macro) | |
1207 (cdr fnc) | |
1208 fnc)) | |
5070
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1209 (args (cdr (function-documentation-1 function t))) |
428 | 1210 (arglist |
5070
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1211 (or args |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1212 (cond ((compiled-function-p fndef) |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1213 (compiled-function-arglist fndef)) |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1214 ((eq (car-safe fndef) 'lambda) |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1215 (nth 1 fndef)) |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1216 ((or (subrp fndef) (eq 'autoload (car-safe fndef))) |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1217 |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1218 ;; If there are no arguments documented for the |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1219 ;; subr, rather don't print anything. |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1220 (cond ((null args) t) |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1221 ((equal args "") nil) |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1222 (args))) |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1223 (t t)))) |
4694
2ac296807b88
Don't needlessly intern symbols, #'function-arglist, #'cl-function-arglist
Aidan Kehoe <kehoea@parhasard.net>
parents:
4671
diff
changeset
|
1224 (print-gensym nil)) |
428 | 1225 (cond ((listp arglist) |
1226 (prin1-to-string | |
4694
2ac296807b88
Don't needlessly intern symbols, #'function-arglist, #'cl-function-arglist
Aidan Kehoe <kehoea@parhasard.net>
parents:
4671
diff
changeset
|
1227 (cons function (loop |
2ac296807b88
Don't needlessly intern symbols, #'function-arglist, #'cl-function-arglist
Aidan Kehoe <kehoea@parhasard.net>
parents:
4671
diff
changeset
|
1228 for arg in arglist |
2ac296807b88
Don't needlessly intern symbols, #'function-arglist, #'cl-function-arglist
Aidan Kehoe <kehoea@parhasard.net>
parents:
4671
diff
changeset
|
1229 collect (if (memq arg '(&optional &rest)) |
2ac296807b88
Don't needlessly intern symbols, #'function-arglist, #'cl-function-arglist
Aidan Kehoe <kehoea@parhasard.net>
parents:
4671
diff
changeset
|
1230 arg |
2ac296807b88
Don't needlessly intern symbols, #'function-arglist, #'cl-function-arglist
Aidan Kehoe <kehoea@parhasard.net>
parents:
4671
diff
changeset
|
1231 (make-symbol (upcase (symbol-name |
2ac296807b88
Don't needlessly intern symbols, #'function-arglist, #'cl-function-arglist
Aidan Kehoe <kehoea@parhasard.net>
parents:
4671
diff
changeset
|
1232 arg)))))) |
2ac296807b88
Don't needlessly intern symbols, #'function-arglist, #'cl-function-arglist
Aidan Kehoe <kehoea@parhasard.net>
parents:
4671
diff
changeset
|
1233 |
428 | 1234 t)) |
1235 ((stringp arglist) | |
5076
d555581e3cba
fix issues with display of argument docstrings
Ben Wing <ben@xemacs.org>
parents:
5071
diff
changeset
|
1236 (if (> (length arglist) 0) |
d555581e3cba
fix issues with display of argument docstrings
Ben Wing <ben@xemacs.org>
parents:
5071
diff
changeset
|
1237 (format "(%s %s)" function arglist) |
d555581e3cba
fix issues with display of argument docstrings
Ben Wing <ben@xemacs.org>
parents:
5071
diff
changeset
|
1238 (format "(%s)" function)))))) |
428 | 1239 |
5070
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1240 ;; If STRIP-ARGLIST is true, return a cons (DOC . ARGS) of the documentation |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1241 ;; with any embedded arglist stripped out, and the arglist that was stripped |
5071 | 1242 ;; out. If STRIP-ARGLIST is false, the cons will be (FULL-DOC . nil), |
5070
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1243 ;; where FULL-DOC is the full documentation without the embedded arglist |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1244 ;; stripped out. |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1245 (defun function-documentation-1 (function &optional strip-arglist) |
428 | 1246 (let ((doc (condition-case nil |
1247 (or (documentation function) | |
1248 (gettext "not documented")) | |
2275 | 1249 (void-function "(alias for undefined function)") |
5070
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1250 (error "(unexpected error from `documentation')"))) |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1251 args) |
4695
fee33ab25966
Add arglist info for autoloaded functions and macros.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4694
diff
changeset
|
1252 (when (and strip-arglist |
5070
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1253 (string-match "[\n\t ]*\narguments: ?(\\(.*\\))\n?\\'" doc)) |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1254 (setq args (match-string 1 doc)) |
4695
fee33ab25966
Add arglist info for autoloaded functions and macros.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4694
diff
changeset
|
1255 (setq doc (substring doc 0 (match-beginning 0))) |
5070
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1256 (and args (setq args (replace-in-string args "[ ]*\\\\\n[ \t]*" " " t))) |
5366
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
1257 (and (eql 0 (length doc)) (setq doc (gettext "not documented")))) |
5070
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1258 (cons doc args))) |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1259 |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1260 (defun function-documentation (function &optional strip-arglist) |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1261 "Return a string giving the documentation for FUNCTION, if any. |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1262 If the optional argument STRIP-ARGLIST is non-nil, remove the arglist |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1263 part of the documentation of internal subroutines, CL lambda forms, etc." |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1264 (car (function-documentation-1 function strip-arglist))) |
442 | 1265 |
462 | 1266 ;; replacement for `princ' that puts the text in the specified face, |
1267 ;; if possible | |
1268 (defun Help-princ-face (object face) | |
1269 (cond ((bufferp standard-output) | |
464 | 1270 (let ((opoint (point standard-output))) |
1271 (princ object) | |
1272 (put-nonduplicable-text-property opoint (point standard-output) | |
1273 'face face standard-output))) | |
1274 ((markerp standard-output) | |
1275 (let ((buf (marker-buffer standard-output)) | |
1276 (pos (marker-position standard-output))) | |
1277 (princ object) | |
1278 (put-nonduplicable-text-property | |
1279 pos (marker-position standard-output) 'face face buf))) | |
1779 | 1280 (t (princ object)))) |
462 | 1281 |
1282 ;; replacement for `prin1' that puts the text in the specified face, | |
1283 ;; if possible | |
1284 (defun Help-prin1-face (object face) | |
1285 (cond ((bufferp standard-output) | |
464 | 1286 (let ((opoint (point standard-output))) |
1287 (prin1 object) | |
1288 (put-nonduplicable-text-property opoint (point standard-output) | |
1289 'face face standard-output))) | |
1290 ((markerp standard-output) | |
1291 (let ((buf (marker-buffer standard-output)) | |
1292 (pos (marker-position standard-output))) | |
1293 (prin1 object) | |
1294 (put-nonduplicable-text-property | |
1295 pos (marker-position standard-output) 'face face buf))) | |
1779 | 1296 (t (prin1 object)))) |
462 | 1297 |
442 | 1298 (defvar help-symbol-regexp |
1299 (let ((sym-char "[+a-zA-Z0-9_:*]") | |
1300 (sym-char-no-dash "[-+a-zA-Z0-9_:*]")) | |
1301 (concat "\\(" | |
1302 ;; a symbol with a - in it. | |
1303 "\\<\\(" sym-char-no-dash "+\\(-" sym-char-no-dash "+\\)+\\)\\>" | |
1304 "\\|" | |
1305 "`\\(" sym-char "+\\)'" | |
1306 "\\)"))) | |
1307 | |
1308 (defun help-symbol-run-function-1 (ev ex fun) | |
1309 (let ((help-sticky-window | |
1310 ;; if we were called from a help buffer, make sure the new help | |
1311 ;; goes in the same window. | |
5793
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1312 (if (and ev |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1313 (event-buffer ev) |
442 | 1314 (symbol-value-in-buffer 'help-window-config |
1315 (event-buffer ev))) | |
1316 (event-window ev) | |
5793
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1317 (if ev help-sticky-window |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1318 (get-buffer-window (current-buffer)))))) |
442 | 1319 (funcall fun (extent-property ex 'help-symbol)))) |
1320 | |
1321 (defun help-symbol-run-function (fun) | |
1322 (let ((ex (extent-at-event last-popup-menu-event 'help-symbol))) | |
1323 (when ex | |
1324 (help-symbol-run-function-1 last-popup-menu-event ex fun)))) | |
1325 | |
1326 (defvar help-symbol-function-context-menu | |
462 | 1327 '(["View %_Documentation" (help-symbol-run-function 'describe-function)] |
4103 | 1328 ["Find %_Function Source" (help-symbol-run-function 'find-function) |
5368
ed74d2ca7082
Use ', not #', when a given symbol may not have a function binding at read time
Aidan Kehoe <kehoea@parhasard.net>
parents:
5366
diff
changeset
|
1329 (fboundp 'find-function)] |
462 | 1330 ["Find %_Tag" (help-symbol-run-function 'find-tag)] |
442 | 1331 )) |
1332 | |
1333 (defvar help-symbol-variable-context-menu | |
462 | 1334 '(["View %_Documentation" (help-symbol-run-function 'describe-variable)] |
4103 | 1335 ["Find %_Variable Source" (help-symbol-run-function 'find-variable) |
5368
ed74d2ca7082
Use ', not #', when a given symbol may not have a function binding at read time
Aidan Kehoe <kehoea@parhasard.net>
parents:
5366
diff
changeset
|
1336 (fboundp 'find-variable)] |
462 | 1337 ["Find %_Tag" (help-symbol-run-function 'find-tag)] |
442 | 1338 )) |
1339 | |
1340 (defvar help-symbol-function-and-variable-context-menu | |
462 | 1341 '(["View Function %_Documentation" (help-symbol-run-function |
442 | 1342 'describe-function)] |
1343 ["View Variable D%_ocumentation" (help-symbol-run-function | |
1344 'describe-variable)] | |
4103 | 1345 ["Find %_Function Source" (help-symbol-run-function 'find-function) |
5368
ed74d2ca7082
Use ', not #', when a given symbol may not have a function binding at read time
Aidan Kehoe <kehoea@parhasard.net>
parents:
5366
diff
changeset
|
1346 (fboundp 'find-function)] |
4103 | 1347 ["Find %_Variable Source" (help-symbol-run-function 'find-variable) |
5368
ed74d2ca7082
Use ', not #', when a given symbol may not have a function binding at read time
Aidan Kehoe <kehoea@parhasard.net>
parents:
5366
diff
changeset
|
1348 (fboundp 'find-variable)] |
462 | 1349 ["Find %_Tag" (help-symbol-run-function 'find-tag)] |
442 | 1350 )) |
1351 | |
1352 (defun frob-help-extents (buffer) | |
1353 ;; Look through BUFFER, starting at the buffer's point and continuing | |
1354 ;; till end of file, and find documented functions and variables. | |
1355 ;; any such symbol found is tagged with an extent, that sets up these | |
1356 ;; properties: | |
1357 ;; 1. mouse-face is 'highlight (so the extent gets highlighted on mouse over) | |
1358 ;; 2. help-symbol is the name of the symbol. | |
464 | 1359 ;; 3. face is 'hyper-apropos-hyperlink. |
462 | 1360 ;; 4. context-menu is a list of context menu items, specific to whether |
442 | 1361 ;; the symbol is a function, variable, or both. |
462 | 1362 ;; 5. activate-function will cause the function or variable to be described, |
442 | 1363 ;; replacing the existing help contents. |
1364 (save-excursion | |
1365 (set-buffer buffer) | |
1366 (let (b e name) | |
1367 (while (re-search-forward help-symbol-regexp nil t) | |
1368 (setq b (or (match-beginning 2) (match-beginning 4))) | |
1369 (setq e (or (match-end 2) (match-end 4))) | |
1370 (setq name (buffer-substring b e)) | |
1371 (let* ((sym (intern-soft name)) | |
1372 (var (and sym (boundp sym) | |
1373 (documentation-property sym | |
1374 'variable-documentation t))) | |
1375 (fun (and sym (fboundp sym) | |
2275 | 1376 (condition-case nil |
1377 (documentation sym t) | |
1378 (void-function "(alias for undefined function)") | |
1379 (error "(unexpected error from `documention')"))))) | |
442 | 1380 (when (or var fun) |
1381 (let ((ex (make-extent b e))) | |
622 | 1382 (require 'hyper-apropos) |
3368 | 1383 |
442 | 1384 (set-extent-property ex 'mouse-face 'highlight) |
1385 (set-extent-property ex 'help-symbol sym) | |
464 | 1386 (set-extent-property ex 'face 'hyper-apropos-hyperlink) |
442 | 1387 (set-extent-property |
1388 ex 'context-menu | |
1389 (cond ((and var fun) | |
1390 help-symbol-function-and-variable-context-menu) | |
1391 (var help-symbol-variable-context-menu) | |
1392 (fun help-symbol-function-context-menu))) | |
1393 (set-extent-property | |
1394 ex 'activate-function | |
1395 (if fun | |
1396 #'(lambda (ev ex) | |
1397 (help-symbol-run-function-1 ev ex 'describe-function)) | |
1398 #'(lambda (ev ex) | |
1399 (help-symbol-run-function-1 ev ex 'describe-variable)))) | |
1400 ))))))) ;; 11 parentheses! | |
428 | 1401 |
1402 (defun describe-function-1 (function &optional nodoc) | |
1403 "This function does the work for `describe-function'." | |
462 | 1404 (princ "`") |
1405 ;; (Help-princ-face function 'font-lock-function-name-face) overkill | |
1406 (princ function) | |
1407 (princ "' is ") | |
428 | 1408 (let* ((def function) |
4595
a1a8728fec10
Distinguish between special forms and subrs, #'describe-function-1.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4535
diff
changeset
|
1409 aliases file-name kbd-macro-p fndef macrop) |
428 | 1410 (while (and (symbolp def) (fboundp def)) |
1411 (when (not (eq def function)) | |
1412 (setq aliases | |
1413 (if aliases | |
1414 ;; I18N3 Need gettext due to concat | |
1415 (concat aliases | |
1416 (format | |
1417 "\n which is an alias for `%s', " | |
1418 (symbol-name def))) | |
1419 (format "an alias for `%s', " (symbol-name def))))) | |
1420 (setq def (symbol-function def))) | |
1421 (if (eq 'macro (car-safe def)) | |
1422 (setq fndef (cdr def) | |
1423 macrop t) | |
1424 (setq fndef def)) | |
1425 (if aliases (princ aliases)) | |
5594
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1426 (labels |
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1427 ((int (string an-p macro-p) |
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1428 (princ (format |
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1429 (gettext (concat |
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1430 (cond ((commandp def) |
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1431 "an interactive ") |
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1432 (an-p "an ") |
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1433 (t "a ")) |
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1434 "%s" |
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1435 (cond |
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1436 ((eq 'neither macro-p) |
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1437 "") |
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1438 (macro-p " macro") |
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1439 (t " function")))) |
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1440 string)))) |
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1441 (declare (inline int)) |
428 | 1442 (cond ((or (stringp def) (vectorp def)) |
1443 (princ "a keyboard macro.") | |
1444 (setq kbd-macro-p t)) | |
4905
755ae5b97edb
Change "special form" to "special operator" in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4695
diff
changeset
|
1445 ((special-operator-p fndef) |
5594
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1446 (int "built-in special operator" nil 'neither)) |
428 | 1447 ((subrp fndef) |
5594
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1448 (int "built-in" nil macrop)) |
428 | 1449 ((compiled-function-p fndef) |
5594
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1450 (int (concat (if (built-in-symbol-file function 'defun) |
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1451 "built-in " |
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1452 "") "compiled Lisp") nil macrop)) |
428 | 1453 ((eq (car-safe fndef) 'lambda) |
5594
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1454 (int "Lisp" nil macrop)) |
428 | 1455 ((eq (car-safe def) 'autoload) |
5594
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1456 (int "autoloaded Lisp" t (elt def 4))) |
428 | 1457 ((and (symbolp def) (not (fboundp def))) |
1458 (princ "a symbol with a void (unbound) function definition.")) | |
1459 (t | |
1460 nil))) | |
1461 (princ "\n") | |
1462 (or file-name | |
4535
69a1eda3da06
Distinguish vars and functions in #'symbol-file, #'describe-{function,variable}
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1463 (setq file-name (symbol-file function 'defun))) |
3368 | 1464 (when file-name |
1465 (princ " -- loaded from \"") | |
1466 (if (not (bufferp standard-output)) | |
1467 (princ file-name) | |
1468 (let ((opoint (point standard-output)) | |
1469 e) | |
1470 (require 'hyper-apropos) | |
1471 (princ file-name) | |
1472 (setq e (make-extent opoint (point standard-output) | |
1473 standard-output)) | |
1474 (set-extent-property e 'face 'hyper-apropos-hyperlink) | |
1475 (set-extent-property e 'mouse-face 'highlight) | |
5793
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1476 (set-extent-property e 'help-symbol function) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1477 (set-extent-property e 'activate-function #'(lambda (ev ex) (help-symbol-run-function-1 ev ex 'find-function))))) |
3368 | 1478 (princ "\"\n")) |
428 | 1479 (if describe-function-show-arglist |
1480 (let ((arglist (function-arglist function))) | |
1481 (when arglist | |
464 | 1482 (require 'hyper-apropos) |
1483 (Help-princ-face arglist 'hyper-apropos-documentation) | |
428 | 1484 (terpri)))) |
1485 (terpri) | |
1486 (cond (kbd-macro-p | |
1487 (princ "These characters are executed:\n\n\t") | |
1488 (princ (key-description def)) | |
1489 (cond ((setq def (key-binding def)) | |
1490 (princ (format "\n\nwhich executes the command `%s'.\n\n" | |
1491 def)) | |
1492 (describe-function-1 def)))) | |
1493 (nodoc nil) | |
1494 (t | |
1495 ;; tell the user about obsoleteness. | |
1496 ;; If the function is obsolete and is aliased, don't | |
1497 ;; even bother to report the documentation, as a further | |
1498 ;; encouragement to use the new function. | |
1499 (let ((obsolete (function-obsoleteness-doc function)) | |
1500 (compatible (function-compatibility-doc function))) | |
1501 (when obsolete | |
1502 (princ obsolete) | |
1503 (terpri) | |
1504 (terpri)) | |
1505 (when compatible | |
1506 (princ compatible) | |
1507 (terpri) | |
1508 (terpri)) | |
1509 (unless (and obsolete aliases) | |
1510 (let ((doc (function-documentation function t))) | |
1511 (princ "Documentation:\n") | |
442 | 1512 (let ((oldp (point standard-output)) |
1513 newp) | |
1514 (princ doc) | |
1515 (setq newp (point standard-output)) | |
1516 (goto-char oldp standard-output) | |
1517 (frob-help-extents standard-output) | |
1518 (goto-char newp standard-output)) | |
428 | 1519 (unless (or (equal doc "") |
1520 (eq ?\n (aref doc (1- (length doc))))) | |
4335
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1521 (terpri))) |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1522 (when (commandp function) |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1523 (princ "\nInvoked with:\n") |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1524 (let ((global-binding |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1525 (where-is-internal function global-map)) |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1526 (global-tty-binding |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1527 (where-is-internal function global-tty-map)) |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1528 (global-window-system-binding |
5679
a81a739181dc
Add command remapping, a more robust alternative to #'substitute-key-definition
Aidan Kehoe <kehoea@parhasard.net>
parents:
5594
diff
changeset
|
1529 (where-is-internal function global-window-system-map)) |
a81a739181dc
Add command remapping, a more robust alternative to #'substitute-key-definition
Aidan Kehoe <kehoea@parhasard.net>
parents:
5594
diff
changeset
|
1530 (command-remapping (command-remapping function)) |
a81a739181dc
Add command remapping, a more robust alternative to #'substitute-key-definition
Aidan Kehoe <kehoea@parhasard.net>
parents:
5594
diff
changeset
|
1531 (commands-remapped-to (commands-remapped-to function))) |
4335
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1532 (if (or global-binding global-tty-binding |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1533 global-window-system-binding) |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1534 (if (and (equal global-binding |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1535 global-tty-binding) |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1536 (equal global-binding |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1537 global-window-system-binding)) |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1538 (princ |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1539 (substitute-command-keys |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1540 (format "\n\\[%s]" function))) |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1541 (when (and global-window-system-binding |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1542 (not (equal global-window-system-binding |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1543 global-binding))) |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1544 (princ |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1545 (format |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1546 "\n%s\n -- under window systems\n" |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1547 (mapconcat #'key-description |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1548 global-window-system-binding |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1549 ", ")))) |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1550 (when (and global-tty-binding |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1551 (not (equal global-tty-binding |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1552 global-binding))) |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1553 (princ |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1554 (format |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1555 "\n%s\n -- under TTYs\n" |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1556 (mapconcat #'key-description |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1557 global-tty-binding |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1558 ", ")))) |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1559 (when global-binding |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1560 (princ |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1561 (format |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1562 "\n%s\n -- generally (that is, unless\ |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1563 overridden by TTY- or |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1564 window-system-specific mappings)\n" |
5679
a81a739181dc
Add command remapping, a more robust alternative to #'substitute-key-definition
Aidan Kehoe <kehoea@parhasard.net>
parents:
5594
diff
changeset
|
1565 (mapconcat #'key-description global-binding |
4335
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1566 ", "))))) |
5679
a81a739181dc
Add command remapping, a more robust alternative to #'substitute-key-definition
Aidan Kehoe <kehoea@parhasard.net>
parents:
5594
diff
changeset
|
1567 (if command-remapping |
a81a739181dc
Add command remapping, a more robust alternative to #'substitute-key-definition
Aidan Kehoe <kehoea@parhasard.net>
parents:
5594
diff
changeset
|
1568 (progn |
a81a739181dc
Add command remapping, a more robust alternative to #'substitute-key-definition
Aidan Kehoe <kehoea@parhasard.net>
parents:
5594
diff
changeset
|
1569 (princ "Its keys are remapped to `") |
a81a739181dc
Add command remapping, a more robust alternative to #'substitute-key-definition
Aidan Kehoe <kehoea@parhasard.net>
parents:
5594
diff
changeset
|
1570 (princ (symbol-name command-remapping)) |
a81a739181dc
Add command remapping, a more robust alternative to #'substitute-key-definition
Aidan Kehoe <kehoea@parhasard.net>
parents:
5594
diff
changeset
|
1571 (princ "'.\n")) |
a81a739181dc
Add command remapping, a more robust alternative to #'substitute-key-definition
Aidan Kehoe <kehoea@parhasard.net>
parents:
5594
diff
changeset
|
1572 (princ (substitute-command-keys |
a81a739181dc
Add command remapping, a more robust alternative to #'substitute-key-definition
Aidan Kehoe <kehoea@parhasard.net>
parents:
5594
diff
changeset
|
1573 (format "\n\\[%s]" function)))) |
a81a739181dc
Add command remapping, a more robust alternative to #'substitute-key-definition
Aidan Kehoe <kehoea@parhasard.net>
parents:
5594
diff
changeset
|
1574 (when commands-remapped-to |
a81a739181dc
Add command remapping, a more robust alternative to #'substitute-key-definition
Aidan Kehoe <kehoea@parhasard.net>
parents:
5594
diff
changeset
|
1575 (if (cdr commands-remapped-to) |
5692
be87f507f510
Handle interactive command remapping a little better than 7371081ce8f7, keymap.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
5691
diff
changeset
|
1576 (princ (format "\n\nThe following functions are \ |
5679
a81a739181dc
Add command remapping, a more robust alternative to #'substitute-key-definition
Aidan Kehoe <kehoea@parhasard.net>
parents:
5594
diff
changeset
|
1577 remapped to it:\n`%s'" (mapconcat #'prin1-to-string commands-remapped-to |
a81a739181dc
Add command remapping, a more robust alternative to #'substitute-key-definition
Aidan Kehoe <kehoea@parhasard.net>
parents:
5594
diff
changeset
|
1578 "', `"))) |
5692
be87f507f510
Handle interactive command remapping a little better than 7371081ce8f7, keymap.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
5691
diff
changeset
|
1579 (princ (format "\n\n`%s' is remapped to it.\n" |
5679
a81a739181dc
Add command remapping, a more robust alternative to #'substitute-key-definition
Aidan Kehoe <kehoea@parhasard.net>
parents:
5594
diff
changeset
|
1580 (car |
a81a739181dc
Add command remapping, a more robust alternative to #'substitute-key-definition
Aidan Kehoe <kehoea@parhasard.net>
parents:
5594
diff
changeset
|
1581 commands-remapped-to)))))))))))))) |
428 | 1582 |
1583 ;;; [Obnoxious, whining people who complain very LOUDLY on Usenet | |
1584 ;;; are binding this to keys.] | |
1585 (defun describe-function-arglist (function) | |
1586 (interactive (list (or (function-at-point) | |
1587 (error "no function call at point")))) | |
1588 (message nil) | |
1589 (message (function-arglist function))) | |
1590 | |
1591 (defun variable-at-point () | |
1592 (ignore-errors | |
1593 (with-syntax-table emacs-lisp-mode-syntax-table | |
1594 (save-excursion | |
1595 (or (not (zerop (skip-syntax-backward "_w"))) | |
1596 (eq (char-syntax (char-after (point))) ?w) | |
1597 (eq (char-syntax (char-after (point))) ?_) | |
1598 (forward-sexp -1)) | |
1599 (skip-chars-forward "'") | |
1600 (let ((obj (read (current-buffer)))) | |
1601 (and (symbolp obj) (boundp obj) obj)))))) | |
1602 | |
442 | 1603 (defun variable-at-event (event) |
1604 "Return the variable whose name is around the position of EVENT. | |
1605 EVENT should be a mouse event. When calling from a popup or context menu, | |
1606 use `last-popup-menu-event' to find out where the mouse was clicked. | |
1607 \(You cannot use (interactive \"e\"), unfortunately. This returns a | |
1608 misc-user event.) | |
1609 | |
1610 If the event contains no position, or the position is not over text, or | |
1611 there is no variable around that point, nil is returned." | |
1612 (if (and event (event-buffer event) (event-point event)) | |
1613 (save-excursion | |
1614 (set-buffer (event-buffer event)) | |
1615 (goto-char (event-point event)) | |
1616 (variable-at-point)))) | |
1617 | |
428 | 1618 (defun variable-obsolete-p (variable) |
1619 "Return non-nil if VARIABLE is obsolete." | |
1620 (not (null (get variable 'byte-obsolete-variable)))) | |
1621 | |
1622 (defun variable-obsoleteness-doc (variable) | |
1623 "If VARIABLE is obsolete, return a string describing this." | |
1624 (let ((obsolete (get variable 'byte-obsolete-variable))) | |
1625 (if obsolete | |
1626 (format "Obsolete; %s" | |
1627 (if (stringp obsolete) | |
1628 obsolete | |
1629 (format "use `%s' instead." obsolete)))))) | |
1630 | |
1631 (defun variable-compatible-p (variable) | |
1632 "Return non-nil if VARIABLE is Emacs compatible." | |
1633 (not (null (get variable 'byte-compatible-variable)))) | |
1634 | |
1635 (defun variable-compatibility-doc (variable) | |
1636 "If VARIABLE is Emacs compatible, return a string describing this." | |
1637 (let ((compatible (get variable 'byte-compatible-variable))) | |
1638 (if compatible | |
1639 (format "Emacs Compatible; %s" | |
1640 (if (stringp compatible) | |
1641 compatible | |
1642 (format "use `%s' instead." compatible)))))) | |
1643 | |
1644 (defun built-in-variable-doc (variable) | |
1645 "Return a string describing whether VARIABLE is built-in." | |
1646 (let ((type (built-in-variable-type variable))) | |
1647 (case type | |
1648 (integer "a built-in integer variable") | |
1649 (const-integer "a built-in constant integer variable") | |
1650 (boolean "a built-in boolean variable") | |
1651 (const-boolean "a built-in constant boolean variable") | |
1652 (object "a simple built-in variable") | |
1653 (const-object "a simple built-in constant variable") | |
1654 (const-specifier "a built-in constant specifier variable") | |
1655 (current-buffer "a built-in buffer-local variable") | |
1656 (const-current-buffer "a built-in constant buffer-local variable") | |
1657 (default-buffer "a built-in default buffer-local variable") | |
1658 (selected-console "a built-in console-local variable") | |
1659 (const-selected-console "a built-in constant console-local variable") | |
1660 (default-console "a built-in default console-local variable") | |
1661 (t | |
1662 (if type "an unknown type of built-in variable?" | |
1663 "a variable declared in Lisp"))))) | |
1664 | |
5793
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1665 (defun describe-variable-custom-version-info (variable) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1666 (let ((custom-version (get variable 'custom-version)) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1667 (cpv (get variable 'custom-package-version)) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1668 (output nil)) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1669 (if custom-version |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1670 (setq output |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1671 (format "This variable was introduced, or its default value was changed, in\nversion %s of XEmacs.\n" |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1672 custom-version)) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1673 (when cpv |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1674 (let* ((package (car-safe cpv)) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1675 (version (if (listp (cdr-safe cpv)) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1676 (car (cdr-safe cpv)) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1677 (cdr-safe cpv))) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1678 (pkg-versions (assq package customize-package-emacs-version-alist)) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1679 (emacsv (cdr (assoc version pkg-versions)))) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1680 (if (and package version) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1681 (setq output |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1682 (format (concat "This variable was introduced, or its default value was changed, in\nversion %s of the %s package" |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1683 (if emacsv |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1684 (format " that is part of XEmacs %s" emacsv)) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1685 ".\n") |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1686 version package)))))) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1687 output)) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1688 |
428 | 1689 (defun describe-variable (variable) |
1690 "Display the full documentation of VARIABLE (a symbol)." | |
1691 (interactive | |
1692 (let* ((v (variable-at-point)) | |
1693 (val (let ((enable-recursive-minibuffers t)) | |
1694 (completing-read | |
1695 (if v | |
1696 (format "Describe variable (default %s): " v) | |
1697 (gettext "Describe variable: ")) | |
430 | 1698 obarray 'boundp t nil 'variable-history |
1699 (symbol-name v))))) | |
1700 (list (intern val)))) | |
428 | 1701 (with-displaying-help-buffer |
1702 (lambda () | |
1703 (let ((origvar variable) | |
1704 aliases) | |
1705 (let ((print-escape-newlines t)) | |
462 | 1706 (princ "`") |
1707 ;; (Help-princ-face (symbol-name variable) | |
502 | 1708 ;; 'font-lock-variable-name-face) overkill |
462 | 1709 (princ (symbol-name variable)) |
1710 (princ "' is ") | |
428 | 1711 (while (variable-alias variable) |
1712 (let ((newvar (variable-alias variable))) | |
1713 (if aliases | |
1714 ;; I18N3 Need gettext due to concat | |
1715 (setq aliases | |
1716 (concat aliases | |
1717 (format "\n which is an alias for `%s'," | |
1718 (symbol-name newvar)))) | |
1719 (setq aliases | |
1720 (format "an alias for `%s'," | |
1721 (symbol-name newvar)))) | |
1722 (setq variable newvar))) | |
1723 (if aliases | |
1724 (princ (format "%s" aliases))) | |
1725 (princ (built-in-variable-doc variable)) | |
1726 (princ ".\n") | |
3368 | 1727 (require 'hyper-apropos) |
4535
69a1eda3da06
Distinguish vars and functions in #'symbol-file, #'describe-{function,variable}
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1728 (let ((file-name (symbol-file variable 'defvar)) |
3368 | 1729 opoint e) |
1730 (when file-name | |
1731 (princ " -- loaded from \"") | |
1732 (if (not (bufferp standard-output)) | |
1733 (princ file-name) | |
1734 (setq opoint (point standard-output)) | |
1735 (princ file-name) | |
1736 (setq e (make-extent opoint (point standard-output) | |
1737 standard-output)) | |
1738 (set-extent-property e 'face 'hyper-apropos-hyperlink) | |
1739 (set-extent-property e 'mouse-face 'highlight) | |
5793
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1740 (set-extent-property e 'help-symbol variable) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1741 (set-extent-property e 'activate-function #'(lambda (ev ex) (help-symbol-run-function-1 ev ex 'find-variable)))) |
3368 | 1742 (princ"\"\n"))) |
428 | 1743 (princ "\nValue: ") |
464 | 1744 (if (not (boundp variable)) |
1745 (Help-princ-face "void\n" 'hyper-apropos-documentation) | |
1746 (Help-prin1-face (symbol-value variable) | |
1747 'hyper-apropos-documentation) | |
428 | 1748 (terpri)) |
1749 (terpri) | |
1750 (cond ((local-variable-p variable (current-buffer)) | |
1751 (let* ((void (cons nil nil)) | |
1752 (def (condition-case nil | |
1753 (default-value variable) | |
1754 (error void)))) | |
1755 (princ "This value is specific to the current buffer.\n") | |
1756 (if (local-variable-p variable nil) | |
1757 (princ "(Its value is local to each buffer.)\n")) | |
1758 (terpri) | |
1759 (if (if (eq def void) | |
1760 (boundp variable) | |
1761 (not (eq (symbol-value variable) def))) | |
1762 ;; #### I18N3 doesn't localize properly! | |
1763 (progn (princ "Default-value: ") | |
1764 (if (eq def void) | |
1765 (princ "void\n") | |
1766 (prin1 def) | |
1767 (terpri)) | |
1768 (terpri))))) | |
1769 ((local-variable-p variable (current-buffer) t) | |
1770 (princ "Setting it would make its value buffer-local.\n\n")))) | |
1771 (princ "Documentation:") | |
1772 (terpri) | |
1773 (let ((doc (documentation-property variable 'variable-documentation)) | |
1774 (obsolete (variable-obsoleteness-doc origvar)) | |
1775 (compatible (variable-compatibility-doc origvar))) | |
1776 (when obsolete | |
1777 (princ obsolete) | |
1778 (terpri) | |
1779 (terpri)) | |
1780 (when compatible | |
1781 (princ compatible) | |
1782 (terpri) | |
1783 (terpri)) | |
1784 ;; don't bother to print anything if variable is obsolete and aliased. | |
1785 (when (or (not obsolete) (not aliases)) | |
1786 (if doc | |
1787 ;; note: documentation-property calls substitute-command-keys. | |
442 | 1788 (let ((oldp (point standard-output)) |
1789 newp) | |
1790 (princ doc) | |
1791 (setq newp (point standard-output)) | |
1792 (goto-char oldp standard-output) | |
1793 (frob-help-extents standard-output) | |
1794 (goto-char newp standard-output)) | |
428 | 1795 (princ "not documented as a variable.")))) |
5793
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1796 ;; Make a link to customize if this variable can be customized. |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1797 (when (custom-variable-p variable) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1798 (let ((customize-label "customize")) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1799 (terpri) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1800 (terpri) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1801 (princ (concat "You can " customize-label " this variable.")) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1802 (with-current-buffer standard-output |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1803 (save-excursion |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1804 (re-search-backward |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1805 (concat "\\(" customize-label "\\)") nil t) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1806 (let ((opoint (point standard-output)) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1807 e) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1808 (require 'hyper-apropos) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1809 ;; (princ variable) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1810 (re-search-forward (concat "\\(" customize-label "\\)") nil t) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1811 (setq e (make-extent opoint (point standard-output) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1812 standard-output)) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1813 (set-extent-property e 'face 'hyper-apropos-hyperlink) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1814 (set-extent-property e 'mouse-face 'highlight) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1815 (set-extent-property e 'help-symbol variable) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1816 (set-extent-property e 'activate-function #'(lambda (ev ex) (help-symbol-run-function-1 ev ex 'customize-variable))))))) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1817 ;; Note variable's version or package version |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1818 (let ((output (describe-variable-custom-version-info variable))) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1819 (when output |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1820 (terpri) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1821 (terpri) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1822 (princ output)))) |
428 | 1823 (terpri))) |
1824 (format "variable `%s'" variable))) | |
1825 | |
1826 (defun sorted-key-descriptions (keys &optional separator) | |
1827 "Sort and separate the key descriptions for KEYS. | |
1828 The sorting is done by length (shortest bindings first), and the bindings | |
1829 are separated with SEPARATOR (\", \" by default)." | |
1830 (mapconcat 'key-description | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5076
diff
changeset
|
1831 (sort* keys #'< :key #'length) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5076
diff
changeset
|
1832 (or separator ", "))) |
428 | 1833 |
1834 (defun where-is (definition &optional insert) | |
1835 "Print message listing key sequences that invoke specified command. | |
1836 Argument is a command definition, usually a symbol with a function definition. | |
1837 When run interactively, it defaults to any function found by | |
1838 `function-at-point'. | |
1839 If INSERT (the prefix arg) is non-nil, insert the message in the buffer." | |
1840 (interactive | |
1841 (let ((fn (function-at-point)) | |
1842 (enable-recursive-minibuffers t) | |
1843 val) | |
1844 (setq val (read-command | |
1845 (if fn (format "Where is command (default %s): " fn) | |
456 | 1846 "Where is command: ") |
1847 (and fn (symbol-name fn)))) | |
428 | 1848 (list (if (equal (symbol-name val) "") |
1849 fn val) | |
1850 current-prefix-arg))) | |
1851 (let ((keys (where-is-internal definition))) | |
1852 (if keys | |
1853 (if insert | |
1854 (princ (format "%s (%s)" (sorted-key-descriptions keys) | |
1855 definition) (current-buffer)) | |
1856 (message "%s is on %s" definition (sorted-key-descriptions keys))) | |
1857 (if insert | |
1858 (princ (format (if (commandp definition) "M-x %s RET" | |
1859 "M-: (%s ...)") definition) (current-buffer)) | |
1860 (message "%s is not on any keys" definition)))) | |
1861 nil) | |
1862 | |
1863 ;; `locate-library' moved to "packages.el" | |
1864 | |
1865 | |
1866 ;; Functions ported from C into Lisp in XEmacs | |
1867 | |
1868 (defun describe-syntax () | |
1869 "Describe the syntax specifications in the syntax table. | |
1870 The descriptions are inserted in a buffer, which is then displayed." | |
1871 (interactive) | |
1872 (with-displaying-help-buffer | |
1873 (lambda () | |
1874 ;; defined in syntax.el | |
1875 (describe-syntax-table (syntax-table) standard-output)) | |
1876 (format "syntax-table for %s" major-mode))) | |
1877 | |
1878 (defun list-processes () | |
1879 "Display a list of all processes. | |
1880 \(Any processes listed as Exited or Signaled are actually eliminated | |
1881 after the listing is made.)" | |
1882 (interactive) | |
1883 (with-output-to-temp-buffer "*Process List*" | |
1884 (set-buffer standard-output) | |
1885 (buffer-disable-undo standard-output) | |
1886 (make-local-variable 'truncate-lines) | |
1887 (setq truncate-lines t) | |
1888 ;; 00000000001111111111222222222233333333334444444444 | |
1889 ;; 01234567890123456789012345678901234567890123456789 | |
1890 ;; rewritten for I18N3. This one should stay rewritten | |
1891 ;; so that the dashes will line up properly. | |
1892 (princ "Proc Status Buffer Tty Command\n---- ------ ------ --- -------\n") | |
1893 (let ((tail (process-list))) | |
1894 (while tail | |
1895 (let* ((p (car tail)) | |
1896 (pid (process-id p)) | |
1897 (s (process-status p))) | |
1898 (setq tail (cdr tail)) | |
1899 (princ (format "%-13s" (process-name p))) | |
1900 (princ s) | |
1901 (if (and (eq s 'exit) (/= (process-exit-status p) 0)) | |
1902 (princ (format " %d" (process-exit-status p)))) | |
1903 (if (memq s '(signal exit closed)) | |
1904 ;; Do delete-exited-processes' work | |
1905 (delete-process p)) | |
1906 (indent-to 22 1) ;#### | |
1907 (let ((b (process-buffer p))) | |
1908 (cond ((not b) | |
1909 (princ "(none)")) | |
1910 ((not (buffer-name b)) | |
1911 (princ "(killed)")) | |
1912 (t | |
1913 (princ (buffer-name b))))) | |
1914 (indent-to 37 1) ;#### | |
1915 (let ((tn (process-tty-name p))) | |
1916 (cond ((not tn) | |
1917 (princ "(none)")) | |
1918 (t | |
1919 (princ (format "%s" tn))))) | |
1920 (indent-to 49 1) ;#### | |
1921 (if (not (integerp pid)) | |
1922 (progn | |
1923 (princ "network stream connection ") | |
1924 (princ (car pid)) | |
1925 (princ "@") | |
1926 (princ (cdr pid))) | |
1927 (let ((cmd (process-command p))) | |
1928 (while cmd | |
1929 (princ (car cmd)) | |
1930 (setq cmd (cdr cmd)) | |
1931 (if cmd (princ " "))))) | |
1932 (terpri)))))) | |
1933 | |
440 | 1934 ;; Stop gap for 21.0 until we do help-char etc properly. |
428 | 1935 (defun help-keymap-with-help-key (keymap form) |
1936 "Return a copy of KEYMAP with an help-key binding according to help-char | |
1937 invoking FORM like help-form. An existing binding is not overridden. | |
1938 If FORM is nil then no binding is made." | |
1939 (let ((map (copy-keymap keymap)) | |
1940 (key (if (characterp help-char) | |
1941 (vector (character-to-event help-char)) | |
1942 help-char))) | |
1943 (when (and form key (not (lookup-key map key))) | |
1944 (define-key map key | |
1945 `(lambda () (interactive) (help-print-help-form ,form)))) | |
1946 map)) | |
1947 | |
1948 (defun help-print-help-form (form) | |
1949 (let ((string (eval form))) | |
1950 (if (stringp string) | |
1951 (with-displaying-help-buffer | |
1952 (insert string))))) | |
1953 | |
5793
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1954 (defun help-activate-function-or-scroll-up (&optional pos) |
3368 | 1955 "Follow any cross reference to source code; if none, scroll up. " |
1956 (interactive "d") | |
5793
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1957 (let ((e (extent-at pos nil 'activate-function))) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1958 (if e |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1959 (funcall (extent-property e 'activate-function) nil e) |
cf0201de66df
Help buffer behaviour synced with GNU
Mats Lidell <mats.lidell@cag.se>
parents:
5692
diff
changeset
|
1960 (scroll-up 1)))) |
3368 | 1961 |
4506
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1962 (define-minor-mode temp-buffer-resize-mode |
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1963 "Toggle the mode which makes windows smaller for temporary buffers. |
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1964 With prefix argument ARG, turn the resizing of windows displaying temporary |
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1965 buffers on if ARG is positive or off otherwise. |
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1966 This makes the window the right height for its contents, but never |
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1967 less than `window-min-height' nor a higher proportion of its frame than |
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1968 `temp-buffer-max-height'. (Note the differing semantics of the latter |
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1969 versus GNU Emacs, where `temp-buffer-max-height' is an integer number of |
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1970 lines.) |
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1971 This applies to `help', `apropos' and `completion' buffers, and some others." |
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1972 :global t :group 'help |
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1973 ;; XEmacs; our implementation of this is very different. |
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1974 (setq temp-buffer-shrink-to-fit temp-buffer-resize-mode)) |
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1975 |
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1976 ;; GNU name for this function. |
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1977 (defalias 'resize-temp-buffer-window 'shrink-window-if-larger-than-buffer) |
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1978 |
428 | 1979 ;;; help.el ends here |