William Grimes
William Grimes

Reputation: 707

Emacs Prelude `whitespace-empty-at-eob-regexp` allow single empty line

On saving a file, whitespace-cleanup does a nice job of cleaning up whitespace:

https://emacsredux.com/blog/2013/05/16/whitespace-cleanup/

However, I would like to be able to leave a blank line at the end of buffer, either globally or add a hook for different modes.

I think if I edit this whitespace-empty-at-eob-regexp I should be able to do it?

whitespace-empty-at-eob-regexp’s value is "^\\([ ]+\\)\\'"

So I thought I could just add a \n but this does not achieve what I want:

"^\\([ ]+\\n\)\\'"

Upvotes: 0

Views: 44

Answers (1)

Tianshu Wang
Tianshu Wang

Reputation: 758

The value of whitespace-empty-at-eob-regexp is "^\\([ \t\n]+\\)\\'" actually.

I you want to leave a blank line at the end of buffer. Try:

(setq whitespace-empty-at-eob-regexp "^[ \t\n]\\([ \t\n]+\\)\\'")

;; Tips: you can use xr and rx to play with regex more relaxed in emacs.
;; (xr "^[ \t\n]\\([ \t\n]+\\)\\'")
;; (seq bol
;;      (any "\t\n ")
;;      (group
;;       (one-or-more
;;        (any "\t\n ")))
;;      eos)

Upvotes: 1

Related Questions