aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTino Calancha2020-08-27 22:47:35 +0200
committerTino Calancha2020-08-27 22:53:35 +0200
commit0382368015bfcdb7b88dd68a739f2bc5cde77bce (patch)
tree8533e0ffa0f198e8a2cf8780b10eaa43291dc80c
parenta1999fb319827a2e0cb2bea17dfa190ac81316ef (diff)
downloademacs-bug#38796-lossage-limit.tar.gz
emacs-bug#38796-lossage-limit.zip
Use only one function to retrieve/set lossage sizebug#38796-lossage-limit
* 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.
-rw-r--r--doc/emacs/help.texi4
-rw-r--r--etc/NEWS9
-rw-r--r--lisp/comint.el2
-rw-r--r--lisp/help.el2
-rw-r--r--lisp/term.el3
-rw-r--r--src/keyboard.c46
-rw-r--r--test/src/keyboard-tests.el15
7 files changed, 42 insertions, 39 deletions
diff --git a/doc/emacs/help.texi b/doc/emacs/help.texi
index 6d9f3f4a29d..34a354891b4 100644
--- a/doc/emacs/help.texi
+++ b/doc/emacs/help.texi
@@ -573,14 +573,12 @@ command works depend on the major mode.
573 573
574@kindex C-h l 574@kindex C-h l
575@findex view-lossage 575@findex view-lossage
576@findex update-lossage-size
577@findex lossage-size 576@findex lossage-size
578 If something surprising happens, and you are not sure what you typed, 577 If something surprising happens, and you are not sure what you typed,
579use @kbd{C-h l} (@code{view-lossage}). @kbd{C-h l} displays your last 578use @kbd{C-h l} (@code{view-lossage}). @kbd{C-h l} displays your last
580input keystrokes and the commands they invoked. By default, Emacs 579input keystrokes and the commands they invoked. By default, Emacs
581stores the last 300 events; if you wish, you can change this number with 580stores the last 300 events; if you wish, you can change this number with
582the command @code{update-lossage-size}. The function @code{lossage-size} 581the command @code{lossage-size}.
583returns the current value for the lossage limit.
584If you see commands that you are not familiar with, you can use @kbd{C-h k} or 582If you see commands that you are not familiar with, you can use @kbd{C-h k} or
585@kbd{C-h f} to find out what they do. 583@kbd{C-h f} to find out what they do.
586 584
diff --git a/etc/NEWS b/etc/NEWS
index 86f4e6a05d8..8bb3527d85b 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -86,15 +86,18 @@ useful on systems such as FreeBSD which ships only with "etc/termcap".
86* Changes in Emacs 28.1 86* Changes in Emacs 28.1
87 87
88+++ 88+++
89** The new command 'lossage-limit' controls the maximum number
90of keystrokes and commands recorded.
91
92+++
89** New variables that hold default buffer names for shell output. 93** New variables that hold default buffer names for shell output.
90The new constants 'shell-command-buffer-name' and 94The new constants 'shell-command-buffer-name' and
91'shell-command-buffer-name-async' store the default buffer names 95'shell-command-buffer-name-async' store the default buffer names
92for the output of, respectively, synchronous and async shell 96for the output of, respectively, synchronous and async shell
93commands. 97commands.
94 98
95+++ 99** The new command lossage-size' allow users to set the maximum
96** The new command 'lossage-limit' controls the maximum number 100number of keystrokes and commands recorded.
97of keystrokes and commands recorded.
98 101
99** Support for '(box . SIZE)' 'cursor-type'. 102** Support for '(box . SIZE)' 'cursor-type'.
100By default, 'box' cursor always has a filled box shape. But if you 103By default, 'box' cursor always has a filled box shape. But if you
diff --git a/lisp/comint.el b/lisp/comint.el
index be0e32b9e09..afc8395b36f 100644
--- a/lisp/comint.el
+++ b/lisp/comint.el
@@ -2393,7 +2393,7 @@ password prompting should occur.")
2393Then send it to the process running in the current buffer. 2393Then send it to the process running in the current buffer.
2394The string is sent using `comint-input-sender'. 2394The string is sent using `comint-input-sender'.
2395Security bug: your string can still be temporarily recovered with 2395Security bug: your string can still be temporarily recovered with
2396\\[view-lossage]; `clear-this-command-keys' can fix that." 2396\\[view-lossage]; `clear-this-command-keys' and `lossage-size' can fix that."
2397 (interactive "P") ; Defeat snooping via C-x ESC ESC 2397 (interactive "P") ; Defeat snooping via C-x ESC ESC
2398 (let ((proc (get-buffer-process (current-buffer))) 2398 (let ((proc (get-buffer-process (current-buffer)))
2399 (prefix 2399 (prefix
diff --git a/lisp/help.el b/lisp/help.el
index 1f12666c7e6..d3b0e02f081 100644
--- a/lisp/help.el
+++ b/lisp/help.el
@@ -458,7 +458,7 @@ the variable `message-log-max'."
458 "Display last input keystrokes and the commands run. 458 "Display last input keystrokes and the commands run.
459For convenience this uses the same format as 459For convenience this uses the same format as
460`edit-last-kbd-macro'. 460`edit-last-kbd-macro'.
461See `update-lossage-size' to update the number of recorded keystrokes. 461See `lossage-size' to update the number of recorded keystrokes.
462 462
463To record all your input, use `open-dribble-file'." 463To record all your input, use `open-dribble-file'."
464 (interactive) 464 (interactive)
diff --git a/lisp/term.el b/lisp/term.el
index e77c2c1331b..e39d03e8cdc 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).
2236 2236
2237Note that the keystrokes comprising the text can still be recovered 2237Note that the keystrokes comprising the text can still be recovered
2238\(temporarily) with \\[view-lossage]. This may be a security bug for some 2238\(temporarily) with \\[view-lossage]. This may be a security bug for some
2239applications." 2239applications. See `clear-this-command-keys' and `lossage-size' for ways
2240to fix that."
2240 (declare (obsolete read-passwd "27.1")) 2241 (declare (obsolete read-passwd "27.1"))
2241 (let ((ans "") 2242 (let ((ans "")
2242 (c 0) 2243 (c 0)
diff --git a/src/keyboard.c b/src/keyboard.c
index d3eb9ae25d6..bf8d75b602f 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -103,9 +103,6 @@ static KBOARD *all_kboards;
103/* True in the single-kboard state, false in the any-kboard state. */ 103/* True in the single-kboard state, false in the any-kboard state. */
104static bool single_kboard; 104static bool single_kboard;
105 105
106/* Minimum allowed size of the recent_keys vector */
107#define MIN_NUM_RECENT_KEYS (100)
108
109/* Index for storing next element into recent_keys. */ 106/* Index for storing next element into recent_keys. */
110static int recent_keys_index; 107static int recent_keys_index;
111 108
@@ -113,7 +110,7 @@ static int recent_keys_index;
113static int total_keys; 110static int total_keys;
114 111
115/* Size of the recent_keys vector */ 112/* Size of the recent_keys vector */
116static int lossage_limit = 3 * MIN_NUM_RECENT_KEYS; 113static int lossage_limit = 300;
117 114
118/* This vector holds the last lossage_limit keystrokes. */ 115/* This vector holds the last lossage_limit keystrokes. */
119static Lisp_Object recent_keys; 116static Lisp_Object recent_keys;
@@ -10415,14 +10412,6 @@ If CHECK-TIMERS is non-nil, timers that are ready to run will do so. */)
10415 ? Qt : Qnil); 10412 ? Qt : Qnil);
10416} 10413}
10417 10414
10418DEFUN ("lossage-size", Flossage_size, Slossage_size, 0, 0, 0,
10419 doc: /* Return the maximum number of saved keystrokes.
10420These are the records shown by `view-lossage'. */ )
10421 (void)
10422{
10423 return make_fixnum(lossage_limit);
10424}
10425
10426/* Reallocate recent_keys copying the keystrokes in the right order */ 10415/* Reallocate recent_keys copying the keystrokes in the right order */
10427static void 10416static void
10428update_recent_keys (int new_size, int kept_keys) 10417update_recent_keys (int new_size, int kept_keys)
@@ -10446,27 +10435,33 @@ update_recent_keys (int new_size, int kept_keys)
10446 10435
10447} 10436}
10448 10437
10449DEFUN ("update-lossage-size", Fupdate_lossage_size, 10438DEFUN ("lossage-size", Flossage_size, Slossage_size, 0, 1,
10450 Supdate_lossage_size, 1, 1, "nnew-size: ", 10439 "(list (read-number \"new-size: \" (lossage-size)))",
10451 doc: /* Update the maximum number of saved keystrokes to ARG. 10440 doc: /* Return the maximum number of saved keystrokes.
10452These are the records shown by `view-lossage'. 10441Called with ARG, then set this number to ARG.
10453usage: (update-lossage-limit ARG) */) 10442
10443The saved keystrokes are the records shown by `view-lossage'.
10444If you want to disable the lossage records, then set this maximum to a
10445small number, e.g. 0.
10446usage: (lossage-size &optional ARG) */)
10454 (Lisp_Object arg) 10447 (Lisp_Object arg)
10455{ 10448{
10449 if (NILP(arg))
10450 return make_fixnum(lossage_limit == 1 ? 0 : lossage_limit);
10451
10456 if (!FIXNATP (arg)) 10452 if (!FIXNATP (arg))
10457 user_error ("Value must be a positive integer"); 10453 user_error ("Value must be a non-negative integer");
10458 int osize = ASIZE (recent_keys); 10454 int osize = ASIZE (recent_keys);
10459 eassert (lossage_limit == osize); 10455 eassert (lossage_limit == osize);
10460 int min_size = MIN_NUM_RECENT_KEYS;
10461 int new_size = XFIXNAT (arg); 10456 int new_size = XFIXNAT (arg);
10462 10457
10463 if (new_size == osize) 10458 if (new_size == osize)
10464 return Qnil; 10459 return Qnil;
10465 if (new_size < min_size) 10460 /* Internally, the minimum lossage_limit is 1; users will likely use
10466 { 10461 0 to disable the lossage, thus here we change 0 -> 1. */
10467 AUTO_STRING (fmt, "Value must be >= %d"); 10462 if (new_size == 0)
10468 Fsignal (Quser_error, list1 (CALLN (Fformat, fmt, make_fixnum (min_size)))); 10463 new_size = 1;
10469 } 10464
10470 int kept_keys = new_size > osize ? total_keys : min (new_size, total_keys); 10465 int kept_keys = new_size > osize ? total_keys : min (new_size, total_keys);
10471 update_recent_keys (new_size, kept_keys); 10466 update_recent_keys (new_size, kept_keys);
10472 10467
@@ -10594,7 +10589,7 @@ The value is always a vector. */)
10594DEFUN ("clear-this-command-keys", Fclear_this_command_keys, 10589DEFUN ("clear-this-command-keys", Fclear_this_command_keys,
10595 Sclear_this_command_keys, 0, 1, 0, 10590 Sclear_this_command_keys, 0, 1, 0,
10596 doc: /* Clear out the vector that `this-command-keys' returns. 10591 doc: /* Clear out the vector that `this-command-keys' returns.
10597Also clear the record of the last 300 input events, unless optional arg 10592Also clear the record of the last input events, unless optional arg
10598KEEP-RECORD is non-nil. */) 10593KEEP-RECORD is non-nil. */)
10599 (Lisp_Object keep_record) 10594 (Lisp_Object keep_record)
10600{ 10595{
@@ -11800,7 +11795,6 @@ syms_of_keyboard (void)
11800 defsubr (&Sinternal_track_mouse); 11795 defsubr (&Sinternal_track_mouse);
11801 defsubr (&Sinput_pending_p); 11796 defsubr (&Sinput_pending_p);
11802 defsubr (&Slossage_size); 11797 defsubr (&Slossage_size);
11803 defsubr (&Supdate_lossage_size);
11804 defsubr (&Srecent_keys); 11798 defsubr (&Srecent_keys);
11805 defsubr (&Sthis_command_keys); 11799 defsubr (&Sthis_command_keys);
11806 defsubr (&Sthis_command_keys_vector); 11800 defsubr (&Sthis_command_keys_vector);
diff --git a/test/src/keyboard-tests.el b/test/src/keyboard-tests.el
index 8f2cfe4adc8..d4ac4a518d0 100644
--- a/test/src/keyboard-tests.el
+++ b/test/src/keyboard-tests.el
@@ -33,13 +33,20 @@
33 ?\C-b))) 33 ?\C-b)))
34 34
35(ert-deftest keyboard-lossage-size () 35(ert-deftest keyboard-lossage-size ()
36 "Test `update-lossage-size'." 36 "Test `lossage-size'."
37 (dolist (val (list 100 300 400 400 500 1000 700 300)) 37 (dolist (val (list 100 300 400 400 500 1000 700 300))
38 (update-lossage-size val) 38 (lossage-size val)
39 (should (= val (lossage-size)))) 39 (should (= val (lossage-size))))
40 (let ((current-size (lossage-size))) 40 (let ((current-size (lossage-size)))
41 (should-error (update-lossage-size 5)) 41 ;; Set lossage size to 1 and 0 are equivalent
42 (should-error (update-lossage-size "200")) 42 (lossage-size 0)
43 (should (zerop (lossage-size)))
44 (lossage-size 1)
45 (should (zerop (lossage-size)))
46 (lossage-size current-size)
47 ;; Argument must be a natural number
48 (should-error (lossage-size -5))
49 (should-error (lossage-size "200"))
43 (should (= (lossage-size) current-size)))) 50 (should (= (lossage-size) current-size))))
44 51
45 52