Function: editorconfig--get-indentation
editorconfig--get-indentation is a byte-compiled function defined in
editorconfig.el.gz.
Signature
(editorconfig--get-indentation PROPS)
Documentation
Get indentation vars according to STYLE, SIZE, and TAB_WIDTH.
Source Code
;; Defined in /usr/src/emacs/lisp/editorconfig.el.gz
(defun editorconfig--get-indentation (props)
"Get indentation vars according to STYLE, SIZE, and TAB_WIDTH."
(let ((style (gethash 'indent_style props))
(size (gethash 'indent_size props))
(tab_width (gethash 'tab_width props)))
(cond
(tab_width (setq tab_width (string-to-number tab_width)))
;; The EditorConfig spec is excessively eager to set `tab-width'
;; even when not explicitly requested (bug#73991).
;; As a trade-off, we accept `indent_style=tab' as a good enough hint.
((and (equal style "tab") (editorconfig-string-integer-p size))
(setq tab_width (string-to-number size))))
;; When users choose `indent_size=tab', they most likely prefer
;; `indent_style=tab' as well.
(when (and (null style) (equal size "tab"))
(setq style "tab"))
(setq size
(cond ((editorconfig-string-integer-p size)
(string-to-number size))
((equal size "tab")
(or tab_width tab-width))
(t
nil)))
`(,@(if tab_width `((tab-width . ,tab_width)))
,@(pcase style
("space" `((indent-tabs-mode . nil)))
("tab" `((indent-tabs-mode . t))))
,@(when (and size (featurep 'evil))
`((evil-shift-width . ,size)))
,@(cond
((null size) nil)
((functionp editorconfig-indent-size-vars)
(funcall editorconfig-indent-size-vars size))
(t (mapcar (lambda (v) `(,v . ,size)) editorconfig-indent-size-vars))))))