emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#38796-lossage-limit 0382368 5/5: Use only one function to retrieve/s


From: Tino Calancha
Subject: bug#38796-lossage-limit 0382368 5/5: Use only one function to retrieve/set lossage size
Date: Thu, 27 Aug 2020 17:11:38 -0400 (EDT)

branch: bug#38796-lossage-limit
commit 0382368015bfcdb7b88dd68a739f2bc5cde77bce
Author: Tino Calancha <ccalancha@suse.com>
Commit: Tino Calancha <ccalancha@suse.com>

    Use only one function to retrieve/set lossage size
    
    * src/keyboard.c (update-lossage-size):
    Rename it as lossage-size.
    Called with no arguments, return the current lossage limit.
    Called with ARG sets the lossage limit.
    All callers updated.
    
    * doc/emacs/help.texi: Ammend documentation.
    * etc/NEWS: Amend entry.
    * lisp/help.el (view-lossage): Fix docstring.
    
    * lisp/comint.el (comint-send-invisible)
    * lisp/term.el (term-read-noecho):
    Mention the new command in the docstrings.
    
    * test/src/keyboard-tests.el: Ammend test.
---
 doc/emacs/help.texi        |  4 +---
 etc/NEWS                   |  9 ++++++---
 lisp/comint.el             |  2 +-
 lisp/help.el               |  2 +-
 lisp/term.el               |  3 ++-
 src/keyboard.c             | 46 ++++++++++++++++++++--------------------------
 test/src/keyboard-tests.el | 15 +++++++++++----
 7 files changed, 42 insertions(+), 39 deletions(-)

diff --git a/doc/emacs/help.texi b/doc/emacs/help.texi
index 6d9f3f4..34a3548 100644
--- a/doc/emacs/help.texi
+++ b/doc/emacs/help.texi
@@ -573,14 +573,12 @@ command works depend on the major mode.
 
 @kindex C-h l
 @findex view-lossage
-@findex update-lossage-size
 @findex lossage-size
   If something surprising happens, and you are not sure what you typed,
 use @kbd{C-h l} (@code{view-lossage}).  @kbd{C-h l} displays your last
 input keystrokes and the commands they invoked.  By default, Emacs
 stores the last 300 events; if you wish, you can change this number with
-the command @code{update-lossage-size}.  The function @code{lossage-size}
-returns the current value for the lossage limit.
+the command @code{lossage-size}.
 If you see commands that you are not familiar with, you can use @kbd{C-h k} or
 @kbd{C-h f} to find out what they do.
 
diff --git a/etc/NEWS b/etc/NEWS
index 86f4e6a..8bb3527 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -86,15 +86,18 @@ useful on systems such as FreeBSD which ships only with 
"etc/termcap".
 * Changes in Emacs 28.1
 
 +++
+** The new command 'lossage-limit' controls the maximum number
+of keystrokes and commands recorded.
+
++++
 ** New variables that hold default buffer names for shell output.
 The new constants 'shell-command-buffer-name' and
 'shell-command-buffer-name-async' store the default buffer names
 for the output of, respectively, synchronous and async shell
 commands.
 
-+++
-** The new command 'lossage-limit' controls the maximum number
-of keystrokes and commands recorded.
+** The new command lossage-size' allow users to set the maximum
+number of keystrokes and commands recorded.
 
 ** Support for '(box . SIZE)' 'cursor-type'.
 By default, 'box' cursor always has a filled box shape.  But if you
