Function: editorconfig--default-indent-size-function

editorconfig--default-indent-size-function is a byte-compiled function defined in editorconfig.el.gz.

Signature

(editorconfig--default-indent-size-function SIZE)

Documentation

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.

Source Code

;; Defined in /usr/src/emacs/lisp/editorconfig.el.gz
(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))
                            ((or (eq 'eval v) (boundp v)) elem))))
                       (if (functionp rule)
                           (funcall rule size)
                         (mapcar (lambda (elem) `(,elem . ,size)) 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))))))