branch: scratch/editorconfig-cc
commit 6bfbea985c29952c7c763823639b5337304d539c
Author: 10sr <8slashes+...@gmail.com>
Commit: Stefan Monnier <monn...@iro.umontreal.ca>

    Catch error thrown from get-properties-function and display it
    
    This commit also fixes `display-warning' usage.
---
 editorconfig.el | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/editorconfig.el b/editorconfig.el
index 014e5dc9e3..c3759ad837 100644
--- a/editorconfig.el
+++ b/editorconfig.el
@@ -248,16 +248,22 @@ It calls `editorconfig-get-properties-from-exec' if
   "Apply EditorConfig properties for current buffer."
   (interactive)
   (when buffer-file-name
-    (let ((props (and (functionp editorconfig-get-properties-function)
-                      (funcall editorconfig-get-properties-function))))
-      (if props
-        (progn
-          (editorconfig-set-coding-system
-            (gethash 'end_of_line props)
-            (gethash 'charset props))
-          (editorconfig-set-line-length (gethash 'max_line_length props))
-          (run-hook-with-args 'editorconfig-custom-hooks props))
-        (display-warning :error "EditorConfig core program is not available.  
Styles will not be applied.")))))
+    (condition-case err
+      (progn
+        (unless (functionp editorconfig-get-properties-function)
+          (error "Invalid editorconfig-get-properties-function value"))
+        (let ((props (funcall editorconfig-get-properties-function)))
+          (progn
+            (editorconfig-set-coding-system
+              (gethash 'end_of_line props)
+              (gethash 'charset props))
+            (editorconfig-set-line-length (gethash 'max_line_length props))
+            (run-hook-with-args 'editorconfig-custom-hooks props))))
+      (error
+        (display-warning 'editorconfig
+          (concat (error-message-string err)
+            ".  Styles will not be applied.")
+          :error)))))
 
 ;;;###autoload
 (define-minor-mode editorconfig-mode

Reply via email to