diff --git a/core/core-editor.el b/core/core-editor.el index f78e9993e..a60e0322e 100644 --- a/core/core-editor.el +++ b/core/core-editor.el @@ -16,6 +16,10 @@ modes are active and the buffer is read-only.") indentation settings or not. This should be set by editorconfig if it successfully sets indent_style/indent_size.") +(defvar doom-detect-indentation-excluded-modes '(fundamental-mode) + "A list of major modes in which indentation should be automatically +detected.") + (setq-default large-file-warning-threshold 30000000 vc-follow-symlinks t @@ -185,6 +189,23 @@ savehist file." (smartparens-global-mode +1)) +;; Automatic detection of indent settings +(def-package! dtrt-indent + :unless noninteractive + :defer t + :init + (defun doom|detect-indentation () + (unless (or (not after-init-time) + doom-inhibit-indent-detection + (member (substring (buffer-name) 0 1) '(" " "*")) + (memq major-mode doom-detect-indentation-excluded-modes)) + (dtrt-indent-mode +1))) + (add-hook! '(change-major-mode-after-body-hook read-only-mode-hook) + #'doom|detect-indentation) + :config + (setq dtrt-indent-verbosity (if doom-debug-mode 2 0)) + (add-to-list 'dtrt-indent-hook-generic-mapping-list '(t tab-width))) + ;; Branching undo (def-package! undo-tree :after-call (doom-exit-buffer-hook after-find-file) @@ -206,22 +227,6 @@ savehist file." (setq command-log-mode-auto-show t command-log-mode-open-log-turns-on-mode t) -(def-package! dtrt-indent - :unless noninteractive - :defer t - :init - (defun doom|detect-indentation () - (unless (or doom-inhibit-indent-detection - buffer-read-only - (memq major-mode '(fundamental-mode org-mode)) - (not (derived-mode-p 'prog-mode 'text-mode 'conf-mode))) - (require 'dtrt-indent) - (dtrt-indent-mode +1))) - (add-hook 'after-change-major-mode-hook #'doom|detect-indentation) - :config - (setq dtrt-indent-verbosity (if doom-debug-mode 2 0)) - (add-to-list 'dtrt-indent-hook-generic-mapping-list '(t tab-width))) - (def-package! expand-region :commands (er/contract-region er/mark-symbol er/mark-word) :config diff --git a/modules/emacs/eshell/config.el b/modules/emacs/eshell/config.el index eaaabf92b..60c3ccd8c 100644 --- a/modules/emacs/eshell/config.el +++ b/modules/emacs/eshell/config.el @@ -71,6 +71,8 @@ You should use `det-eshell-alias!' to change this.") eshell-glob-case-insensitive t eshell-error-if-no-glob t) + (add-to-list 'doom-detect-indentation-excluded-modes 'eshell-mode nil #'eq) + ;; Consider eshell buffers real (add-hook 'eshell-mode-hook #'doom|mark-buffer-as-real) diff --git a/modules/emacs/term/config.el b/modules/emacs/term/config.el index c70417601..bc1f88337 100644 --- a/modules/emacs/term/config.el +++ b/modules/emacs/term/config.el @@ -8,4 +8,5 @@ (after! term (set-env! "SHELL") - (add-hook 'term-mode-hook #'doom|mark-buffer-as-real)) + (add-hook 'term-mode-hook #'doom|mark-buffer-as-real) + (add-to-list 'doom-detect-indentation-excluded-modes 'term-mode nil #'eq)) diff --git a/modules/lang/emacs-lisp/config.el b/modules/lang/emacs-lisp/config.el index 44213cafe..2f2a3b441 100644 --- a/modules/lang/emacs-lisp/config.el +++ b/modules/lang/emacs-lisp/config.el @@ -41,6 +41,9 @@ ("add-hook" "remove-hook") ("add-hook!" "remove-hook!"))) + ;; variable-width indentation is superior in elisp + (add-to-list 'doom-detect-indentation-excluded-modes 'emacs-lisp-mode nil #'eq) + (add-hook! 'emacs-lisp-mode-hook #'(;; 3rd-party functionality auto-compile-on-save-mode doom|enable-delete-trailing-whitespace diff --git a/modules/lang/org/config.el b/modules/lang/org/config.el index d9b884fe1..f11ac9f46 100644 --- a/modules/lang/org/config.el +++ b/modules/lang/org/config.el @@ -191,6 +191,9 @@ unfold to point on startup." org-preview-latex-image-directory (concat doom-cache-dir "org-latex/") org-format-latex-options (plist-put org-format-latex-options :scale 1.5)) + ;; Don't do automatic indent detection in org files + (add-to-list 'doom-detect-indentation-excluded-modes 'org-mode nil #'eq) + ;; Previews are usually rendered with light backgrounds, so ensure their ;; background (and foreground) match the current theme. (defun +org|update-latex-preview-background-color ()