[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] prevent accidental pastes in ERC
From: |
Eric Hanchrow |
Subject: |
[PATCH] prevent accidental pastes in ERC |
Date: |
Mon, 28 May 2012 14:57:41 -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
- [PATCH] prevent accidental pastes in ERC,
Eric Hanchrow <=