emacs-diffs
[Top][All Lists]
Advanced

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

bug#38796-lossage-limit c86d060 4/4: Do not expose the size of recent_ke


From: Tino Calancha
Subject: bug#38796-lossage-limit c86d060 4/4: Do not expose the size of recent_keys to Lisp
Date: Sun, 28 Jun 2020 17:34:41 -0400 (EDT)

branch: bug#38796-lossage-limit
commit c86d060b460bdaecdd71d297fa84012fcd397d66
Author: Tino Calancha <tino.calancha@gmail.com>
Commit: Tino Calancha <tino.calancha@gmail.com>

    Do not expose the size of recent_keys to Lisp
    
    That prevents from unintentional crashes if the users
    modify the variable with setq or if they let-bind it.
    
    Users can still safely modify the lossage limit with the
    command `update-lossage-size'.  For convenience, add
    a function `lossage-size' to return the current limit.
    
    * src/keyboard.c (lossage_limit): Do not expose it
    to Lisp; make it a static variable.
    Keep the current Emacs default (300); accept only values >= 100.
    (lossage-size): New function; it returns the current size
    of recent_keys.
    (update-lossage-size):
    Rename it from update-lossage-limit (all callers updated);
    make it a command.
    
    * doc/emacs/help.texi (Misc Help)
    * etc/NEWS
    * lisp/cus-start.el
    * lisp/edmacro.el
    * lisp/help.el:
    Update all references with the new name.
    
    * test/src/keyboard-tests.el (keyboard-lossage-limit):
    Amend the test.
---
 doc/emacs/help.texi        |  8 +++++---
 etc/NEWS                   |  5 +++--
 lisp/cus-start.el          |  2 --
 lisp/edmacro.el            |  4 ++--
 lisp/help.el               |  2 +-
 src/keyboard.c             | 38 ++++++++++++++++++--------------------
 test/src/keyboard-tests.el | 18 +++++++++---------
 7 files changed, 38 insertions(+), 39 deletions(-)

diff --git a/doc/emacs/help.texi b/doc/emacs/help.texi
index e2c0dc6..26cdf16 100644
--- a/doc/emacs/help.texi
+++ b/doc/emacs/help.texi
@@ -563,12 +563,14 @@ command works depend on the major mode.
 
 @kindex C-h l
 @findex view-lossage
-@vindex lossage-limit
+@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 option @code{lossage-limit}.
+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.
 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 da204c5..5fc4cb4 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -71,8 +71,9 @@ useful on systems such as FreeBSD which ships only with 
"etc/termcap".
 * Changes in Emacs 28.1
 
 +++
-** The new option 'lossage-limit' controls the maximum number
-of keystrokes and commands recorded.
+** The new command 'update-lossage-size' allow users to set the maximum
+number of keystrokes and commands recorded.  The new function 'lossage-size'
+returns the current value of this limit
 
 ** Support for '(box . SIZE)' 'cursor-type'.
 By default, 'box' cursor always has a filled box shape.  But if you
diff --git a/lisp/cus-start.el b/lisp/cus-start.el
index 1ebf554..6632687 100644
--- a/lisp/cus-start.el
+++ b/lisp/cus-start.el
@@ -352,8 +352,6 @@ Leaving \"Default\" unchecked is equivalent with specifying 
a default of
             ;; indent.c
             (indent-tabs-mode indent boolean)
             ;; keyboard.c
-             (lossage-limit keyboard integer "28.1"
-                            :set (lambda (_ val) (update-lossage-limit val)))
             (meta-prefix-char keyboard character)
             (auto-save-interval auto-save integer)
              (auto-save-no-message auto-save boolean "27.1")
diff --git a/lisp/edmacro.el b/lisp/edmacro.el
index 089fea1..52cbf5b 100644
--- a/lisp/edmacro.el
+++ b/lisp/edmacro.el
@@ -35,7 +35,7 @@
 ;;  * `M-x' followed by a command name, to edit a named command
 ;;    whose definition is a keyboard macro.
 ;;
-;;  * `C-h l' (view-lossage), to edit the `lossage-limit' most recent
+;;  * `C-h l' (view-lossage), to edit the 300 most recent
 ;;    keystrokes and install them as the "current" macro.
 ;;
 ;;  * any key sequence whose definition is a keyboard macro.
@@ -88,7 +88,7 @@ Default nil means to write characters above \\177 in octal 
notation."
   "Edit a keyboard macro.
 At the prompt, type any key sequence which is bound to a keyboard macro.
 Or, type `\\[kmacro-end-and-call-macro]' or RET to edit the last
