From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eric Hanchrow Newsgroups: gmane.emacs.devel Subject: [PATCH] prevent accidental pastes in ERC Date: Mon, 28 May 2012 14:57:41 -0700 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: dough.gmane.org 1338242291 799 80.91.229.3 (28 May 2012 21:58:11 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 28 May 2012 21:58:11 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon May 28 23:58:11 2012 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SZ7x3-0001pN-Hm for ged-emacs-devel@m.gmane.org; Mon, 28 May 2012 23:58:09 +0200 Original-Received: from localhost ([::1]:59734 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SZ7x3-00015T-8E for ged-emacs-devel@m.gmane.org; Mon, 28 May 2012 17:58:09 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:55028) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SZ7x0-00015O-MC for emacs-devel@gnu.org; Mon, 28 May 2012 17:58:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SZ7wy-0008QO-Tf for emacs-devel@gnu.org; Mon, 28 May 2012 17:58:06 -0400 Original-Received: from mail-we0-f169.google.com ([74.125.82.169]:48377) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SZ7wy-0008QJ-Lc for emacs-devel@gnu.org; Mon, 28 May 2012 17:58:04 -0400 Original-Received: by wefh52 with SMTP id h52so2797897wef.0 for ; Mon, 28 May 2012 14:58:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=zKloRz9/yYxnQAipCmRicbkZHfybf0cTUERhoFqD2xY=; b=mZ2wX8+PwYxv7XQvbA4uXY7ual5fSyFK1GdGqLyHCv+tTPyq/gWtZWM7aYAVZj+jN9 yzd3C6KK57b2o3Q0dy5Qp2Wka1ND9rS2sj8iJnmses6kaR/72HwXjmk9SfVkm/Cwah5b N2aZ94OzEb68hpCWPY05vsoa/FVAR4QjDNF/Zm1ykl4hDQAiO3GjqSNV38GovLOp6Lxn 48Pu4Fggu8rbPJSPmuIN/EQfsJjTbbknzpYWlHjhEWWLmn1PtunGJ5XYIyrOSQ5OWknx xHX0zj/VeuJzQPYpnk7yqS3mJ/nXXC7GZ0Gxpq9kk2Wa1R9f9GwEIQvc4PLrGe6TWU03 NqtA== Original-Received: by 10.216.215.194 with SMTP id e44mr5991381wep.61.1338242281994; Mon, 28 May 2012 14:58:01 -0700 (PDT) Original-Received: by 10.223.123.193 with HTTP; Mon, 28 May 2012 14:57:41 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 74.125.82.169 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:150673 Archived-At: 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