aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Hanchrow2012-11-30 12:18:22 +0800
committerChong Yidong2012-11-30 12:18:22 +0800
commit21859ebcafcda497a086a9db4701f0406db599ef (patch)
treed2ab8cdb9a0a16903af05e92cbbfd8373151f0f2
parentcc37e70f6699cbadb1a8f5467e8dc9fcea986aa1 (diff)
downloademacs-21859ebcafcda497a086a9db4701f0406db599ef.tar.gz
emacs-21859ebcafcda497a086a9db4701f0406db599ef.zip
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
-rw-r--r--etc/NEWS15
-rw-r--r--lisp/erc/ChangeLog11
-rw-r--r--lisp/erc/erc.el97
3 files changed, 82 insertions, 41 deletions
diff --git a/etc/NEWS b/etc/NEWS
index fb86920303a..05a57e9afe7 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -29,10 +29,6 @@ so we will look at it and add it to the manual.
29 29
30* Changes in Specialized Modes and Packages in Emacs 24.4 30* Changes in Specialized Modes and Packages in Emacs 24.4
31 31
32** Icomplete is a bit more like IDO.
33*** key bindings to navigate through and select the completions.
34*** The icomplete-separator is customizable, and its default has changed.
35*** Removed icomplete-show-key-bindings.
36** Calc 32** Calc
37 33
38*** Calc by default now uses the Gregorian calendar for all dates, and 34*** Calc by default now uses the Gregorian calendar for all dates, and
@@ -47,6 +43,17 @@ Nil, the default value, means to always use the Gregorian calendar.
47The value (YEAR MONTH DAY) means to start using the Gregorian calendar 43The value (YEAR MONTH DAY) means to start using the Gregorian calendar
48on the given date. 44on the given date.
49 45
46** ERC
47
48*** New option `erc-accidental-paste-threshold-seconds'.
49If set to a number, this can be used to avoid accidentally paste large
50amounts of data into the ERC input.
51
52** Icomplete is a bit more like IDO.
53*** key bindings to navigate through and select the completions.
54*** The icomplete-separator is customizable, and its default has changed.
55*** Removed icomplete-show-key-bindings.
56
50** MH-E has been updated to MH-E version 8.4. 57** MH-E has been updated to MH-E version 8.4.
51See MH-E-NEWS for details. 58See MH-E-NEWS for details.
52 59
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 @@
12012-11-30 Eric Hanchrow <eric.hanchrow@gmail.com>
2
3 * erc.el (erc-last-input-time): New variable.
4 (erc-accidental-paste-threshold-seconds): New option to avoid
5 sending accidentally-pasted text to the server (Bug#11592).
6 (erc-send-current-line): Use it.
7
82012-11-30 Chong Yidong <cyd@gnu.org>
9
10 * erc.el (erc-lurker-cleanup, erc-lurker-p): Use float-time.
11
12012-11-23 Stefan Monnier <monnier@iro.umontreal.ca> 122012-11-23 Stefan Monnier <monnier@iro.umontreal.ca>
2 13
3 * erc-backend.el: Fix last change that missed calls to `second' 14 * 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."
2534 (maphash 2534 (maphash
2535 (lambda (nick last-PRIVMSG-time) 2535 (lambda (nick last-PRIVMSG-time)
2536 (when 2536 (when
2537 (> (time-to-seconds (time-subtract 2537 (> (float-time (time-subtract
2538 (current-time) 2538 (current-time)
2539 last-PRIVMSG-time)) 2539 last-PRIVMSG-time))
2540 erc-lurker-threshold-time) 2540 erc-lurker-threshold-time)
2541 (remhash nick hash))) 2541 (remhash nick hash)))
2542 hash) 2542 hash)
@@ -2602,7 +2602,7 @@ server within `erc-lurker-threshold-time'. See also
2602 (gethash (erc-lurker-maybe-trim nick) 2602 (gethash (erc-lurker-maybe-trim nick)
2603 (gethash server erc-lurker-state (make-hash-table))))) 2603 (gethash server erc-lurker-state (make-hash-table)))))
2604 (or (null last-PRIVMSG-time) 2604 (or (null last-PRIVMSG-time)
2605 (> (time-to-seconds 2605 (> (float-time
2606 (time-subtract (current-time) last-PRIVMSG-time)) 2606 (time-subtract (current-time) last-PRIVMSG-time))
2607 erc-lurker-threshold-time)))) 2607 erc-lurker-threshold-time))))
2608 2608
@@ -5215,42 +5215,65 @@ Specifically, return the position of `erc-insert-marker'."
5215 "Return the value of `point' at the end of the input line." 5215 "Return the value of `point' at the end of the input line."
5216 (point-max)) 5216 (point-max))
5217 5217
5218(defvar erc-last-input-time 0
5219 "Time of last call to `erc-send-current-line'.
5220If that function has never been called, the value is 0.")
5221
5222(defcustom erc-accidental-paste-threshold-seconds nil
5223 "Minimum time, in seconds, before sending new lines via IRC.
5224If the value is a number, `erc-send-current-line' signals an
5225error if its previous invocation was less than this much time
5226ago. This is useful so that if you accidentally enter large
5227amounts of text into the ERC buffer, that text is not sent to the
5228IRC server.
5229
5230If the value is nil, `erc-send-current-line' always considers any
5231submitted line to be intentional."
5232 :group 'erc
5233 :type '(choice number (other :tag "disabled" nil)))
5234
5218(defun erc-send-current-line () 5235(defun erc-send-current-line ()
5219 "Parse current line and send it to IRC." 5236 "Parse current line and send it to IRC."
5220 (interactive) 5237 (interactive)
5221 (save-restriction 5238 (let ((now (float-time)))
5222 (widen) 5239 (if (or (not erc-accidental-paste-threshold-seconds)
5223 (if (< (point) (erc-beg-of-input-line)) 5240 (< erc-accidental-paste-threshold-seconds
5224 (erc-error "Point is not in the input area") 5241 (- now erc-last-input-time)))
5225 (let ((inhibit-read-only t) 5242 (save-restriction
5226 (str (erc-user-input)) 5243 (widen)
5227 (old-buf (current-buffer))) 5244 (if (< (point) (erc-beg-of-input-line))
5228 (if (and (not (erc-server-buffer-live-p)) 5245 (erc-error "Point is not in the input area")
5229 (not (erc-command-no-process-p str))) 5246 (let ((inhibit-read-only t)
5230 (erc-error "ERC: No process running") 5247 (str (erc-user-input))
5231 (erc-set-active-buffer (current-buffer)) 5248 (old-buf (current-buffer)))
5232 5249 (if (and (not (erc-server-buffer-live-p))
5233 ;; Kill the input and the prompt 5250 (not (erc-command-no-process-p str)))
5234 (delete-region (erc-beg-of-input-line) 5251 (erc-error "ERC: No process running")
5235 (erc-end-of-input-line)) 5252 (erc-set-active-buffer (current-buffer))
5236 5253 ;; Kill the input and the prompt
5237 (unwind-protect 5254 (delete-region (erc-beg-of-input-line)
5238 (erc-send-input str) 5255 (erc-end-of-input-line))
5239 ;; Fix the buffer if the command didn't kill it 5256 (unwind-protect
5240 (when (buffer-live-p old-buf) 5257 (erc-send-input str)
5241 (with-current-buffer old-buf 5258 ;; Fix the buffer if the command didn't kill it
5242 (save-restriction 5259 (when (buffer-live-p old-buf)
5243 (widen) 5260 (with-current-buffer old-buf
5244 (goto-char (point-max)) 5261 (save-restriction
5245 (when (processp erc-server-process) 5262 (widen)
5246 (set-marker (process-mark erc-server-process) (point))) 5263 (goto-char (point-max))
5247 (set-marker erc-insert-marker (point)) 5264 (when (processp erc-server-process)
5248 (let ((buffer-modified (buffer-modified-p))) 5265 (set-marker (process-mark erc-server-process) (point)))
5249 (erc-display-prompt) 5266 (set-marker erc-insert-marker (point))
5250 (set-buffer-modified-p buffer-modified)))))) 5267 (let ((buffer-modified (buffer-modified-p)))
5251 5268 (erc-display-prompt)
5252 ;; Only when last hook has been run... 5269 (set-buffer-modified-p buffer-modified))))))
5253 (run-hook-with-args 'erc-send-completed-hook str)))))) 5270
5271 ;; Only when last hook has been run...
5272 (run-hook-with-args 'erc-send-completed-hook str))))
5273 (setq erc-last-input-time now))
5274 (switch-to-buffer "*ERC Accidental Paste Overflow*")
5275 (lwarn 'erc :warning
5276 "You seem to have accidentally pasted some text!"))))
5254 5277
5255(defun erc-user-input () 5278(defun erc-user-input ()
5256 "Return the input of the user in the current buffer." 5279 "Return the input of the user in the current buffer."