]> git.eshelyaron.com Git - emacs.git/commitdiff
Refactor out setting `whitespace-indent-tabs-mode' and
authorTassilo Horn <tsdh@gnu.org>
Thu, 1 Aug 2013 12:58:28 +0000 (14:58 +0200)
committerTassilo Horn <tsdh@gnu.org>
Thu, 1 Aug 2013 12:58:28 +0000 (14:58 +0200)
`whitespace-tab-width' buffer-locally to own function, so that
`whitespace-cleanup' and friends work appropriately without
needing to enable `whitespace-mode'.

* whitespace.el (whitespace-ensure-local-variables): New function.
(whitespace-cleanup-region): Call it.
(whitespace-turn-on): Call it.

lisp/ChangeLog
lisp/whitespace.el

index e80c34d384283bd6f6c8a3f2de07a6bfd4dd67ca..d6623caed0818eed1ce619c75f49af43b351e332 100644 (file)
@@ -1,3 +1,9 @@
+2013-08-01  Tassilo Horn  <tsdh@gnu.org>
+
+       * whitespace.el (whitespace-ensure-local-variables): New function.
+       (whitespace-cleanup-region): Call it.
+       (whitespace-turn-on): Call it.
+
 2013-08-01  Michael Albinus  <michael.albinus@gmx.de>
 
        Complete file name handlers.
index 801cdc52047bd571371aff96f07c8428bce2c372..b462cf0b8113e7015c836f5820a5947f16ee9e94 100644 (file)
@@ -1471,6 +1471,12 @@ documentation."
     ;; PROBLEM 6: 8 or more SPACEs after TAB
     (whitespace-cleanup-region (point-min) (point-max)))))
 
+(defun whitespace-ensure-local-variables ()
+  "Set `whitespace-indent-tabs-mode' and `whitespace-tab-width' locally."
+  (set (make-local-variable 'whitespace-indent-tabs-mode)
+       indent-tabs-mode)
+  (set (make-local-variable 'whitespace-tab-width)
+       tab-width))
 
 ;;;###autoload
 (defun whitespace-cleanup-region (start end)
@@ -1517,6 +1523,7 @@ documentation."
       ;; read-only buffer
       (whitespace-warn-read-only "cleanup region")
     ;; non-read-only buffer
+    (whitespace-ensure-local-variables)
     (let ((rstart           (min start end))
          (rend             (copy-marker (max start end)))
          (indent-tabs-mode whitespace-indent-tabs-mode)
@@ -2095,7 +2102,6 @@ resultant list will be returned."
 (defvar whitespace-display-table-was-local nil
   "Used to remember whether a buffer initially had a local display table.")
 
-
 (defun whitespace-turn-on ()
   "Turn on whitespace visualization."
   ;; prepare local hooks
@@ -2108,10 +2114,7 @@ resultant list will be returned."
        (if (listp whitespace-style)
           whitespace-style
         (list whitespace-style)))
-  (set (make-local-variable 'whitespace-indent-tabs-mode)
-       indent-tabs-mode)
-  (set (make-local-variable 'whitespace-tab-width)
-       tab-width)
+  (whitespace-ensure-local-variables)
   ;; turn on whitespace
   (when whitespace-active-style
     (whitespace-color-on)