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
This commit is contained in:
parent
1b0ec9f1b5
commit
c1c6f167b2
2 changed files with 38 additions and 3 deletions
|
@ -2373,9 +2373,10 @@ Also refontify when necessary."
|
|||
(let (vecs vec)
|
||||
;; Remember whether a buffer has a local display table.
|
||||
(unless whitespace-display-table-was-local
|
||||
(setq whitespace-display-table-was-local t
|
||||
whitespace-display-table
|
||||
(copy-sequence buffer-display-table))
|
||||
(setq whitespace-display-table-was-local t)
|
||||
(unless (or whitespace-mode global-whitespace-mode)
|
||||
(setq whitespace-display-table
|
||||
(copy-sequence buffer-display-table)))
|
||||
;; Assure `buffer-display-table' is unique
|
||||
;; when two or more windows are visible.
|
||||
(setq buffer-display-table
|
||||
|
|
|
@ -47,6 +47,40 @@
|
|||
(should (equal (whitespace-tests--cleanup-string "a \n\t \n\n")
|
||||
"a \n"))))
|
||||
|
||||
|
||||
;; We cannot call whitespace-mode because it will do nothing in batch
|
||||
;; mode. So we call its innards instead.
|
||||
(defun whitespace-tests-whitespace-mode-on ()
|
||||
"Turn whitespace-mode on even in batch mode."
|
||||
(whitespace-turn-on)
|
||||
(whitespace-action-when-on)
|
||||
(setq whitespace-mode t))
|
||||
|
||||
(ert-deftest whitespace-tests-display-tables ()
|
||||
"Test whitespace stores and restores the buffer display table - bug26892."
|
||||
(with-temp-buffer
|
||||
(whitespace-mode -1) ; turn off in case global ws mode is active
|
||||
(let ((whitespace-style '(space-mark tab-mark newline-mark))
|
||||
(whitespace-display-mappings '((space-mark 32 [183] [46])
|
||||
(space-mark 160 [164] [95])
|
||||
(newline-mark 10 [36 10])
|
||||
(tab-mark 9 [187 9] [92 9])))
|
||||
(buffer-display-table nil))
|
||||
;test the display table actually changes
|
||||
(should-not (equal nil
|
||||
(progn (whitespace-tests-whitespace-mode-on)
|
||||
buffer-display-table)))
|
||||
;test the display table restores correctly
|
||||
(should (equal nil
|
||||
(progn (whitespace-turn-off)
|
||||
buffer-display-table)))
|
||||
;test the stored display table is preserved
|
||||
(should (equal nil
|
||||
(progn (whitespace-tests-whitespace-mode-on)
|
||||
(whitespace-tests-whitespace-mode-on)
|
||||
(whitespace-turn-off)
|
||||
buffer-display-table))))))
|
||||
|
||||
(provide 'whitespace-tests)
|
||||
|
||||
;;; whitespace-tests.el ends here
|
||||
|
|
Loading…
Add table
Reference in a new issue