Make whitespace-injection more robust

+ No longer try to affect read-only buffers
+ Only activate if indent-tabs-mode is nil (spaces)
This commit is contained in:
Henrik Lissner 2017-06-16 14:22:05 +02:00
parent 9c9e410898
commit 8f9bd835a5
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -198,10 +198,10 @@ mode is detected.")
buffer so that `highlight-indentation-mode' will display uninterrupted indent buffer so that `highlight-indentation-mode' will display uninterrupted indent
markers. This whitespace is stripped out on save, as not to affect the resulting markers. This whitespace is stripped out on save, as not to affect the resulting
file." file."
(interactive (progn (barf-if-buffer-read-only) (interactive (if (use-region-p)
(if (use-region-p)
(list (region-beginning) (region-end)) (list (region-beginning) (region-end))
(list nil nil)))) (list nil nil)))
(barf-if-buffer-read-only)
(unless indent-tabs-mode (unless indent-tabs-mode
(with-silent-modifications (with-silent-modifications
(save-excursion (save-excursion
@ -229,6 +229,7 @@ file."
nil) nil)
(defun doom|init-highlight-indentation () (defun doom|init-highlight-indentation ()
(unless (or indent-tabs-mode buffer-read-only)
(if (or highlight-indentation-mode highlight-indentation-current-column-mode) (if (or highlight-indentation-mode highlight-indentation-current-column-mode)
(progn (progn
(doom|inject-trailing-whitespace) (doom|inject-trailing-whitespace)
@ -237,7 +238,7 @@ file."
(remove-hook 'before-save-hook #'delete-trailing-whitespace t) (remove-hook 'before-save-hook #'delete-trailing-whitespace t)
(remove-hook 'after-save-hook #'doom|inject-trailing-whitespace t) (remove-hook 'after-save-hook #'doom|inject-trailing-whitespace t)
(with-silent-modifications (with-silent-modifications
(delete-trailing-whitespace)))) (delete-trailing-whitespace)))))
(add-hook! (highlight-indentation-mode highlight-indentation-current-column-mode) (add-hook! (highlight-indentation-mode highlight-indentation-current-column-mode)
#'doom|init-highlight-indentation)) #'doom|init-highlight-indentation))