New option to enable global-whitespace-mode in special-buffers (bug#79230)
* lisp/whitespace.el (whitespace-global-mode-buffers): New custom option. (whitespace-enable-predicate): Use it. (whitespace-global-modes): Refer to the new option.
This commit is contained in:
committed by
Eli Zaretskii
parent
0801652979
commit
e4aa9cfbab
@@ -904,7 +904,12 @@ of the list is negated if it begins with `not'. For example:
|
||||
(c-mode c++-mode)
|
||||
|
||||
means that `whitespace-mode' is turned on for buffers in C and
|
||||
C++ modes only."
|
||||
C++ modes only.
|
||||
|
||||
Global `whitespace-mode' will not automatically turn on in internal
|
||||
buffers (with name starting from space) and special buffers (with name
|
||||
starting from \"*\"), except \"*scratch*\" buffer. Use
|
||||
`whitespace-global-mode-buffers' to customize this behavior."
|
||||
:type '(choice :tag "Global Modes"
|
||||
(const :tag "None" nil)
|
||||
(const :tag "All" t)
|
||||
@@ -914,6 +919,12 @@ C++ modes only."
|
||||
(repeat :inline t
|
||||
(symbol :tag "Mode")))))
|
||||
|
||||
(defcustom whitespace-global-mode-buffers (list (regexp-quote "*scratch*"))
|
||||
"Buffer name regexps where global `whitespace-mode' can be auto-enabled.
|
||||
The value is a list of regexps. Set this custom option when you need
|
||||
`whitespace-mode' in special buffers like *Org Src*."
|
||||
:type '(list (regexp :tag "Regexp matching buffer name"))
|
||||
:version "31.1")
|
||||
|
||||
(defcustom whitespace-action nil
|
||||
"Specify which action is taken when a buffer is visited or written.
|
||||
@@ -1042,7 +1053,10 @@ See also `whitespace-newline' and `whitespace-display-mappings'."
|
||||
;; ...the buffer is not special (name starts with *)
|
||||
(or (not (eq (aref (buffer-name) 0) ?*))
|
||||
;; except the scratch buffer.
|
||||
(string= (buffer-name) "*scratch*"))))
|
||||
(seq-find
|
||||
(lambda (re)
|
||||
(string-match-p re (buffer-name)))
|
||||
whitespace-global-mode-buffers))))
|
||||
"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'.
|
||||
|
||||
Reference in New Issue
Block a user