aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Roberts2007-06-08 10:09:24 +0000
committerNick Roberts2007-06-08 10:09:24 +0000
commit95f731dbb5881fba80ac8dc60d136c5b256e6f7c (patch)
tree569fef3798a52b112a23581be926c0bc3baf5dc7
parentda38057d95c3f5f8946335485cfd6a35513ca330 (diff)
downloademacs-95f731dbb5881fba80ac8dc60d136c5b256e6f7c.tar.gz
emacs-95f731dbb5881fba80ac8dc60d136c5b256e6f7c.zip
(help-xref-forward-stack)
(help-xref-stack-forward-item, help-forward-label): New variables. (help-forward): New button type. (help-setup-xref): Initialise help-xref-forward-stack. (help-make-xrefs): Add forward button, if appropriate. (help-xref-go-back): Push item on forward stack. (help-xref-go-forward, help-go-forward): New functions.
-rw-r--r--lisp/help-mode.el60
1 files changed, 59 insertions, 1 deletions
diff --git a/lisp/help-mode.el b/lisp/help-mode.el
index afaf06bec3c..f7c33d85286 100644
--- a/lisp/help-mode.el
+++ b/lisp/help-mode.el
@@ -40,6 +40,7 @@
40 40
41(define-key help-mode-map [mouse-2] 'help-follow-mouse) 41(define-key help-mode-map [mouse-2] 'help-follow-mouse)
42(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)
43(define-key help-mode-map "\C-c\C-f" 'help-go-forward)
43(define-key help-mode-map "\C-c\C-c" 'help-follow-symbol) 44(define-key help-mode-map "\C-c\C-c" 'help-follow-symbol)
44;; Documentation only, since we use minor-mode-overriding-map-alist. 45;; Documentation only, since we use minor-mode-overriding-map-alist.
45(define-key help-mode-map "\r" 'help-follow) 46(define-key help-mode-map "\r" 'help-follow)
@@ -52,13 +53,28 @@ To use the element, do (apply FUNCTION ARGS) then goto the point.")
52(put 'help-xref-stack 'permanent-local t) 53(put 'help-xref-stack 'permanent-local t)
53(make-variable-buffer-local 'help-xref-stack) 54(make-variable-buffer-local 'help-xref-stack)
54 55
56(defvar help-xref-forward-stack nil
57 "The stack of used to navigate help forwards after using the back button.
58Used by `help-follow' and `help-xref-go-forward'.
59An element looks like (POSITION FUNCTION ARGS...).
60To use the element, do (apply FUNCTION ARGS) then goto the point.")
61(put 'help-xref-forward-stack 'permanent-local t)
62(make-variable-buffer-local 'help-xref-forward-stack)
63
55(defvar help-xref-stack-item nil 64(defvar help-xref-stack-item nil
56 "An item for `help-follow' in this buffer to push onto `help-xref-stack'. 65 "An item for `help-follow' in this buffer to push onto `help-xref-stack'.
57The format is (FUNCTION ARGS...).") 66The format is (FUNCTION ARGS...).")
58(put 'help-xref-stack-item 'permanent-local t) 67(put 'help-xref-stack-item 'permanent-local t)
59(make-variable-buffer-local 'help-xref-stack-item) 68(make-variable-buffer-local 'help-xref-stack-item)
60 69
70(defvar help-xref-stack-forward-item nil
71 "An item for `help-go-back' to push onto `help-xref-forward-stack'.
72The format is (FUNCTION ARGS...).")
73(put 'help-xref-stack-forward-item 'permanent-local t)
74(make-variable-buffer-local 'help-xref-stack-forward-item)
75
61(setq-default help-xref-stack nil help-xref-stack-item nil) 76(setq-default help-xref-stack nil help-xref-stack-item nil)
77(setq-default help-xref-forward-stack nil help-xref-forward-stack-item nil)
62 78
63(defcustom help-mode-hook nil 79(defcustom help-mode-hook nil
64 "Hook run by `help-mode'." 80 "Hook run by `help-mode'."
@@ -123,6 +139,11 @@ The format is (FUNCTION ARGS...).")
123 'help-function #'help-xref-go-back 139 'help-function #'help-xref-go-back
124 'help-echo (purecopy "mouse-2, RET: go back to previous help buffer")) 140 'help-echo (purecopy "mouse-2, RET: go back to previous help buffer"))
125 141
142(define-button-type 'help-forward
143 :supertype 'help-xref
144 'help-function #'help-xref-go-forward
145 'help-echo (purecopy "mouse-2, RET: move forward to next help buffer"))
146
126(define-button-type 'help-info 147(define-button-type 'help-info
127 :supertype 'help-xref 148 :supertype 'help-xref
128 'help-function #'info 149 'help-function #'info
@@ -242,6 +263,9 @@ Commands:
242(defvar help-back-label (purecopy "[back]") 263(defvar help-back-label (purecopy "[back]")
243 "Label to use by `help-make-xrefs' for the go-back reference.") 264 "Label to use by `help-make-xrefs' for the go-back reference.")
244 265
266(defvar help-forward-label (purecopy "[forward]")
267 "Label to use by `help-make-xrefs' for the go-forward reference.")
268
245(defconst help-xref-symbol-regexp 269(defconst help-xref-symbol-regexp
246 (purecopy (concat "\\(\\<\\(\\(variable\\|option\\)\\|" ; Link to var 270 (purecopy (concat "\\(\\<\\(\\(variable\\|option\\)\\|" ; Link to var
247 "\\(function\\|command\\)\\|" ; Link to function 271 "\\(function\\|command\\)\\|" ; Link to function
@@ -286,7 +310,8 @@ because we want to record the \"previous\" position of point so we can
286restore it properly when going back." 310restore it properly when going back."
287 (with-current-buffer (help-buffer) 311 (with-current-buffer (help-buffer)
288 (when help-xref-stack-item 312 (when help-xref-stack-item
289 (push (cons (point) help-xref-stack-item) help-xref-stack)) 313 (push (cons (point) help-xref-stack-item) help-xref-stack)
314 (setq help-xref-forward-stack nil))
290 (when interactive-p 315 (when interactive-p
291 (let ((tail (nthcdr 10 help-xref-stack))) 316 (let ((tail (nthcdr 10 help-xref-stack)))
292 ;; Truncate the stack. 317 ;; Truncate the stack.
@@ -480,6 +505,11 @@ that."
480 (insert "\n") 505 (insert "\n")
481 (help-insert-xref-button help-back-label 'help-back 506 (help-insert-xref-button help-back-label 'help-back
482 (current-buffer)) 507 (current-buffer))
508 (insert "\t"))
509 ;; Make a forward-reference in this buffer if appropriate.
510 (when help-xref-forward-stack
511 (help-insert-xref-button help-forward-label 'help-forward
512 (current-buffer))
483 (insert "\n"))) 513 (insert "\n")))
484 ;; View mode steals RET from us. 514 ;; View mode steals RET from us.
485 (set (make-local-variable 'minor-mode-overriding-map-alist) 515 (set (make-local-variable 'minor-mode-overriding-map-alist)
@@ -598,6 +628,7 @@ help buffer."
598 "From BUFFER, go back to previous help buffer text using `help-xref-stack'." 628 "From BUFFER, go back to previous help buffer text using `help-xref-stack'."
599 (let (item position method args) 629 (let (item position method args)
600 (with-current-buffer buffer 630 (with-current-buffer buffer
631 (push (cons (point) help-xref-stack-item) help-xref-forward-stack)
601 (when help-xref-stack 632 (when help-xref-stack
602 (setq item (pop help-xref-stack) 633 (setq item (pop help-xref-stack)
603 ;; Clear the current item so that it won't get pushed 634 ;; Clear the current item so that it won't get pushed
@@ -613,12 +644,39 @@ help buffer."
613 (set-window-point (get-buffer-window buffer) position) 644 (set-window-point (get-buffer-window buffer) position)
614 (goto-char position))))) 645 (goto-char position)))))
615 646
647(defun help-xref-go-forward (buffer)
648 "From BUFFER, go forward to next help buffer."
649 (let (item position method args)
650 (with-current-buffer buffer
651 (push (cons (point) help-xref-stack-item) help-xref-stack)
652 (when help-xref-forward-stack
653 (setq item (pop help-xref-forward-stack)
654 ;; Clear the current item so that it won't get pushed
655 ;; by the function we're about to call. TODO: We could also
656 ;; push it onto a "forward" stack and add a `forw' button.
657 help-xref-stack-item nil
658 position (car item)
659 method (cadr item)
660 args (cddr item))))
661 (apply method args)
662 (with-current-buffer buffer
663 (if (get-buffer-window buffer)
664 (set-window-point (get-buffer-window buffer) position)
665 (goto-char position)))))
666
616(defun help-go-back () 667(defun help-go-back ()
617 "Go back to previous topic in this help buffer." 668 "Go back to previous topic in this help buffer."
618 (interactive) 669 (interactive)
619 (if help-xref-stack 670 (if help-xref-stack
620 (help-xref-go-back (current-buffer)) 671 (help-xref-go-back (current-buffer))
621 (error "No previous help buffer"))) 672 (error "No previous help buffer")))
673
674(defun help-go-forward ()
675 "Go back to next topic in this help buffer."
676 (interactive)
677 (if help-xref-forward-stack
678 (help-xref-go-forward (current-buffer))
679 (error "No next help buffer")))
622 680
623(defun help-do-xref (pos function args) 681(defun help-do-xref (pos function args)
624 "Call the help cross-reference function FUNCTION with args ARGS. 682 "Call the help cross-reference function FUNCTION with args ARGS.