Skip to content

Commit 1e9931d

Browse files
monnierxuhdev
andauthored
Cherrypick of Emacs fix for issue #380 (#386)
* (editorconfig-core-get-properties-hash): Simplify * editorconfig-core.el (editorconfig-core-get-properties-hash): Remove code that sets tab_width from indent_size and vice-versa, since that's better done (and is done) later in `editorconfig.el`. Also remove autoload cookie since this file is already `require`d from the caller anyway. Remove`confversion` arg, not used. (editorconfig-core-get-properties): Move to `editorconfig-el`. * bin/editorconfig-el (editorconfig-core-get-properties): New function taken from `editorconfig-core.el`. * editorconfig-core-handle.el: Fix silent misparse Cherrypick of Emacs commit e233513d2821. See #380 * lisp/editorconfig-core-handle.el (editorconfig-core-handle--parse-file): Fix regexp to not inadvertently match LF. Remove an O(N²) complexity. Use `line-number-at-pos`. * lisp/editorconfig.el (editorconfig--get-coding-system): Don't let errors propagate. --------- Co-authored-by: Hong Xu <hong@topbug.net>
1 parent 646c31b commit 1e9931d

2 files changed

Lines changed: 19 additions & 20 deletions

File tree

editorconfig-core-handle.el

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,7 @@ If CONF is not found return nil."
169169
;; nil when pattern not appeared yet, "" when pattern is empty ("[]")
170170
(pattern nil)
171171
;; Alist of properties for current PATTERN
172-
(props ())
173-
174-
;; Current line num
175-
(current-line-number 1))
172+
(props ()))
176173
(while (not (eobp))
177174
(skip-chars-forward " \t\f")
178175
(cond
@@ -190,7 +187,7 @@ If CONF is not found return nil."
190187
(setq props nil)
191188
(setq pattern newpattern)))
192189

193-
((looking-at "\\([^=: \t][^=:]*\\)[ \t]*[=:][ \t]*\\(.*?\\)[ \t]*$")
190+
((looking-at "\\([^=: \n\t][^=:\n]*\\)[ \t]*[=:][ \t]*\\(.*?\\)[ \t]*$")
194191
(let ((key (downcase (string-trim (match-string 1))))
195192
(value (match-string 2)))
196193
(if pattern
@@ -200,12 +197,10 @@ If CONF is not found return nil."
200197
top-props))))
201198

202199
(t (error "Error while reading config file: %s:%d:\n %s\n"
203-
conf current-line-number
200+
conf (line-number-at-pos)
204201
(buffer-substring-no-properties (line-beginning-position)
205202
(line-end-position)))))
206-
(setq current-line-number (1+ current-line-number))
207-
(goto-char (point-min))
208-
(forward-line (1- current-line-number)))
203+
(forward-line 1))
209204
(when pattern
210205
(push (make-editorconfig-core-handle-section
211206
:name pattern

editorconfig.el

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -837,17 +837,21 @@ F is that function, and FILENAME and ARGS are arguments passed to F."
837837
(defun editorconfig--get-coding-system (&optional _size)
838838
"Return the coding system to use according to EditorConfig.
839839
Meant to be used on `auto-coding-functions'."
840-
(when (and (stringp auto-coding-file-name)
841-
(file-name-absolute-p auto-coding-file-name)
842-
;; Don't recurse infinitely.
843-
(not (member auto-coding-file-name
844-
editorconfig--getting-coding-system)))
845-
(let* ((editorconfig--getting-coding-system
846-
(cons auto-coding-file-name editorconfig--getting-coding-system))
847-
(props (editorconfig-call-get-properties-function
848-
auto-coding-file-name)))
849-
(editorconfig-merge-coding-systems (gethash 'end_of_line props)
850-
(gethash 'charset props)))))
840+
;; Not only we don't want that an error in the `.editorconfig' file
841+
;; prevents opening a file but we don't want an error to be dropped on
842+
;; the floor by some `ignore-errors' higher up.
843+
(with-demoted-errors "EditorConfig: %S"
844+
(when (and (stringp auto-coding-file-name)
845+
(file-name-absolute-p auto-coding-file-name)
846+
;; Don't recurse infinitely.
847+
(not (member auto-coding-file-name
848+
editorconfig--getting-coding-system)))
849+
(let* ((editorconfig--getting-coding-system
850+
(cons auto-coding-file-name editorconfig--getting-coding-system))
851+
(props (editorconfig-call-get-properties-function
852+
auto-coding-file-name)))
853+
(editorconfig-merge-coding-systems (gethash 'end_of_line props)
854+
(gethash 'charset props))))))
851855

852856
;;;###autoload
853857
(define-minor-mode editorconfig-mode

0 commit comments

Comments
 (0)