diff options
author | Eric Hanchrow <eric.hanchrow@gmail.com> | 2012-11-30 12:18:22 +0800 |
---|---|---|
committer | Chong Yidong <cyd@gnu.org> | 2012-11-30 12:18:22 +0800 |
commit | 21859ebcafcda497a086a9db4701f0406db599ef (patch) | |
tree | d2ab8cdb9a0a16903af05e92cbbfd8373151f0f2 /lisp/erc | |
parent | cc37e70f6699cbadb1a8f5467e8dc9fcea986aa1 (diff) | |
download | emacs-21859ebcafcda497a086a9db4701f0406db599ef.tar.gz |
New ERC option to avoid sending accidentally-pasted text to the server.
* erc.el (erc-last-input-time): New variable.
(erc-accidental-paste-threshold-seconds): New option to avoid
sending accidentally-pasted text to the server.
(erc-send-current-line): Use it.
Also,
* erc.el (erc-lurker-cleanup, erc-lurker-p): Use float-time.
Fixes: debbugs:11592
Diffstat (limited to 'lisp/erc')
-rw-r--r-- | lisp/erc/ChangeLog | 11 | ||||
-rw-r--r-- | lisp/erc/erc.el | 97 |
2 files changed, 71 insertions, 37 deletions
diff --git a/lisp/erc/ChangeLog b/lisp/erc/ChangeLog index 3f9824545cf..eeb31f99037 100644 --- a/lisp/erc/ChangeLog +++ b/lisp/erc/ChangeLog @@ -1,3 +1,14 @@ +2012-11-30 Eric Hanchrow <eric.hanchrow@gmail.com> + + * erc.el (erc-last-input-time): New variable. + (erc-accidental-paste-threshold-seconds): New option to avoid + sending accidentally-pasted text to the server (Bug#11592). + (erc-send-current-line): Use it. + +2012-11-30 Chong Yidong <cyd@gnu.org> + + * erc.el (erc-lurker-cleanup, erc-lurker-p): Use float-time. + 2012-11-23 Stefan Monnier <monnier@iro.umontreal.ca> * erc-backend.el: Fix last change that missed calls to `second' diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index cec9718e751..e03a0c5dc43 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -2534,9 +2534,9 @@ consumption for long-lived IRC or Emacs sessions." (maphash (lambda (nick last-PRIVMSG-time) (when - (> (time-to-seconds (time-subtract - (current-time) - last-PRIVMSG-time)) + (> (float-time (time-subtract + (current-time) + last-PRIVMSG-time)) erc-lurker-threshold-time) (remhash nick hash))) hash) @@ -2602,7 +2602,7 @@ server within `erc-lurker-threshold-time'. See also (gethash (erc-lurker-maybe-trim nick) (gethash server erc-lurker-state (make-hash-table))))) (or (null last-PRIVMSG-time) - (> (time-to-seconds + (> (float-time (time-subtract (current-time) last-PRIVMSG-time)) erc-lurker-threshold-time)))) @@ -5215,42 +5215,65 @@ 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'. +If that function has never been called, the value is 0.") + +(defcustom erc-accidental-paste-threshold-seconds nil + "Minimum time, in seconds, before sending new lines via IRC. +If the value is a number, `erc-send-current-line' signals an +error if its previous invocation was less than this much time +ago. This is useful so that if you accidentally enter large +amounts of text into the ERC buffer, that text is not sent to the +IRC server. + +If the value is nil, `erc-send-current-line' always considers any +submitted 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." |