From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#13837: 24.2; Make it possible to turn whitespace-mode only when there are no existing problems Date: Sun, 26 Jan 2014 20:52:50 -0500 Message-ID: References: <878v69fn8q.fsf@sc3d.org> <87mwiiz5im.fsf@yandex.ru> <52E5A807.1040804@yandex.ru> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1390787596 14296 80.91.229.3 (27 Jan 2014 01:53:16 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 27 Jan 2014 01:53:16 +0000 (UTC) Cc: 13837@debbugs.gnu.org, Dmitry Gutov To: Reuben Thomas Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Jan 27 02:53:22 2014 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 1W7bO4-0001yW-WA for geb-bug-gnu-emacs@m.gmane.org; Mon, 27 Jan 2014 02:53:21 +0100 Original-Received: from localhost ([::1]:56980 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W7bO4-0003Gt-Mq for geb-bug-gnu-emacs@m.gmane.org; Sun, 26 Jan 2014 20:53:20 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44002) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W7bNu-0003Gl-6a for bug-gnu-emacs@gnu.org; Sun, 26 Jan 2014 20:53:17 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W7bNm-0002Zs-Mo for bug-gnu-emacs@gnu.org; Sun, 26 Jan 2014 20:53:10 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:51282) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W7bNm-0002Zn-JN for bug-gnu-emacs@gnu.org; Sun, 26 Jan 2014 20:53:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1W7bNm-0004z0-4E for bug-gnu-emacs@gnu.org; Sun, 26 Jan 2014 20:53:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 27 Jan 2014 01:53: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.139078757519141 (code B ref 13837); Mon, 27 Jan 2014 01:53:01 +0000 Original-Received: (at 13837) by debbugs.gnu.org; 27 Jan 2014 01:52:55 +0000 Original-Received: from localhost ([127.0.0.1]:37068 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1W7bNe-0004yf-Kg for submit@debbugs.gnu.org; Sun, 26 Jan 2014 20:52:55 -0500 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.181]:27997) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1W7bNb-0004yW-P7 for 13837@debbugs.gnu.org; Sun, 26 Jan 2014 20:52:52 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av8EABK/CFFsoXJr/2dsb2JhbABEuzWDWRdzgh4BAQQBViMFCwsOJgcLFBgNJIgeBsEtkQoDiGGJeZIggV6DFQ X-IPAS-Result: Av8EABK/CFFsoXJr/2dsb2JhbABEuzWDWRdzgh4BAQQBViMFCwsOJgcLFBgNJIgeBsEtkQoDiGGJeZIggV6DFQ X-IronPort-AV: E=Sophos;i="4.84,565,1355115600"; d="scan'208";a="46125162" Original-Received: from 108-161-114-107.dsl.teksavvy.com (HELO pastel.home) ([108.161.114.107]) by ironport2-out.teksavvy.com with ESMTP/TLS/ADH-AES256-SHA; 26 Jan 2014 20:52:50 -0500 Original-Received: by pastel.home (Postfix, from userid 20848) id 4DD4160286; Sun, 26 Jan 2014 20:52:50 -0500 (EST) In-Reply-To: (Reuben Thomas's message of "Mon, 27 Jan 2014 00:41:19 +0000") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.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:84079 Archived-At: > Thanks for that information, I can try to remember to tag bugs in future > when I provide a patch. I could be convinced to install it if it's "obviously safe". The patch as sent is a large chunk of "new" code plus a large chunk of "removed" code, so it's not very appealing. Diffing while ignoring whitespace indicates it's more of a "refactoring", and by introducing an "artificial" new function while helps keep the text lines in the original order (and hence helps reduce the size of the diff), I get the patch below. But it's not obviously safe to me. Two non-obvious parts are: - the removal of "(add-to-list 'whitespace-style (car option))". - the change from has-bogus to bogus-list, where bogus-list will (initially) only be nil if whitespace-report-list is nil. Another problem is that the docstring of whitespace-test-region does not accurately describe its return value. So it's probably best to keep it for after 24.4, but let's try to deal with it as soon as the trunk reopens (real soon now). Stefan === modified file 'lisp/whitespace.el' --- lisp/whitespace.el 2014-01-06 06:25:30 +0000 +++ lisp/whitespace.el 2014-01-27 01:35:49 +0000 @@ -1779,7 +1779,20 @@ 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: +For a description of whitespace problems, see +`whitespace-test-region'." + (interactive "r") + (setq force (or current-prefix-arg force)) + (whitespace--report-region start end force report-if-bogus)) + +;;;###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. @@ -1800,18 +1813,13 @@ See `whitespace-style' for documentation. See also `whitespace-cleanup' and `whitespace-cleanup-region' for cleaning up these problems." - (interactive "r") - (setq force (or current-prefix-arg force)) (save-excursion (save-match-data ;FIXME: Why? - (let* ((has-bogus nil) - (rstart (min start end)) + (let* ((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 @@ -1830,9 +1838,14 @@ (t (cdr option))))) (and (re-search-forward regexp rend t) - (setq has-bogus t)))) + t))) whitespace-report-list))) - (when (if report-if-bogus has-bogus t) + bogus-list)))) + +(defun whitespace--report-region (start end &optional force report-if-bogus) + (save-excursion + (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 @@ -1855,14 +1868,14 @@ (forward-line 1) (whitespace-insert-value ws-indent-tabs-mode) (whitespace-insert-value ws-tab-width) - (when has-bogus + (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))))) - has-bogus)))) + (null bogus-list)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;