]> code.delx.au - gnu-emacs/blobdiff - lisp/help-macro.el
(help-make-xrefs): Default info references to an
[gnu-emacs] / lisp / help-macro.el
index 55fc7a126fee7291052f4cecd3b8e7b2bf869d55..3a04fa65b2b75418a9643a8f84d3c74e3ade446a 100644 (file)
@@ -84,16 +84,21 @@ A value of nil means skip the middle step, so that
 When invoked, FNAME shows HELP-LINE and reads a command using HELPED-MAP.
 If the command is the help character, FNAME displays HELP-TEXT
 and continues trying to read a command using HELPED-MAP.
+If HELP-TEXT contains the sequence `%THIS-KEY%', that is replaced
+with the key sequence that invoked FNAME.
 When FNAME finally does get a command, it executes that command
 and then returns."
-  (` (defun (, fname) ()
-          (, help-text)
+ (let ((doc-fn (intern (concat (symbol-name fname) "-doc"))))
+  `(progn
+    (defun ,doc-fn () ,help-text)
+    (defun ,fname ()
+          "Help command."
           (interactive)
           (let ((line-prompt
-                 (substitute-command-keys (, help-line))))
+                 (substitute-command-keys ,help-line)))
             (if three-step-help
                 (message "%s" line-prompt))
-            (let* ((help-screen (documentation (quote (, fname))))
+            (let* ((help-screen (documentation (quote ,doc-fn)))
                    ;; We bind overriding-local-map for very small
                    ;; sections, *excluding* where we switch buffers
                    ;; and where we execute the chosen help command.
@@ -101,10 +106,17 @@ and then returns."
                    (minor-mode-map-alist nil)
                    (prev-frame (selected-frame))
                    config new-frame key char)
+              (if (string-match "%THIS-KEY%" help-screen)
+                  (setq help-screen
+                        (replace-match (key-description (substring (this-command-keys) 0 -1))
+                                       t t help-screen)))
               (unwind-protect
                   (progn
-                    (setcdr local-map (, helped-map))
+                    (setcdr local-map ,helped-map)
                     (define-key local-map [t] 'undefined)
+                    ;; Make the scroll bar keep working normally.
+                    (define-key local-map [vertical-scroll-bar]
+                      (lookup-key global-map [vertical-scroll-bar]))
                     (if three-step-help
                         (progn
                           (setq key (let ((overriding-local-map local-map))
@@ -130,7 +142,7 @@ and then returns."
                           (help-mode)
                           (goto-char (point-min))
                           (while (or (memq char (append help-event-list
-                                                        (cons help-char '(?? ?\C-v ?\ ?\177 delete backspace ?\M-v))))
+                                                        (cons help-char '(?? ?\C-v ?\ ?\177 delete backspace vertical-scroll-bar ?\M-v))))
                                      (eq (car-safe char) 'switch-frame)
                                      (equal key "\M-v"))
                             (condition-case nil
@@ -150,8 +162,14 @@ and then returns."
                                          (format "Type one of the options listed%s: "
                                                  (if (pos-visible-in-window-p
                                                       (point-max))
-                                                     "" " or Space to scroll")))
-                                    char (aref key 0))))))
+                                                     "" ", or SPACE or DEL to scroll")))
+                                    char (aref key 0)))
+
+                            ;; If this is a scroll bar command, just run it.
+                            (when (eq char 'vertical-scroll-bar)
+                              (command-execute (lookup-key local-map key) nil key)))))
+                    ;; We don't need the prompt any more.
+                    (message "")
                     ;; Mouse clicks are not part of the help feature,
                     ;; so reexecute them in the standard environment.
                     (if (listp char)
@@ -173,7 +191,7 @@ and then returns."
                 (if new-frame (iconify-frame new-frame))
                 (if config
                     (set-window-configuration config))))))
-     ))
+     )))
 
 ;;; help-macro.el