Function: editorconfig-core-handle--parse-file
editorconfig-core-handle--parse-file is a byte-compiled function
defined in editorconfig-core-handle.el.gz.
Signature
(editorconfig-core-handle--parse-file CONF)
Documentation
Parse EditorConfig file CONF.
This function returns a editorconfig-core-handle.
If CONF is not found return nil.
Source Code
;; Defined in /usr/src/emacs/lisp/editorconfig-core-handle.el.gz
(defun editorconfig-core-handle--parse-file (conf)
"Parse EditorConfig file CONF.
This function returns a `editorconfig-core-handle'.
If CONF is not found return nil."
(when (file-readable-p conf)
(with-temp-buffer
;; NOTE: Use this instead of insert-file-contents-literally to enable
;; code conversion
(insert-file-contents conf)
(goto-char (point-min))
(let ((sections ())
(top-props nil)
;; nil when pattern not appeared yet, "" when pattern is empty ("[]")
(pattern nil)
;; Alist of properties for current PATTERN
(props ())
;; Current line num
(current-line-number 1))
(while (not (eobp))
(skip-chars-forward " \t\f")
(cond
((looking-at "\\(?:[#;].*\\)?$")
nil)
;; Start of section
((looking-at "\\[\\(.*\\)\\][ \t]*$")
(let ((newpattern (match-string 1)))
(when pattern
(push (make-editorconfig-core-handle-section
:name pattern
:props (nreverse props))
sections))
(setq props nil)
(setq pattern newpattern)))
((looking-at "\\([^=: \t]+\\)[ \t]*[=:][ \t]*\\(.*?\\)[ \t]*$")
(let ((key (downcase (match-string 1)))
(value (match-string 2)))
(when (and (< (length key) 51)
(< (length value) 256))
(if pattern
(when (< (length pattern) 4097) ;;FIXME: 4097?
(push `(,key . ,value)
props))
(push `(,key . ,value)
top-props)))))
(t (error "Error while reading config file: %s:%d:\n %s\n"
conf current-line-number
(buffer-substring-no-properties (line-beginning-position)
(line-end-position)))))
(setq current-line-number (1+ current-line-number))
(goto-char (point-min))
(forward-line (1- current-line-number)))
(when pattern
(push (make-editorconfig-core-handle-section
:name pattern
:props (nreverse props))
sections))
(make-editorconfig-core-handle
:top-props (nreverse top-props)
:sections (nreverse sections)
:mtime (nth 5 (file-attributes conf))
:path conf)))))