GNU bug report logs -
#18761
[PATCH] Add pasting in terminal check.
Previous Next
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.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
Your message dated Tue, 20 Jan 2015 14:11:42 +0100
with message-id <xa1tk30h7g1d.fsf <at> mina86.com>
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
help-debbugs <at> gnu.org.)
--
18761: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=18761
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
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--
[Message part 3 (message/rfc822, inline)]
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--
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.