diff --git a/core/core-editor.el b/core/core-editor.el index 03fa0cae3..da456d948 100644 --- a/core/core-editor.el +++ b/core/core-editor.el @@ -10,6 +10,11 @@ modes are active and the buffer is read-only.") doc-view-mode doc-view-mode-maybe ebrowse-tree-mode pdf-view-mode) "Major modes that `doom|check-large-file' will ignore.") +(defvar-local doom-inhibit-indent-detection nil + "A buffer-local flag that indicates whether `dtrt-indent' should try to detect +indentation settings or not. This should be set by editorconfig if it +successfully sets indent_style/indent_size.") + (setq-default vc-follow-symlinks t ;; Save clipboard contents into kill-ring before replacing them @@ -170,6 +175,15 @@ fundamental-mode) for performance sake." (setq command-log-mode-auto-show t command-log-mode-open-log-turns-on-mode t)) +(def-package! dtrt-indent + :config + (setq dtrt-indent-verbosity (if doom-debug-mode 2 0)) + + (defun doom|detect-indentation () + (unless (or doom-inhibit-indent-detection (eq major-mode 'fundamental-mode)) + (dtrt-indent-mode +1))) + (add-hook 'after-change-major-mode-hook #'doom|detect-indentation)) + (def-package! expand-region :commands (er/expand-region er/contract-region er/mark-symbol er/mark-word) :config diff --git a/core/packages.el b/core/packages.el index 1483cfd3e..7edaaa5ba 100644 --- a/core/packages.el +++ b/core/packages.el @@ -23,6 +23,7 @@ (package! ace-window) (package! avy) (package! command-log-mode) +(package! dtrt-indent) (package! expand-region) (package! helpful) (package! pcre2el) diff --git a/modules/tools/editorconfig/config.el b/modules/tools/editorconfig/config.el index bbe4cbaf6..2e5d98795 100644 --- a/modules/tools/editorconfig/config.el +++ b/modules/tools/editorconfig/config.el @@ -39,6 +39,12 @@ extension, try to guess one." (apply orig-fn args))) (advice-add #'editorconfig-call-editorconfig-exec :around #'doom*editorconfig-smart-detection) + (defun +editorconfig|disable-indent-detection (props) + (when (or (gethash 'indent_style props) + (gethash 'indent_size props)) + (setq doom-inhibit-indent-detection t))) + (add-hook 'editorconfig-custom-hooks #'+editorconfig|disable-indent-detection) + ;; Editorconfig makes indentation too rigid in Lisp modes, so tell ;; editorconfig to ignore indentation there. I prefer dynamic indentation ;; support built into Emacs.