]> code.delx.au - gnu-emacs/blobdiff - lisp/help-mode.el
Protect against changes of interval tree when adding/removing text props.
[gnu-emacs] / lisp / help-mode.el
index 5906683071be40f94a6e05ed9d7cd4ef8797e419..b5aca1a44450dc63c1566eebf1968e1bab6b2197 100644 (file)
@@ -1,7 +1,7 @@
 ;;; help-mode.el --- `help-mode' used by *Help* buffers
 
-;; Copyright (C) 1985-1986, 1993-1994, 1998-2011
-;;   Free Software Foundation, Inc.
+;; Copyright (C) 1985-1986, 1993-1994, 1998-2013 Free Software
+;; Foundation, Inc.
 
 ;; Maintainer: FSF
 ;; Keywords: help, internal
@@ -30,7 +30,6 @@
 ;;; Code:
 
 (require 'button)
-(require 'view)
 (eval-when-compile (require 'easymenu))
 
 (defvar help-mode-map
@@ -40,6 +39,8 @@
     (define-key map [mouse-2] 'help-follow-mouse)
     (define-key map "\C-c\C-b" 'help-go-back)
     (define-key map "\C-c\C-f" 'help-go-forward)
+    (define-key map [XF86Back] 'help-go-back)
+    (define-key map [XF86Forward] 'help-go-forward)
     (define-key map "\C-c\C-c" 'help-follow-symbol)
     (define-key map "\r" 'help-follow)
     map)
@@ -264,7 +265,18 @@ The format is (FUNCTION ARGS...).")
   :supertype 'help-xref
   'help-function 'customize-create-theme
   'help-echo (purecopy "mouse-2, RET: edit this theme file"))
+
+(define-button-type 'help-dir-local-var-def
+  :supertype 'help-xref
+  'help-function (lambda (var &optional file)
+                  ;; FIXME: this should go to the point where the
+                  ;; local variable was defined.
+                  (find-file file))
+  'help-echo (purecopy "mouse-2, RET: open directory-local variables file"))
+
 \f
+(defvar bookmark-make-record-function)
+
 ;;;###autoload
 (define-derived-mode help-mode special-mode "Help"
   "Major mode for viewing help text and navigating references in it.
@@ -272,7 +284,9 @@ Entry to this mode runs the normal hook `help-mode-hook'.
 Commands:
 \\{help-mode-map}"
   (set (make-local-variable 'revert-buffer-function)
-       'help-mode-revert-buffer))
+       'help-mode-revert-buffer)
+  (set (make-local-variable 'bookmark-make-record-function)
+       'help-bookmark-make-record))
 
 ;;;###autoload
 (defun help-mode-setup ()
@@ -282,10 +296,7 @@ Commands:
 ;;;###autoload
 (defun help-mode-finish ()
   (when (eq major-mode 'help-mode)
-    ;; View mode's read-only status of existing *Help* buffer is lost
-    ;; by with-output-to-temp-buffer.
-    (toggle-read-only 1)
-
+    (setq buffer-read-only t)
     (save-excursion
       (goto-char (point-min))
       (let ((inhibit-read-only t))
@@ -311,7 +322,7 @@ Commands:
 
 (defconst help-xref-symbol-regexp
   (purecopy (concat "\\(\\<\\(\\(variable\\|option\\)\\|"  ; Link to var
-                   "\\(function\\|command\\)\\|"          ; Link to function
+                   "\\(function\\|command\\|call\\)\\|"   ; Link to function
                    "\\(face\\)\\|"                        ; Link to face
                    "\\(symbol\\|program\\|property\\)\\|" ; Don't link
                    "\\(source \\(?:code \\)?\\(?:of\\|for\\)\\)\\)"
@@ -497,11 +508,9 @@ that."
                              (or
                               (documentation-property
                                sym 'variable-documentation)
-                              (condition-case nil
-                                  (documentation-property
-                                   (indirect-variable sym)
-                                   'variable-documentation)
-                                (cyclic-variable-indirection nil))))
+                              (documentation-property
+                               (indirect-variable sym)
+                               'variable-documentation)))
                             (help-xref-button 8 'help-variable sym))
                            ((fboundp sym)
                             (help-xref-button 8 'help-function sym)))))))
@@ -668,7 +677,8 @@ help buffer."
                    " is also a " "face." "\n\n" facedoc))
          ;; Don't record the `describe-function' item in the stack.
          (setq help-xref-stack-item nil)
-         (help-setup-xref (list #'help-xref-interned symbol) nil)))))))
+         (help-setup-xref (list #'help-xref-interned symbol) nil))))
+      (goto-char (point-min)))))
 
 \f
 ;; Navigation/hyperlinking with xrefs
@@ -789,6 +799,37 @@ help buffer by other means."
   (with-output-to-temp-buffer (help-buffer)
     (insert string)))
 
+\f
+;; Bookmark support
+
+(declare-function bookmark-prop-get "bookmark" (bookmark prop))
+(declare-function bookmark-make-record-default "bookmark"
+                  (&optional no-file no-context posn))
+
+(defun help-bookmark-make-record ()
+  "Create and return a help-mode bookmark record.
+Implements `bookmark-make-record-function' for help-mode buffers."
+  (unless (car help-xref-stack-item)
+    (error "Cannot create bookmark - help command not known"))
+  `(,@(bookmark-make-record-default 'NO-FILE 'NO-CONTEXT)
+      (help-fn     . ,(car help-xref-stack-item))
+      (help-args   . ,(cdr help-xref-stack-item))
+      (position    . ,(point))
+      (handler     . help-bookmark-jump)))
+
+;;;###autoload
+(defun help-bookmark-jump (bookmark)
+  "Jump to help-mode bookmark BOOKMARK.
+Handler function for record returned by `help-bookmark-make-record'.
+BOOKMARK is a bookmark name or a bookmark record."
+  (let ((help-fn    (bookmark-prop-get bookmark 'help-fn))
+        (help-args  (bookmark-prop-get bookmark 'help-args))
+        (position   (bookmark-prop-get bookmark 'position)))
+    (apply help-fn help-args)
+    (pop-to-buffer "*Help*")
+    (goto-char position)))
+
+
 (provide 'help-mode)
 
 ;;; help-mode.el ends here