From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Reuben Thomas Newsgroups: gmane.emacs.bugs Subject: bug#13837: 24.2; Make it possible to turn whitespace-mode only when there are no existing problems Date: Sat, 2 Mar 2013 07:49:35 +0000 Message-ID: References: <878v69fn8q.fsf@sc3d.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1362210605 19443 80.91.229.3 (2 Mar 2013 07:50:05 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 2 Mar 2013 07:50:05 +0000 (UTC) Cc: 13837@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Mar 02 08:50:29 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1UBhD9-0003T7-Iv for geb-bug-gnu-emacs@m.gmane.org; Sat, 02 Mar 2013 08:50:27 +0100 Original-Received: from localhost ([::1]:45589 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UBhCo-0001K3-Fi for geb-bug-gnu-emacs@m.gmane.org; Sat, 02 Mar 2013 02:50:06 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:44875) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UBhCj-0001FP-Sg for bug-gnu-emacs@gnu.org; Sat, 02 Mar 2013 02:50:03 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UBhCh-0003Nx-W5 for bug-gnu-emacs@gnu.org; Sat, 02 Mar 2013 02:50:01 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:50450) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UBhCh-0003Ns-S1 for bug-gnu-emacs@gnu.org; Sat, 02 Mar 2013 02:49:59 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1UBhCj-0004Ht-M1 for bug-gnu-emacs@gnu.org; Sat, 02 Mar 2013 02:50:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Reuben Thomas Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 02 Mar 2013 07:50:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 13837 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 13837-submit@debbugs.gnu.org id=B13837.136221058416452 (code B ref 13837); Sat, 02 Mar 2013 07:50:01 +0000 Original-Received: (at 13837) by debbugs.gnu.org; 2 Mar 2013 07:49:44 +0000 Original-Received: from localhost ([127.0.0.1]:54559 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UBhCR-0004HH-JA for submit@debbugs.gnu.org; Sat, 02 Mar 2013 02:49:44 -0500 Original-Received: from exprod7og107.obsmtp.com ([64.18.2.167]:60288) by debbugs.gnu.org with smtp (Exim 4.72) (envelope-from ) id 1UBhCN-0004H8-8F for 13837@debbugs.gnu.org; Sat, 02 Mar 2013 02:49:41 -0500 Original-Received: from mail-wi0-f198.google.com ([209.85.212.198]) (using TLSv1) by exprod7ob107.postini.com ([64.18.6.12]) with SMTP ID DSNKUTGvDzY863+BDSdzJb5cN0CHVWD6uIEE@postini.com; Fri, 01 Mar 2013 23:49:36 PST Original-Received: by mail-wi0-f198.google.com with SMTP id hm6so365752wib.5 for <13837@debbugs.gnu.org>; Fri, 01 Mar 2013 23:49:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:mime-version:x-received:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding:x-gm-message-state; bh=eYNrVxK5/LKEvtldLEAKL4JHSwDF7fTiOvPgcyFx6rQ=; b=D/aIkKYXyeKc6wrDEo1w9takCup0nSnvV8BiNzooLjJ+GDi+PVkRSPgIJ+ZME9D4cd UGW9kcFR7uQRtMkaHYobS9fV04nkFPmMUvRS9kq6EDrOl0gk114tlkW0fGcHGfZ/hlw0 l8PNeh6G1CUaGt0t+NV4vXJSWbO0QaFqKz+Hri1nM6zPoDoF2HEvwDrGAsqNMcmT+6L9 tVbH8VgcnPP7HT5DyPFcVVBReDyo9zv/U7KKA7NRMuM5FUZpvFy2Ssff9E04Um8jFRVk eshTeSDOvNeATN2aoIsuaBxSEMBDpLEx3SQupSJgwkbRxRKckXMVEWG1BvVVr1xM3n7U Dwww== X-Received: by 10.152.146.199 with SMTP id te7mr11393673lab.23.1362210575583; Fri, 01 Mar 2013 23:49:35 -0800 (PST) X-Received: by 10.152.146.199 with SMTP id te7mr11393666lab.23.1362210575469; Fri, 01 Mar 2013 23:49:35 -0800 (PST) Original-Received: by 10.152.5.40 with HTTP; Fri, 1 Mar 2013 23:49:35 -0800 (PST) In-Reply-To: X-Gm-Message-State: ALoCoQm4eP2B0Zz/i7LifTAAdzdWNLqxxqo2uDBJ740oYfC4L5mipiaiAWPU+KuCExLPw0wqnJ3XnYLZ+TPXuXn1YhctN1xKte/JoRrUMjzufWmfSj5gAy6x9m9dxC71osUf+7iYj+uoumy//1lNP3la37ucUjMdmRhw7RT9jheLflckDHbLaSk= X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:72021 Archived-At: On 2 March 2013 03:01, Stefan Monnier wrote: >>> You can =85 refactor the >>> whitespace-report-region so as to provide whitespace-test-region. >> Here's an attempt at that: > > Can you please (re)send it as a patch? Sure: =3D=3D=3D modified file 'lisp/whitespace.el' --- lisp/whitespace.el 2013-01-11 23:08:55 +0000 +++ lisp/whitespace.el 2013-03-02 07:47:43 +0000 @@ -1821,6 +1821,64 @@ ;;;###autoload +(defun whitespace-test-region (start end) + "Find whether there are whitespace problems in a region. + +Return a list of whitespace problems (hence, nil if there is no +whitespace problem). + +A whitespace problem is one of the following: + +* If `indent-tabs-mode' is non-nil: + empty 1. empty lines at beginning of buffer. + empty 2. empty lines at end of buffer. + trailing 3. SPACEs or TABs at end of line. + indentation 4. 8 or more SPACEs at beginning of line. + space-before-tab 5. SPACEs before TAB. + space-after-tab 6. 8 or more SPACEs after TAB. + +* If `indent-tabs-mode' is nil: + empty 1. empty lines at beginning of buffer. + empty 2. empty lines at end of buffer. + trailing 3. SPACEs or TABs at end of line. + indentation 4. TABS at beginning of line. + space-before-tab 5. SPACEs before TAB. + space-after-tab 6. 8 or more SPACEs after TAB. + +See `whitespace-style' for documentation. +See also `whitespace-cleanup' and `whitespace-cleanup-region' for +cleaning up these problems." + (save-excursion + (save-match-data ;FIXME: Why? + (let* ((has-bogus nil) + (rstart (min start end)) + (rend (max start end)) + (bogus-list + (mapcar + #'(lambda (option) + (goto-char rstart) + (let ((regexp + (cond + ((eq (car option) 'indentation) + (whitespace-indentation-regexp)) + ((eq (car option) 'indentation::tab) + (whitespace-indentation-regexp 'tab)) + ((eq (car option) 'indentation::space) + (whitespace-indentation-regexp 'space)) + ((eq (car option) 'space-after-tab) + (whitespace-space-after-tab-regexp)) + ((eq (car option) 'space-after-tab::tab) + (whitespace-space-after-tab-regexp 'tab)) + ((eq (car option) 'space-after-tab::space) + (whitespace-space-after-tab-regexp 'space)) + (t + (cdr option))))) + (and (re-search-forward regexp rend t) + t))) + whitespace-report-list))) + bogus-list)))) + +;;;###autoload (defun whitespace-report-region (start end &optional force report-if-bogus= ) "Report some whitespace problems in a region. @@ -1840,90 +1898,43 @@ If REPORT-IF-BOGUS is non-nil, it reports only when there are any whitespace problems in buffer. -Report if some of the following whitespace problems exist: - -* If `indent-tabs-mode' is non-nil: - empty 1. empty lines at beginning of buffer. - empty 2. empty lines at end of buffer. - trailing 3. SPACEs or TABs at end of line. - indentation 4. 8 or more SPACEs at beginning of line. - space-before-tab 5. SPACEs before TAB. - space-after-tab 6. 8 or more SPACEs after TAB. - -* If `indent-tabs-mode' is nil: - empty 1. empty lines at beginning of buffer. - empty 2. empty lines at end of buffer. - trailing 3. SPACEs or TABs at end of line. - indentation 4. TABS at beginning of line. - space-before-tab 5. SPACEs before TAB. - space-after-tab 6. 8 or more SPACEs after TAB. - -See `whitespace-style' for documentation. -See also `whitespace-cleanup' and `whitespace-cleanup-region' for -cleaning up these problems." +For a description of whitespace problems, see +`whitespace-test-region'." (interactive "r") (setq force (or current-prefix-arg force)) (save-excursion - (save-match-data ;FIXME: Why? - (let* ((has-bogus nil) - (rstart (min start end)) - (rend (max start end)) - (bogus-list - (mapcar - #'(lambda (option) - (when force - (add-to-list 'whitespace-style (car option))) - (goto-char rstart) - (let ((regexp - (cond - ((eq (car option) 'indentation) - (whitespace-indentation-regexp)) - ((eq (car option) 'indentation::tab) - (whitespace-indentation-regexp 'tab)) - ((eq (car option) 'indentation::space) - (whitespace-indentation-regexp 'space)) - ((eq (car option) 'space-after-tab) - (whitespace-space-after-tab-regexp)) - ((eq (car option) 'space-after-tab::tab) - (whitespace-space-after-tab-regexp 'tab)) - ((eq (car option) 'space-after-tab::space) - (whitespace-space-after-tab-regexp 'space)) - (t - (cdr option))))) - (and (re-search-forward regexp rend t) - (setq has-bogus t)))) - whitespace-report-list))) - (when (if report-if-bogus has-bogus t) - (whitespace-kill-buffer whitespace-report-buffer-name) - ;; `whitespace-indent-tabs-mode' is local to current buffer - ;; `whitespace-tab-width' is local to current buffer - (let ((ws-indent-tabs-mode whitespace-indent-tabs-mode) - (ws-tab-width whitespace-tab-width)) - (with-current-buffer (get-buffer-create - whitespace-report-buffer-name) - (erase-buffer) - (insert (if ws-indent-tabs-mode - (car whitespace-report-text) - (cdr whitespace-report-text))) - (goto-char (point-min)) - (forward-line 3) - (dolist (option whitespace-report-list) - (forward-line 1) - (whitespace-mark-x - 27 (memq (car option) whitespace-style)) - (whitespace-mark-x 7 (car bogus-list)) - (setq bogus-list (cdr bogus-list))) - (forward-line 1) - (whitespace-insert-value ws-indent-tabs-mode) - (whitespace-insert-value ws-tab-width) - (when has-bogus - (goto-char (point-max)) - (insert " Type `M-x whitespace-cleanup'" - " to cleanup the buffer.\n\n" - " Type `M-x whitespace-cleanup-region'" - " to cleanup a region.\n\n")) - (whitespace-display-window (current-buffer))))) - has-bogus)))) + (let ((bogus-list (whitespace-test-region start end))) + (when (if report-if-bogus bogus-list t) + (whitespace-kill-buffer whitespace-report-buffer-name) + ;; `whitespace-indent-tabs-mode' is local to current buffer + ;; `whitespace-tab-width' is local to current buffer + (let ((ws-indent-tabs-mode whitespace-indent-tabs-mode) + (ws-tab-width whitespace-tab-width)) + (with-current-buffer (get-buffer-create + whitespace-report-buffer-name) + (erase-buffer) + (insert (if ws-indent-tabs-mode + (car whitespace-report-text) + (cdr whitespace-report-text))) + (goto-char (point-min)) + (forward-line 3) + (dolist (option whitespace-report-list) + (forward-line 1) + (whitespace-mark-x + 27 (memq (car option) whitespace-style)) + (whitespace-mark-x 7 (car bogus-list)) + (setq bogus-list (cdr bogus-list))) + (forward-line 1) + (whitespace-insert-value ws-indent-tabs-mode) + (whitespace-insert-value ws-tab-width) + (when bogus-list + (goto-char (point-max)) + (insert " Type `M-x whitespace-cleanup'" + " to cleanup the buffer.\n\n" + " Type `M-x whitespace-cleanup-region'" + " to cleanup a region.\n\n")) + (whitespace-display-window (current-buffer))))) + (null bogus-list)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -- http://rrt.sc3d.org