From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.bugs Subject: bug#38796: 26.3; `view-lossage': Use a variable for the lossage limit Date: Sun, 28 Jun 2020 23:52:57 +0200 Message-ID: <87wo3qj1s6.fsf@calancha-pc.dy.bbexcite.jp> References: <43aac56d-ecf1-44ed-9be1-ffb8e5f8a7ce@default> <83zhfbm448.fsf@gnu.org> <87zh8pij6e.fsf@calancha-pc.dy.bbexcite.jp> <83v9jc3o3q.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="72220"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: uyennhi.qm@gmail.com, 38796@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jun 28 23:54:13 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jpfFc-000If2-2s for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 28 Jun 2020 23:54:12 +0200 Original-Received: from localhost ([::1]:38508 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jpfFa-0003wd-UA for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 28 Jun 2020 17:54:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:59686) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpfFS-0003wI-Mx for bug-gnu-emacs@gnu.org; Sun, 28 Jun 2020 17:54:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:35573) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jpfFR-0008TV-Kb for bug-gnu-emacs@gnu.org; Sun, 28 Jun 2020 17:54:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jpfFR-0003Ui-Jx for bug-gnu-emacs@gnu.org; Sun, 28 Jun 2020 17:54:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 28 Jun 2020 21:54:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 38796 X-GNU-PR-Package: emacs Original-Received: via spool by 38796-submit@debbugs.gnu.org id=B38796.159338119613378 (code B ref 38796); Sun, 28 Jun 2020 21:54:01 +0000 Original-Received: (at 38796) by debbugs.gnu.org; 28 Jun 2020 21:53:16 +0000 Original-Received: from localhost ([127.0.0.1]:47119 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jpfEh-0003Th-Et for submit@debbugs.gnu.org; Sun, 28 Jun 2020 17:53:16 -0400 Original-Received: from mail-ej1-f68.google.com ([209.85.218.68]:45103) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jpfEe-0003TO-8P for 38796@debbugs.gnu.org; Sun, 28 Jun 2020 17:53:14 -0400 Original-Received: by mail-ej1-f68.google.com with SMTP id a1so14640422ejg.12 for <38796@debbugs.gnu.org>; Sun, 28 Jun 2020 14:53:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=2FO6NofNmbXIQuOApZsMst63I5leCi/Oe4CvpNOsUhU=; b=S0dlFmxGAW5bDPkrEzfWQgpXZfodpdglVrJCOJn/F0Hr1XycaZMTY7W0taqdhHu0yj 6p0uG/eI37TZCNsALc+1Jc/svS5WKzEAUhPrb3SNfup1clm0WQ8qF//b9qx8moz/UXT8 fgzeu860sl+z4l82tBgeH7MDo3WqroRNiepSVQ5n2J2/WK7cOWWezacKonyeK20Vyj6w vlGWRTAGsGmviAUtO5zry3NbUONfdhuv/UU3NEjDOf3UfehcPdqYhcVvebKRL9CDtsnN P7q3eSM3NQw1Tzbe8miada9pyLJDW5y0CQ91zD1Iorx2x97q3tDtEENwUcfmKHsxN3Ov YEtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=2FO6NofNmbXIQuOApZsMst63I5leCi/Oe4CvpNOsUhU=; b=IKrxX1TSw8ghCWlg05JKRByxxsMpNncjuhqtfLPgCbf3FAlvs/94xI0mn3jh5xYKAT wlC1MOA62Kt3latihZe62netIowQ6AUEIm4uwWDhZni/uMvxmDWUI6euDn+B9Mdcj43J w6MwvWLU9fBJ+bJIsIOB7Iut7qkNJAdfb9o1aOkoHqtLWWpO31p4Z//bdH0C6bHQP2jo SKEGJ/UqZ7WNuOKYO/g4cYTm7X6gLfCohHBOhFRBpZJpdmTXERepzQ+AC0Nm9CKIHyM0 RMT+Cg3v6w5x1GFYNElq0LW6PicJmCTC3H9wzPiQQ4K0XwoYBT/asawoh/t/RgfQDVxg CGXA== X-Gm-Message-State: AOAM530QKlLNrnVX0zktNz0wvXUwa9ELs85g6MXItbUccQYOoZtNQY7H lrRRZ9b15xw+8u2r25nC9KQunbY7Qs4= X-Google-Smtp-Source: ABdhPJxs2wLut/vWIhkJ7t2/KXj2IvYU4vw/jU8IVjnEhbdHl+wOUifPi54KVqDhSaHcQLg/Nns1RQ== X-Received: by 2002:a17:906:2b50:: with SMTP id b16mr12059912ejg.410.1593381185805; Sun, 28 Jun 2020 14:53:05 -0700 (PDT) Original-Received: from calancha-pc.dy.bbexcite.jp ([31.7.242.222]) by smtp.gmail.com with ESMTPSA id v19sm21548992eda.70.2020.06.28.14.53.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jun 2020 14:53:04 -0700 (PDT) In-Reply-To: (Stefan Monnier's message of "Sun, 28 Jun 2020 14:00:33 -0400") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:182491 Archived-At: On Sun, 28 Jun 2020, Drew Adams wrote: > OP here. I was waiting for you. Welcome!! :-) Stefan Monnier writes: > I agree that disabling should not necessarily be implemented by > "abusing" the max-lossage setting. Yeah, it was appealing to me at first look: the code was offering another feature for free! After your comments I rethink about it and become less excited: it always posible that we might be hit back in other parts of the code if they assume a 'sensible large enough' value. > But I don't see any reason to impose a 300 minimum either. I think it's > fine to impose a minimum, but it should be dictated by the limits of the > code. I'm not saying we should work to push this lower limit down, but > just that it should reflect what the code can do safely rather than > being an arbitrary number like 300 (I'm pretty sure 100 would be safe as > well, since that's what we've used for many years). Sure, 100 must be absolutely fine. I have updated the branch 'bug#38796-lossage-limit'. Now, the limit is not exposed to Lisp anymore. The function to update it now is a command 'update-lossage-size' We also have a 'lossage-size' function to retrieve its current value. --8<-----------------------------cut here---------------start------------->8--- commit c86d060b460bdaecdd71d297fa84012fcd397d66 Author: Tino Calancha Date: Sun Jun 28 23:30:07 2020 +0200 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. diff --git a/doc/emacs/help.texi b/doc/emacs/help.texi index e2c0dc6802..26cdf161d5 100644 --- a/doc/emacs/help.texi +++ b/doc/emacs/help.texi @@ -563,12 +563,14 @@ Misc Help @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 da204c5825..5fc4cb4d87 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 1ebf554b2b..6632687da4 100644 --- a/lisp/cus-start.el +++ b/lisp/cus-start.el @@ -352,8 +352,6 @@ minibuffer-prompt-properties--setter ;; 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 089fea17ef..52cbf5b5a6 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 @@ edit-kbd-macro "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 9e3d0922d0..01ee739a16 100644 --- a/lisp/help.el +++ b/lisp/help.el @@ -459,7 +459,7 @@ view-lossage "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 a4d27c94fb..29b157700c 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 017d239246..8f2cfe4adc 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) --8<-----------------------------cut here---------------end--------------->8--- In GNU Emacs 28.0.50 (build 25, x86_64-pc-linux-gnu, GTK+ Version 3.24.5, cairo version 1.16.0) of 2020-06-28 built on calancha-pc.dy.bbexcite.jp Repository revision: e13fd1fc373b35f510b70998bfddbb7af5989912 Repository branch: bug#38796-lossage-limit Windowing system distributor 'The X.Org Foundation', version 11.0.12004000 System Description: Debian GNU/Linux 10 (buster)