-keyboard macro, `\\[view-lossage]' to edit the last `lossage-limit'
+keyboard macro, `\\[view-lossage]' to edit the last 300
 keystrokes as a keyboard macro, or `\\[execute-extended-command]'
 to edit a macro by its command name.
 With a prefix argument, format the macro in a more concise way."
diff --git a/lisp/help.el b/lisp/help.el
index 9e3d092..01ee739 100644
--- a/lisp/help.el
+++ b/lisp/help.el
@@ -459,7 +459,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 `lossage-limit' to update the number of recorded keystrokes.
+See `update-lossage-size' to update the number of recorded keystrokes.
 
 To record all your input, use `open-dribble-file'."
   (interactive)
diff --git a/src/keyboard.c b/src/keyboard.c
index a4d27c9..29b1577 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -103,6 +103,7 @@ 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.  */
@@ -111,6 +112,9 @@ static int recent_keys_index;
 /* Total number of elements stored into recent_keys.  */
 static int total_keys;
 
+/* Size of the recent_keys vector */
+static int lossage_limit = 3 * MIN_NUM_RECENT_KEYS;
+
 /* This vector holds the last lossage_limit keystrokes.  */
 static Lisp_Object recent_keys;
 
@@ -10411,6 +10415,15 @@ 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)
 {
@@ -10433,10 +10446,10 @@ update_recent_keys (int new_size, int kept_keys)
 
 }
 
-/* Reallocate recent_keys copying the keystrokes in the right order */
-DEFUN ("update-lossage-limit", Fupdate_lossage_limit,
-       Supdate_lossage_limit, 1, 1, 0,
+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)  */)
   (Lisp_Object arg)
 {
@@ -11736,22 +11749,6 @@ syms_of_keyboard (void)
     staticpro (&modifier_symbols);
   }
 
-  DEFVAR_INT ("lossage-limit", lossage_limit,
-              doc: /* Maximum number of stored keyboard events and commands 
run.
-
-Please, do not set this variable in Lisp with `setq' neither
-let-bind it, that will likely crash Emacs.  This is because
-`setq' only changes the variable, but it doesn't update
-the size of the internal vector that holds the keystrokes.
-
-To update this variable use the customization menu, or
-call from Lisp the following expression:
-
-  (update-lossage-limit new-limit)
-
-That takes care of both, the variable and the internal vector.*/);
-  lossage_limit = 3 * MIN_NUM_RECENT_KEYS;
-
   recent_keys = make_nil_vector (lossage_limit);
   staticpro (&recent_keys);
 
@@ -11802,7 +11799,8 @@ That takes care of both, the variable and the internal 
vector.*/);
   defsubr (&Srecursive_edit);
   defsubr (&Sinternal_track_mouse);
   defsubr (&Sinput_pending_p);
-  defsubr (&Supdate_lossage_limit);
+  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 017d239..8f2cfe4 100644
--- a/test/src/keyboard-tests.el
+++ b/test/src/keyboard-tests.el
@@ -32,15 +32,15 @@
                         (read-event nil nil 2))
                  ?\C-b)))
 
-(ert-deftest keyboard-lossage-limit ()
-  "Test `lossage-limit' updates."
-  (dolist (val (list 100 100 200 500 300 1000 700))
-    (update-lossage-limit val)
-    (should (= val lossage-limit)))
-  (let ((current-limit lossage-limit))
-    (should-error (update-lossage-limit 5))
-    (should-error (update-lossage-limit "200"))
-    (should (= lossage-limit current-limit))))
+(ert-deftest keyboard-lossage-size ()
+  "Test `update-lossage-size'."
+  (dolist (val (list 100 300 400 400 500 1000 700 300))
+    (update-lossage-size val)
+    (should (= val (lossage-size))))
+  (let ((current-size (lossage-size)))
+    (should-error (update-lossage-size 5))
+    (should-error (update-lossage-size "200"))
+    (should (= (lossage-size) current-size))))
 
 
 (provide 'keyboard-tests)



reply via email to

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