emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Aaron Zeng <azeng@janestreet.com>
To: emacs-orgmode@gnu.org
Cc: app-emacs-dev@janestreet.com
Subject: [PATCH] Fix bug in orgtbl-self-insert-command when used with evil-escape
Date: Mon, 03 Apr 2023 14:35:23 -0400	[thread overview]
Message-ID: <q7mcz4koluc.fsf@janestreet.com> (raw)

[-- 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


             reply	other threads:[~2023-04-06 16:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-03 18:35 Aaron Zeng [this message]
2023-04-07 10:38 ` [PATCH] Fix bug in orgtbl-self-insert-command when used with evil-escape Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=q7mcz4koluc.fsf@janestreet.com \
    --to=azeng@janestreet.com \
    --cc=app-emacs-dev@janestreet.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).