Commit 03823680 authored by Tino Calancha's avatar Tino Calancha

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.
parent a1999fb3
Pipeline #6655 failed with stage
in 85 minutes and 25 seconds
......@@ -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.
......
......@@ -85,6 +85,10 @@ 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
......@@ -92,9 +96,8 @@ The new constants 'shell-command-buffer-name' and
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
......
......@@ -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
......
......@@ -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)
......
......@@ -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)
......
......@@ -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);
......
......@@ -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))))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment