emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r111032: New ERC option to avoid send


From: Chong Yidong
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r111032: New ERC option to avoid sending accidentally-pasted text to the server.
Date: Fri, 30 Nov 2012 12:18:22 +0800
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 111032
fixes bug: http://debbugs.gnu.org/11592
author: Eric Hanchrow <address@hidden>
committer: Chong Yidong <address@hidden>
branch nick: trunk
timestamp: Fri 2012-11-30 12:18:22 +0800
message:
  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.
modified:
  etc/NEWS
  lisp/erc/ChangeLog
  lisp/erc/erc.el
=== modified file 'etc/NEWS'
--- a/etc/NEWS  2012-11-29 21:32:24 +0000
+++ b/etc/NEWS  2012-11-30 04:18:22 +0000
@@ -29,10 +29,6 @@
 
 * 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 @@
 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.
 

=== modified file 'lisp/erc/ChangeLog'
--- a/lisp/erc/ChangeLog        2012-11-23 16:00:57 +0000
+++ b/lisp/erc/ChangeLog        2012-11-30 04:18:22 +0000
@@ -1,3 +1,14 @@
+2012-11-30  Eric Hanchrow  <address@hidden>
+
+       * 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  <address@hidden>
+
+       * erc.el (erc-lurker-cleanup, erc-lurker-p): Use float-time.
+
 2012-11-23  Stefan Monnier  <address@hidden>
 
        * erc-backend.el: Fix last change that missed calls to `second'

=== modified file 'lisp/erc/erc.el'
--- a/lisp/erc/erc.el   2012-11-19 17:24:12 +0000
+++ b/lisp/erc/erc.el   2012-11-30 04:18:22 +0000
@@ -2534,9 +2534,9 @@
      (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 @@
            (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 @@
   "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."


reply via email to

[Prev in Thread] Current Thread [Next in Thread]