diff --git a/lisp/whitespace.el b/lisp/whitespace.el index 2e89d2ae977..9eb88eb35d0 100644 --- a/lisp/whitespace.el +++ b/lisp/whitespace.el @@ -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'.