fix(lib): doom/set-indent-width on Emacs >=30

A built-in `editorconfig` package was added in Emacs 30, with a somewhat
different API from the other package of the same name.

Fix: #8072
This commit is contained in:
Henrik Lissner 2024-09-14 04:18:15 -04:00
parent d34770407c
commit 66a2972ebf
No known key found for this signature in database
GPG key ID: B60957CA074D39A3
2 changed files with 11 additions and 2 deletions

View file

@ -368,7 +368,15 @@ editorconfig or dtrt-indent installed."
(setq-local standard-indent width)
(when (boundp 'evil-shift-width)
(setq evil-shift-width width))
(cond ((require 'editorconfig nil t)
;; REVIEW: Only use `editorconfig' once we drop 29.x support.
(cond ((let ((load-path (get 'load-path 'initial-value)))
;; A built-in `editorconfig' package was added in Emacs 30.x, but
;; with a different API. Since it's built in, prefer it over the
;; upstream one, but we still need to adapt:
(require 'editorconfig nil t))
(pcase-dolist (`(,var . ,val) (editorconfig--default-indent-size-function width))
(set (make-local-variable var) val)))
((require 'editorconfig nil t)
(let (editorconfig-lisp-use-default-indent)
(editorconfig-set-indentation nil width)))
((require 'dtrt-indent nil t)
@ -376,7 +384,7 @@ editorconfig or dtrt-indent installed."
(dolist (var (ensure-list vars))
(doom-log "Updated %s = %d" var width)
(set var width)))))
(message "Changed indentation to %d" width))
(message "Changed buffer's indent-size to %d" width))
;;

View file

@ -1,5 +1,6 @@
;;; tools/editorconfig/config.el -*- lexical-binding: t; -*-
;; TODO: Adapt to built-in `editorconfig' in Emacs 30+
;; Handles whitespace (tabs/spaces) settings externally. This way projects can
;; specify their own formatting rules.
(use-package! editorconfig