From d60d4a94f79574fe1b16698458c1f7367bae8323 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Wed, 12 Jun 2024 18:05:43 -0400 Subject: [PATCH] (editorconfig--should-set): Eliminate `lisp-indent-offset` special case Instead of treating `lisp-indent-offset` specially in `editorconfig--should-set` (to obey `editorconfig-lisp-use-default-indent`), use a new function `editorconfig-set-indentation-lisp-mode` for Lisp modes. * lisp/editorconfig.el (editorconfig--should-set): Remove `size` argument. (editorconfig-set-indentation): Adjust calls accordingly. (editorconfig-set-indentation-lisp-mode): New function. (editorconfig-indentation-alist): Use it. (cherry picked from commit 25523847e7931de1f0ee638d2a8847d979fdb496) --- lisp/editorconfig.el | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/lisp/editorconfig.el b/lisp/editorconfig.el index 070d6b460eb..b8eced27807 100644 --- a/lisp/editorconfig.el +++ b/lisp/editorconfig.el @@ -141,7 +141,7 @@ This hook will be run even when there are no matching sections in (csharp-mode c-basic-offset) (csharp-ts-mode c-basic-offset csharp-ts-mode-indent-offset) - (emacs-lisp-mode lisp-indent-offset) + (emacs-lisp-mode . editorconfig-set-indentation-lisp-mode) (ess-mode ess-indent-offset) (feature-mode feature-indent-offset feature-indent-level) @@ -154,7 +154,7 @@ This hook will be run even when there are no matching sections in (js-mode js-indent-level) (jsonian-mode jsonian-default-indentation) (latex-mode . editorconfig-set-indentation-latex-mode) - (lisp-mode lisp-indent-offset) + (lisp-mode . editorconfig-set-indentation-lisp-mode) (matlab-mode matlab-indent-level) (octave-mode octave-block-offset) ;; No need to change `php-mode-coding-style' value for php-mode @@ -235,15 +235,20 @@ Make a message by passing ARGS to `format-message'." (setq-local LaTeX-item-indent size) (setq-local TeX-brace-indent-level size)) -(cl-defun editorconfig--should-set (symbol &optional size) - "Determine if editorconfig should set SYMBOL. - -Optional arg SIZE is used when symbol is `lisp-indent-offset'. -See `editorconfig-lisp-use-default-indent' for details." +(defun editorconfig-set-indentation-lisp-mode (size) + "Set indent size to SIZE for Lisp mode(s)." + (when (cond ((null editorconfig-lisp-use-default-indent) t) + ((eql t editorconfig-lisp-use-default-indent) nil) + ((numberp editorconfig-lisp-use-default-indent) + (not (eql size editorconfig-lisp-use-default-indent))) + (t t)) + (setq-local lisp-indent-offset size))) + +(cl-defun editorconfig--should-set (symbol) + "Determine if editorconfig should set SYMBOL." (display-warning '(editorconfig editorconfig--should-set) - (format "symbol: %S | size: %S" - symbol - size) + (format "symbol: %S" + symbol) :debug) (when (assq symbol file-local-variables-alist) (cl-return-from editorconfig--should-set @@ -253,14 +258,6 @@ See `editorconfig-lisp-use-default-indent' for details." (cl-return-from editorconfig--should-set nil)) - (when (eq symbol 'lisp-indent-offset) - (cl-return-from editorconfig--should-set - (cond ((null editorconfig-lisp-use-default-indent) t) - ((eql t editorconfig-lisp-use-default-indent) nil) - ((numberp editorconfig-lisp-use-default-indent) - (not (eql size editorconfig-lisp-use-default-indent))) - (t t)))) - t) (defun editorconfig-set-indentation (style &optional size tab_width) -- 2.39.2