* [PATCH] prevent accidental pastes in ERC
@ 2012-05-28 21:57 Eric Hanchrow
2012-05-30 8:10 ` Julien Danjou
2012-05-31 0:32 ` bug#11592: " Eric Hanchrow
0 siblings, 2 replies; 8+ messages in thread
From: Eric Hanchrow @ 2012-05-28 21:57 UTC (permalink / raw
To: emacs-devel
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] 8+ messages in thread
* Re: [PATCH] prevent accidental pastes in ERC
2012-05-28 21:57 [PATCH] prevent accidental pastes in ERC Eric Hanchrow
@ 2012-05-30 8:10 ` Julien Danjou
2012-05-31 0:32 ` bug#11592: " Eric Hanchrow
1 sibling, 0 replies; 8+ messages in thread
From: Julien Danjou @ 2012-05-30 8:10 UTC (permalink / raw
To: Eric Hanchrow; +Cc: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 176 bytes --]
On Mon, May 28 2012, Eric Hanchrow wrote:
Eric, I suggest you open a bug report with that patch, otherwise it's
likely to be forgotten for ever.
--
Julien
[-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#11592: [PATCH] prevent accidental pastes in ERC
2012-05-28 21:57 [PATCH] prevent accidental pastes in ERC Eric Hanchrow
2012-05-30 8:10 ` Julien Danjou
@ 2012-05-31 0:32 ` Eric Hanchrow
2012-05-31 19:24 ` Glenn Morris
1 sibling, 1 reply; 8+ 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] 8+ messages in thread
* bug#11592: [PATCH] prevent accidental pastes in ERC
2012-05-31 0:32 ` bug#11592: " Eric Hanchrow
@ 2012-05-31 19:24 ` Glenn Morris
2012-05-31 20:08 ` Deniz Dogan
0 siblings, 1 reply; 8+ 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] 8+ 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; 8+ 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] 8+ 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; 8+ 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] 8+ 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; 8+ 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] 8+ messages in thread
end of thread, other threads:[~2012-06-10 22:04 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-28 21:57 [PATCH] prevent accidental pastes in ERC Eric Hanchrow
2012-05-30 8:10 ` Julien Danjou
2012-05-31 0:32 ` bug#11592: " 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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.