From 66a2972ebf5fd18cd8adb6eb71a48ec08ce418b8 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 14 Sep 2024 04:18:15 -0400 Subject: [PATCH] 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 --- lisp/lib/text.el | 12 ++++++++++-- modules/tools/editorconfig/config.el | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lisp/lib/text.el b/lisp/lib/text.el index e44e127c4..0bd7a3e7a 100644 --- a/lisp/lib/text.el +++ b/lisp/lib/text.el @@ -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)) ;; diff --git a/modules/tools/editorconfig/config.el b/modules/tools/editorconfig/config.el index f98078c97..1d2d65817 100644 --- a/modules/tools/editorconfig/config.el +++ b/modules/tools/editorconfig/config.el @@ -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