From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!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: Sat, 12 Sep 2020 14:29:45 +0200 Message-ID: <87blibdvpi.fsf@gmail.com> References: <43aac56d-ecf1-44ed-9be1-ffb8e5f8a7ce@default> <83zhfbm448.fsf@gnu.org> <87zh8pij6e.fsf@calancha-pc.dy.bbexcite.jp> <83v9jc3o3q.fsf@gnu.org> <87wo3qj1s6.fsf@calancha-pc.dy.bbexcite.jp> <87eenygyrx.fsf@gnus.org> <87d03beq3g.fsf@gmail.com> <83zh6fz4q1.fsf@gnu.org> <87363xj3be.fsf@gmail.com> <83o8mlu4mh.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30833"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: larsi@gnus.org, stefankangas@gmail.com, monnier@iro.umontreal.ca, 38796@debbugs.gnu.org, uyennhi.qm@gmail.com To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Sep 12 14:30:15 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 1kH4fX-0007vX-9q for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 12 Sep 2020 14:30:15 +0200 Original-Received: from localhost ([::1]:47206 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kH4fV-00012H-WF for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 12 Sep 2020 08:30:14 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36958) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kH4fL-00010c-94 for bug-gnu-emacs@gnu.org; Sat, 12 Sep 2020 08:30:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:35003) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kH4fK-00077r-VM for bug-gnu-emacs@gnu.org; Sat, 12 Sep 2020 08:30:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kH4fK-0000X4-Qr for bug-gnu-emacs@gnu.org; Sat, 12 Sep 2020 08:30:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 12 Sep 2020 12:30:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 38796 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 38796-submit@debbugs.gnu.org id=B38796.15999137982010 (code B ref 38796); Sat, 12 Sep 2020 12:30:02 +0000 Original-Received: (at 38796) by debbugs.gnu.org; 12 Sep 2020 12:29:58 +0000 Original-Received: from localhost ([127.0.0.1]:46549 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kH4fF-0000WM-W3 for submit@debbugs.gnu.org; Sat, 12 Sep 2020 08:29:58 -0400 Original-Received: from mail-ed1-f68.google.com ([209.85.208.68]:35154) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kH4fC-0000W7-AE for 38796@debbugs.gnu.org; Sat, 12 Sep 2020 08:29:56 -0400 Original-Received: by mail-ed1-f68.google.com with SMTP id i1so13111108edv.2 for <38796@debbugs.gnu.org>; Sat, 12 Sep 2020 05:29:54 -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=5t5HmW2X8yQzzxHQOcalBJ7Xle1+vDddC5683nvM7fI=; b=jaCaQtfN7t6qa1qP4OrYWZO3zJpOUKg4u2CO1z9Yb5a7PQHbjfH5zPBDiLpHpGjxv1 AvGb05OUkal2FrHLM2LqG3F+iy/QOSpWDa6EvAZidUV7xOL9vmzC0QBxx4dUwQbflJ94 BpKvArUcHGBMMxanr0yh/FyGto9jzJbyRkS8ehHvDPIvAE4K8sXPB3HdKPXiLYk4OCwU tRLM4vvElF0Ok18AyxkZbzDiGxjcHhCBBBjH7z+DVVhoghOqDL+pQeXlZyRZw5Vyc1oy FmLpNP3TZxI3JcuuyYrOjoZL4Wh68o0N9SE0aDj2dXw6LNXLL8T3evpLSRwaAeqOzURq Knmw== 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=5t5HmW2X8yQzzxHQOcalBJ7Xle1+vDddC5683nvM7fI=; b=BuTu4ZOrcKSWRTCm8tstZAR5jeK6XZ1hAjwrEt7dAx4niqc1JG+4aTQrm/1zgxnXrQ oeXVBVvu+QOUf0e/V3Yk1j0qpyahItVCACratYdQwKohxO0wUkVZF+3uA+D2Bj02BTD3 R6gEvhY0Brgt+lHJZaShg3xmJXoMnhgWpKsNujQ8bR3VbOgapK2VJK46GzGb20hCYfM4 s/ttRGq32RkuURlDvkxhRzTlddfnTh7xzmcRBasZbGV67xJVJLR3BXM8L3tv5Ekx7ctp yh2UVmBvbRtqoNU1bK0/jS84fkYpECpEdfkPIytyDd1G+F9HyoJUzAA88auZY7li68vh SfqA== X-Gm-Message-State: AOAM532BePh1SmlzzibU/ySNwlrPhzbcMwHOXCC60/K8hL8q+2QLeD6i pN+xSj1kDhEM9bVW6mxu3S0= X-Google-Smtp-Source: ABdhPJy+UkUPrQtvjGZfHr8DQ4+6Z2Vn0fEWrbWLWOk6swV7pLUkQ6u/dm0y0TzaZoLAb0ju3B+hKA== X-Received: by 2002:a05:6402:144c:: with SMTP id d12mr8250541edx.168.1599913788251; Sat, 12 Sep 2020 05:29:48 -0700 (PDT) Original-Received: from localhost.example.com ([31.7.242.222]) by smtp.gmail.com with ESMTPSA id f10sm4477607edk.34.2020.09.12.05.29.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Sep 2020 05:29:47 -0700 (PDT) In-Reply-To: <83o8mlu4mh.fsf@gnu.org> (Eli Zaretskii's message of "Fri, 04 Sep 2020 15:07:50 +0300") 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:187896 Archived-At: Eli Zaretskii writes: Thank you for the review Eli. I have fixed all your comments. Regarding the feature to disable the recording of keystrokes, I am not happy with my hackish implementation either: I have dropped it. I prefer just to keep my patch within the scope of the original proposal: i.e., be able to set the lossage limit with Lisp (within well tested limits). I am glad to push the following patch next week if there are no complaints. --8<-----------------------------cut here---------------start------------->8--- commit bee193a5d6cd7889183cf811eb001e0071052724 Author: Tino Calancha Date: Sat Sep 12 14:14:45 2020 +0200 Give Lisp control on the lossage size Add a command 'lossage-size' to set the maximum number or recorded keystrokes (Bug#38796). * src/keyboard.c (lossage_limit): Static variable with the current lossage size limit. (MIN_NUM_RECENT_KEYS): Renamed from NUM_RECENT_KEYS. Set it as 100 and use it as the minimum value for lossage_limit. Keep the same default for the vector size as before (300). (lossage-size): New command. (update_recent_keys): Helper function. (command_loop_1) (record_char) (recent-keys) (syms_of_keyboard): Use lossage_limit as the vector size. * lisp/help.el (view-lossage): Mention the new command in the docstring. * etc/NEWS (Changes in Emacs 28.1): Announce this change. * doc/emacs/help.texi (Misc Help): Update manual. * test/src/keyboard-tests.el (keyboard-lossage-size): Add test. diff --git a/doc/emacs/help.texi b/doc/emacs/help.texi index 06ad5a583d..232b611f41 100644 --- a/doc/emacs/help.texi +++ b/doc/emacs/help.texi @@ -573,10 +573,13 @@ Misc Help @kindex C-h l @findex view-lossage +@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 -300 input keystrokes and the commands they invoked. If you see -commands that you are not familiar with, you can use @kbd{C-h k} or +input keystrokes and the commands they invoked. By default, Emacs +stores the last 300 keystrokes; if you wish, you can change this number with +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. @kindex C-h e diff --git a/etc/NEWS b/etc/NEWS index 8ff62b6dc0..6fd23422cf 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -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-size' allow users to set the maximum +number of keystrokes and commands recorded. + +++ *** Emacs now defaults to UTF-8 instead of ISO-8859-1. This is only for the default, where the user has set no LANG (or diff --git a/lisp/help.el b/lisp/help.el index 729684af6b..edef78d207 100644 --- a/lisp/help.el +++ b/lisp/help.el @@ -458,6 +458,7 @@ view-lossage "Display last few input keystrokes and the commands run. For convenience this uses the same format as `edit-last-kbd-macro'. +See `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 590d183c4c..c0a41e6c4c 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -103,7 +103,8 @@ Copyright (C) 1985-1989, 1993-1997, 1999-2020 Free Software Foundation, /* True in the single-kboard state, false in the any-kboard state. */ static bool single_kboard; -#define NUM_RECENT_KEYS (300) +/* 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; @@ -111,7 +112,10 @@ #define NUM_RECENT_KEYS (300) /* Total number of elements stored into recent_keys. */ static int total_keys; -/* This vector holds the last NUM_RECENT_KEYS keystrokes. */ +/* 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; /* Vector holding the key sequence that invoked the current command. @@ -1421,10 +1425,10 @@ command_loop_1 (void) /* Execute the command. */ { - total_keys += total_keys < NUM_RECENT_KEYS; + total_keys += total_keys < lossage_limit; ASET (recent_keys, recent_keys_index, Fcons (Qnil, cmd)); - if (++recent_keys_index >= NUM_RECENT_KEYS) + if (++recent_keys_index >= lossage_limit) recent_keys_index = 0; } Vthis_command = cmd; @@ -3248,15 +3252,15 @@ record_char (Lisp_Object c) int ix1, ix2, ix3; if ((ix1 = recent_keys_index - 1) < 0) - ix1 = NUM_RECENT_KEYS - 1; + ix1 = lossage_limit - 1; ev1 = AREF (recent_keys, ix1); if ((ix2 = ix1 - 1) < 0) - ix2 = NUM_RECENT_KEYS - 1; + ix2 = lossage_limit - 1; ev2 = AREF (recent_keys, ix2); if ((ix3 = ix2 - 1) < 0) - ix3 = NUM_RECENT_KEYS - 1; + ix3 = lossage_limit - 1; ev3 = AREF (recent_keys, ix3); if (EQ (XCAR (c), Qhelp_echo)) @@ -3307,12 +3311,12 @@ record_char (Lisp_Object c) { if (!recorded) { - total_keys += total_keys < NUM_RECENT_KEYS; + total_keys += total_keys < lossage_limit; ASET (recent_keys, recent_keys_index, /* Copy the event, in case it gets modified by side-effect by some remapping function (bug#30955). */ CONSP (c) ? Fcopy_sequence (c) : c); - if (++recent_keys_index >= NUM_RECENT_KEYS) + if (++recent_keys_index >= lossage_limit) recent_keys_index = 0; } else if (recorded < 0) @@ -3326,10 +3330,10 @@ record_char (Lisp_Object c) while (recorded++ < 0 && total_keys > 0) { - if (total_keys < NUM_RECENT_KEYS) + if (total_keys < lossage_limit) total_keys--; if (--recent_keys_index < 0) - recent_keys_index = NUM_RECENT_KEYS - 1; + recent_keys_index = lossage_limit - 1; ASET (recent_keys, recent_keys_index, Qnil); } } @@ -10410,6 +10414,62 @@ DEFUN ("input-pending-p", Finput_pending_p, Sinput_pending_p, 0, 1, 0, ? Qt : Qnil); } +/* Reallocate recent_keys copying the keystrokes in the right order */ +static void +update_recent_keys (int new_size, int kept_keys) +{ + int osize = ASIZE (recent_keys); + eassert (recent_keys_index < osize); + eassert (kept_keys <= min (osize, new_size)); + Lisp_Object v = make_nil_vector (new_size); + int i, idx; + for (i = 0; i < kept_keys; ++i) + { + idx = recent_keys_index - kept_keys + i; + while (idx < 0) + idx += osize; + ASET (v, i, AREF (recent_keys, idx)); + } + recent_keys = v; + total_keys = kept_keys; + recent_keys_index = total_keys % new_size; + lossage_limit = new_size; + +} + +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 limit to ARG and return it. + +The saved keystrokes are the records shown by `view-lossage'. */) + (Lisp_Object arg) +{ + if (NILP(arg)) + return make_fixnum (lossage_limit); + + if (!FIXNATP (arg)) + user_error ("Value must be a positive 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 make_fixnum (lossage_limit); + + if (new_size < min_size) + { + AUTO_STRING (fmt, "Value must be >= %d"); + Fsignal (Quser_error, list1 (CALLN (Fformat, fmt, make_fixnum (min_size)))); + } + + int kept_keys = new_size > osize ? total_keys : min (new_size, total_keys); + update_recent_keys (new_size, kept_keys); + + return make_fixnum (lossage_limit); +} + DEFUN ("recent-keys", Frecent_keys, Srecent_keys, 0, 1, 0, doc: /* Return vector of last few events, not counting those from keyboard macros. If INCLUDE-CMDS is non-nil, include the commands that were run, @@ -10419,21 +10479,21 @@ DEFUN ("recent-keys", Frecent_keys, Srecent_keys, 0, 1, 0, bool cmds = !NILP (include_cmds); if (!total_keys - || (cmds && total_keys < NUM_RECENT_KEYS)) + || (cmds && total_keys < lossage_limit)) return Fvector (total_keys, XVECTOR (recent_keys)->contents); else { Lisp_Object es = Qnil; - int i = (total_keys < NUM_RECENT_KEYS + int i = (total_keys < lossage_limit ? 0 : recent_keys_index); - eassert (recent_keys_index < NUM_RECENT_KEYS); + eassert (recent_keys_index < lossage_limit); do { Lisp_Object e = AREF (recent_keys, i); if (cmds || !CONSP (e) || !NILP (XCAR (e))) es = Fcons (e, es); - if (++i >= NUM_RECENT_KEYS) + if (++i >= lossage_limit) i = 0; } while (i != recent_keys_index); es = Fnreverse (es); @@ -11686,7 +11746,7 @@ syms_of_keyboard (void) staticpro (&modifier_symbols); } - recent_keys = make_nil_vector (NUM_RECENT_KEYS); + recent_keys = make_nil_vector (lossage_limit); staticpro (&recent_keys); this_command_keys = make_nil_vector (40); @@ -11736,6 +11796,7 @@ syms_of_keyboard (void) defsubr (&Srecursive_edit); defsubr (&Sinternal_track_mouse); defsubr (&Sinput_pending_p); + defsubr (&Slossage_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 1988ba51a7..970a53555f 100644 --- a/test/src/keyboard-tests.el +++ b/test/src/keyboard-tests.el @@ -32,5 +32,20 @@ keyboard-unread-command-events (read-event nil nil 2)) ?\C-b))) +(ert-deftest keyboard-lossage-size () + "Test `lossage-size'." + (let ((min-value 100) + (lossage-orig (lossage-size))) + (dolist (factor (list 1 3 4 5 10 7 3)) + (let ((new-lossage (* factor min-value))) + (should (= new-lossage (lossage-size new-lossage))))) + ;; Wrong type + (should-error (lossage-size -5)) + (should-error (lossage-size "200")) + ;; Less that minimum value + (should-error (lossage-size (1- min-value))) + (should (= lossage-orig (lossage-size lossage-orig))))) + + (provide 'keyboard-tests) ;;; keyboard-tests.el ends here --8<-----------------------------cut here---------------end--------------->8--- In GNU Emacs 28.0.50 (build 6, x86_64-pc-linux-gnu, GTK+ Version 3.24.22, cairo version 1.16.0) of 2020-09-12 built on localhost.example.com Repository revision: 4c3f3bf25623c936ca07249203147ae0332d64ed Repository branch: master