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
This commit is contained in:
Eric Hanchrow 2012-11-30 12:18:22 +08:00 committed by Chong Yidong
parent cc37e70f66
commit 21859ebcaf
3 changed files with 81 additions and 40 deletions

View file

@ -29,10 +29,6 @@ so we will look at it and add it to the manual.
* Changes in Specialized Modes and Packages in Emacs 24.4
** Icomplete is a bit more like IDO.
*** key bindings to navigate through and select the completions.
*** The icomplete-separator is customizable, and its default has changed.
*** Removed icomplete-show-key-bindings.
** Calc
*** 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.
The value (YEAR MONTH DAY) means to start using the Gregorian calendar
on the given date.
** ERC
*** New option `erc-accidental-paste-threshold-seconds'.
If set to a number, this can be used to avoid accidentally paste large
amounts of data into the ERC input.
** Icomplete is a bit more like IDO.
*** key bindings to navigate through and select the completions.
*** The icomplete-separator is customizable, and its default has changed.
*** Removed icomplete-show-key-bindings.
** MH-E has been updated to MH-E version 8.4.
See MH-E-NEWS for details.

View file

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

View file

@ -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))
(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))))))
;; 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))))))
;; 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."