]> code.delx.au - gnu-emacs/blobdiff - lisp/help.el
Minor typo fixes in vc-src.el.
[gnu-emacs] / lisp / help.el
index fdbf91f7dbdffbee4f6ff1fd6f0aa59330c3c11f..eaee6d147363450b4007898f1536f7d2c90b7668 100644 (file)
@@ -23,7 +23,7 @@
 
 ;;; Commentary:
 
-;; This code implements GNU Emacs's on-line help system, the one invoked by
+;; This code implements GNU Emacs's built-in help system, the one invoked by
 ;; `M-x help-for-help'.
 
 ;;; Code:
@@ -202,13 +202,13 @@ d PATTERN   Show a list of functions, variables, and other items whose
               documentation matches the PATTERN (a list of words or a regexp).
 e           Go to the *Messages* buffer which logs echo-area messages.
 f FUNCTION  Display documentation for the given function.
-F COMMAND   Show the on-line manual's section that describes the command.
+F COMMAND   Show the Emacs manual's section that describes the command.
 g           Display information about the GNU project.
 h           Display the HELLO file which illustrates various scripts.
-i           Start the Info documentation reader: read on-line manuals.
+i           Start the Info documentation reader: read included manuals.
 I METHOD    Describe a specific input method, or RET for current.
 k KEYS      Display the full documentation for the key sequence.
-K KEYS      Show the on-line manual's section for the command bound to KEYS.
+K KEYS      Show the Emacs manual's section for the command bound to KEYS.
 l           Show last 300 input keystrokes (lossage).
 L LANG-ENV  Describes a specific language environment, or RET for current.
 m           Display documentation of current minor modes and current major mode,
@@ -218,7 +218,7 @@ p TOPIC     Find packages matching a given topic keyword.
 P PACKAGE   Describe the given Emacs Lisp package.
 r           Display the Emacs manual in Info mode.
 s           Display contents of current syntax table, plus explanations.
-S SYMBOL    Show the section for the given symbol in the on-line manual
+S SYMBOL    Show the section for the given symbol in the Info manual
               for the programming language used in this buffer.
 t           Start the Emacs learn-by-doing tutorial.
 v VARIABLE  Display the given variable's documentation and value.
@@ -296,10 +296,11 @@ If that doesn't give a function, return nil."
   (interactive)
   (view-help-file "COPYING"))
 
+;; Maybe this command should just be removed.
 (defun describe-gnu-project ()
-  "Display info on the GNU project."
+  "Browse online information on the GNU project."
   (interactive)
-  (view-help-file "THE-GNU-PROJECT"))
+  (browse-url "http://www.gnu.org/gnu/thegnuproject.html"))
 
 (define-obsolete-function-alias 'describe-project 'describe-gnu-project "22.2")
 
@@ -447,25 +448,32 @@ is specified by the variable `message-log-max'."
   (info "(efaq)Packages that do not come with Emacs"))
 
 (defun view-lossage ()
-  "Display last 300 input keystrokes.
+  "Display last few input keystrokes and the commands run.
 
 To record all your input, use `open-dribble-file'."
   (interactive)
   (help-setup-xref (list #'view-lossage)
                   (called-interactively-p 'interactive))
   (with-help-window (help-buffer)
+    (princ " ")
     (princ (mapconcat (lambda (key)
-                       (if (or (integerp key) (symbolp key) (listp key))
-                           (single-key-description key)
-                         (prin1-to-string key nil)))
-                     (recent-keys)
+                       (cond
+                        ((and (consp key) (null (car key)))
+                         (format "[%s]\n" (if (symbolp (cdr key)) (cdr key)
+                                          "anonymous-command")))
+                        ((or (integerp key) (symbolp key) (listp key))
+                         (single-key-description key))
+                        (t
+                         (prin1-to-string key nil))))
+                     (recent-keys 'include-cmds)
                      " "))
     (with-current-buffer standard-output
       (goto-char (point-min))
-      (while (progn (move-to-column 50) (not (eobp)))
-        (when (search-forward " " nil t)
-          (delete-char -1))
-        (insert "\n"))
+      (while (not (eobp))
+       (move-to-column 50)
+       (unless (eolp)
+         (fill-region (line-beginning-position) (line-end-position)))
+       (forward-line 1))
       ;; jidanni wants to see the last keystrokes immediately.
       (set-marker help-window-point-marker (point)))))
 
@@ -485,8 +493,11 @@ or a buffer name."
   (or buffer (setq buffer (current-buffer)))
   (help-setup-xref (list #'describe-bindings prefix buffer)
                   (called-interactively-p 'interactive))
-  (with-current-buffer buffer
-    (describe-bindings-internal nil prefix)))
+  (with-help-window (help-buffer)
+    ;; Be aware that `describe-buffer-bindings' puts its output into
+    ;; the current buffer.
+    (with-current-buffer (help-buffer)
+      (describe-buffer-bindings buffer prefix))))
 
 ;; This function used to be in keymap.c.
 (defun describe-bindings-internal (&optional menus prefix)
@@ -497,6 +508,7 @@ The optional argument MENUS, if non-nil, says to mention menu bindings.
 \(Ordinarily these are omitted from the output.)
 The optional argument PREFIX, if non-nil, should be a key sequence;
 then we display only bindings that start with that prefix."
+  (declare (obsolete describe-buffer-bindings "24.4"))
   (let ((buf (current-buffer)))
     (with-help-window (help-buffer)
       ;; Be aware that `describe-buffer-bindings' puts its output into
@@ -516,8 +528,10 @@ If INSERT (the prefix arg) is non-nil, insert the message in the buffer."
                (if fn
                    (format "Where is command (default %s): " fn)
                  "Where is command: ")
-               obarray 'commandp t))
-     (list (if (equal val "") fn (intern val)) current-prefix-arg)))
+               obarray 'commandp t nil nil
+               (and fn (symbol-name fn))))
+     (list (unless (equal val "") (intern val))
+          current-prefix-arg)))
   (unless definition (error "No command"))
   (let ((func (indirect-function definition))
         (defs nil)
@@ -643,6 +657,68 @@ temporarily enables it to allow getting help on disabled items and buttons."
        (princ (format "%s%s is undefined" key-desc mouse-msg))
       (princ (format "%s%s runs the command %S" key-desc mouse-msg defn)))))
 
+(defun help--key-binding-keymap (key &optional accept-default no-remap position)
+  "Return a keymap holding a binding for KEY within current keymaps.
+The effect of the arguments KEY, ACCEPT-DEFAULT, NO-REMAP and
+POSITION is as documented in the function `key-binding'."
+  (let* ((active-maps (current-active-maps t position))
+         map found)
+    ;; We loop over active maps like key-binding does.
+    (while (and
+            (not found)
+            (setq map (pop active-maps)))
+      (setq found (lookup-key map key accept-default))
+      (when (integerp found)
+        ;; The first `found' characters of KEY were found but not the
+        ;; whole sequence.
+        (setq found nil)))
+    (when found
+      (if (and (symbolp found)
+               (not no-remap)
+               (command-remapping found))
+          ;; The user might want to know in which map the binding is
+          ;; found, or in which map the remapping is found.  The
+          ;; default is to show the latter.
+          (help--key-binding-keymap (vector 'remap found))
+        map))))
+
+(defun help--binding-locus (key position)
+  "Describe in which keymap KEY is defined.
+Return a symbol pointing to that keymap if one exists ; otherwise
+return nil."
+  (let ((map (help--key-binding-keymap key t nil position)))
+    (when map
+      (catch 'found
+        (let ((advertised-syms (nconc
+                                (list 'overriding-terminal-local-map
+                                      'overriding-local-map)
+                                (delq nil
+                                      (mapcar
+                                       (lambda (mode-and-map)
+                                         (let ((mode (car mode-and-map)))
+                                           (when (symbol-value mode)
+                                             (intern-soft
+                                              (format "%s-map" mode)))))
+                                       minor-mode-map-alist))
+                                (list 'global-map
+                                      (intern-soft (format "%s-map" major-mode)))))
+              found)
+          ;; Look into these advertised symbols first.
+          (dolist (sym advertised-syms)
+            (when (and
+                   (boundp sym)
+                   (eq map (symbol-value sym)))
+              (throw 'found sym)))
+          ;; Only look in other symbols otherwise.
+          (mapatoms
+           (lambda (x)
+             (when (and (boundp x)
+                        ;; Avoid let-bound symbols.
+                        (special-variable-p x)
+                        (eq (symbol-value x) map))
+               (throw 'found x))))
+          nil)))))
+
 (defun describe-key (&optional key untranslated up-event)
   "Display documentation of the function invoked by KEY.
 KEY can be any kind of a key sequence; it can include keyboard events,
@@ -705,6 +781,7 @@ temporarily enables it to allow getting help on disabled items and buttons."
         (mouse-msg (if (or (memq 'click modifiers) (memq 'down modifiers)
                            (memq 'drag modifiers)) " at that spot" ""))
         (defn (key-binding key t))
+         key-locus key-locus-up key-locus-up-tricky
         defn-up defn-up-tricky ev-type
         mouse-1-remapped mouse-1-tricky)
 
@@ -743,15 +820,19 @@ temporarily enables it to allow getting help on disabled items and buttons."
                   (setcar up-event (elt mouse-1-remapped 0)))
                  (t (setcar up-event 'mouse-2))))
          (setq defn-up (key-binding sequence nil nil (event-start up-event)))
+          (setq key-locus-up (help--binding-locus sequence (event-start up-event)))
          (when mouse-1-tricky
            (setq sequence (vector up-event))
            (aset sequence 0 'mouse-1)
-           (setq defn-up-tricky (key-binding sequence nil nil (event-start up-event))))))
+           (setq defn-up-tricky (key-binding sequence nil nil (event-start up-event)))
+            (setq key-locus-up-tricky (help--binding-locus sequence (event-start up-event))))))
+      (setq key-locus (help--binding-locus key (event-start event)))
       (with-help-window (help-buffer)
        (princ (help-key-description key untranslated))
-       (princ (format "\
-%s runs the command %S, which is "
-                      mouse-msg defn))
+       (princ (format "%s runs the command %S%s, which is "
+                      mouse-msg defn (if key-locus
+                                          (format " (found in %s)" key-locus)
+                                        "")))
        (describe-function-1 defn)
        (when up-event
          (unless (or (null defn-up)
@@ -761,13 +842,15 @@ temporarily enables it to allow getting help on disabled items and buttons."
 
 ----------------- up-event %s----------------
 
-%s%s%s runs the command %S, which is "
+%s%s%s runs the command %S%s, which is "
                           (if mouse-1-tricky "(short click) " "")
                           (key-description (vector up-event))
                           mouse-msg
                           (if mouse-1-remapped
                                " is remapped to <mouse-2>, which" "")
-                          defn-up))
+                          defn-up (if key-locus-up
+                                       (format " (found in %s)" key-locus-up)
+                                     "")))
            (describe-function-1 defn-up))
          (unless (or (null defn-up-tricky)
                      (integerp defn-up-tricky)
@@ -777,10 +860,12 @@ temporarily enables it to allow getting help on disabled items and buttons."
 ----------------- up-event (long click) ----------------
 
 Pressing <%S>%s for longer than %d milli-seconds
-runs the command %S, which is "
+runs the command %S%s, which is "
                           ev-type mouse-msg
                           mouse-1-click-follows-link
-                          defn-up-tricky))
+                          defn-up-tricky (if key-locus-up-tricky
+                                              (format " (found in %s)" key-locus-up-tricky)
+                                            "")))
            (describe-function-1 defn-up-tricky)))))))
 \f
 (defun describe-mode (&optional buffer)