branch: externals-release/org
commit 0dc647ff54ba8a1e40d22237e2c095cb30905247
Author: Ihor Radchenko <yanta...@posteo.net>
Commit: Ihor Radchenko <yanta...@posteo.net>

    org-mode: Be more aggressive setting tab-width to 8
    
    * lisp/org.el (org--set-tab-width): New helper to set `tab-width'.
    (org-mode): Override file-local and directory-local settings for
    `tab-width', if any.  With non-standard `tab-width', parser cannot
    work properly.
    
    Reported-by: Steinar Bang <s...@dod.no>
    Link: https://orgmode.org/list/87msdrw5qt....@dod.no
---
 lisp/org.el | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/lisp/org.el b/lisp/org.el
index b080b62281..122e57a90b 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -4926,6 +4926,10 @@ This is for getting out of special buffers like 
capture.")
     st)
   "Syntax table including \"@\" and \"_\" as word constituents.")
 
+(defun org--set-tab-width (&rest _)
+  "Set `tab-width' to be 8."
+  (setq-local tab-width 8))
+
 ;;;###autoload
 (define-derived-mode org-mode outline-mode "Org"
   "Outline-based notes management and organizer, alias
@@ -4948,7 +4952,16 @@ The following commands are available:
   (setq-local org-mode-loading t)
   ;; Force tab width - indentation is significant in lists, so we need
   ;; to make sure that it is consistent across configurations.
-  (setq-local tab-width 8)
+  (org--set-tab-width)
+  ;; Really force it, even if dir-locals or file-locals set it - we
+  ;; need tab-width = 8 as a part of Org syntax.
+  (add-hook 'hack-local-variables-hook
+            #'org--set-tab-width 90 'local)
+  ;; In Emacs <30, editorconfig-mode uses advices, so we cannot rely
+  ;; upon `hack-local-variables-hook' to run after editorconfig
+  ;; tab-width settings are applied.
+  (add-hook 'editorconfig-after-apply-functions
+            #'org--set-tab-width 90 'local)
   (org-load-modules-maybe)
   (when org-agenda-file-menu-enabled
     (org-install-agenda-files-menu))

Reply via email to