-
-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Description
I am trying to use editorconfig in my project.
However, I cannot set nix's indentation with .editorconfig, because editorconfig.el will not find it.
It only lookes for
"-indent-level" "-basic-offset" "-indent-offset"
This works in my config.
(defvaralias 'nix-ts-mode-indent-offset 'nix-ts-indent-offset)This is the function in editorconfig.el.
(defun editorconfig--default-indent-size-function (size)
"Guess which variables to set to for the indentation step to have size SIZE.
This relies on `editorconfig-indentation-alist' supplemented with a crude
heuristic for those modes not found there."
(let ((parents (if (fboundp 'derived-mode-all-parents) ;Emacs-30
(derived-mode-all-parents major-mode)
(let ((modes nil)
(mode major-mode))
(while mode
(push mode modes)
(setq mode (get mode 'derived-mode--parent)))
(nreverse modes))))
entry)
(let ((parents parents))
(while (and parents (not entry))
(setq entry (assq (pop parents) editorconfig-indentation-alist))))
(or
(when entry
(let ((rule (cdr entry)))
;; Filter out settings of unknown vars.
(delq nil
(mapcar
(lambda (elem)
(let ((v (car elem)))
(cond
((not (symbolp v))
(message "Unsupported element in `editorconfig-indentation-alist': %S" elem))
((boundp v) elem))))
(if (functionp rule)
(let ((result (funcall rule size)))
(if (and (consp (car-safe result))
(boundp (caar result)))
result
(message "Invalid return value for: %S"
rule)
nil))
(mapcar
(lambda (elem)
(cond
((symbolp elem) `(,elem . ,size))
((consp elem)
(message "Old-style entry in editorconfig-indentation-alist: %S" elem)
`(,(car elem)
. ,(let ((spec (cdr elem)))
(cond ((functionp spec) (funcall spec size))
((integerp spec) (* spec size))
(t spec)))))))
rule))))))
;; Fallback, let's try and guess.
(let ((suffixes '("-indent-level" "-basic-offset" "-indent-offset"))
(guess ()))
(while (and parents (not guess))
(let* ((mode (pop parents))
(modename (symbol-name mode))
(name (substring modename 0
(string-match "-mode\\'" modename))))
(dolist (suffix suffixes)
(let ((sym (intern-soft (concat name suffix))))
(when (and sym (boundp sym))
(setq guess sym))))))
(when guess `((,guess . ,size))))
(and (local-variable-p 'smie-rules-function)
`((smie-indent-basic . ,size))))))Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels