]> code.delx.au - gnu-emacs/blobdiff - lisp/help.el
(ps-print-preprint): Special handling if
[gnu-emacs] / lisp / help.el
index d81e433f7551c4cc90d0c5d949e48de1eae2022c..ff1e9c8da1bae973cd99bf9fbcf0a66cc7cc1470 100644 (file)
@@ -18,8 +18,9 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to
-;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
 
 ;;; Commentary:
 
@@ -167,12 +168,29 @@ Commands:
     (and (symbolp type)
         (memq 'down (event-modifiers type))
         (read-event)))
-  (let ((defn (key-binding key)))
-    (if (or (null defn) (integerp defn))
-        (message "%s is undefined" (key-description key))
-      (message "%s runs the command %s"
-              (key-description key)
-              (if (symbolp defn) defn (prin1-to-string defn))))))
+  (save-excursion
+    (let ((modifiers (event-modifiers (aref key 0)))
+         window position)
+      ;; For a mouse button event, go to the button it applies to
+      ;; to get the right key bindings.  And go to the right place
+      ;; in case the keymap depends on where you clicked.
+      (if (or (memq 'click modifiers) (memq 'down modifiers)
+             (memq 'drag modifiers))
+         (setq window (posn-window (event-start (aref key 0)))
+               position (posn-point (event-start (aref key 0)))))
+      (if (windowp window)
+         (progn
+           (set-buffer (window-buffer window))
+           (goto-char position)))
+      ;; Ok, now look up the key and name the command.
+      (let ((defn (key-binding key)))
+       (if (or (null defn) (integerp defn))
+           (message "%s is undefined" (key-description key))
+         (message (if (windowp window)
+                      "%s at that spot runs the command %s"
+                    "%s runs the command %s")
+                  (key-description key)
+                  (if (symbolp defn) defn (prin1-to-string defn))))))))
 
 (defun print-help-return-message (&optional function)
   "Display or return message saying how to restore windows after help command.
@@ -255,19 +273,39 @@ If FUNCTION is nil, applies `message' to it, thus printing it."
     (and (symbolp type)
         (memq 'down (event-modifiers type))
         (read-event)))
-  (let ((defn (key-binding key)))
-    (if (or (null defn) (integerp defn))
-        (message "%s is undefined" (key-description key))
-      (with-output-to-temp-buffer "*Help*"
-       (prin1 defn)
-       (princ ":\n")
-       (if (documentation defn)
-           (princ (documentation defn))
-         (princ "not documented"))
-       (save-excursion
-         (set-buffer standard-output)
-         (help-mode))
-       (print-help-return-message)))))
+  (save-excursion
+    (let ((modifiers (event-modifiers (aref key 0)))
+         window position)
+      ;; For a mouse button event, go to the button it applies to
+      ;; to get the right key bindings.  And go to the right place
+      ;; in case the keymap depends on where you clicked.
+      (if (or (memq 'click modifiers) (memq 'down modifiers)
+             (memq 'drag modifiers))
+         (setq window (posn-window (event-start (aref key 0)))
+               position (posn-point (event-start (aref key 0)))))
+      (if (windowp window)
+         (progn
+           (set-buffer (window-buffer window))
+           (goto-char position)))
+      (let ((defn (key-binding key)))
+       (if (or (null defn) (integerp defn))
+           (message "%s is undefined" (key-description key))
+         (with-output-to-temp-buffer "*Help*"
+           (princ (key-description key))
+           (if (windowp window)
+               (princ " at that spot"))
+           (princ " runs the command ")
+           (prin1 defn)
+           (princ ":\n")
+           (let ((doc (documentation defn)))
+             (if doc
+                 (progn (terpri)
+                        (princ doc))
+               (princ "not documented")))
+           (save-excursion
+             (set-buffer standard-output)
+             (help-mode))
+           (print-help-return-message)))))))
 
 (defun describe-mode ()
   "Display documentation of current major mode and minor modes.
@@ -296,8 +334,11 @@ describes the minor mode."
                                      0 (match-beginning 0)))))
                (while (and indicator (symbolp indicator))
                  (setq indicator (symbol-value indicator)))
-               (princ (format "%s minor mode (indicator%s):\n"
-                              pretty-minor-mode indicator))
+               (princ (format "%s minor mode (%s):\n"
+                              pretty-minor-mode
+                              (if indicator
+                                  (format "indicator%s" indicator)
+                                "no indicator")))
                (princ (documentation minor-mode))
                (princ "\n\n"))))
        (setq minor-modes (cdr minor-modes))))
@@ -532,11 +573,11 @@ C-w print information on absence of warranty for GNU Emacs."
                                       (intern (upcase (symbol-name arg)))))
                                   arglist)))
              (terpri))))
-      (if (documentation function)
-         (progn (terpri)
-                (princ (documentation function)))
-       (princ "not documented"))
-      )
+      (let ((doc (documentation function)))
+       (if doc
+           (progn (terpri)
+                  (princ doc))
+         (princ "not documented"))))
     (print-help-return-message)
     (save-excursion
       (set-buffer standard-output)
@@ -592,9 +633,7 @@ Returns the documentation as a string, also."
     (princ "Documentation:")
     (terpri)
     (let ((doc (documentation-property variable 'variable-documentation)))
-      (if doc
-         (princ (substitute-command-keys doc))
-       (princ "not documented as a variable.")))
+      (princ (or doc "not documented as a variable.")))
     (print-help-return-message)
     (save-excursion
       (set-buffer standard-output)