aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2001-10-11 23:33:52 +0000
committerStefan Monnier2001-10-11 23:33:52 +0000
commit89f5b33fc70bdc2f0edc4a0ef75542a1a12bc133 (patch)
tree67d6530f50ae20faf24edd4aa7199efe6afa3fdd
parent94ea540bda316cd73e2d8d69e8cb4114508dd4b3 (diff)
downloademacs-89f5b33fc70bdc2f0edc4a0ef75542a1a12bc133.tar.gz
emacs-89f5b33fc70bdc2f0edc4a0ef75542a1a12bc133.zip
(help-buffer): New function.
Returns the buffer-name to use for help output. Change all the code to use it instead of hard-coding *Help*. (help-mode-map): Put back the mouse-2 binding. (help-xref-stack): Change the format and make buffer-local. (help-xref-stack-item): Make buffer-local. (help-setup-xref): Do the `push' here rather than in help-do-xref. (help-xref-interned): Display the face doc as well. (help-follow-mouse): Re-introduce. (help-xref-go-back): Adapt to the new use of help-xref-stack. (help-do-xref): Don't `push' any more. (help-follow): Also follow face names.
-rw-r--r--lisp/help-mode.el112
1 files changed, 80 insertions, 32 deletions
diff --git a/lisp/help-mode.el b/lisp/help-mode.el
index 24ab7b62e36..79aa2033bc7 100644
--- a/lisp/help-mode.el
+++ b/lisp/help-mode.el
@@ -38,6 +38,7 @@
38 38
39(set-keymap-parent help-mode-map button-buffer-map) 39(set-keymap-parent help-mode-map button-buffer-map)
40 40
41(define-key help-mode-map [mouse-2] 'help-follow-mouse)
41(define-key help-mode-map "\C-c\C-b" 'help-go-back) 42(define-key help-mode-map "\C-c\C-b" 'help-go-back)
42(define-key help-mode-map "\C-c\C-c" 'help-follow) 43(define-key help-mode-map "\C-c\C-c" 'help-follow)
43;; Documentation only, since we use minor-mode-overriding-map-alist. 44;; Documentation only, since we use minor-mode-overriding-map-alist.
@@ -46,16 +47,16 @@
46(defvar help-xref-stack nil 47(defvar help-xref-stack nil
47 "A stack of ways by which to return to help buffers after following xrefs. 48 "A stack of ways by which to return to help buffers after following xrefs.
48Used by `help-follow' and `help-xref-go-back'. 49Used by `help-follow' and `help-xref-go-back'.
49An element looks like (POSITION FUNCTION ARGS...), where POSITION is 50An element looks like (POSITION FUNCTION ARGS...).
50`(POINT . BUFFER-NAME)'. 51To use the element, do (apply FUNCTION ARGS) then goto the point.")
51To use the element, do (apply FUNCTION ARGS) then goto the point in
52the named buffer.")
53(put 'help-xref-stack 'permanent-local t) 52(put 'help-xref-stack 'permanent-local t)
53(make-variable-buffer-local 'help-xref-stack)
54 54
55(defvar help-xref-stack-item nil 55(defvar help-xref-stack-item nil
56 "An item for `help-follow' in this buffer to push onto `help-xref-stack'. 56 "An item for `help-follow' in this buffer to push onto `help-xref-stack'.
57The format is (FUNCTION ARGS...).") 57The format is (FUNCTION ARGS...).")
58(put 'help-xref-stack-item 'permanent-local t) 58(put 'help-xref-stack-item 'permanent-local t)
59(make-variable-buffer-local 'help-xref-stack-item)
59 60
60(setq-default help-xref-stack nil help-xref-stack-item nil) 61(setq-default help-xref-stack nil help-xref-stack-item nil)
61 62
@@ -208,14 +209,30 @@ when help commands related to multilingual environment (e.g.,
208ITEM is a (FUNCTION . ARGS) pair appropriate for recreating the help 209ITEM is a (FUNCTION . ARGS) pair appropriate for recreating the help
209buffer after following a reference. INTERACTIVE-P is non-nil if the 210buffer after following a reference. INTERACTIVE-P is non-nil if the
210calling command was invoked interactively. In this case the stack of 211calling command was invoked interactively. In this case the stack of
211items for help buffer \"back\" buttons is cleared." 212items for help buffer \"back\" buttons is cleared.
212 (if interactive-p 213
213 (setq help-xref-stack nil)) 214This should be called very early, before the output buffer is cleared,
214 (setq help-xref-stack-item item)) 215because we want to record the \"previous\" position of point so we can
216restore it properly when going back."
217 (with-current-buffer (help-buffer)
218 (if interactive-p
219 ;; Why do we want to prevent the user from going back ?? -stef
220 (setq help-xref-stack nil)
221 (when help-xref-stack-item
222 (push (cons (point) help-xref-stack-item) help-xref-stack)))
223 (setq help-xref-stack-item item)))
215 224
216(defvar help-xref-following nil 225(defvar help-xref-following nil
217 "Non-nil when following a help cross-reference.") 226 "Non-nil when following a help cross-reference.")
218 227
228(defun help-buffer ()
229 (unless (equal help-xref-following (eq major-mode 'help-mode))
230 (debug))
231 (buffer-name ;for with-output-to-temp-buffer
232 (if help-xref-following
233 (current-buffer)
234 (get-buffer-create "*Help*"))))
235
219;;;###autoload 236;;;###autoload
220(defun help-make-xrefs (&optional buffer) 237(defun help-make-xrefs (&optional buffer)
221 "Parse and hyperlink documentation cross-references in the given BUFFER. 238 "Parse and hyperlink documentation cross-references in the given BUFFER.
@@ -356,7 +373,7 @@ that."
356 (while (and (not (bobp)) (bolp)) 373 (while (and (not (bobp)) (bolp))
357 (delete-char -1)) 374 (delete-char -1))
358 ;; Make a back-reference in this buffer if appropriate. 375 ;; Make a back-reference in this buffer if appropriate.
359 (when (and help-xref-following help-xref-stack) 376 (when help-xref-stack
360 (insert "\n\n") 377 (insert "\n\n")
361 (help-insert-xref-button help-back-label 'help-back 378 (help-insert-xref-button help-back-label 'help-back
362 (current-buffer)))) 379 (current-buffer))))
@@ -422,47 +439,82 @@ See `help-make-xrefs'."
422;; Additional functions for (re-)creating types of help buffers. 439;; Additional functions for (re-)creating types of help buffers.
423(defun help-xref-interned (symbol) 440(defun help-xref-interned (symbol)
424 "Follow a hyperlink which appeared to be an arbitrary interned SYMBOL. 441 "Follow a hyperlink which appeared to be an arbitrary interned SYMBOL.
425 442Both variable, function and face documentation are extracted into a single
426Both variable and function documentation are extracted into a single
427help buffer." 443help buffer."
428 (let ((fdoc (when (fboundp symbol) (describe-function symbol))) 444 (with-current-buffer (help-buffer)
429 (facedoc (when (facep symbol) (describe-face symbol)))) 445 ;; Push the previous item on the stack before clobbering the output buffer.
430 (when (or (boundp symbol) (not fdoc)) 446 (help-setup-xref nil nil)
431 (describe-variable symbol) 447 (let ((facedoc (when (facep symbol)
432 ;; We now have a help buffer on the variable. Insert the function 448 ;; Don't record the current entry in the stack.
433 ;; text before it. 449 (setq help-xref-stack-item nil)
450 (describe-face symbol)))
451 (fdoc (when (fboundp symbol)
452 ;; Don't record the current entry in the stack.
453 (setq help-xref-stack-item nil)
454 (describe-function symbol)))
455 (sdoc (when (boundp symbol)
456 ;; Don't record the current entry in the stack.
457 (setq help-xref-stack-item nil)
458 (describe-variable symbol))))
459 (cond
460 (sdoc
461 ;; We now have a help buffer on the variable.
462 ;; Insert the function and face text before it.
434 (when (or fdoc facedoc) 463 (when (or fdoc facedoc)
435 (with-current-buffer "*Help*"
436 (goto-char (point-min)) 464 (goto-char (point-min))
437 (let ((inhibit-read-only t)) 465 (let ((inhibit-read-only t))
438 (when fdoc 466 (when fdoc
439 (insert fdoc "\n\n")) 467 (insert fdoc "\n\n")
440 (when facedoc 468 (when facedoc
441 (insert (make-string 30 ?-) "\n\n" (symbol-name symbol) 469 (insert (make-string 30 ?-) "\n\n" (symbol-name symbol)
442 " is also a " "face." "\n\n" facedoc "\n\n")) 470 " is also a " "face." "\n\n")))
471 (when facedoc
472 (insert facedoc "\n\n"))
443 (insert (make-string 30 ?-) "\n\n" (symbol-name symbol) 473 (insert (make-string 30 ?-) "\n\n" (symbol-name symbol)
444 " is also a " "variable." "\n\n")) 474 " is also a " "variable." "\n\n"))
445 (help-setup-xref (list #'help-xref-interned symbol) nil)))))) 475 ;; Don't record the `describe-variable' item in the stack.
476 (setq help-xref-stack-item nil)
477 (help-setup-xref (list #'help-xref-interned symbol) nil)))
478 (fdoc
479 ;; We now have a help buffer on the function.
480 ;; Insert face text before it.
481 (when facedoc
482 (goto-char (point-max))
483 (let ((inhibit-read-only t))
484 (insert "\n\n" (make-string 30 ?-) "\n\n" (symbol-name symbol)
485 " is also a " "face." "\n\n" facedoc))
486 ;; Don't record the `describe-function' item in the stack.
487 (setq help-xref-stack-item nil)
488 (help-setup-xref (list #'help-xref-interned symbol) nil)))))))
446 489
447 490
448;;; Navigation/hyperlinking with xrefs 491;;; Navigation/hyperlinking with xrefs
449 492
493(defun help-follow-mouse (click)
494 "Follow the cross-reference that you CLICK on."
495 (interactive "e")
496 (let* ((start (event-start click))
497 (window (car start))
498 (pos (car (cdr start))))
499 (with-current-buffer (window-buffer window)
500 (help-follow pos))))
501
450(defun help-xref-go-back (buffer) 502(defun help-xref-go-back (buffer)
451 "From BUFFER, go back to previous help buffer text using `help-xref-stack'." 503 "From BUFFER, go back to previous help buffer text using `help-xref-stack'."
452 (let (item position method args) 504 (let (item position method args)
453 (with-current-buffer buffer 505 (with-current-buffer buffer
454 (when help-xref-stack 506 (when help-xref-stack
455 (setq help-xref-stack (cdr help-xref-stack)) ; due to help-follow
456 (setq item (pop help-xref-stack) 507 (setq item (pop help-xref-stack)
508 ;; Clear the current item so that it won't get pushed
509 ;; by the function we're about to call. TODO: We could also
510 ;; push it onto a "forward" stack and add a `forw' button.
511 help-xref-stack-item nil
457 position (car item) 512 position (car item)
458 method (cadr item) 513 method (cadr item)
459 args (cddr item)))) 514 args (cddr item))))
460 (apply method args) 515 (apply method args)
461 ;; We assume that the buffer we just recreated has the saved name, 516 ;; FIXME: are we sure we're in the right buffer ?
462 ;; which might not always be true. 517 (goto-char position)))
463 (when (get-buffer (cdr position))
464 (with-current-buffer (cdr position)
465 (goto-char (car position))))))
466 518
467(defun help-go-back () 519(defun help-go-back ()
468 "Invoke the [back] button (if any) in the Help mode buffer." 520 "Invoke the [back] button (if any) in the Help mode buffer."
@@ -476,10 +528,6 @@ help buffer."
476 "Call the help cross-reference function FUNCTION with args ARGS. 528 "Call the help cross-reference function FUNCTION with args ARGS.
477Things are set up properly so that the resulting help-buffer has 529Things are set up properly so that the resulting help-buffer has
478a proper [back] button." 530a proper [back] button."
479 (setq help-xref-stack (cons (cons (cons pos (buffer-name))
480 help-xref-stack-item)
481 help-xref-stack))
482 (setq help-xref-stack-item nil)
483 ;; There is a reference at point. Follow it. 531 ;; There is a reference at point. Follow it.
484 (let ((help-xref-following t)) 532 (let ((help-xref-following t))
485 (apply function args))) 533 (apply function args)))
@@ -500,7 +548,7 @@ For the cross-reference format, see `help-make-xrefs'."
500 (buffer-substring (point) 548 (buffer-substring (point)
501 (progn (skip-syntax-forward "w_") 549 (progn (skip-syntax-forward "w_")
502 (point))))))) 550 (point)))))))
503 (when (or (boundp sym) (fboundp sym)) 551 (when (or (boundp sym) (fboundp sym) (facep sym))
504 (help-do-xref pos #'help-xref-interned (list sym)))))) 552 (help-do-xref pos #'help-xref-interned (list sym))))))
505 553
506 554