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: Thu, 28 Feb 2013 11:23:33 -0500 Message-ID: References: <878v69fn8q.fsf@sc3d.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1362068652 24343 80.91.229.3 (28 Feb 2013 16:24:12 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 28 Feb 2013 16:24:12 +0000 (UTC) Cc: 13837@debbugs.gnu.org To: Reuben Thomas Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Feb 28 17:24:35 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 1UB6HY-0005cs-Jo for geb-bug-gnu-emacs@m.gmane.org; Thu, 28 Feb 2013 17:24:32 +0100 Original-Received: from localhost ([::1]:36123 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UB6HD-0000v6-Gx for geb-bug-gnu-emacs@m.gmane.org; Thu, 28 Feb 2013 11:24:11 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:58184) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UB6H9-0000tZ-Ng for bug-gnu-emacs@gnu.org; Thu, 28 Feb 2013 11:24:09 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UB6H8-0006Tt-Cm for bug-gnu-emacs@gnu.org; Thu, 28 Feb 2013 11:24:07 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:50923) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UB6H8-0006To-9s for bug-gnu-emacs@gnu.org; Thu, 28 Feb 2013 11:24:06 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1UB6J0-0002QA-L1 for bug-gnu-emacs@gnu.org; Thu, 28 Feb 2013 11:26:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 28 Feb 2013 16:26:02 +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.13620687369271 (code B ref 13837); Thu, 28 Feb 2013 16:26:02 +0000 Original-Received: (at 13837) by debbugs.gnu.org; 28 Feb 2013 16:25:36 +0000 Original-Received: from localhost ([127.0.0.1]:56387 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UB6IY-0002PT-Sb for submit@debbugs.gnu.org; Thu, 28 Feb 2013 11:25:35 -0500 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.182]:23261) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UB6IW-0002PL-2K for 13837@debbugs.gnu.org; Thu, 28 Feb 2013 11:25:32 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av8EABK/CFFFpaTU/2dsb2JhbABEuzWDWRdzgh4BAQQBViMFCwsOJgcLFBgNJC6HcAbBLZEKA4hhnBmBXoMVgUgk X-IPAS-Result: Av8EABK/CFFFpaTU/2dsb2JhbABEuzWDWRdzgh4BAQQBViMFCwsOJgcLFBgNJC6HcAbBLZEKA4hhnBmBXoMVgUgk X-IronPort-AV: E=Sophos;i="4.84,565,1355115600"; d="scan'208";a="2694313" Original-Received: from 69-165-164-212.dsl.teksavvy.com (HELO pastel.home) ([69.165.164.212]) by ironport2-out.teksavvy.com with ESMTP/TLS/ADH-AES256-SHA; 28 Feb 2013 11:23:32 -0500 Original-Received: by pastel.home (Postfix, from userid 20848) id BC98E6BDCD; Thu, 28 Feb 2013 11:23:33 -0500 (EST) In-Reply-To: <878v69fn8q.fsf@sc3d.org> (Reuben Thomas's message of "Wed, 27 Feb 2013 21:41:41 +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.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:71952 Archived-At: > Unfortunately, my current solution is non-optional: it requires > modifying whitespace-turn-on-if-enabled. This could be fixed, for > example by adding a preference. Indeed. I suggest to add a whitespace-enable-predicate hook. Then you can do (defun whitespace-check-cleanliness () (not (whitespace-test-region (point-min) (point-max)))) (add-function :after-while whitespace-enable-predicate #'whitespace-check-cleanliness) > If maintainers are interested in adding this feature, I'd be happy to > take guidance on how to modify my code into a patch (currently it just > sits in my .emacs). You can start with the patch below, and refactor the whitespace-report-region so as to provide whitespace-test-region. Your .emacs can then be reduced to the above 4 lines, and if you add the whitespace-check-cleanliness function to whitespace.el that gets reduced to just 2 lines. Stefan === modified file 'lisp/whitespace.el' --- lisp/whitespace.el 2013-01-11 23:08:55 +0000 +++ lisp/whitespace.el 2013-02-28 16:19:01 +0000 @@ -1145,29 +1145,31 @@ (unless whitespace-mode (whitespace-turn-off))))))) - -(defun whitespace-turn-on-if-enabled () - (when (cond +(defvar whitespace-enable-predicate + (lambda () + (and (cond ((eq whitespace-global-modes t)) ((listp whitespace-global-modes) (if (eq (car-safe whitespace-global-modes) 'not) (not (memq major-mode (cdr whitespace-global-modes))) (memq major-mode whitespace-global-modes))) (t nil)) - (let (inhibit-quit) - ;; Don't turn on whitespace mode if... - (or - ;; ...we don't have a display (we're running a batch job) - noninteractive - ;; ...or if the buffer is invisible (name starts with a space) - (eq (aref (buffer-name) 0) ?\ ) - ;; ...or if the buffer is temporary (name starts with *) - (and (eq (aref (buffer-name) 0) ?*) + ;; ...we have a display (we're running a batch job) + (not noninteractive) + ;; ...the buffer is not internal (name starts with a space) + (not (eq (aref (buffer-name) 0) ?\ )) + ;; ...the buffer is not special (name starts with *) + (or (not (eq (aref (buffer-name) 0) ?*)) ;; except the scratch buffer. - (not (string= (buffer-name) "*scratch*"))) - ;; Otherwise, turn on whitespace mode. - (whitespace-turn-on))))) + (string= (buffer-name) "*scratch*")))) + "Predicate to decide which buffers obey `global-whitespace-mode'. +This function is called with no argument and should return non-nil +if the current buffer should obey `global-whitespace-mode'. +This variable is normally modified via `add-function'.") +(defun whitespace-turn-on-if-enabled () + (when (funcall whitespace-enable-predicate) + (whitespace-turn-on))) ;;;###autoload (define-minor-mode global-whitespace-newline-mode