emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Fix bug in orgtbl-self-insert-command when used with evil-escape
@ 2023-04-03 18:35 Aaron Zeng
  2023-04-07 10:38 ` Ihor Radchenko
  0 siblings, 1 reply; 2+ messages in thread
From: Aaron Zeng @ 2023-04-03 18:35 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: app-emacs-dev

[-- Attachment #1: Type: text/plain, Size: 681 bytes --]

There appears to be a bug in orgtbl-self-insert-command, which uses last-input-event instead of last-command-event.  self-insert-command itself uses the latter variable.

Reproduction steps:

1. Enable evil-mode and evil-escape-mode
2. Set `evil-escape-key-sequence' to "fd" (the default)
3. In an empty text-mode buffer with orgtbl-mode enabled:
   a. Press `f RET' slowly; this inserts f and then a newline
   b. Press `f RET` quickly; this inserts just two newlines

After step 3b, view-lossage contains:

 f                 ;; orgtbl-self-insert-command
 <return> <return> ;; orgtbl-hijacker-command-100

With the patch, the above steps correctly insert f and then a newline.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-table-Refactor-away-unnecessary-variable.patch --]
[-- Type: text/x-patch, Size: 1060 bytes --]

From 8ae98a51a15bdd4d4c2014e7870ab36afd03562d Mon Sep 17 00:00:00 2001
From: "Aaron L. Zeng" <azeng@janestreet.com>
Date: Mon, 3 Apr 2023 13:46:26 -0400
Subject: [PATCH 1/2] org-table: Refactor away unnecessary variable

* org-table.el (orgtbl-self-insert-command): Remove unnecessary
intermediate variable.  `(cdr nil)` is nil.

TINYCHANGE
---
 lisp/org-table.el | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/lisp/org-table.el b/lisp/org-table.el
index 97120fffd..f477d74a0 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -5408,11 +5408,9 @@ overwritten, and the table is not marked as requiring realignment."
 	(self-insert-command N))
     (setq org-table-may-need-update t)
     (let* (orgtbl-mode
-	   a
 	   (cmd (or (key-binding
 		     (or (and (listp function-key-map)
-			      (setq a (assoc last-input-event function-key-map))
-			      (cdr a))
+			      (cdr (assoc last-input-event function-key-map)))
 			 (vector last-input-event)))
 		    'self-insert-command)))
       (call-interactively cmd)
-- 
2.30.2


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-org-table-Fix-incorrect-input-when-used-with-evil-es.patch --]
[-- Type: text/x-patch, Size: 1381 bytes --]

From 4ca188a09c2f628a03b5731b1725bd603620227a Mon Sep 17 00:00:00 2001
From: "Aaron L. Zeng" <azeng@janestreet.com>
Date: Mon, 3 Apr 2023 13:53:57 -0400
Subject: [PATCH 2/2] org-table: Fix incorrect input when used with evil-escape

* org-table.el (org-self-insert-command): Use `last-command-event'
instead of `last-input-event'.  Using `last-input-event' causes
problems in the presence of `evil-escape'.  Consider a buffer that has
`orgtbl-mode' enabled while evil-escape is in use.  Assume the
evil-escape sequence is "fd".  Typing "f RET" will instead insert "RET
RET" into the buffer, since `last-input-event' is "RET", but
`last-command-event' is "f".

TINYCHANGE
---
 lisp/org-table.el | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lisp/org-table.el b/lisp/org-table.el
index f477d74a0..e0cc84ed6 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -5410,8 +5410,8 @@ overwritten, and the table is not marked as requiring realignment."
     (let* (orgtbl-mode
 	   (cmd (or (key-binding
 		     (or (and (listp function-key-map)
-			      (cdr (assoc last-input-event function-key-map)))
-			 (vector last-input-event)))
+			      (cdr (assoc last-command-event function-key-map)))
+			 (vector last-command-event)))
 		    'self-insert-command)))
       (call-interactively cmd)
       (if (and org-self-insert-cluster-for-undo
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-04-07 10:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-03 18:35 [PATCH] Fix bug in orgtbl-self-insert-command when used with evil-escape Aaron Zeng
2023-04-07 10:38 ` Ihor Radchenko

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).