GNU bug report logs - #18761
[PATCH] Add pasting in terminal check.

Previous Next

Package: emacs;

Reported by: Michal Nazarewicz <mina86 <at> mina86.com>

Date: Sat, 18 Oct 2014 12:07:01 UTC

Severity: wishlist

Tags: patch

Done: Michal Nazarewicz <mpn <at> google.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 18761 in the body.
You can then email your comments to 18761 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#18761; Package emacs. (Sat, 18 Oct 2014 12:07:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Michal Nazarewicz <mina86 <at> mina86.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 18 Oct 2014 12:07:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Michal Nazarewicz <mina86 <at> mina86.com>
To: bug-gnu-emacs <at> gnu.org
Subject: [PATCH] Add pasting in terminal check.
Date: Sat, 18 Oct 2014 14:06:23 +0200
When user types text, Emacs inserts undo boundaries every 20
characters.  This means that when user pastes (eg. via middle click)
a lot of text into Emacs running in a terminal, the text is divided
into 20-character long chunks each being a separate undo entry.

Detect such situation by assuming that user cannot type 20 characters
in less than 100 milliseconds.  If text is input too fast, assume it
is pasted and do not insert boundary thus treating the whole inserted
text as a single undo entry.
---
 etc/NEWS   |  6 ++++++
 src/cmds.c | 18 +++++++++++++++++-
 2 files changed, 23 insertions(+), 1 deletion(-)

 Admittedly, I don't really use this feature myself but it has been
 contemplated by a colleague.  This is actually a re-posting of almost
 two year old patch[1].

 [1] http://lists.gnu.org/archive/html/emacs-devel/2013-01/msg00389.html

diff --git a/etc/NEWS b/etc/NEWS
index 7113786..5ec644e 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -120,6 +120,12 @@ for Unicode 8.0.  This includes full support for directional isolates
 and the Bidirectional Parentheses Algorithm (BPA) specified by these
 Unicode standards.
 
+** Pasting in terminal detection added.
+In tty mode, if a lot of text is typed into a buffer in a short time, Emacs
+will now assume it has been pasted (eg. by using middle-click on a terminal
+emulator) and treats the whole text as a single undo event.  Previously it
+would split the text in 20-character long chunks and undo each individually.
+
 
 * Changes in Specialized Modes and Packages in Emacs 25.1
 
diff --git a/src/cmds.c b/src/cmds.c
index 9a05218..93a861d 100644
--- a/src/cmds.c
+++ b/src/cmds.c
@@ -257,6 +257,21 @@ because it respects values of `delete-active-region' and `overwrite-mode'.  */)
   return Qnil;
 }
 
+static bool
+is_human_typing(void)
+{
+  static struct timespec undo_timer;
+
+  struct timespec t;
+
+  t = undo_timer;
+  undo_timer = current_timespec();
+  t = timespec_sub(undo_timer, t);
+
+  /* Assume it's human if typing 20 chars took at least 100 ms. */
+  return t.tv_sec >= 1 || t.tv_nsec >= 100000000;
+}
+
 static int nonundocount;
 
 /* Note that there's code in command_loop_1 which typically avoids
@@ -286,7 +301,8 @@ At the end, it runs `post-self-insert-hook'.  */)
     {
       if (nonundocount <= 0 || nonundocount >= 20)
 	{
-	  remove_boundary = 0;
+	  if (is_human_typing())
+	    remove_boundary = 0;
 	  nonundocount = 0;
 	}
       nonundocount++;
-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +--<mpn <at> google.com>--<xmpp:mina86 <at> jabber.org>--ooO--(_)--Ooo--




Reply sent to Michal Nazarewicz <mpn <at> google.com>:
You have taken responsibility. (Tue, 20 Jan 2015 13:12:02 GMT) Full text and rfc822 format available.

Notification sent to Michal Nazarewicz <mina86 <at> mina86.com>:
bug acknowledged by developer. (Tue, 20 Jan 2015 13:12:02 GMT) Full text and rfc822 format available.

Message #10 received at 18761-done <at> debbugs.gnu.org (full text, mbox):

From: Michal Nazarewicz <mpn <at> google.com>
To: 18761-done <at> debbugs.gnu.org
Subject: Re: [PATCH] Add pasting in terminal check.
Date: Tue, 20 Jan 2015 14:11:42 +0100
It looks like ‘bracketed paste mode’ largely fixes this.  My
rxvt-unicode seems to still split a long paste into several shorter
ones, but not as short as 20-characters, and in xterm things seem to
work flawlessly.

-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +--<mpn <at> google.com>--<xmpp:mina86 <at> jabber.org>--ooO--(_)--Ooo--




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 18 Feb 2015 12:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 10 years and 184 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.