From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Bruno =?utf-8?Q?F=C3=A9lix?= Rezende Ribeiro Newsgroups: gmane.emacs.devel Subject: Re: Please add a lossage-limit option for `view-lossage' Date: Mon, 06 Apr 2020 09:23:09 -0300 Message-ID: <87pnck4xci.fsf@oitofelix.com> References: <7d79be75-058d-4678-a9b7-f9db23abe460@default> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="121011"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) Cc: Emacs developers To: Drew Adams Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Apr 06 14:24:09 2020 Return-path: Envelope-to: ged-emacs-devel@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 1jLQnP-000VHl-Ki for ged-emacs-devel@m.gmane-mx.org; Mon, 06 Apr 2020 14:24:07 +0200 Original-Received: from localhost ([::1]:59528 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jLQnO-0008Sf-MI for ged-emacs-devel@m.gmane-mx.org; Mon, 06 Apr 2020 08:24:06 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39976) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jLQmX-0007vD-TR for emacs-devel@gnu.org; Mon, 06 Apr 2020 08:23:20 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:57339) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1jLQmW-00047N-Vu; Mon, 06 Apr 2020 08:23:13 -0400 Original-Received: from [189.15.134.166] (port=57608 helo=felix-laptop) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1jLQmW-0002ZH-CQ; Mon, 06 Apr 2020 08:23:12 -0400 In-Reply-To: <7d79be75-058d-4678-a9b7-f9db23abe460@default> (Drew Adams's message of "Wed, 25 Dec 2019 12:29:06 -0800 (PST)") X-Face: %,T7Hsg=SK$Zh)wiU4Qdv9-fZ26Pf5*+}Ld,{LeV'Cq-1?=kA"hc,'i""S85]g; _W+{nZfx 2GnAMS1K\E_E&:{h[wQd+Tqj5#PtH:W&8^crA0>i?nmD7hOL$K".`@An_8.7gaObQLlMy0\%%I0Jp. Lue$J0B Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAIAAADYYG7QAAACcElEQVRYw93YzXHCQAwF4G0h Fw4caYEW0oJbSAtuwa1AldGg8PKQtP+GMHkHxkDG/qLVrtek6x65UCZPleYdH485HA4zrHHQ4R5F cPSTl4L0qigJDoxpoFRpUmMGKzR1sbpB3DTLsnzd83nL+XyeNHWDoBHEeg9YQlQWCtZrSmOa1YVN ktDkiz0FwmDJVbd7CizTUhcXLByDINXIiGyUQqnkL8Nm8iCY5CD1lkf+9UYQFykEhb7UqEGFeLwK Q6YgnXTovEtDZkHGZFpbR21nkLlhlUFqWig63XYGyevxeGSQXFjXG4lclSnyyekW/Ur+jFfzWRD6 31RoeQxAnxQB6cErQBKsywDpW6Yo93UgFAMg3DqgMaCqaRzEc4pBPh50fdxk9oF4zvPCCBDml6fo sIagnClVNTmQn/BAmOXxn4LMXQan45vrJCg07QPC/JI8BeT3BjidLNkGpOu1anSNbgd5U6qWx4Ak DOL1RotkTLMV8ouEWYc8yNzezcBNVchv5MIK8VKEHjKrM0D+malvyFoqxG2kLBHIMCmo3EAjFfLl MSAeNSzZoeZZIH/SHAim3I1MMwvC7syAeBuEyV++s3aA2suDHkI7nyi6UUTCHwLGKxSCsFjzzpV3 ZNUihc+s9QqF7YwtEW88zAMQt5Ec7AkKx4uvWjChwaujFoAay+PLUHhQ5LQXKeVu7y2a0GRY/LZq +gG1jBROap4Sy0XyX1VNyf8Ekav8lom5dqFyocn0k62QOenWkBC05uNNDyCv2fpj2mUtxve7vGZB 21CqI1X1BaBhTfiz1QDL9tAMaN70C8L8ei/Q32rYlN6hgdj0DS+u5+J4AqFYAAAAAElFTkSuQmCC X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:246516 Archived-At: --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hello Drew, Drew Adams writes: > The request (and thus the change that RMS asked to be > made) was this: > Any chance that the number of keystrokes displayed > by `view-lossage', currently hard-coded at 100, > could be made a user option? > ^^^^^^^^^^^ > Since then, the hard-coded limit was upped to 300. > But there still is no user option, is there? Could > we please add an option for this now? The code is > in C - it's not simple for a user to change the > value without a Lisp variable for it. I took this task as a goal in my first attempt to write code to Emacs C core. What I could get for now is in the patch attached. It seems to work fine for =E2=80=98num-recent-keys=E2=80=99[1] strictly positive, but i= t segfaults promptly for other values (understandably). What I did was to replace the C macro constant =E2=80=98NUM_RECENT_KEYS=E2= =80=99 , with the Lisp-visible variable =E2=80=98num-recent-keys=E2=80=99, defined using = =E2=80=98DEFVAR_INT=E2=80=99, and then define a C function called =E2=80=98ensure_recent_keys_size=E2=80= =99 to keep the size of the vector =E2=80=98recent-keys=E2=80=99 truthful to that; shri= nking or enlarging the vector.[2] The problem is, I had to place calls to =E2=80=98ensure_recent_keys_size=E2= =80=99 scattered throughout the source --- strategically before references to =E2=80=98num_recent_keys=E2=80=99. This is clearly not the right approach.= What is needed is a way to intercept changes to that variable and do the job once, before anything else happens. I think this would fix my fragile hack. Furthermore, that interception routine could prevent values smaller than 1 --- set from the Lisp world --- to be rejected (not only non-integers), hopefully preventing the crashes I=E2=80=99m experiencing no= w. In the Lisp reference documentation, I was unable to find a way to do that. I thought that if that mechanism existed it=E2=80=99d be important e= nough to be documented. I couldn=E2=80=99t find it in a quick look around the co= de neither. How is the interception of change of variables from the Lisp world canonically handled by Emacs C source code? Footnotes:=20 [1] This is the requested user option. [2] Actually creating another vector of the right size and copying the data over as needed. --=-=-= Content-Type: text/x-diff; charset=utf-8 Content-Disposition: inline; filename=0001-Transform-C-constant-NUM_RECENT_KEYS-into-num-recent.patch Content-Transfer-Encoding: quoted-printable From=20f87911cf8f6d12046f25e2964bbbdbcd3ca0581d Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?Bruno=3D20F=3DC3=3DA9lix=3D20Rezende=3D20Ribeiro?=3D Date: Mon, 6 Apr 2020 08:30:16 -0300 Subject: [PATCH] =3D?UTF-8?q?Transform=3D20C=3D20constant=3D20=3DE2=3D80=3D= 98NUM=3D5FRECEN?=3D =3D?UTF-8?q?T=3D5FKEYS=3DE2=3D80=3D99=3D20into=3D20=3DE2=3D80=3D98num-rece= nt-keys=3DE2=3D80=3D99=3D20?=3D =3D?UTF-8?q?Lisp=3D20variable?=3D MIME-Version: 1.0 Content-Type: text/plain; charset=3DUTF-8 Content-Transfer-Encoding: 8bit * src/keyboard.c: remove NUM_RECENT_KEYS constant. (ensure_recent_keys_size): new function. (command_loop_1, record_char, recent-keys): add calls to =E2=80=98ensure_recent_key_size=E2=80=99. (syms_of_keyboard): add =E2=80=98num-recent-keys=E2=80=99 Lisp integer va= riable. * lisp/cus-start.el: add =E2=80=98num-recent-keys=E2=80=99. =2D-- lisp/cus-start.el | 1 + src/keyboard.c | 62 ++++++++++++++++++++++++++++++++++++++-------------= ---- 2 files changed, 44 insertions(+), 19 deletions(-) diff --git a/lisp/cus-start.el b/lisp/cus-start.el index dff4d9a..001f79b 100644 =2D-- a/lisp/cus-start.el +++ b/lisp/cus-start.el @@ -353,6 +353,7 @@ minibuffer-prompt-properties--setter (indent-tabs-mode indent boolean) ;; keyboard.c (meta-prefix-char keyboard character) + (num-recent-keys keyboard integer) (auto-save-interval auto-save integer) (auto-save-no-message auto-save boolean "27.1") (auto-save-timeout auto-save (choice (const :tag "off" nil) diff --git a/src/keyboard.c b/src/keyboard.c index 9ce168c..cbbb572 100644 =2D-- a/src/keyboard.c +++ b/src/keyboard.c @@ -103,15 +103,13 @@ Copyright (C) 1985-1989, 1993-1997, 1999-2020 Free So= ftware Foundation, /* True in the single-kboard state, false in the any-kboard state. */ static bool single_kboard; =20 =2D#define NUM_RECENT_KEYS (300) =2D /* Index for storing next element into recent_keys. */ static int recent_keys_index; =20 /* Total number of elements stored into recent_keys. */ static int total_keys; =20 =2D/* This vector holds the last NUM_RECENT_KEYS keystrokes. */ +/* This vector holds the last num_recent_keys keystrokes. */ static Lisp_Object recent_keys; =20 /* Vector holding the key sequence that invoked the current command. @@ -371,6 +369,7 @@ #define READABLE_EVENTS_IGNORE_SQUEEZABLES (1 << 2) static void deliver_user_signal (int); static char *find_user_signal_name (int); static void store_user_signal_events (void); +static void ensure_recent_keys_size (void); =20 /* Advance or retreat a buffered input event pointer. */ =20 @@ -448,6 +447,20 @@ kset_system_key_syms (struct kboard *kb, Lisp_Object v= al) } =20 +void +ensure_recent_keys_size (void) +{ + if (ASIZE (recent_keys) !=3D num_recent_keys) + { + Lisp_Object new_recent_keys =3D make_nil_vector (num_recent_keys); + memcpy (XVECTOR (new_recent_keys)->contents, XVECTOR (recent_keys)->= contents, + min (ASIZE (recent_keys), num_recent_keys) + * sizeof *XVECTOR (recent_keys)->contents); + recent_keys =3D new_recent_keys; + } +} + + static bool echo_keystrokes_p (void) { @@ -1421,10 +1434,11 @@ command_loop_1 (void) /* Execute the command. */ =20 { =2D total_keys +=3D total_keys < NUM_RECENT_KEYS; + ensure_recent_keys_size (); + total_keys +=3D total_keys < num_recent_keys; ASET (recent_keys, recent_keys_index, Fcons (Qnil, cmd)); =2D if (++recent_keys_index >=3D NUM_RECENT_KEYS) + if (++recent_keys_index >=3D num_recent_keys) recent_keys_index =3D 0; } Vthis_command =3D cmd; @@ -3249,16 +3263,18 @@ record_char (Lisp_Object c) Lisp_Object ev1, ev2, ev3; int ix1, ix2, ix3; =20 + ensure_recent_keys_size (); + if ((ix1 =3D recent_keys_index - 1) < 0) =2D ix1 =3D NUM_RECENT_KEYS - 1; + ix1 =3D num_recent_keys - 1; ev1 =3D AREF (recent_keys, ix1); =20 if ((ix2 =3D ix1 - 1) < 0) =2D ix2 =3D NUM_RECENT_KEYS - 1; + ix2 =3D num_recent_keys - 1; ev2 =3D AREF (recent_keys, ix2); =20 if ((ix3 =3D ix2 - 1) < 0) =2D ix3 =3D NUM_RECENT_KEYS - 1; + ix3 =3D num_recent_keys - 1; ev3 =3D AREF (recent_keys, ix3); =20 if (EQ (XCAR (c), Qhelp_echo)) @@ -3309,12 +3325,13 @@ record_char (Lisp_Object c) { if (!recorded) { =2D total_keys +=3D total_keys < NUM_RECENT_KEYS; + ensure_recent_keys_size (); + total_keys +=3D total_keys < num_recent_keys; 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); =2D if (++recent_keys_index >=3D NUM_RECENT_KEYS) + if (++recent_keys_index >=3D num_recent_keys) recent_keys_index =3D 0; } else if (recorded < 0) @@ -3328,10 +3345,11 @@ record_char (Lisp_Object c) =20 while (recorded++ < 0 && total_keys > 0) { =2D if (total_keys < NUM_RECENT_KEYS) + ensure_recent_keys_size (); + if (total_keys < num_recent_keys) total_keys--; if (--recent_keys_index < 0) =2D recent_keys_index =3D NUM_RECENT_KEYS - 1; + recent_keys_index =3D num_recent_keys - 1; ASET (recent_keys, recent_keys_index, Qnil); } } @@ -10420,22 +10438,24 @@ DEFUN ("recent-keys", Frecent_keys, Srecent_keys,= 0, 1, 0, { bool cmds =3D !NILP (include_cmds); =20 + ensure_recent_keys_size (); + if (!total_keys =2D || (cmds && total_keys < NUM_RECENT_KEYS)) + || (cmds && total_keys < num_recent_keys)) return Fvector (total_keys, XVECTOR (recent_keys)->contents); else { Lisp_Object es =3D Qnil; =2D int i =3D (total_keys < NUM_RECENT_KEYS + int i =3D (total_keys < num_recent_keys ? 0 : recent_keys_index); =2D eassert (recent_keys_index < NUM_RECENT_KEYS); + eassert (recent_keys_index < num_recent_keys); do { Lisp_Object e =3D AREF (recent_keys, i); if (cmds || !CONSP (e) || !NILP (XCAR (e))) es =3D Fcons (e, es); =2D if (++i >=3D NUM_RECENT_KEYS) + if (++i >=3D num_recent_keys) i =3D 0; } while (i !=3D recent_keys_index); es =3D Fnreverse (es); @@ -11690,9 +11710,6 @@ syms_of_keyboard (void) staticpro (&modifier_symbols); } =20 =2D recent_keys =3D make_nil_vector (NUM_RECENT_KEYS); =2D staticpro (&recent_keys); =2D this_command_keys =3D make_nil_vector (40); staticpro (&this_command_keys); =20 @@ -11858,6 +11875,13 @@ syms_of_keyboard (void) result of looking up the original command in the active keymaps. */); Vthis_original_command =3D Qnil; =20 + DEFVAR_INT ("num-recent-keys", num_recent_keys, + doc: /* Number of input events to consider. */); + num_recent_keys =3D 300; + + recent_keys =3D make_nil_vector (num_recent_keys); + staticpro (&recent_keys); + DEFVAR_INT ("auto-save-interval", auto_save_interval, doc: /* Number of input events between auto-saves. Zero means disable autosaving due to number of characters typed. */); =2D-=20 2.7.4 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable =2D-=20 Bruno F=C3=A9lix Rezende Ribeiro (oitofelix) [0x28D618AF] --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEcBAEBCAAGBQJeix8tAAoJECe5xv0o1hivrIoIAKxCqCekf1p7qT94vUx7huCj e4p2oK189pLnXyoySjU7vNEU+Anvi3sLhHfxgqTre+2SGA4kAKVwVTymFZgOlyDj 1eZOPjXQLwLi5cl7i7VXMBDVZfG6ZtiNeZWhQqOsYOkyQGV04Krxtqq52GdaRB4A 43RBPODfmSPibmE3P+baJkWOIPYqbqdWvjo52iDx7wM6k6O3EjqmmNgrN4n40aPd znFlyQF1RqqHB1LoXz28P9njRynZeb55DrWduvf59Hd70GhHZ5IpZx43wgb7ffYk ctzU2Ck3DhQD+icQ/312V4utvXqAUjI03NoyzqvShI3GyPlDCCss3KBRuxC+o6w= =+End -----END PGP SIGNATURE----- --==-=-=--