aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Helm2017-05-19 15:20:59 +0300
committerEli Zaretskii2017-05-19 15:20:59 +0300
commitc1c6f167b2e683db3e2cee7cb29ab2eb745e1713 (patch)
treee049daba66259b9de5a092be777994fa6df495a1
parent1b0ec9f1b5c2587d6cd402f59f8ec14d81d3e551 (diff)
downloademacs-c1c6f167b2e683db3e2cee7cb29ab2eb745e1713.tar.gz
emacs-c1c6f167b2e683db3e2cee7cb29ab2eb745e1713.zip
Fix turning off whitespace-mode
* lisp/whitespace.el (whitespace-display-char-on): Correct the way the original buffer-display-table is saved and restored when global-whitespace-mode is active. (Bug#26892) * test/lisp/whitespace-tests.el (whitespace-tests-whitespace-mode-on): New function. (whitespace-tests-display-tables): New test. Copyright-paperwork-exempt: yes
-rw-r--r--lisp/whitespace.el7
-rw-r--r--test/lisp/whitespace-tests.el34
2 files changed, 38 insertions, 3 deletions
diff --git a/lisp/whitespace.el b/lisp/whitespace.el
index 6aca47cd437..c6d5b16caeb 100644
--- a/lisp/whitespace.el
+++ b/lisp/whitespace.el
@@ -2373,9 +2373,10 @@ Also refontify when necessary."
2373 (let (vecs vec) 2373 (let (vecs vec)
2374 ;; Remember whether a buffer has a local display table. 2374 ;; Remember whether a buffer has a local display table.
2375 (unless whitespace-display-table-was-local 2375 (unless whitespace-display-table-was-local
2376 (setq whitespace-display-table-was-local t 2376 (setq whitespace-display-table-was-local t)
2377 whitespace-display-table 2377 (unless (or whitespace-mode global-whitespace-mode)
2378 (copy-sequence buffer-display-table)) 2378 (setq whitespace-display-table
2379 (copy-sequence buffer-display-table)))
2379 ;; Assure `buffer-display-table' is unique 2380 ;; Assure `buffer-display-table' is unique
2380 ;; when two or more windows are visible. 2381 ;; when two or more windows are visible.
2381 (setq buffer-display-table 2382 (setq buffer-display-table
diff --git a/test/lisp/whitespace-tests.el b/test/lisp/whitespace-tests.el
index 99cc3c4ec07..1e455352f2e 100644
--- a/test/lisp/whitespace-tests.el
+++ b/test/lisp/whitespace-tests.el
@@ -47,6 +47,40 @@
47 (should (equal (whitespace-tests--cleanup-string "a \n\t \n\n") 47 (should (equal (whitespace-tests--cleanup-string "a \n\t \n\n")
48 "a \n")))) 48 "a \n"))))
49 49
50
51;; We cannot call whitespace-mode because it will do nothing in batch
52;; mode. So we call its innards instead.
53(defun whitespace-tests-whitespace-mode-on ()
54 "Turn whitespace-mode on even in batch mode."
55 (whitespace-turn-on)
56 (whitespace-action-when-on)
57 (setq whitespace-mode t))
58
59(ert-deftest whitespace-tests-display-tables ()
60 "Test whitespace stores and restores the buffer display table - bug26892."
61 (with-temp-buffer
62 (whitespace-mode -1) ; turn off in case global ws mode is active
63 (let ((whitespace-style '(space-mark tab-mark newline-mark))
64 (whitespace-display-mappings '((space-mark 32 [183] [46])
65 (space-mark 160 [164] [95])
66 (newline-mark 10 [36 10])
67 (tab-mark 9 [187 9] [92 9])))
68 (buffer-display-table nil))
69 ;test the display table actually changes
70 (should-not (equal nil
71 (progn (whitespace-tests-whitespace-mode-on)
72 buffer-display-table)))
73 ;test the display table restores correctly
74 (should (equal nil
75 (progn (whitespace-turn-off)
76 buffer-display-table)))
77 ;test the stored display table is preserved
78 (should (equal nil
79 (progn (whitespace-tests-whitespace-mode-on)
80 (whitespace-tests-whitespace-mode-on)
81 (whitespace-turn-off)
82 buffer-display-table))))))
83
50(provide 'whitespace-tests) 84(provide 'whitespace-tests)
51 85
52;;; whitespace-tests.el ends here 86;;; whitespace-tests.el ends here