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: Fri, 1 Mar 2013 22:21:41 +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 1362176527 21134 80.91.229.3 (1 Mar 2013 22:22:07 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 1 Mar 2013 22:22:07 +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 Fri Mar 01 23:22:28 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 1UBYLR-0001sn-H5 for geb-bug-gnu-emacs@m.gmane.org; Fri, 01 Mar 2013 23:22:25 +0100 Original-Received: from localhost ([::1]:40642 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UBYL5-0000gO-Vu for geb-bug-gnu-emacs@m.gmane.org; Fri, 01 Mar 2013 17:22:03 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:48211) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UBYL2-0000gJ-Rh for bug-gnu-emacs@gnu.org; Fri, 01 Mar 2013 17:22:01 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UBYL0-0006zj-C7 for bug-gnu-emacs@gnu.org; Fri, 01 Mar 2013 17:22:00 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:53242) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UBYL0-0006zf-8G for bug-gnu-emacs@gnu.org; Fri, 01 Mar 2013 17:21:58 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1UBYMz-0006MY-Ta for bug-gnu-emacs@gnu.org; Fri, 01 Mar 2013 17:24: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: Fri, 01 Mar 2013 22:24: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.136217663124442 (code B ref 13837); Fri, 01 Mar 2013 22:24:01 +0000 Original-Received: (at 13837) by debbugs.gnu.org; 1 Mar 2013 22:23:51 +0000 Original-Received: from localhost ([127.0.0.1]:58706 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UBYMo-0006MB-Vv for submit@debbugs.gnu.org; Fri, 01 Mar 2013 17:23:51 -0500 Original-Received: from exprod7og104.obsmtp.com ([64.18.2.161]:60799) by debbugs.gnu.org with smtp (Exim 4.72) (envelope-from ) id 1UBYMm-0006M2-8j for 13837@debbugs.gnu.org; Fri, 01 Mar 2013 17:23:49 -0500 Original-Received: from mail-fa0-f71.google.com ([209.85.161.71]) (using TLSv1) by exprod7ob104.postini.com ([64.18.6.12]) with SMTP ID DSNKUTEp95DM7AB82mqSwvPYmnmHNYh8etGX@postini.com; Fri, 01 Mar 2013 14:21:43 PST Original-Received: by mail-fa0-f71.google.com with SMTP id t1so4232365fae.10 for <13837@debbugs.gnu.org>; Fri, 01 Mar 2013 14:21:41 -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=/bbT8rzj9XKdnIlAZj9/7OEo6+GSaFCTL9dsgSdNxBE=; b=e/0Gk5JfBS/6zQpYhN49QDCU2Pgwzd0xvW/X5xATXUoz5MhuppZDyiwJ8DQ8Pe7njo 4dTpVe/iuZbScuIrKuFUTNNvdaiL+EVNBu4ZouSUsar/dgrwqugPJugIBGR1abTcOjvR IOolvw/1PBAHFnS1HJJ2+ZxSzapPK/oOP9IM8YB5WKR8u5l9k0qsSTPS4LTYBNv5g5cG WTsHW/Fa/MfjI3z6HXuCAk6b9p3KmsRfnwIUm/bSg8BwHAusmApvQBqN/MCSMFr8DEjW iAurmj26Uw/dXRlRSWocRiqlpNSC5UoVCcRrYlia7dX0fevVHgVvuIfbMKzlP82kk/jQ D4GQ== X-Received: by 10.152.109.112 with SMTP id hr16mr10560163lab.38.1362176501610; Fri, 01 Mar 2013 14:21:41 -0800 (PST) X-Received: by 10.152.109.112 with SMTP id hr16mr10560158lab.38.1362176501464; Fri, 01 Mar 2013 14:21:41 -0800 (PST) Original-Received: by 10.152.5.40 with HTTP; Fri, 1 Mar 2013 14:21:41 -0800 (PST) In-Reply-To: X-Gm-Message-State: ALoCoQlBKf6gLalDsXlpnS1lfzExEABlTgEibpuTV9gM4DdOj5UK5IOHQqhmEaj8F6KHXDASndG8G/gck7RuK+pVUCeFVbb6KCD5a/bun3VIuFOT8Yjok9onlvyDL6oUy0jCtR6QfERJXW8enL5XXABlc44yYvT2CuDG9xowtiEMTqTHZDeUlmM= 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:72005 Archived-At: On 28 February 2013 16:23, Stefan Monnier wrote: > > You can =85 refactor the > whitespace-report-region so as to provide whitespace-test-region. Here's an attempt at that: (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)))) (defun whitespace-report-region (start end &optional force report-if-bogus) "Report some whitespace problems in a region. Return nil if there is no whitespace problem; otherwise, return non-nil. If FORCE is non-nil or \\[universal-argument] was pressed just before calling `whitespace-report-region' interactively, it forces `whitespace-style' to have: empty indentation space-before-tab trailing space-after-tab If REPORT-IF-BOGUS is non-nil, it reports only when there are any whitespace problems in buffer. For a description of whitespace problems, see `whitespace-test-region'." (interactive "r") (setq force (or current-prefix-arg force)) (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 (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))))