diff options
| author | Tino Calancha | 2020-08-27 22:47:35 +0200 |
|---|---|---|
| committer | Tino Calancha | 2020-08-27 22:53:35 +0200 |
| commit | 0382368015bfcdb7b88dd68a739f2bc5cde77bce (patch) | |
| tree | 8533e0ffa0f198e8a2cf8780b10eaa43291dc80c | |
| parent | a1999fb319827a2e0cb2bea17dfa190ac81316ef (diff) | |
| download | emacs-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.texi | 4 | ||||
| -rw-r--r-- | etc/NEWS | 9 | ||||
| -rw-r--r-- | lisp/comint.el | 2 | ||||
| -rw-r--r-- | lisp/help.el | 2 | ||||
| -rw-r--r-- | lisp/term.el | 3 | ||||
| -rw-r--r-- | src/keyboard.c | 46 | ||||
| -rw-r--r-- | 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 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, |
| 579 | use @kbd{C-h l} (@code{view-lossage}). @kbd{C-h l} displays your last | 578 | use @kbd{C-h l} (@code{view-lossage}). @kbd{C-h l} displays your last |
| 580 | input keystrokes and the commands they invoked. By default, Emacs | 579 | input keystrokes and the commands they invoked. By default, Emacs |
| 581 | stores the last 300 events; if you wish, you can change this number with | 580 | stores the last 300 events; if you wish, you can change this number with |
| 582 | the command @code{update-lossage-size}. The function @code{lossage-size} | 581 | the command @code{lossage-size}. |
| 583 | returns the current value for the lossage limit. | ||
| 584 | If you see commands that you are not familiar with, you can use @kbd{C-h k} or | 582 | If 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 | ||
| @@ -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 | ||
| 90 | of 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. |
| 90 | The new constants 'shell-command-buffer-name' and | 94 | The 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 |
| 92 | for the output of, respectively, synchronous and async shell | 96 | for the output of, respectively, synchronous and async shell |
| 93 | commands. | 97 | commands. |
| 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 | 100 | number of keystrokes and commands recorded. |
| 97 | of keystrokes and commands recorded. | ||
| 98 | 101 | ||
| 99 | ** Support for '(box . SIZE)' 'cursor-type'. | 102 | ** Support for '(box . SIZE)' 'cursor-type'. |
| 100 | By default, 'box' cursor always has a filled box shape. But if you | 103 | By 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.") | |||
| 2393 | Then send it to the process running in the current buffer. | 2393 | Then send it to the process running in the current buffer. |
| 2394 | The string is sent using `comint-input-sender'. | 2394 | The string is sent using `comint-input-sender'. |
| 2395 | Security bug: your string can still be temporarily recovered with | 2395 | Security 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. |
| 459 | For convenience this uses the same format as | 459 | For convenience this uses the same format as |
| 460 | `edit-last-kbd-macro'. | 460 | `edit-last-kbd-macro'. |
| 461 | See `update-lossage-size' to update the number of recorded keystrokes. | 461 | See `lossage-size' to update the number of recorded keystrokes. |
| 462 | 462 | ||
| 463 | To record all your input, use `open-dribble-file'." | 463 | To 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 | ||
| 2237 | Note that the keystrokes comprising the text can still be recovered | 2237 | Note 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 |
| 2239 | applications." | 2239 | applications. See `clear-this-command-keys' and `lossage-size' for ways |
| 2240 | to 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. */ |
| 104 | static bool single_kboard; | 104 | static 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. */ |
| 110 | static int recent_keys_index; | 107 | static int recent_keys_index; |
| 111 | 108 | ||
| @@ -113,7 +110,7 @@ static int recent_keys_index; | |||
| 113 | static int total_keys; | 110 | static int total_keys; |
| 114 | 111 | ||
| 115 | /* Size of the recent_keys vector */ | 112 | /* Size of the recent_keys vector */ |
| 116 | static int lossage_limit = 3 * MIN_NUM_RECENT_KEYS; | 113 | static int lossage_limit = 300; |
| 117 | 114 | ||
| 118 | /* This vector holds the last lossage_limit keystrokes. */ | 115 | /* This vector holds the last lossage_limit keystrokes. */ |
| 119 | static Lisp_Object recent_keys; | 116 | static 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 | ||
| 10418 | DEFUN ("lossage-size", Flossage_size, Slossage_size, 0, 0, 0, | ||
| 10419 | doc: /* Return the maximum number of saved keystrokes. | ||
| 10420 | These 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 */ |
| 10427 | static void | 10416 | static void |
| 10428 | update_recent_keys (int new_size, int kept_keys) | 10417 | update_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 | ||
| 10449 | DEFUN ("update-lossage-size", Fupdate_lossage_size, | 10438 | DEFUN ("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. |
| 10452 | These are the records shown by `view-lossage'. | 10441 | Called with ARG, then set this number to ARG. |
| 10453 | usage: (update-lossage-limit ARG) */) | 10442 | |
| 10443 | The saved keystrokes are the records shown by `view-lossage'. | ||
| 10444 | If you want to disable the lossage records, then set this maximum to a | ||
| 10445 | small number, e.g. 0. | ||
| 10446 | usage: (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. */) | |||
| 10594 | DEFUN ("clear-this-command-keys", Fclear_this_command_keys, | 10589 | DEFUN ("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. |
| 10597 | Also clear the record of the last 300 input events, unless optional arg | 10592 | Also clear the record of the last input events, unless optional arg |
| 10598 | KEEP-RECORD is non-nil. */) | 10593 | KEEP-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 | ||