GNU bug report logs - #11592
[PATCH] prevent accidental pastes in ERC

Previous Next

Package: emacs;

Reported by: Eric Hanchrow <eric.hanchrow <at> gmail.com>

Date: Thu, 31 May 2012 00:36:02 UTC

Severity: wishlist

Tags: patch

Done: Chong Yidong <cyd <at> gnu.org>

Bug is archived. No further changes may be made.

Forwarded to http://lists.gnu.org/archive/html/emacs-devel/2012-05/msg00504.html

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 11592 in the body.
You can then email your comments to 11592 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#11592; Package emacs. (Thu, 31 May 2012 00:36:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Eric Hanchrow <eric.hanchrow <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 31 May 2012 00:36:03 GMT) Full text and rfc822 format available.

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

From: Eric Hanchrow <eric.hanchrow <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: [PATCH] prevent accidental pastes in ERC
Date: Wed, 30 May 2012 17:32:52 -0700
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 2d8c256..5677445 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -5020,42 +5020,63 @@ Specifically, return the position of
`erc-insert-marker'."
  "Return the value of `point' at the end of the input line."
  (point-max))

+(defvar erc-last-input-time 0
+  "Time of last call to `erc-send-current-line' (as returned by `float-time'),
+or 0 if that function has never been called.
+
+Used to detect accidental pastes (i.e., large amounts of text
+accidentally entered into the ERC buffer.)")
+
+(defcustom erc-accidental-paste-threshold-seconds nil
+  "Time in seconds that must pass between invocations of
+  `erc-send-current-line' in order for that function to consider
+  the new line intentional.  If nil, erc-send-current-line always
+  considers the new line to be intentional."
+  :group 'erc
+  :type '(choice number (other :tag "disabled" nil)))
+
 (defun erc-send-current-line ()
  "Parse current line and send it to IRC."
  (interactive)
-  (save-restriction
-    (widen)
-    (if (< (point) (erc-beg-of-input-line))
-       (erc-error "Point is not in the input area")
-      (let ((inhibit-read-only t)
-           (str (erc-user-input))
-           (old-buf (current-buffer)))
-       (if (and (not (erc-server-buffer-live-p))
-                (not (erc-command-no-process-p str)))
-           (erc-error "ERC: No process running")
-         (erc-set-active-buffer (current-buffer))
-
-         ;; Kill the input and the prompt
-         (delete-region (erc-beg-of-input-line)
-                        (erc-end-of-input-line))
-
-         (unwind-protect
-             (erc-send-input str)
-           ;; Fix the buffer if the command didn't kill it
-           (when (buffer-live-p old-buf)
-             (with-current-buffer old-buf
-               (save-restriction
-                 (widen)
-                 (goto-char (point-max))
-                 (when (processp erc-server-process)
-                   (set-marker (process-mark erc-server-process) (point)))
-                 (set-marker erc-insert-marker (point))
-                 (let ((buffer-modified (buffer-modified-p)))
-                   (erc-display-prompt)
-                   (set-buffer-modified-p buffer-modified))))))
-
-         ;; Only when last hook has been run...
-         (run-hook-with-args 'erc-send-completed-hook str))))))
+  (let ((now (float-time)))
+    (if (or (not erc-accidental-paste-threshold-seconds)
+           (< erc-accidental-paste-threshold-seconds (- now
erc-last-input-time)))
+       (save-restriction
+         (widen)
+         (if (< (point) (erc-beg-of-input-line))
+             (erc-error "Point is not in the input area")
+           (let ((inhibit-read-only t)
+                 (str (erc-user-input))
+                 (old-buf (current-buffer)))
+             (if (and (not (erc-server-buffer-live-p))
+                      (not (erc-command-no-process-p str)))
+                 (erc-error "ERC: No process running")
+               (erc-set-active-buffer (current-buffer))
+
+               ;; Kill the input and the prompt
+               (delete-region (erc-beg-of-input-line)
+                              (erc-end-of-input-line))
+
+               (unwind-protect
+                   (erc-send-input str)
+                 ;; Fix the buffer if the command didn't kill it
+                 (when (buffer-live-p old-buf)
+                   (with-current-buffer old-buf
+                     (save-restriction
+                       (widen)
+                       (goto-char (point-max))
+                       (when (processp erc-server-process)
+                         (set-marker (process-mark
erc-server-process) (point)))
+                       (set-marker erc-insert-marker (point))
+                       (let ((buffer-modified (buffer-modified-p)))
+                         (erc-display-prompt)
+                         (set-buffer-modified-p buffer-modified))))))
+
+               ;; Only when last hook has been run...
+               (run-hook-with-args 'erc-send-completed-hook str))))
+         (setq erc-last-input-time now))
+      (switch-to-buffer "*ERC Accidental Paste Overflow*")
+      (lwarn 'erc :warning "You seem to have accidentally pasted some
text!"))))

 (defun erc-user-input ()
  "Return the input of the user in the current buffer."
--
1.7.9.5

Set bug forwarded-to-address to 'http://lists.gnu.org/archive/html/emacs-devel/2012-05/msg00504.html'. Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Thu, 31 May 2012 00:41:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11592; Package emacs. (Thu, 31 May 2012 19:27:01 GMT) Full text and rfc822 format available.

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

From: Glenn Morris <rgm <at> gnu.org>
To: Eric Hanchrow <eric.hanchrow <at> gmail.com>
Cc: 11592 <at> debbugs.gnu.org
Subject: Re: bug#11592: [PATCH] prevent accidental pastes in ERC
Date: Thu, 31 May 2012 15:24:43 -0400
Perhaps you could give the motivation/explanation for this change.
Why are accidental pastes into an erc buffer more of an issue than for
say, a shell buffer?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11592; Package emacs. (Thu, 31 May 2012 20:11:01 GMT) Full text and rfc822 format available.

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

From: Deniz Dogan <deniz <at> dogan.se>
To: Glenn Morris <rgm <at> gnu.org>
Cc: Eric Hanchrow <eric.hanchrow <at> gmail.com>, 11592 <at> debbugs.gnu.org
Subject: Re: bug#11592: [PATCH] prevent accidental pastes in ERC
Date: Thu, 31 May 2012 22:08:33 +0200
Glenn Morris skrev 2012-05-31 21:24:
>
> Perhaps you could give the motivation/explanation for this change.
> Why are accidental pastes into an erc buffer more of an issue than for
> say, a shell buffer?
>

Accidentally pasting (and thereafter sending) large amounts of data on 
an IRC server will in many cases cause you to either be disconnected due 
to "excess flood" and in other cases, where some anti-flood client 
setting prevents that, just cause lots of disruption in the IRC channel.

Having said that: I don't really know how suitable this patch is.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11592; Package emacs. (Fri, 01 Jun 2012 00:10:01 GMT) Full text and rfc822 format available.

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

From: Eric Hanchrow <eric.hanchrow <at> gmail.com>
To: Deniz Dogan <deniz <at> dogan.se>
Cc: Glenn Morris <rgm <at> gnu.org>, 11592 <at> debbugs.gnu.org
Subject: Re: bug#11592: [PATCH] prevent accidental pastes in ERC
Date: Thu, 31 May 2012 17:07:26 -0700
If I accidentally paste into a shell buffer, I (generally) harm nobody
but myself.  But if I accidentally paste into an IRC buffer, I can
annoy everybody on that channel.  I've done it many times, and it
happens to other people often too.

On Thu, May 31, 2012 at 1:08 PM, Deniz Dogan <deniz <at> dogan.se> wrote:
> Glenn Morris skrev 2012-05-31 21:24:
>
>>
>> Perhaps you could give the motivation/explanation for this change.
>> Why are accidental pastes into an erc buffer more of an issue than for
>> say, a shell buffer?
>>
>
> Accidentally pasting (and thereafter sending) large amounts of data on an
> IRC server will in many cases cause you to either be disconnected due to
> "excess flood" and in other cases, where some anti-flood client setting
> prevents that, just cause lots of disruption in the IRC channel.
>
> Having said that: I don't really know how suitable this patch is.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11592; Package emacs. (Sat, 02 Jun 2012 07:42:01 GMT) Full text and rfc822 format available.

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

From: Chong Yidong <cyd <at> gnu.org>
To: Eric Hanchrow <eric.hanchrow <at> gmail.com>
Cc: Deniz Dogan <deniz <at> dogan.se>, 11592 <at> debbugs.gnu.org
Subject: Re: bug#11592: [PATCH] prevent accidental pastes in ERC
Date: Sat, 02 Jun 2012 15:39:25 +0800
Eric Hanchrow <eric.hanchrow <at> gmail.com> writes:

> If I accidentally paste into a shell buffer, I (generally) harm nobody
> but myself.  But if I accidentally paste into an IRC buffer, I can
> annoy everybody on that channel.  I've done it many times, and it
> happens to other people often too.

Does this patch disable all pasting of multi-line text?  That might be
annoying, since people might want to do that sometimes.  If the problem
is pasting a lot of text, maybe the better approach is to set up a
maximum amount of text that can be yanked into an erc buffer.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11592; Package emacs. (Sun, 10 Jun 2012 22:08:02 GMT) Full text and rfc822 format available.

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

From: Eric Hanchrow <eric.hanchrow <at> gmail.com>
To: 11592 <at> debbugs.gnu.org
Subject: Fwd: bug#11592: [PATCH] prevent accidental pastes in ERC
Date: Sun, 10 Jun 2012 15:04:48 -0700
[Message part 1 (text/plain, inline)]
---------- Forwarded message ----------
From: Eric Hanchrow <eric.hanchrow <at> gmail.com>
Date: Sat, Jun 2, 2012 at 7:00 AM
Subject: Re: bug#11592: [PATCH] prevent accidental pastes in ERC
To: Chong Yidong <cyd <at> gnu.org>


On Sat, Jun 2, 2012 at 12:39 AM, Chong Yidong <cyd <at> gnu.org> wrote:
> Does this patch disable all pasting of multi-line text?

By default, it has no effect.  But when you enable it by setting the
variable erc-accidental-paste-threshold-seconds to a numeric value, it
indeed prevents pasting of multi-line text.

> That might be
> annoying, since people might want to do that sometimes.

If people ignore the variable, everything will work as it always has.
Only by deliberately setting this variable will people see a change in
Emacs' behavior.

> If the problem
> is pasting a lot of text, maybe the better approach is to set up a
> maximum amount of text that can be yanked into an erc buffer.

It's not yanking we're talking about; it's "pasting".  Pasting is
relevant only when emacs is in console mode (I should probably have
said something about that in the patch).  When I say "pasting", I mean
selecting some text in another application, then focusing _your
console program in which Emacs is running_, and then pressing the
middle mouse button (or shift+insert, or whatever).  From emacs' point
of view, "pasting" is indistinguishable from ordinary, albeit rapid,
typing.  That is why my patch is based on the time between calls to
erc-send-current-line: I can't think of any other way to distinguish
an accidental paste from ordinary typing.
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11592; Package emacs. (Sun, 08 Jul 2012 06:21:02 GMT) Full text and rfc822 format available.

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

From: Michael Olson <mwolson <at> gnu.org>
To: Chong Yidong <cyd <at> gnu.org>, 11592 <at> debbugs.gnu.org
Subject: Re: Patch for Bug#11592
Date: Sat, 7 Jul 2012 23:15:00 -0700
[Message part 1 (text/plain, inline)]
The change seems good.  It would help to add the option to the manual as
well, so that people can discover it, but not required.

-- 
Michael Olson  |  http://mwolson.org/
[Message part 2 (text/html, inline)]

Reply sent to Chong Yidong <cyd <at> gnu.org>:
You have taken responsibility. (Fri, 30 Nov 2012 04:22:02 GMT) Full text and rfc822 format available.

Notification sent to Eric Hanchrow <eric.hanchrow <at> gmail.com>:
bug acknowledged by developer. (Fri, 30 Nov 2012 04:22:02 GMT) Full text and rfc822 format available.

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

From: Chong Yidong <cyd <at> gnu.org>
To: Eric Hanchrow <eric.hanchrow <at> gmail.com>
Cc: Michael Olson <mwolson <at> gnu.org>, 11592-done <at> debbugs.gnu.org
Subject: Re: bug#11592: Patch for Bug#11592
Date: Fri, 30 Nov 2012 12:19:20 +0800
Michael Olson <mwolson <at> gnu.org> writes:

> The change seems good. It would help to add the option to the manual
> as well, so that people can discover it, but not required.

Thanks.  I have committed the patch to trunk, with a NEWS entry.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 28 Dec 2012 12:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 11 years and 129 days ago.

Previous Next


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