branch: scratch/editorconfig-cc commit 6cf680e9c73a920db0233b4374a901f634b70501 Author: 10sr <8slashes+...@gmail.com> Commit: Stefan Monnier <monn...@iro.umontreal.ca>
Print line number and its content on parse error (#95) --- editorconfig-core-handle.el | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/editorconfig-core-handle.el b/editorconfig-core-handle.el index 042d05c356..84e69e8fa2 100644 --- a/editorconfig-core-handle.el +++ b/editorconfig-core-handle.el @@ -157,6 +157,8 @@ If CONF is not found return nil." ;; Alist of properties for current PATTERN (props ()) + ;; Current line num + (current-line-number 1) ) (while (not (eq (point) point-max)) (setq line @@ -183,8 +185,10 @@ If CONF is not found return nil." (let ((idx (string-match "=\\|:" line))) (unless idx - (error (format "Failed to parse file: %s" - conf))) + (error "Error while reading config file: %s:%d:\n %s\n" + conf + current-line-number + line)) (let ( (key (downcase (editorconfig-core-handle--string-trim (substring line @@ -202,7 +206,12 @@ If CONF is not found return nil." (setq top-props `(,@top-props (,key . ,value)))))))) ) - (forward-line 1)) + (setq current-line-number + (1+ current-line-number)) + ;; Use this code instead of goto-line for Lisp program + (goto-char (point-min)) + (forward-line (1- current-line-number)) + ) (when pattern (setq all-props `(,@all-props (,pattern . ,props))))