2018-05-08 19:59:08 +02:00
|
|
|
;;; tools/editorconfig/config.el -*- lexical-binding: t; -*-
|
|
|
|
|
2024-09-14 04:18:15 -04:00
|
|
|
;; TODO: Adapt to built-in `editorconfig' in Emacs 30+
|
2018-05-08 19:59:08 +02:00
|
|
|
;; Handles whitespace (tabs/spaces) settings externally. This way projects can
|
|
|
|
;; specify their own formatting rules.
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! editorconfig
|
2020-05-28 14:40:34 -04:00
|
|
|
:hook (doom-first-buffer . editorconfig-mode)
|
2018-05-08 19:59:08 +02:00
|
|
|
:config
|
2020-03-27 21:14:47 -04:00
|
|
|
(when (require 'ws-butler nil t)
|
|
|
|
(setq editorconfig-trim-whitespaces-mode 'ws-butler-mode))
|
|
|
|
|
2021-05-16 15:21:42 -04:00
|
|
|
;; Fix #5057 archives don't need editorconfig settings, and they may otherwise
|
|
|
|
;; interfere with the process of opening them (office formats are zipped XML
|
|
|
|
;; formats).
|
|
|
|
(add-to-list 'editorconfig-exclude-regexps
|
|
|
|
"\\.\\(zip\\|\\(doc\\|xls\\|ppt\\)x\\)\\'")
|
|
|
|
|
2019-07-28 14:52:59 +02:00
|
|
|
(add-hook! 'editorconfig-after-apply-functions
|
2019-07-22 23:28:12 +02:00
|
|
|
(defun +editorconfig-disable-indent-detection-h (props)
|
|
|
|
"Inhibit `dtrt-indent' if an explicit indent_style and indent_size is
|
2018-08-31 13:56:50 +02:00
|
|
|
specified by editorconfig."
|
2024-03-10 23:50:14 -04:00
|
|
|
(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)))))
|