Spelling fixes.
[bpt/emacs.git] / lisp / help-mode.el
index 724b018..5906683 100644 (file)
 
 (defvar help-mode-map
   (let ((map (make-sparse-keymap)))
-    (set-keymap-parent map button-buffer-map)
-
+    (set-keymap-parent map (make-composed-keymap button-buffer-map
+                                                 special-mode-map))
     (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 "\C-c\C-c" 'help-follow-symbol)
-    ;; Documentation only, since we use minor-mode-overriding-map-alist.
     (define-key map "\r" 'help-follow)
     map)
   "Keymap for help mode.")
@@ -142,7 +141,7 @@ The format is (FUNCTION ARGS...).")
   'help-function 'describe-character-set
   'help-echo (purecopy "mouse-2, RET: describe this character set"))
 
-;; make some more ideosyncratic button types
+;; Make some more idiosyncratic button types.
 
 (define-button-type 'help-symbol
   :supertype 'help-xref
@@ -162,7 +161,7 @@ The format is (FUNCTION ARGS...).")
 (define-button-type 'help-info-variable
   :supertype 'help-xref
   ;; the name of the variable is put before the argument to Info
-  'help-function (lambda (a v) (info v))
+  'help-function (lambda (_a v) (info v))
   'help-echo (purecopy "mouse-2, RET: read this Info node"))
 
 (define-button-type 'help-info
@@ -267,36 +266,13 @@ The format is (FUNCTION ARGS...).")
   'help-echo (purecopy "mouse-2, RET: edit this theme file"))
 \f
 ;;;###autoload
-(defun help-mode ()
+(define-derived-mode help-mode special-mode "Help"
   "Major mode for viewing help text and navigating references in it.
 Entry to this mode runs the normal hook `help-mode-hook'.
 Commands:
 \\{help-mode-map}"
-  (interactive)
-  (kill-all-local-variables)
-  (use-local-map help-mode-map)
-  (setq mode-name "Help")
-  (setq major-mode 'help-mode)
-
-  (view-mode)
-  (set (make-local-variable 'view-no-disable-on-exit) t)
-  ;; With Emacs 22 `view-exit-action' could delete the selected window
-  ;; disregarding whether the help buffer was shown in that window at
-  ;; all.  Since `view-exit-action' is called with the help buffer as
-  ;; argument it seems more appropriate to have it work on the buffer
-  ;; only and leave it to `view-mode-exit' to delete any associated
-  ;; window(s).
-  (setq view-exit-action
-       (lambda (buffer)
-         ;; Use `with-current-buffer' to make sure that `bury-buffer'
-         ;; also removes BUFFER from the selected window.
-         (with-current-buffer buffer
-           (bury-buffer))))
-
   (set (make-local-variable 'revert-buffer-function)
-       'help-mode-revert-buffer)
-
-  (run-mode-hooks 'help-mode-hook))
+       'help-mode-revert-buffer))
 
 ;;;###autoload
 (defun help-mode-setup ()
@@ -305,23 +281,6 @@ Commands:
 
 ;;;###autoload
 (defun help-mode-finish ()
-  (if (eq help-window t)
-      ;; If `help-window' is t, `view-return-to-alist' is handled by
-      ;; `with-help-window'.  In this case set `help-window' to the
-      ;; selected window since now is the only moment where we can
-      ;; unambiguously identify it.
-      (setq help-window (selected-window))
-    (let ((entry (assq (selected-window) view-return-to-alist)))
-      (if entry
-         ;; When entering Help mode from the Help window,
-         ;; such as by following a link, preserve the same
-         ;; meaning for the q command.
-         ;; (setcdr entry (cons (selected-window) help-return-method))
-         nil
-       (setq view-return-to-alist
-             (cons (cons (selected-window) help-return-method)
-                   view-return-to-alist)))))
-
   (when (eq major-mode 'help-mode)
     ;; View mode's read-only status of existing *Help* buffer is lost
     ;; by with-output-to-temp-buffer.
@@ -330,7 +289,7 @@ Commands:
     (save-excursion
       (goto-char (point-min))
       (let ((inhibit-read-only t))
-       (when (re-search-forward "^This \\w+ is advised.$" nil t)
+       (when (re-search-forward "^This [^[:space:]]+ is advised.$" nil t)
          (put-text-property (match-beginning 0)
                             (match-end 0)
                             'face 'font-lock-warning-face))))
@@ -409,20 +368,16 @@ restore it properly when going back."
 (defun help-buffer ()
   "Return the name of a buffer for inserting help.
 If `help-xref-following' is non-nil, this is the name of the
-current buffer.
-Otherwise, it is *Help*; if no buffer with that name currently
-exists, it is created."
+current buffer.  Signal an error if this buffer is not derived
+from `help-mode'.
+Otherwise, return \"*Help*\", creating a buffer with that name if
+it does not already exist."
   (buffer-name                         ;for with-output-to-temp-buffer
-   (if help-xref-following
-       (current-buffer)
-     (get-buffer-create "*Help*"))))
-
-(defvar help-xref-override-view-map
-  (let ((map (make-sparse-keymap)))
-    (set-keymap-parent map view-mode-map)
-    (define-key map "\r" nil)
-    map)
-  "Replacement keymap for `view-mode' in help buffers.")
+   (if (not help-xref-following)
+       (get-buffer-create "*Help*")
+     (unless (derived-mode-p 'help-mode)
+       (error "Current buffer is not in Help mode"))
+     (current-buffer))))
 
 ;;;###autoload
 (defun help-make-xrefs (&optional buffer)
@@ -608,9 +563,6 @@ that."
                                      (current-buffer)))
           (when (or help-xref-stack help-xref-forward-stack)
             (insert "\n")))
-        ;; View mode steals RET from us.
-        (set (make-local-variable 'minor-mode-overriding-map-alist)
-             (list (cons 'view-mode help-xref-override-view-map)))
         (set-buffer-modified-p old-modified)))))
 
 ;;;###autoload
@@ -775,7 +727,7 @@ help buffer."
       (help-xref-go-forward (current-buffer))
     (error "No next help buffer")))
 
-(defun help-do-xref (pos function args)
+(defun help-do-xref (_pos function args)
   "Call the help cross-reference function FUNCTION with args ARGS.
 Things are set up properly so that the resulting help-buffer has
 a proper [back] button."
@@ -816,7 +768,7 @@ Show all docs for that symbol as either a variable, function or face."
              (fboundp sym) (facep sym))
       (help-do-xref pos #'help-xref-interned (list sym)))))
 
-(defun help-mode-revert-buffer (ignore-auto noconfirm)
+(defun help-mode-revert-buffer (_ignore-auto noconfirm)
   (when (or noconfirm (yes-or-no-p "Revert help buffer? "))
     (let ((pos (point))
          (item help-xref-stack-item)