]> git.eshelyaron.com Git - emacs.git/commitdiff
Make `view-lossage' output of chars read from `read-char' more logical
authorLars Ingebrigtsen <larsi@gnus.org>
Mon, 5 Aug 2019 10:43:09 +0000 (12:43 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Mon, 5 Aug 2019 10:43:17 +0000 (12:43 +0200)
* lisp/help.el (view-lossage): Use the new data format to output
data from `read-char' and the like in a more understandable
fashion (bug#21867).

* src/keyboard.c (command_loop_1): Record (in recent_keys) the end
of commands.
(Frecent_keys): Don't include `end-of-command' in non-command outputs.
(syms_of_keyboard): Define `end-of-command'.

lisp/help.el
src/keyboard.c

index 039d0c44e4f562979c1d4ed1863c1a90f3289f7a..ba76d26757154355e7e00c4fc61993a10e85d36b 100644 (file)
@@ -465,18 +465,28 @@ To record all your input, use `open-dribble-file'."
   (help-setup-xref (list #'view-lossage)
                   (called-interactively-p 'interactive))
   (with-help-window (help-buffer)
-    (princ " ")
-    (princ (mapconcat (lambda (key)
-                       (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
+      (let ((prev-command nil))
+        (mapc
+         (lambda (key)
+          (cond
+           ((and (consp key) (null (car key)))
+            (princ (format ";; %s\n"
+                            (setq prev-command
+                                  (if (symbolp (cdr key))
+                                      (cdr key)
+                                   "anonymous-command")))))
+            ((eq key 'end-of-command)
+             (unless (bolp)
+               (princ (format ";; <during %s>\n" (or prev-command
+                                                     "unknown command")))))
+           ((or (integerp key) (symbolp key) (listp key))
+            (princ (single-key-description key))
+             (princ " "))
+           (t
+            (prin1 key)
+             (princ " "))))
+         (recent-keys 'include-cmds))))
     (with-current-buffer standard-output
       (goto-char (point-min))
       (let ((comment-start ";; ")
index 30686a2589834671fc3ab85736d5c4b248f76184..158daba260cd3ec46da96ed3c7d8467b1cec87eb 100644 (file)
@@ -307,6 +307,7 @@ static Lisp_Object command_loop (void);
 
 static void echo_now (void);
 static ptrdiff_t echo_length (void);
+static void record_char (Lisp_Object c);
 
 /* Incremented whenever a timer is run.  */
 unsigned timers_run;
@@ -1421,6 +1422,8 @@ command_loop_1 (void)
              Fcons (Qnil, cmd));
        if (++recent_keys_index >= NUM_RECENT_KEYS)
          recent_keys_index = 0;
+       /* Mark this as a complete command in recent_keys. */
+       record_char (Qend_of_command);
       }
       Vthis_command = cmd;
       Vreal_this_command = cmd;
@@ -1471,6 +1474,9 @@ command_loop_1 (void)
 
       safe_run_hooks (Qpost_command_hook);
 
+      /* Mark this as a complete command in recent_keys. */
+      record_char (Qend_of_command);
+
       /* If displaying a message, resize the echo area window to fit
         that message's size exactly.  Do this only if the echo area
         window is the minibuffer window of the selected frame.  See
@@ -2089,7 +2095,6 @@ show_help_echo (Lisp_Object help, Lisp_Object window, Lisp_Object object,
 
 static Lisp_Object kbd_buffer_get_event (KBOARD **kbp, bool *used_mouse_menu,
                                         struct timespec *end_time);
-static void record_char (Lisp_Object c);
 
 static Lisp_Object help_form_saved_window_configs;
 static void
@@ -9996,7 +10001,9 @@ represented as pseudo-events of the form (nil . COMMAND).  */)
       do
        {
          Lisp_Object e = AREF (recent_keys, i);
-         if (cmds || !CONSP (e) || !NILP (XCAR (e)))
+         if (cmds
+             || ((!CONSP (e) || !NILP (XCAR (e)))
+                 && !EQ (e, Qend_of_command)))
            es = Fcons (e, es);
          if (++i >= NUM_RECENT_KEYS)
            i = 0;
@@ -11066,6 +11073,8 @@ syms_of_keyboard (void)
 
   DEFSYM (Qundefined, "undefined");
 
+  DEFSYM (Qend_of_command, "end-of-command");
+
   /* Hooks to run before and after each command.  */
   DEFSYM (Qpre_command_hook, "pre-command-hook");
   DEFSYM (Qpost_command_hook, "post-command-hook");