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: Wed, 27 Feb 2013 21:41:41 +0000 Message-ID: <878v69fn8q.fsf@sc3d.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1362001439 9274 80.91.229.3 (27 Feb 2013 21:43:59 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 27 Feb 2013 21:43:59 +0000 (UTC) To: 13837@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Feb 27 22:44:20 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 1UAonR-0001gh-Bd for geb-bug-gnu-emacs@m.gmane.org; Wed, 27 Feb 2013 22:44:17 +0100 Original-Received: from localhost ([::1]:58103 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UAon3-0001I0-4a for geb-bug-gnu-emacs@m.gmane.org; Wed, 27 Feb 2013 16:43:53 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:42541) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UAomj-0001Dy-4W for bug-gnu-emacs@gnu.org; Wed, 27 Feb 2013 16:43:50 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UAomP-0002jf-Sy for bug-gnu-emacs@gnu.org; Wed, 27 Feb 2013 16:43:27 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:48633) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UAomP-0002j2-Oz for bug-gnu-emacs@gnu.org; Wed, 27 Feb 2013 16:43:13 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1UAooA-0007rl-HC for bug-gnu-emacs@gnu.org; Wed, 27 Feb 2013 16:45:02 -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: Wed, 27 Feb 2013 21:45:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 13837 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.136200148530197 (code B ref -1); Wed, 27 Feb 2013 21:45:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 27 Feb 2013 21:44:45 +0000 Original-Received: from localhost ([127.0.0.1]:54096 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UAons-0007qz-3x for submit@debbugs.gnu.org; Wed, 27 Feb 2013 16:44:45 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:59336) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UAonn-0007qq-UU for submit@debbugs.gnu.org; Wed, 27 Feb 2013 16:44:42 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UAolo-0002aO-9d for submit@debbugs.gnu.org; Wed, 27 Feb 2013 16:42:44 -0500 Original-Received: from lists.gnu.org ([208.118.235.17]:39304) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UAolo-0002ZR-6L for submit@debbugs.gnu.org; Wed, 27 Feb 2013 16:42:36 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:42327) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UAolX-00010Y-6c for bug-gnu-emacs@gnu.org; Wed, 27 Feb 2013 16:42:30 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UAolH-0002NO-EB for bug-gnu-emacs@gnu.org; Wed, 27 Feb 2013 16:42:11 -0500 Original-Received: from exprod7og106.obsmtp.com ([64.18.2.165]:38265) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1UAolG-0002G6-UZ for bug-gnu-emacs@gnu.org; Wed, 27 Feb 2013 16:42:03 -0500 Original-Received: from mail-lb0-f197.google.com ([209.85.217.197]) (using TLSv1) by exprod7ob106.postini.com ([64.18.6.12]) with SMTP ID DSNKUS59mWEXobptxGFDM8IRV+TF6qWekgcY@postini.com; Wed, 27 Feb 2013 13:42:02 PST Original-Received: by mail-lb0-f197.google.com with SMTP id gg6so1310832lbb.8 for ; Wed, 27 Feb 2013 13:41:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-received:from:to:subject:date:message-id:mime-version :content-type:x-gm-message-state; bh=huc69VK243YUcyfqm2UfAU+MCiNglmNHXTFEFjusYGw=; b=WVE3r4vGNtbrXSXrUlkWuaYpurtckDesCYF5GbliqeZEjbdgSHCXYQLMCdqAyqmA9c Abvhf6XIIAmmLbMdMpFwZ8wmvxSiU7/sfYwmyUW6CkPV+r3K1szUEk/b4kiFoVA6VTMW PyT1QrDcowCK0uKQCM/A1ztfubHhop7rueWFYTAGXA89UPglSJ81M6RiNr1snScL0Dz0 LQufYwf8DgmYyVUrIPVqEYqufwebU7BpHpfixTWCkT30FOER5gWLgZ5LKinvEDGJpSRP OQK2wdBsxXt+S27Gaexy0LmRSb/ybse2oSG+TKhX+LeD7EJEWuuXZKW2UIKienUqGkHp 3iyQ== X-Received: by 10.181.13.175 with SMTP id ez15mr28886187wid.8.1362001303124; Wed, 27 Feb 2013 13:41:43 -0800 (PST) X-Received: by 10.181.13.175 with SMTP id ez15mr28886180wid.8.1362001303010; Wed, 27 Feb 2013 13:41:43 -0800 (PST) Original-Received: from skwd ([149.241.115.91]) by mx.google.com with ESMTPS id j4sm29914512wiz.10.2013.02.27.13.41.41 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 27 Feb 2013 13:41:42 -0800 (PST) X-Gm-Message-State: ALoCoQncziAOq/zNHJ628dNhbaQ/lhj0Ctxld1xIg3xifv6vZBMQYPpCudqJHQ+fI7rR2F4LsTSpxWzEohC+w0ABAnbvmYQk2ZId6BuuqqBh8RI3Y/RXO5PvargxqOdGidSnW/ouFiaevip1mT1+XUKPGf7gxAbzWbTTRJuDMYEJ2jDnhulyO5w= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x 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:71929 Archived-At: I like global-whitespace-mode, but it has a downside: it keeps activating in files that have whitespace problems, but which don't belong to me, so I don't want to fix them. Typically I want to make a small edit to someone else's code, and they, entirely reasonably, don't want a big diff. The following code implements a solution to that, which is to check if the buffer is whitespace-clean before activating whitespace-mode. 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. The other part of the solution is easier to integrate: I've factored out part of whitespace-report-region into whitespace-test-region, in a way which is easy to use to implement whitespace-report-region. 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). ;; Make whitespace-turn-on-if-enabled to turn on only if no ;; whitespace problems in current buffer. (require 'whitespace) (defun whitespace-test-region (start end) "Find whether there are whitespace problems in a region. Return nil if there is no whitespace problem; otherwise, return non-nil. 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) (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))) has-bogus)))) (defun whitespace-turn-on-if-enabled () (when (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) ?*) ;; except the scratch buffer. (not (string= (buffer-name) "*scratch*"))) ;; Otherwise, turn on whitespace mode. (whitespace-find-problems-region (point-min) (point-max)) (whitespace-turn-on))))) In GNU Emacs 24.2.1 (x86_64-pc-linux-gnu, GTK+ Version 2.24.13) of 2012-12-13 on komainu, modified by Debian Windowing system distributor `The X.Org Foundation', version 11.0.11300000 Configured using: `configure '--build' 'x86_64-linux-gnu' '--build' 'x86_64-linux-gnu' '--prefix=/usr' '--sharedstatedir=/var/lib' '--libexecdir=/usr/lib' '--localstatedir=/var/lib' '--infodir=/usr/share/info' '--mandir=/usr/share/man' '--with-pop=yes' '--enable-locallisppath=/etc/emacs24:/etc/emacs:/usr/local/share/emacs/24.2/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/24.2/site-lisp:/usr/share/emacs/site-lisp' '--with-crt-dir=/usr/lib/x86_64-linux-gnu' '--with-x=yes' '--with-x-toolkit=gtk' '--with-toolkit-scroll-bars' 'build_alias=x86_64-linux-gnu' 'CFLAGS=-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wall' 'CPPFLAGS=-D_FORTIFY_SOURCE=2'' Important settings: value of $LC_ALL: nil value of $LC_COLLATE: nil value of $LC_CTYPE: nil value of $LC_MESSAGES: nil value of $LC_MONETARY: en_GB.UTF-8 value of $LC_NUMERIC: en_GB.UTF-8 value of $LC_TIME: en_GB.UTF-8 value of $LANG: en_GB.UTF-8 value of $XMODIFIERS: nil locale-coding-system: utf-8-unix default enable-multibyte-characters: t Major mode: Emacs-Lisp Minor modes in effect: recentf-mode: t show-paren-mode: t server-mode: t savehist-mode: t minibuffer-electric-default-mode: t iswitchb-mode: t icomplete-mode: t global-whitespace-mode: t global-auto-revert-mode: t dtrt-indent-mode: t desktop-save-mode: t TeX-PDF-mode: t TeX-source-correlate-mode: t tooltip-mode: t mouse-wheel-mode: t file-name-shadow-mode: t global-font-lock-mode: t font-lock-mode: t blink-cursor-mode: t auto-composition-mode: t auto-encryption-mode: t auto-compression-mode: t column-number-mode: t line-number-mode: t transient-mark-mode: t Recent input: SPC SPC C-x C-s C-x k C-x k C-x b C-x b C-s C-a C-] C-] C-] C-x b f u n s C-a C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-SPC C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-p C-g C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-n M a k e C-x C-s C-a C-SPC C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-p M-w M-x r e p o r t - b e m a c s - b u g Recent messages: Saving file /home/rrt/Software/hacked/cw/bar.c... Wrote /home/rrt/Software/hacked/cw/bar.c Quit call-interactively: No recursive edit is in progress [2 times] Mark set Quit Saving file /home/rrt/.emacs.d/funs.el... Wrote /home/rrt/.emacs.d/funs.el Mark activated Saved text from ";; Make whitespace-turn-on-if-enabled to" Load-path shadows: /home/rrt/local/share/emacs/site-lisp/browse-kill-ring hides /usr/share/emacs24/site-lisp/emacs-goodies-el/browse-kill-ring /home/rrt/local/share/emacs/site-lisp/dict hides /usr/share/emacs24/site-lisp/emacs-goodies-el/dict /home/rrt/.emacs.d/elpa/dictionary-1.8.7/dictionary-init hides /usr/share/emacs24/site-lisp/dictionary-el/dictionary-init /home/rrt/.emacs.d/elpa/dictionary-1.8.7/dictionary hides /usr/share/emacs24/site-lisp/dictionary-el/dictionary /home/rrt/.emacs.d/elpa/dictionary-1.8.7/link hides /usr/share/emacs24/site-lisp/dictionary-el/link /home/rrt/.emacs.d/elpa/dictionary-1.8.7/connection hides /usr/share/emacs24/site-lisp/dictionary-el/connection /usr/share/emacs24/site-lisp/auctex/tex-style hides /usr/share/emacs/site-lisp/auctex/tex-style /usr/share/emacs24/site-lisp/auctex/tex-mik hides /usr/share/emacs/site-lisp/auctex/tex-mik /usr/share/emacs24/site-lisp/auctex/multi-prompt hides /usr/share/emacs/site-lisp/auctex/multi-prompt /usr/share/emacs24/site-lisp/auctex/tex-jp hides /usr/share/emacs/site-lisp/auctex/tex-jp /usr/share/emacs24/site-lisp/auctex/tex-info hides /usr/share/emacs/site-lisp/auctex/tex-info /usr/share/emacs24/site-lisp/auctex/plain-tex hides /usr/share/emacs/site-lisp/auctex/plain-tex /usr/share/emacs24/site-lisp/auctex/latex hides /usr/share/emacs/site-lisp/auctex/latex /usr/share/emacs24/site-lisp/auctex/preview hides /usr/share/emacs/site-lisp/auctex/preview /usr/share/emacs24/site-lisp/auctex/tex hides /usr/share/emacs/site-lisp/auctex/tex /usr/share/emacs24/site-lisp/auctex/texmathp hides /usr/share/emacs/site-lisp/auctex/texmathp /usr/share/emacs24/site-lisp/auctex/context-nl hides /usr/share/emacs/site-lisp/auctex/context-nl /usr/share/emacs24/site-lisp/auctex/tex-font hides /usr/share/emacs/site-lisp/auctex/tex-font /usr/share/emacs24/site-lisp/auctex/toolbar-x hides /usr/share/emacs/site-lisp/auctex/toolbar-x /usr/share/emacs24/site-lisp/auctex/tex-buf hides /usr/share/emacs/site-lisp/auctex/tex-buf /usr/share/emacs24/site-lisp/auctex/bib-cite hides /usr/share/emacs/site-lisp/auctex/bib-cite /usr/share/emacs24/site-lisp/auctex/context-en hides /usr/share/emacs/site-lisp/auctex/context-en /usr/share/emacs24/site-lisp/auctex/tex-fold hides /usr/share/emacs/site-lisp/auctex/tex-fold /usr/share/emacs24/site-lisp/auctex/tex-bar hides /usr/share/emacs/site-lisp/auctex/tex-bar /usr/share/emacs24/site-lisp/auctex/context hides /usr/share/emacs/site-lisp/auctex/context /usr/share/emacs24/site-lisp/auctex/prv-emacs hides /usr/share/emacs/site-lisp/auctex/prv-emacs /usr/share/emacs24/site-lisp/auctex/font-latex hides /usr/share/emacs/site-lisp/auctex/font-latex /usr/share/emacs/site-lisp/golang-mode/go-mode-load hides /usr/share/emacs/24.2/site-lisp/golang-mode/go-mode-load /usr/share/emacs/site-lisp/golang-mode/go-mode hides /usr/share/emacs/24.2/site-lisp/golang-mode/go-mode /usr/share/emacs/24.2/site-lisp/cmake-data/cmake-mode hides /usr/share/emacs/site-lisp/cmake-mode /usr/share/emacs/24.2/site-lisp/cdargs hides /usr/share/emacs/site-lisp/cdargs /usr/share/emacs/site-lisp/rst hides /usr/share/emacs/24.2/lisp/textmodes/rst /usr/share/emacs24/site-lisp/dictionaries-common/ispell hides /usr/share/emacs/24.2/lisp/textmodes/ispell /usr/share/emacs24/site-lisp/dictionaries-common/flyspell hides /usr/share/emacs/24.2/lisp/textmodes/flyspell /home/rrt/local/share/emacs/site-lisp/flymake hides /usr/share/emacs/24.2/lisp/progmodes/flymake Features: (shadow sort mail-extr emacsbug message format-spec rfc822 mml mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums mail-utils find-func help-mode view cperl-mode sh-script executable nroff-mode conf-mode newcomment misearch multi-isearch jka-compr rect todoo noutline outline lua-mode autoconf autoconf-mode make-mode vc-git cc-mode cc-fonts cc-guess cc-menus cc-cmds cc-styles cc-align cc-engine cc-vars cc-defs flymake compile comint ansi-color ring face-remap flyspell ispell smart-quotes auto-dictionary-autoloads c-eldoc-autoloads dictionary-autoloads diff-git-autoloads dired-isearch-autoloads full-ack-autoloads guess-style-autoloads kill-ring-search-autoloads magit-autoloads mv-shell-autoloads tumble-autoloads http-post-simple-autoloads package tabulated-list completing-help recentf tree-widget wid-edit uniquify paren server savehist minibuf-eldef iswitchb icomplete whitespace autorevert dtrt-indent desktop cus-start cus-load ropemacs pymacs warnings url-util url-parse auth-source eieio byte-opt bytecomp byte-compile cconv macroexp gnus-util password-cache url-vars mm-util mail-prsvr tex dbus xml regexp-opt remember user-site-loaddefs advice advice-preload yasnippet help-fns derived edmacro kmacro easymenu assoc cl muse-autoloads go-mode-load emacs-goodies-el emacs-goodies-custom emacs-goodies-loaddefs easy-mmode preview-latex tex-site auto-loads time-date tooltip ediff-hook vc-hooks lisp-float-type mwheel x-win x-dnd tool-bar dnd fontset image fringe lisp-mode register page menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock font-lock syntax facemenu font-core frame cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean japanese hebrew greek romanian slovak czech european ethiopic indian cyrillic chinese case-table epa-hook jka-cmpr-hook help simple abbrev minibuffer loaddefs button faces cus-face files text-properties overlay sha1 md5 base64 format env code-pages mule custom widget hashtable-print-readable backquote make-network-process dbusbind dynamic-setting system-font-setting font-render-setting move-toolbar gtk x-toolkit x multi-tty emacs) -- http://rrt.sc3d.org/