unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#11592: [PATCH] prevent accidental pastes in ERC
       [not found] <CAHZoxq-3j2ksOMRsL9UEitu3oEjk0ro1CKoOfUhcUGeZtsQv9w@mail.gmail.com>
@ 2012-05-31  0:32 ` Eric Hanchrow
  2012-05-31 19:24   ` Glenn Morris
  0 siblings, 1 reply; 6+ messages in thread
From: Eric Hanchrow @ 2012-05-31  0:32 UTC (permalink / raw)
  To: 11592

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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* bug#11592: [PATCH] prevent accidental pastes in ERC
  2012-05-31  0:32 ` bug#11592: [PATCH] prevent accidental pastes in ERC Eric Hanchrow
@ 2012-05-31 19:24   ` Glenn Morris
  2012-05-31 20:08     ` Deniz Dogan
  0 siblings, 1 reply; 6+ messages in thread
From: Glenn Morris @ 2012-05-31 19:24 UTC (permalink / raw)
  To: Eric Hanchrow; +Cc: 11592


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?





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#11592: [PATCH] prevent accidental pastes in ERC
  2012-05-31 19:24   ` Glenn Morris
@ 2012-05-31 20:08     ` Deniz Dogan
  2012-06-01  0:07       ` Eric Hanchrow
  0 siblings, 1 reply; 6+ messages in thread
From: Deniz Dogan @ 2012-05-31 20:08 UTC (permalink / raw)
  To: Glenn Morris; +Cc: Eric Hanchrow, 11592

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.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#11592: [PATCH] prevent accidental pastes in ERC
  2012-05-31 20:08     ` Deniz Dogan
@ 2012-06-01  0:07       ` Eric Hanchrow
  2012-06-02  7:39         ` Chong Yidong
  0 siblings, 1 reply; 6+ messages in thread
From: Eric Hanchrow @ 2012-06-01  0:07 UTC (permalink / raw)
  To: Deniz Dogan; +Cc: 11592

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@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.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#11592: [PATCH] prevent accidental pastes in ERC
  2012-06-01  0:07       ` Eric Hanchrow
@ 2012-06-02  7:39         ` Chong Yidong
       [not found]           ` <CAHZoxq8yfAYwp_LH0nMnsw-QAg9pX9AVEnLCXos7N0yTgAVeDQ@mail.gmail.com>
  0 siblings, 1 reply; 6+ messages in thread
From: Chong Yidong @ 2012-06-02  7:39 UTC (permalink / raw)
  To: Eric Hanchrow; +Cc: 11592

Eric Hanchrow <eric.hanchrow@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.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#11592: Fwd: bug#11592: [PATCH] prevent accidental pastes in ERC
       [not found]           ` <CAHZoxq8yfAYwp_LH0nMnsw-QAg9pX9AVEnLCXos7N0yTgAVeDQ@mail.gmail.com>
@ 2012-06-10 22:04             ` Eric Hanchrow
  0 siblings, 0 replies; 6+ messages in thread
From: Eric Hanchrow @ 2012-06-10 22:04 UTC (permalink / raw)
  To: 11592

[-- Attachment #1: Type: text/plain, Size: 1568 bytes --]

---------- Forwarded message ----------
From: Eric Hanchrow <eric.hanchrow@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@gnu.org>


On Sat, Jun 2, 2012 at 12:39 AM, Chong Yidong <cyd@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.

[-- Attachment #2: Type: text/html, Size: 2109 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-06-10 22:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CAHZoxq-3j2ksOMRsL9UEitu3oEjk0ro1CKoOfUhcUGeZtsQv9w@mail.gmail.com>
2012-05-31  0:32 ` bug#11592: [PATCH] prevent accidental pastes in ERC Eric Hanchrow
2012-05-31 19:24   ` Glenn Morris
2012-05-31 20:08     ` Deniz Dogan
2012-06-01  0:07       ` Eric Hanchrow
2012-06-02  7:39         ` Chong Yidong
     [not found]           ` <CAHZoxq8yfAYwp_LH0nMnsw-QAg9pX9AVEnLCXos7N0yTgAVeDQ@mail.gmail.com>
2012-06-10 22:04             ` bug#11592: Fwd: " Eric Hanchrow

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).