emacs-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[debbugs-tracker] bug#18761: closed ([PATCH] Add pasting in terminal che


From: GNU bug Tracking System
Subject: [debbugs-tracker] bug#18761: closed ([PATCH] Add pasting in terminal check.)
Date: Tue, 20 Jan 2015 13:12:02 +0000

Your message dated Tue, 20 Jan 2015 14:11:42 +0100
with message-id <address@hidden>
and subject line Re: [PATCH] Add pasting in terminal check.
has caused the debbugs.gnu.org bug report #18761,
regarding [PATCH] Add pasting in terminal check.
to be marked as done.

(If you believe you have received this mail in error, please contact
address@hidden)


-- 
18761: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=18761
GNU Bug Tracking System
Contact address@hidden with problems
--- Begin Message --- Subject: [PATCH] Add pasting in terminal check. Date: Sat, 18 Oct 2014 14:06:23 +0200 User-agent: Notmuch/0.17+15~gb65ca8e (http://notmuchmail.org) Emacs/25.0.50.1 (x86_64-unknown-linux-gnu)
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 +--<address@hidden>--<xmpp:address@hidden>--ooO--(_)--Ooo--



--- End Message ---
--- Begin Message --- Subject: Re: [PATCH] Add pasting in terminal check. Date: Tue, 20 Jan 2015 14:11:42 +0100 User-agent: Notmuch/0.19~rc1+1~g03aea4f (http://notmuchmail.org) Emacs/25.0.50.1 (x86_64-unknown-linux-gnu)
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 +--<address@hidden>--<xmpp:address@hidden>--ooO--(_)--Ooo--


--- End Message ---

reply via email to

[Prev in Thread] Current Thread [Next in Thread]