fix(editorconfig): prevent changes to tab-width in org-mode

- Add another measure for preventing changes to tab-width in org-mode.
  The hook introduced in 2757a97 runs too early and could be overwritten
  by editorconfig.
- Fix the hook in 2757a97 to run much later, ensuring (as a last resort)
  no other packages can overwrite tab-width either.

Amend: 2757a97a30
Ref: #7670
This commit is contained in:
Henrik Lissner 2024-03-10 23:50:14 -04:00
parent 198fe82b6d
commit 43870bf831
No known key found for this signature in database
GPG key ID: B60957CA074D39A3
2 changed files with 19 additions and 4 deletions

View file

@ -1438,7 +1438,12 @@ between the two."
;; HACK: Somehow, users/packages still find a way to modify tab-width in
;; org-mode. Since org-mode treats a non-standerd tab-width as an error
;; state, I use this hook to makes it much harder to change by accident.
(add-hook! 'org-mode-hook :depth 110 (setq-local tab-width 8))
(add-hook! 'org-mode-hook
(add-hook! 'after-change-major-mode-hook :local
;; The second check is necessary, in case of `org-edit-src-code' which
;; clones a buffer and changes its major-mode.
(when (derived-mode-p 'org-mode)
(setq tab-width 8))))
;; Save target buffer after archiving a node.
(setq org-archive-subtree-save-file-p t)

View file

@ -48,6 +48,16 @@ extension, try to guess one."
(defun +editorconfig-disable-indent-detection-h (props)
"Inhibit `dtrt-indent' if an explicit indent_style and indent_size is
specified by editorconfig."
(when (or (gethash 'indent_style props)
(gethash 'indent_size props))
(setq doom-inhibit-indent-detection 'editorconfig)))))
(when (and (not doom-inhibit-indent-detection)
(or (gethash 'indent_style props)
(gethash 'indent_size props)))
(setq doom-inhibit-indent-detection 'editorconfig)))
;; I use a hook over `editorconfig-exclude-modes' because the option
;; inhibits all settings, and I only want to inhibit indent_size. Plus modes
;; in that option won't apply to derived modes, so we'd have to add *all*
;; possible org-mode derivatives to it.
(defun +editorconfig-unset-tab-width-in-org-mode-h (props)
"A tab-width != 8 is an error state in org-mode, so prevent changing it."
(when (and (gethash 'indent_size props)
(derived-mode-p 'org-mode))
(setq tab-width 8)))))