aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorReuben Thomas2017-03-02 12:50:06 +0000
committerNoam Postavsky2017-04-20 22:39:15 -0400
commita6b375ba4bfc9453abc428dcb73e65bfcf61b794 (patch)
treee1ee2f1544f7d3c40e1131992eec95de4423f0aa
parentd490770dd09f1121b637eebdad82531de654189b (diff)
downloademacs-a6b375ba4bfc9453abc428dcb73e65bfcf61b794.tar.gz
emacs-a6b375ba4bfc9453abc428dcb73e65bfcf61b794.zip
Fix reading of tab settings in whitespace-mode
lisp/whitespace.el (whitespace-indent-tabs-mode) whitespace-tab-width): Remove these variables. The underlying variables `indent-tabs-mode' and `tab-width' are already buffer-local when needed, and whitespace-mode never changes them. (whitespace-ensure-local-variables): Remove this function, which only existed to set the above variables. (whitespace-cleanup-region, whitespace-regexp) (whitespace-indentation-regexp, whitespace-report-region) (whitespace-turn-on, whitespace-color-on): Adjust these functions to use `indent-tabs-mode' and `tab-width' directly, and not call `whitespace-ensure-local-variables'.
-rw-r--r--lisp/whitespace.el52
1 files changed, 18 insertions, 34 deletions
diff --git a/lisp/whitespace.el b/lisp/whitespace.el
index 6c4f59d2879..6aca47cd437 100644
--- a/lisp/whitespace.el
+++ b/lisp/whitespace.el
@@ -1134,12 +1134,6 @@ SYMBOL is a valid symbol associated with CHAR.
1134(defvar whitespace-active-style nil 1134(defvar whitespace-active-style nil
1135 "Used to save locally `whitespace-style' value.") 1135 "Used to save locally `whitespace-style' value.")
1136 1136
1137(defvar whitespace-indent-tabs-mode indent-tabs-mode
1138 "Used to save locally `indent-tabs-mode' value.")
1139
1140(defvar whitespace-tab-width tab-width
1141 "Used to save locally `tab-width' value.")
1142
1143(defvar whitespace-point (point) 1137(defvar whitespace-point (point)
1144 "Used to save locally current point value. 1138 "Used to save locally current point value.
1145Used by function `whitespace-trailing-regexp' (which see).") 1139Used by function `whitespace-trailing-regexp' (which see).")
@@ -1415,12 +1409,6 @@ documentation."
1415 ;; PROBLEM 6: `tab-width' or more SPACEs after TAB 1409 ;; PROBLEM 6: `tab-width' or more SPACEs after TAB
1416 (whitespace-cleanup-region (point-min) (point-max))))) 1410 (whitespace-cleanup-region (point-min) (point-max)))))
1417 1411
1418(defun whitespace-ensure-local-variables ()
1419 "Set `whitespace-indent-tabs-mode' and `whitespace-tab-width' locally."
1420 (set (make-local-variable 'whitespace-indent-tabs-mode)
1421 indent-tabs-mode)
1422 (set (make-local-variable 'whitespace-tab-width)
1423 tab-width))
1424 1412
1425;;;###autoload 1413;;;###autoload
1426(defun whitespace-cleanup-region (start end) 1414(defun whitespace-cleanup-region (start end)
@@ -1467,11 +1455,8 @@ documentation."
1467 ;; read-only buffer 1455 ;; read-only buffer
1468 (whitespace-warn-read-only "cleanup region") 1456 (whitespace-warn-read-only "cleanup region")
1469 ;; non-read-only buffer 1457 ;; non-read-only buffer
1470 (whitespace-ensure-local-variables)
1471 (let ((rstart (min start end)) 1458 (let ((rstart (min start end))
1472 (rend (copy-marker (max start end))) 1459 (rend (copy-marker (max start end)))
1473 (indent-tabs-mode whitespace-indent-tabs-mode)
1474 (tab-width whitespace-tab-width)
1475 overwrite-mode ; enforce no overwrite 1460 overwrite-mode ; enforce no overwrite
1476 tmp) 1461 tmp)
1477 (save-excursion 1462 (save-excursion
@@ -1512,7 +1497,7 @@ documentation."
1512 ;; by SPACEs. 1497 ;; by SPACEs.
1513 ((memq 'space-after-tab whitespace-style) 1498 ((memq 'space-after-tab whitespace-style)
1514 (whitespace-replace-action 1499 (whitespace-replace-action
1515 (if whitespace-indent-tabs-mode 'tabify 'untabify) 1500 (if indent-tabs-mode 'tabify 'untabify)
1516 rstart rend (whitespace-space-after-tab-regexp) 1)) 1501 rstart rend (whitespace-space-after-tab-regexp) 1))
1517 ;; ACTION: replace `tab-width' or more SPACEs by TABs. 1502 ;; ACTION: replace `tab-width' or more SPACEs by TABs.
1518 ((memq 'space-after-tab::tab whitespace-style) 1503 ((memq 'space-after-tab::tab whitespace-style)
@@ -1531,9 +1516,9 @@ documentation."
1531 ;; by SPACEs. 1516 ;; by SPACEs.
1532 ((memq 'space-before-tab whitespace-style) 1517 ((memq 'space-before-tab whitespace-style)
1533 (whitespace-replace-action 1518 (whitespace-replace-action
1534 (if whitespace-indent-tabs-mode 'tabify 'untabify) 1519 (if indent-tabs-mode 'tabify 'untabify)
1535 rstart rend whitespace-space-before-tab-regexp 1520 rstart rend whitespace-space-before-tab-regexp
1536 (if whitespace-indent-tabs-mode 0 2))) 1521 (if indent-tabs-mode 0 2)))
1537 ;; ACTION: replace SPACEs before TAB by TABs. 1522 ;; ACTION: replace SPACEs before TAB by TABs.
1538 ((memq 'space-before-tab::tab whitespace-style) 1523 ((memq 'space-before-tab::tab whitespace-style)
1539 (whitespace-replace-action 1524 (whitespace-replace-action
@@ -1564,25 +1549,25 @@ See also `tab-width'."
1564 1549
1565 1550
1566(defun whitespace-regexp (regexp &optional kind) 1551(defun whitespace-regexp (regexp &optional kind)
1567 "Return REGEXP depending on `whitespace-indent-tabs-mode'." 1552 "Return REGEXP depending on `indent-tabs-mode'."
1568 (format 1553 (format
1569 (cond 1554 (cond
1570 ((or (eq kind 'tab) 1555 ((or (eq kind 'tab)
1571 whitespace-indent-tabs-mode) 1556 indent-tabs-mode)
1572 (car regexp)) 1557 (car regexp))
1573 ((or (eq kind 'space) 1558 ((or (eq kind 'space)
1574 (not whitespace-indent-tabs-mode)) 1559 (not indent-tabs-mode))
1575 (cdr regexp))) 1560 (cdr regexp)))
1576 whitespace-tab-width)) 1561 tab-width))
1577 1562
1578 1563
1579(defun whitespace-indentation-regexp (&optional kind) 1564(defun whitespace-indentation-regexp (&optional kind)
1580 "Return the indentation regexp depending on `whitespace-indent-tabs-mode'." 1565 "Return the indentation regexp depending on `indent-tabs-mode'."
1581 (whitespace-regexp whitespace-indentation-regexp kind)) 1566 (whitespace-regexp whitespace-indentation-regexp kind))
1582 1567
1583 1568
1584(defun whitespace-space-after-tab-regexp (&optional kind) 1569(defun whitespace-space-after-tab-regexp (&optional kind)
1585 "Return the space-after-tab regexp depending on `whitespace-indent-tabs-mode'." 1570 "Return the space-after-tab regexp depending on `indent-tabs-mode'."
1586 (whitespace-regexp whitespace-space-after-tab-regexp kind)) 1571 (whitespace-regexp whitespace-space-after-tab-regexp kind))
1587 1572
1588 1573
@@ -1744,10 +1729,10 @@ cleaning up these problems."
1744 whitespace-report-list))) 1729 whitespace-report-list)))
1745 (when (pcase report-if-bogus (`nil t) (`never nil) (_ has-bogus)) 1730 (when (pcase report-if-bogus (`nil t) (`never nil) (_ has-bogus))
1746 (whitespace-kill-buffer whitespace-report-buffer-name) 1731 (whitespace-kill-buffer whitespace-report-buffer-name)
1747 ;; `whitespace-indent-tabs-mode' is local to current buffer 1732 ;; `indent-tabs-mode' may be local to current buffer
1748 ;; `whitespace-tab-width' is local to current buffer 1733 ;; `tab-width' may be local to current buffer
1749 (let ((ws-indent-tabs-mode whitespace-indent-tabs-mode) 1734 (let ((ws-indent-tabs-mode indent-tabs-mode)
1750 (ws-tab-width whitespace-tab-width)) 1735 (ws-tab-width tab-width))
1751 (with-current-buffer (get-buffer-create 1736 (with-current-buffer (get-buffer-create
1752 whitespace-report-buffer-name) 1737 whitespace-report-buffer-name)
1753 (erase-buffer) 1738 (erase-buffer)
@@ -2027,7 +2012,6 @@ resultant list will be returned."
2027 (if (listp whitespace-style) 2012 (if (listp whitespace-style)
2028 whitespace-style 2013 whitespace-style
2029 (list whitespace-style))) 2014 (list whitespace-style)))
2030 (whitespace-ensure-local-variables)
2031 ;; turn on whitespace 2015 ;; turn on whitespace
2032 (when whitespace-active-style 2016 (when whitespace-active-style
2033 (whitespace-color-on) 2017 (whitespace-color-on)
@@ -2105,10 +2089,10 @@ resultant list will be returned."
2105 `((,(let ((line-column (or whitespace-line-column fill-column))) 2089 `((,(let ((line-column (or whitespace-line-column fill-column)))
2106 (format 2090 (format
2107 "^\\([^\t\n]\\{%s\\}\\|[^\t\n]\\{0,%s\\}\t\\)\\{%d\\}%s\\(.+\\)$" 2091 "^\\([^\t\n]\\{%s\\}\\|[^\t\n]\\{0,%s\\}\t\\)\\{%d\\}%s\\(.+\\)$"
2108 whitespace-tab-width 2092 tab-width
2109 (1- whitespace-tab-width) 2093 (1- tab-width)
2110 (/ line-column whitespace-tab-width) 2094 (/ line-column tab-width)
2111 (let ((rem (% line-column whitespace-tab-width))) 2095 (let ((rem (% line-column tab-width)))
2112 (if (zerop rem) 2096 (if (zerop rem)
2113 "" 2097 ""
2114 (format ".\\{%d\\}" rem))))) 2098 (format ".\\{%d\\}" rem)))))
@@ -2123,7 +2107,7 @@ resultant list will be returned."
2123 ,(cond 2107 ,(cond
2124 ((memq 'space-before-tab whitespace-active-style) 2108 ((memq 'space-before-tab whitespace-active-style)
2125 ;; Show SPACEs before TAB (indent-tabs-mode). 2109 ;; Show SPACEs before TAB (indent-tabs-mode).
2126 (if whitespace-indent-tabs-mode 1 2)) 2110 (if indent-tabs-mode 1 2))
2127 ((memq 'space-before-tab::tab whitespace-active-style) 2111 ((memq 'space-before-tab::tab whitespace-active-style)
2128 1) 2112 1)
2129 ((memq 'space-before-tab::space whitespace-active-style) 2113 ((memq 'space-before-tab::space whitespace-active-style)