branch: elpa/editorconfig
commit 1e9931d5f38a8d8cb8a92cf726d64696550bfc95
Author: monnier <[email protected]>
Commit: GitHub <[email protected]>
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 https://github.com/editorconfig/editorconfig-emacs/issues/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 <[email protected]>
---
editorconfig-core-handle.el | 13 ++++---------
editorconfig.el | 26 +++++++++++++++-----------
2 files changed, 19 insertions(+), 20 deletions(-)
diff --git a/editorconfig-core-handle.el b/editorconfig-core-handle.el
index 588419fac9d..fda04202b57 100644
--- a/editorconfig-core-handle.el
+++ b/editorconfig-core-handle.el
@@ -169,10 +169,7 @@ If CONF is not found return 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))
+ (props ()))
(while (not (eobp))
(skip-chars-forward " \t\f")
(cond
@@ -190,7 +187,7 @@ If CONF is not found return nil."
(setq props nil)
(setq pattern newpattern)))
- ((looking-at "\\([^=: \t][^=:]*\\)[ \t]*[=:][ \t]*\\(.*?\\)[ \t]*$")
+ ((looking-at "\\([^=: \n\t][^=:\n]*\\)[ \t]*[=:][ \t]*\\(.*?\\)[
\t]*$")
(let ((key (downcase (string-trim (match-string 1))))
(value (match-string 2)))
(if pattern
@@ -200,12 +197,10 @@ If CONF is not found return nil."
top-props))))
(t (error "Error while reading config file: %s:%d:\n %s\n"
- conf current-line-number
+ conf (line-number-at-pos)
(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)))
+ (forward-line 1))
(when pattern
(push (make-editorconfig-core-handle-section
:name pattern
diff --git a/editorconfig.el b/editorconfig.el
index f82f49d703e..84b04dacb6a 100644
--- a/editorconfig.el
+++ b/editorconfig.el
@@ -837,17 +837,21 @@ F is that function, and FILENAME and ARGS are arguments
passed to F."
(defun editorconfig--get-coding-system (&optional _size)
"Return the coding system to use according to EditorConfig.
Meant to be used on `auto-coding-functions'."
- (when (and (stringp auto-coding-file-name)
- (file-name-absolute-p auto-coding-file-name)
- ;; Don't recurse infinitely.
- (not (member auto-coding-file-name
- editorconfig--getting-coding-system)))
- (let* ((editorconfig--getting-coding-system
- (cons auto-coding-file-name editorconfig--getting-coding-system))
- (props (editorconfig-call-get-properties-function
- auto-coding-file-name)))
- (editorconfig-merge-coding-systems (gethash 'end_of_line props)
- (gethash 'charset props)))))
+ ;; Not only we don't want that an error in the `.editorconfig' file
+ ;; prevents opening a file but we don't want an error to be dropped on
+ ;; the floor by some `ignore-errors' higher up.
+ (with-demoted-errors "EditorConfig: %S"
+ (when (and (stringp auto-coding-file-name)
+ (file-name-absolute-p auto-coding-file-name)
+ ;; Don't recurse infinitely.
+ (not (member auto-coding-file-name
+ editorconfig--getting-coding-system)))
+ (let* ((editorconfig--getting-coding-system
+ (cons auto-coding-file-name editorconfig--getting-coding-system))
+ (props (editorconfig-call-get-properties-function
+ auto-coding-file-name)))
+ (editorconfig-merge-coding-systems (gethash 'end_of_line props)
+ (gethash 'charset props))))))
;;;###autoload
(define-minor-mode editorconfig-mode