From unknown Tue Aug 19 02:50:31 2025 X-Loop: help-debbugs@gnu.org Subject: bug#18761: [PATCH] Add pasting in terminal check. Resent-From: Michal Nazarewicz Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 18 Oct 2014 12:07:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 18761 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: 18761@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.141363400811055 (code B ref -1); Sat, 18 Oct 2014 12:07:01 +0000 Received: (at submit) by debbugs.gnu.org; 18 Oct 2014 12:06:48 +0000 Received: from localhost ([127.0.0.1]:47934 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XfSmV-0002sF-EC for submit@debbugs.gnu.org; Sat, 18 Oct 2014 08:06:47 -0400 Received: from eggs.gnu.org ([208.118.235.92]:46695) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XfSmT-0002s7-Ck for submit@debbugs.gnu.org; Sat, 18 Oct 2014 08:06:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XfSmO-00034t-Hl for submit@debbugs.gnu.org; Sat, 18 Oct 2014 08:06:45 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:36238) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XfSmO-00034o-ER for submit@debbugs.gnu.org; Sat, 18 Oct 2014 08:06:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48396) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XfSmJ-0005Un-SX for bug-gnu-emacs@gnu.org; Sat, 18 Oct 2014 08:06:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XfSmF-00032j-Bg for bug-gnu-emacs@gnu.org; Sat, 18 Oct 2014 08:06:35 -0400 Received: from mail-lb0-x22c.google.com ([2a00:1450:4010:c04::22c]:43981) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XfSmE-00032S-VD for bug-gnu-emacs@gnu.org; Sat, 18 Oct 2014 08:06:31 -0400 Received: by mail-lb0-f172.google.com with SMTP id b6so1882876lbj.17 for ; Sat, 18 Oct 2014 05:06:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:subject:organization:user-agent:face:date:message-id :mime-version:content-type:content-transfer-encoding; bh=we5RIdytHqPg9j/luoxAM3V2dLqhVIG6bmvI9GO+b2I=; b=mu7pDmgBvq2Y11VniecDbiHOGFMLyHntGrMQArNyP/ie5oR9H1LN9o91Bha2vZJd10 jgS2/19z6iUZSziWeyqEgiiPaOESW3Y7awUb3IHFILMmErj2B3r0kkFrwYTJ/3rKMmPu cfgFobBGeLTdEEYaZ4S6nNuBKd1t6ngdkNMMd52SYCfIt6UmIQa7N+NyH1mxbVUDczAd u+KUlY8nCLqUFo3RXHpOIDcfPbFCM7w844CXdOOtbkjGJ0iXYBCBF2EkLZ62AWmN3S+W sFymXlVoGwGZGP6QD/8TuPKi/3cn59u1vhvzyNv8g3fAqEP4duRmE3opncWhiBeXJbEz xLOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:subject:organization:user-agent :face:date:message-id:mime-version:content-type :content-transfer-encoding; bh=we5RIdytHqPg9j/luoxAM3V2dLqhVIG6bmvI9GO+b2I=; b=kECgMRibKnsVnXhF3D8Cv47DubXap2psD41+AkG7S9nobT/Pcj1c7l0U5pVg6oPJEG X3G/yQKOFqqPwMaSfXdXr3ts1nyAYYPUkxQOQLNRJr1aPM0hUukZZXTOaMXZXGeNppB0 N9QLmdX4eOHdDgs3RMDK0xhNkstfnqaeNhefOAQUcvDsL+cnFEgu6az1dOOjfTCn68mk MM2nK0B+Ne9WjBzLP+4x020+g4mW7X38kr76fJ34E0riaMLso6pSopAVxBSEY/L8Pfw1 zwXIu5P2tL9CLliZ8iJ3xjbk5yKTimRjqbnJ70Ag9aPavl789MLABJMqSeQDvlc8wQPY w2dg== X-Gm-Message-State: ALoCoQkT3PNEOSrgs36mcJI7h44FDrCFOboDWXG8DmkXuufVcQ+w0zSHgXitg4+ckc6tBBGbnTGI X-Received: by 10.152.7.233 with SMTP id m9mr15043030laa.32.1413633989636; Sat, 18 Oct 2014 05:06:29 -0700 (PDT) Received: from mpn-glaptop.roam.corp.google.com ([88.128.80.16]) by mx.google.com with ESMTPSA id l13sm1281564lbh.32.2014.10.18.05.06.26 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sat, 18 Oct 2014 05:06:28 -0700 (PDT) From: Michal Nazarewicz Organization: Google Inc User-Agent: Notmuch/0.17+15~gb65ca8e (http://notmuchmail.org) Emacs/25.0.50.1 (x86_64-unknown-linux-gnu) X-Face: PbkBB1w#)bOqd`iCe"Ds{e+!C7`pkC9a|f)Qo^BMQvy\q5x3?vDQJeN(DS?|-^$uMti[3D*#^_Ts"pU$jBQLq~Ud6iNwAw_r_o_4]|JO?]}P_}Nc&"p#D(ZgUb4uCNPe7~a[DbPG0T~!&c.y$Ur,=N4RT>]dNpd; KFrfMCylc}gc??'U2j,!8%xdD Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAJFBMVEWbfGlUPDDHgE57V0jUupKjgIObY0PLrom9mH4dFRK4gmjPs41MxjOgAAACQElEQVQ4jW3TMWvbQBQHcBk1xE6WyALX1069oZBMlq+ouUwpEQQ6uRjttkWP4CmBgGM0BQLBdPFZYPsyFUo6uEtKDQ7oy/U96XR2Ux8ehH/89Z6enqxBcS7Lg81jmSuujrfCZcLI/TYYvbGj+jbgFpHJ/bqQAUISj8iLyu4LuFHJTosxsucO4jSDNE0Hq3hwK/ceQ5sx97b8LcUDsILfk+ovHkOIsMbBfg43VuQ5Ln9YAGCkUdKJoXR9EclFBhixy3EGVz1K6eEkhxCAkeMMnqoAhAKwhoUJkDrCqvbecaYINlFKSRS1i12VKH1XpUd4qxL876EkMcDvHj3s5RBajHHMlA5iK32e0C7VgG0RlzFPvoYHZLRmAC0BmNcBruhkE0KsMsbEc62ZwUJDxWUdMsMhVqovoT96i/DnX/ASvz/6hbCabELLk/6FF/8PNpPCGqcZTGFcBhhAaZZDbQPaAB3+KrWWy2XgbYDNIinkdWAFcCpraDE/knwe5DBqGmgzESl1p2E4MWAz0VUPgYYzmfWb9yS4vCvgsxJriNTHoIBz5YteBvg+VGISQWUqhMiByPIPpygeDBE6elD973xWwKkEiHZAHKjhuPsFnBuArrzxtakRcISv+XMIPl4aGBUJm8Emk7qBYU8IlgNEIpiJhk/No24jHwkKTFHDWfPniR4iw5vJaw2nzSjfq2zffcE/GDjRC2dn0J0XwPAbDL84TvaFCJEU4Oml9pRyEUhR3Cl2t01AoEjRbs0sYugp14/4X5n4pU4EHHnMAAAAAElFTkSuQmCC X-PGP: 50751FF4 X-PGP-FP: AC1F 5F5C D418 88F8 CC84 5858 2060 4012 5075 1FF4 Date: Sat, 18 Oct 2014 14:06:23 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.0 (----) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.0 (----) 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 direc= tional isolates and the Bidirectional Parentheses Algorithm (BPA) specified by these Unicode standards. =20 +** 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 individuall= y. + * Changes in Specialized Modes and Packages in Emacs 25.1 =20 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' a= nd `overwrite-mode'. */) return Qnil; } =20 +static bool +is_human_typing(void) +{ + static struct timespec undo_timer; + + struct timespec t; + + t =3D undo_timer; + undo_timer =3D current_timespec(); + t =3D timespec_sub(undo_timer, t); + + /* Assume it's human if typing 20 chars took at least 100 ms. */ + return t.tv_sec >=3D 1 || t.tv_nsec >=3D 100000000; +} + static int nonundocount; =20 /* 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 <=3D 0 || nonundocount >=3D 20) { - remove_boundary =3D 0; + if (is_human_typing()) + remove_boundary =3D 0; nonundocount =3D 0; } nonundocount++; --=20 Best regards, _ _ .o. | Liege of Serenely Enlightened Majesty of o' \,=3D./ `o ..o | Computer Science, Micha=C5=82 =E2=80=9Cmina86=E2=80=9D Nazarewicz = (o o) ooo +------ooO--(_)--Ooo-- From unknown Tue Aug 19 02:50:31 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.503 (Entity 5.503) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Michal Nazarewicz Subject: bug#18761: closed (Re: [PATCH] Add pasting in terminal check.) Message-ID: References: X-Gnu-PR-Message: they-closed 18761 X-Gnu-PR-Package: emacs X-Gnu-PR-Keywords: patch Reply-To: 18761@debbugs.gnu.org Date: Tue, 20 Jan 2015 13:12:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1421759522-4319-1" This is a multi-part message in MIME format... ------------=_1421759522-4319-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #18761: [PATCH] Add pasting in terminal check. which was filed against the emacs package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 18761@debbugs.gnu.org. --=20 18761: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D18761 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1421759522-4319-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 18761-done) by debbugs.gnu.org; 20 Jan 2015 13:11:54 +0000 Received: from localhost ([127.0.0.1]:50312 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YDYb4-00017K-2h for submit@debbugs.gnu.org; Tue, 20 Jan 2015 08:11:54 -0500 Received: from mail-we0-f173.google.com ([74.125.82.173]:43451) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YDYb1-000174-NI for 18761-done@debbugs.gnu.org; Tue, 20 Jan 2015 08:11:52 -0500 Received: by mail-we0-f173.google.com with SMTP id q58so37082940wes.4 for <18761-done@debbugs.gnu.org>; Tue, 20 Jan 2015 05:11:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:subject:organization:user-agent:face:date:message-id :mime-version:content-type:content-transfer-encoding; bh=j8ph52K/X4dJyQNkQIxyOoxFXuc3jQhCqbvwLjRikuY=; b=XK8EXv11BJ46k4joDT+F9BJ1/J294nB6X4cYikpcDwFddGly8kPbY9CsqT/kEwRyXH 0W8zYUAimEs2ZpPiyk0yzcFypqq1TwNb8+ZcG+NfGHgUaiJRs1kodUe7+IqR5jVHMJ9d nTx2qAgSF+oWxHoxFPPyJPIqTfiNWS/4+GmudMWlVEnRKiEbwXmHQCbmLE5JUFo3RopH Wrbo1Dh+pVTcWbGxFKiILPbz55B0tZmebFIKW0hwlY6/1gIc7fIYppyKaIqYC4R0UtT9 xufvwnln6v2W/ywtsHS6t4bfg131Q6vPovi/VhlQLkWZ9foHbLja2DTQd2IN7SogFq8u 5xvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:organization:user-agent:face :date:message-id:mime-version:content-type:content-transfer-encoding; bh=j8ph52K/X4dJyQNkQIxyOoxFXuc3jQhCqbvwLjRikuY=; b=Kc96qMqj5OVWfIyN2s9uTA9Ddl1ksbTDlR2F2b9iFOcGeU9HT8UKRrR2woJisQR4cv 7DWJp8w3fQH6TSZ559to5eStye3LTXXGmV016YanVkhisCNwbYV21fq5F4ewz5KmorpC mQw1os2lUHCPacDjzgQ2eaLl84r5a22Zu0zBy0zn5YbKGf8E1iYhqvqicAVQW3+w1R5H BDF4V91wfJfPOxyPWhCZWH6SipiodZqHF8I+HEiZZ3o+OLH9HenbO4e/iZTcet5T/yPV zfkKotFNRo6iYoZGq8J2esd56e8f7ZxSs3/N1VyB1WT41bFXlGJk4x5N4OsxJXGnmGvT b2IA== X-Gm-Message-State: ALoCoQlIgJCk4+csFTiV8RuOw5fSpBoBEMZEfPTYWzwPXsZ/DxW5w+3hm3gZtvjjBI1p3PbYhTZ7 X-Received: by 10.180.211.176 with SMTP id nd16mr25087375wic.23.1421759505739; Tue, 20 Jan 2015 05:11:45 -0800 (PST) Received: from mpn-glaptop ([2620:0:105f:310:359a:ef79:5f3d:4707]) by mx.google.com with ESMTPSA id vh8sm21240530wjc.12.2015.01.20.05.11.43 for <18761-done@debbugs.gnu.org> (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 20 Jan 2015 05:11:44 -0800 (PST) From: Michal Nazarewicz To: 18761-done@debbugs.gnu.org Subject: Re: [PATCH] Add pasting in terminal check. Organization: Google Inc User-Agent: Notmuch/0.19~rc1+1~g03aea4f (http://notmuchmail.org) Emacs/25.0.50.1 (x86_64-unknown-linux-gnu) X-Face: PbkBB1w#)bOqd`iCe"Ds{e+!C7`pkC9a|f)Qo^BMQvy\q5x3?vDQJeN(DS?|-^$uMti[3D*#^_Ts"pU$jBQLq~Ud6iNwAw_r_o_4]|JO?]}P_}Nc&"p#D(ZgUb4uCNPe7~a[DbPG0T~!&c.y$Ur,=N4RT>]dNpd; KFrfMCylc}gc??'U2j,!8%xdD Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAJFBMVEWbfGlUPDDHgE57V0jUupKjgIObY0PLrom9mH4dFRK4gmjPs41MxjOgAAACQElEQVQ4jW3TMWvbQBQHcBk1xE6WyALX1069oZBMlq+ouUwpEQQ6uRjttkWP4CmBgGM0BQLBdPFZYPsyFUo6uEtKDQ7oy/U96XR2Ux8ehH/89Z6enqxBcS7Lg81jmSuujrfCZcLI/TYYvbGj+jbgFpHJ/bqQAUISj8iLyu4LuFHJTosxsucO4jSDNE0Hq3hwK/ceQ5sx97b8LcUDsILfk+ovHkOIsMbBfg43VuQ5Ln9YAGCkUdKJoXR9EclFBhixy3EGVz1K6eEkhxCAkeMMnqoAhAKwhoUJkDrCqvbecaYINlFKSRS1i12VKH1XpUd4qxL876EkMcDvHj3s5RBajHHMlA5iK32e0C7VgG0RlzFPvoYHZLRmAC0BmNcBruhkE0KsMsbEc62ZwUJDxWUdMsMhVqovoT96i/DnX/ASvz/6hbCabELLk/6FF/8PNpPCGqcZTGFcBhhAaZZDbQPaAB3+KrWWy2XgbYDNIinkdWAFcCpraDE/knwe5DBqGmgzESl1p2E4MWAz0VUPgYYzmfWb9yS4vCvgsxJriNTHoIBz5YteBvg+VGISQWUqhMiByPIPpygeDBE6elD973xWwKkEiHZAHKjhuPsFnBuArrzxtakRcISv+XMIPl4aGBUJm8Emk7qBYU8IlgNEIpiJhk/No24jHwkKTFHDWfPniR4iw5vJaw2nzSjfq2zffcE/GDjRC2dn0J0XwPAbDL84TvaFCJEU4Oml9pRyEUhR3Cl2t01AoEjRbs0sYugp14/4X5n4pU4EHHnMAAAAAElFTkSuQmCC X-PGP: 50751FF4 X-PGP-FP: AC1F 5F5C D418 88F8 CC84 5858 2060 4012 5075 1FF4 Date: Tue, 20 Jan 2015 14:11:42 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 18761-done X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) It looks like =E2=80=98bracketed paste mode=E2=80=99 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. --=20 Best regards, _ _ .o. | Liege of Serenely Enlightened Majesty of o' \,=3D./ `o ..o | Computer Science, Micha=C5=82 =E2=80=9Cmina86=E2=80=9D Nazarewicz = (o o) ooo +------ooO--(_)--Ooo-- ------------=_1421759522-4319-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 18 Oct 2014 12:06:48 +0000 Received: from localhost ([127.0.0.1]:47934 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XfSmV-0002sF-EC for submit@debbugs.gnu.org; Sat, 18 Oct 2014 08:06:47 -0400 Received: from eggs.gnu.org ([208.118.235.92]:46695) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XfSmT-0002s7-Ck for submit@debbugs.gnu.org; Sat, 18 Oct 2014 08:06:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XfSmO-00034t-Hl for submit@debbugs.gnu.org; Sat, 18 Oct 2014 08:06:45 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:36238) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XfSmO-00034o-ER for submit@debbugs.gnu.org; Sat, 18 Oct 2014 08:06:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48396) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XfSmJ-0005Un-SX for bug-gnu-emacs@gnu.org; Sat, 18 Oct 2014 08:06:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XfSmF-00032j-Bg for bug-gnu-emacs@gnu.org; Sat, 18 Oct 2014 08:06:35 -0400 Received: from mail-lb0-x22c.google.com ([2a00:1450:4010:c04::22c]:43981) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XfSmE-00032S-VD for bug-gnu-emacs@gnu.org; Sat, 18 Oct 2014 08:06:31 -0400 Received: by mail-lb0-f172.google.com with SMTP id b6so1882876lbj.17 for ; Sat, 18 Oct 2014 05:06:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:subject:organization:user-agent:face:date:message-id :mime-version:content-type:content-transfer-encoding; bh=we5RIdytHqPg9j/luoxAM3V2dLqhVIG6bmvI9GO+b2I=; b=mu7pDmgBvq2Y11VniecDbiHOGFMLyHntGrMQArNyP/ie5oR9H1LN9o91Bha2vZJd10 jgS2/19z6iUZSziWeyqEgiiPaOESW3Y7awUb3IHFILMmErj2B3r0kkFrwYTJ/3rKMmPu cfgFobBGeLTdEEYaZ4S6nNuBKd1t6ngdkNMMd52SYCfIt6UmIQa7N+NyH1mxbVUDczAd u+KUlY8nCLqUFo3RXHpOIDcfPbFCM7w844CXdOOtbkjGJ0iXYBCBF2EkLZ62AWmN3S+W sFymXlVoGwGZGP6QD/8TuPKi/3cn59u1vhvzyNv8g3fAqEP4duRmE3opncWhiBeXJbEz xLOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:subject:organization:user-agent :face:date:message-id:mime-version:content-type :content-transfer-encoding; bh=we5RIdytHqPg9j/luoxAM3V2dLqhVIG6bmvI9GO+b2I=; b=kECgMRibKnsVnXhF3D8Cv47DubXap2psD41+AkG7S9nobT/Pcj1c7l0U5pVg6oPJEG X3G/yQKOFqqPwMaSfXdXr3ts1nyAYYPUkxQOQLNRJr1aPM0hUukZZXTOaMXZXGeNppB0 N9QLmdX4eOHdDgs3RMDK0xhNkstfnqaeNhefOAQUcvDsL+cnFEgu6az1dOOjfTCn68mk MM2nK0B+Ne9WjBzLP+4x020+g4mW7X38kr76fJ34E0riaMLso6pSopAVxBSEY/L8Pfw1 zwXIu5P2tL9CLliZ8iJ3xjbk5yKTimRjqbnJ70Ag9aPavl789MLABJMqSeQDvlc8wQPY w2dg== X-Gm-Message-State: ALoCoQkT3PNEOSrgs36mcJI7h44FDrCFOboDWXG8DmkXuufVcQ+w0zSHgXitg4+ckc6tBBGbnTGI X-Received: by 10.152.7.233 with SMTP id m9mr15043030laa.32.1413633989636; Sat, 18 Oct 2014 05:06:29 -0700 (PDT) Received: from mpn-glaptop.roam.corp.google.com ([88.128.80.16]) by mx.google.com with ESMTPSA id l13sm1281564lbh.32.2014.10.18.05.06.26 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sat, 18 Oct 2014 05:06:28 -0700 (PDT) From: Michal Nazarewicz To: bug-gnu-emacs@gnu.org Subject: [PATCH] Add pasting in terminal check. Organization: Google Inc User-Agent: Notmuch/0.17+15~gb65ca8e (http://notmuchmail.org) Emacs/25.0.50.1 (x86_64-unknown-linux-gnu) X-Face: PbkBB1w#)bOqd`iCe"Ds{e+!C7`pkC9a|f)Qo^BMQvy\q5x3?vDQJeN(DS?|-^$uMti[3D*#^_Ts"pU$jBQLq~Ud6iNwAw_r_o_4]|JO?]}P_}Nc&"p#D(ZgUb4uCNPe7~a[DbPG0T~!&c.y$Ur,=N4RT>]dNpd; KFrfMCylc}gc??'U2j,!8%xdD Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAJFBMVEWbfGlUPDDHgE57V0jUupKjgIObY0PLrom9mH4dFRK4gmjPs41MxjOgAAACQElEQVQ4jW3TMWvbQBQHcBk1xE6WyALX1069oZBMlq+ouUwpEQQ6uRjttkWP4CmBgGM0BQLBdPFZYPsyFUo6uEtKDQ7oy/U96XR2Ux8ehH/89Z6enqxBcS7Lg81jmSuujrfCZcLI/TYYvbGj+jbgFpHJ/bqQAUISj8iLyu4LuFHJTosxsucO4jSDNE0Hq3hwK/ceQ5sx97b8LcUDsILfk+ovHkOIsMbBfg43VuQ5Ln9YAGCkUdKJoXR9EclFBhixy3EGVz1K6eEkhxCAkeMMnqoAhAKwhoUJkDrCqvbecaYINlFKSRS1i12VKH1XpUd4qxL876EkMcDvHj3s5RBajHHMlA5iK32e0C7VgG0RlzFPvoYHZLRmAC0BmNcBruhkE0KsMsbEc62ZwUJDxWUdMsMhVqovoT96i/DnX/ASvz/6hbCabELLk/6FF/8PNpPCGqcZTGFcBhhAaZZDbQPaAB3+KrWWy2XgbYDNIinkdWAFcCpraDE/knwe5DBqGmgzESl1p2E4MWAz0VUPgYYzmfWb9yS4vCvgsxJriNTHoIBz5YteBvg+VGISQWUqhMiByPIPpygeDBE6elD973xWwKkEiHZAHKjhuPsFnBuArrzxtakRcISv+XMIPl4aGBUJm8Emk7qBYU8IlgNEIpiJhk/No24jHwkKTFHDWfPniR4iw5vJaw2nzSjfq2zffcE/GDjRC2dn0J0XwPAbDL84TvaFCJEU4Oml9pRyEUhR3Cl2t01AoEjRbs0sYugp14/4X5n4pU4EHHnMAAAAAElFTkSuQmCC X-PGP: 50751FF4 X-PGP-FP: AC1F 5F5C D418 88F8 CC84 5858 2060 4012 5075 1FF4 Date: Sat, 18 Oct 2014 14:06:23 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.0 (----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.0 (----) 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 direc= tional isolates and the Bidirectional Parentheses Algorithm (BPA) specified by these Unicode standards. =20 +** 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 individuall= y. + * Changes in Specialized Modes and Packages in Emacs 25.1 =20 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' a= nd `overwrite-mode'. */) return Qnil; } =20 +static bool +is_human_typing(void) +{ + static struct timespec undo_timer; + + struct timespec t; + + t =3D undo_timer; + undo_timer =3D current_timespec(); + t =3D timespec_sub(undo_timer, t); + + /* Assume it's human if typing 20 chars took at least 100 ms. */ + return t.tv_sec >=3D 1 || t.tv_nsec >=3D 100000000; +} + static int nonundocount; =20 /* 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 <=3D 0 || nonundocount >=3D 20) { - remove_boundary =3D 0; + if (is_human_typing()) + remove_boundary =3D 0; nonundocount =3D 0; } nonundocount++; --=20 Best regards, _ _ .o. | Liege of Serenely Enlightened Majesty of o' \,=3D./ `o ..o | Computer Science, Micha=C5=82 =E2=80=9Cmina86=E2=80=9D Nazarewicz = (o o) ooo +------ooO--(_)--Ooo-- ------------=_1421759522-4319-1--