diff --git a/lisp/comint.el b/lisp/comint.el
index be0e32b..afc8395 100644
--- a/lisp/comint.el
+++ b/lisp/comint.el
@@ -2393,7 +2393,7 @@ password prompting should occur.")
 Then send it to the process running in the current buffer.
 The string is sent using `comint-input-sender'.
 Security bug: your string can still be temporarily recovered with
-\\[view-lossage]; `clear-this-command-keys' can fix that."
+\\[view-lossage]; `clear-this-command-keys' and `lossage-size' can fix that."
   (interactive "P")                    ; Defeat snooping via C-x ESC ESC
   (let ((proc (get-buffer-process (current-buffer)))
        (prefix
diff --git a/lisp/help.el b/lisp/help.el
index 1f12666..d3b0e02 100644
--- a/lisp/help.el
+++ b/lisp/help.el
@@ -458,7 +458,7 @@ the variable `message-log-max'."
   "Display last input keystrokes and the commands run.
 For convenience this uses the same format as
 `edit-last-kbd-macro'.
-See `update-lossage-size' to update the number of recorded keystrokes.
+See `lossage-size' to update the number of recorded keystrokes.
 
 To record all your input, use `open-dribble-file'."
   (interactive)
diff --git a/lisp/term.el b/lisp/term.el
index e77c2c1..e39d03e 100644
--- a/lisp/term.el
+++ b/lisp/term.el
@@ -2236,7 +2236,8 @@ filter and C-g is pressed, this function returns nil 
rather than a string).
 
 Note that the keystrokes comprising the text can still be recovered
 \(temporarily) with \\[view-lossage].  This may be a security bug for some
-applications."
+applications.  See `clear-this-command-keys' and `lossage-size' for ways
+to fix that."
   (declare (obsolete read-passwd "27.1"))
   (let ((ans "")
        (c 0)
diff --git a/src/keyboard.c b/src/keyboard.c
index d3eb9ae..bf8d75b 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -103,9 +103,6 @@ static KBOARD *all_kboards;
 /* True in the single-kboard state, false in the any-kboard state.  */
 static bool single_kboard;
 
-/* Minimum allowed size of the recent_keys vector */
-#define MIN_NUM_RECENT_KEYS (100)
-
 /* Index for storing next element into recent_keys.  */
 static int recent_keys_index;
 
@@ -113,7 +110,7 @@ static int recent_keys_index;
 static int total_keys;
 
 /* Size of the recent_keys vector */
-static int lossage_limit = 3 * MIN_NUM_RECENT_KEYS;
+static int lossage_limit = 300;
 
 /* This vector holds the last lossage_limit keystrokes.  */
 static Lisp_Object recent_keys;
@@ -10415,14 +10412,6 @@ If CHECK-TIMERS is non-nil, timers that are ready to 
run will do so.  */)
          ? Qt : Qnil);
 }
 
-DEFUN ("lossage-size", Flossage_size, Slossage_size, 0, 0, 0,
-       doc: /* Return the maximum number of saved keystrokes.
-These are the records shown by `view-lossage'. */ )
-  (void)
-{
-  return make_fixnum(lossage_limit);
-}
-
 /* Reallocate recent_keys copying the keystrokes in the right order */
 static void
 update_recent_keys (int new_size, int kept_keys)
@@ -10446,27 +10435,33 @@ update_recent_keys (int new_size, int kept_keys)
 
 }
 
-DEFUN ("update-lossage-size", Fupdate_lossage_size,
-       Supdate_lossage_size, 1, 1, "nnew-size: ",
-       doc: /* Update the maximum number of saved keystrokes to ARG.
-These are the records shown by `view-lossage'.
-usage: (update-lossage-limit ARG)  */)
+DEFUN ("lossage-size", Flossage_size, Slossage_size, 0, 1,
+       "(list (read-number \"new-size: \" (lossage-size)))",
+       doc: /* Return the maximum number of saved keystrokes.
+Called with ARG, then set this number to ARG.
+
+The saved keystrokes are the records shown by `view-lossage'.
+If you want to disable the lossage records, then set this maximum to a
+small number, e.g. 0.
+usage: (lossage-size &optional ARG) */)
   (Lisp_Object arg)
 {
+  if (NILP(arg))
+    return make_fixnum(lossage_limit == 1 ? 0 : lossage_limit);
+
   if (!FIXNATP (arg))
-    user_error ("Value must be a positive integer");
+    user_error ("Value must be a non-negative integer");
   int osize = ASIZE (recent_keys);
   eassert (lossage_limit == osize);
-  int min_size = MIN_NUM_RECENT_KEYS;
   int new_size = XFIXNAT (arg);
 
   if (new_size == osize)
     return Qnil;
-  if (new_size < min_size)
-    {
-      AUTO_STRING (fmt, "Value must be >= %d");
-      Fsignal (Quser_error, list1 (CALLN (Fformat, fmt, make_fixnum 
(min_size))));
-    }
+  /* Internally, the minimum lossage_limit is 1; users will likely use
+     0 to disable the lossage, thus here we change 0 -> 1.  */
+  if (new_size == 0)
+    new_size = 1;
+
   int kept_keys = new_size > osize ? total_keys : min (new_size, total_keys);
   update_recent_keys (new_size, kept_keys);
 
@@ -10594,7 +10589,7 @@ The value is always a vector.  */)
 DEFUN ("clear-this-command-keys", Fclear_this_command_keys,
        Sclear_this_command_keys, 0, 1, 0,
        doc: /* Clear out the vector that `this-command-keys' returns.
-Also clear the record of the last 300 input events, unless optional arg
+Also clear the record of the last input events, unless optional arg
 KEEP-RECORD is non-nil.  */)
   (Lisp_Object keep_record)
 {
@@ -11800,7 +11795,6 @@ syms_of_keyboard (void)
   defsubr (&Sinternal_track_mouse);
   defsubr (&Sinput_pending_p);
   defsubr (&Slossage_size);
-  defsubr (&Supdate_lossage_size);
   defsubr (&Srecent_keys);
   defsubr (&Sthis_command_keys);
   defsubr (&Sthis_command_keys_vector);
diff --git a/test/src/keyboard-tests.el b/test/src/keyboard-tests.el
index 8f2cfe4..d4ac4a5 100644
--- a/test/src/keyboard-tests.el
+++ b/test/src/keyboard-tests.el
@@ -33,13 +33,20 @@
                  ?\C-b)))
 
 (ert-deftest keyboard-lossage-size ()
-  "Test `update-lossage-size'."
+  "Test `lossage-size'."
   (dolist (val (list 100 300 400 400 500 1000 700 300))
-    (update-lossage-size val)
+    (lossage-size val)
     (should (= val (lossage-size))))
   (let ((current-size (lossage-size)))
-    (should-error (update-lossage-size 5))
-    (should-error (update-lossage-size "200"))
+    ;; Set lossage size to 1 and 0 are equivalent
+    (lossage-size 0)
+    (should (zerop (lossage-size)))
+    (lossage-size 1)
+    (should (zerop (lossage-size)))
+    (lossage-size current-size)
+    ;; Argument must be a natural number
+    (should-error (lossage-size -5))
+    (should-error (lossage-size "200"))
     (should (= (lossage-size) current-size))))
 
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]