emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r111994: * lisp/whitespace.el (whites


From: Stefan Monnier
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r111994: * lisp/whitespace.el (whitespace-enable-predicate): New variable.
Date: Sun, 10 Mar 2013 17:39:11 -0400
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 111994
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Sun 2013-03-10 17:39:11 -0400
message:
  * lisp/whitespace.el (whitespace-enable-predicate): New variable.
  (whitespace-enable-predicate): Use it.
modified:
  lisp/ChangeLog
  lisp/whitespace.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2013-03-10 21:37:42 +0000
+++ b/lisp/ChangeLog    2013-03-10 21:39:11 +0000
@@ -1,5 +1,8 @@
 2013-03-10  Stefan Monnier  <address@hidden>
 
+       * whitespace.el (whitespace-enable-predicate): New variable.
+       (whitespace-enable-predicate): Use it.
+
        * comint.el (comint-send-input, comint-snapshot-last-prompt)
        (comint-output-filter, comint-update-fence):
        Use with-silent-modifications.

=== modified file 'lisp/whitespace.el'
--- a/lisp/whitespace.el        2013-01-11 23:08:55 +0000
+++ b/lisp/whitespace.el        2013-03-10 21:39:11 +0000
@@ -1145,29 +1145,31 @@
        (unless whitespace-mode
          (whitespace-turn-off)))))))
 
+(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))
+         ;; ...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.
+             (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 (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-turn-on)))))
-
+  (when (funcall whitespace-enable-predicate)
+    (whitespace-turn-on)))
 
 ;;;###autoload
 (define-minor-mode global-whitespace-newline-mode


reply via email to

[Prev in Thread] Current Thread [Next in Thread]