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

    Use core in elisp as a fallback
    
    editorconfig-core-get-properties-hash will be called when editorconfig
    executable is not found.
---
 editorconfig.el | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/editorconfig.el b/editorconfig.el
index 174ad8f679..a7947ac0ed 100644
--- a/editorconfig.el
+++ b/editorconfig.el
@@ -39,6 +39,10 @@
 
 ;;; Code:
 
+(declare-function editorconfig-core-get-properties-hash
+  "editorconfig-core"
+  nil)
+
 (defcustom editorconfig-exec-path
   "editorconfig"
   "EditorConfig command"
@@ -50,7 +54,7 @@
   "0.5")
 
 (defcustom editorconfig-get-properties-function
-  'editorconfig-get-properties-from-exec
+  'editorconfig-get-properties
   "Function to get EditorConofig properties for current buffer.
 This function will be called with no argument and should return a hash object
 containing properties, or nil if any core program is not available.
@@ -188,7 +192,7 @@ NOTE: Only the **buffer local** value of VARIABLE will be 
set."
   (when (editorconfig-string-integer-p length)
     (set-fill-column (string-to-number length))))
 
-(defun editorconfig-get-properties ()
+(defun editorconfig-call-editorconfig-exec ()
   )
 
 (defun editorconfig-parse-properties (props-string)
@@ -197,11 +201,21 @@ NOTE: Only the **buffer local** value of VARIABLE will be 
set."
 (defun editorconfig-get-properties-from-exec ()
   "Get EditorConfig properties of current buffer by calling 
`editorconfig-exec-path'."
   (if (executable-find editorconfig-exec-path)
-    (editorconfig-parse-properties (editorconfig-get-properties))
+    (editorconfig-parse-properties (editorconfig-call-editorconfig-exec))
     (display-warning :error
       "Unable to find editorconfig executable.")
     nil))
 
+(defun editorconfig-get-properties ()
+  "Get EditorConfig properties of current buffer.
+
+It calls `editorconfig-get-properties-from-exec' if
+`editorconfig-exec-path` is found, otherwise
+`editorconfig-core-get-properties-hash'."
+  (if (executable-find editorconfig-exec-path)
+    (editorconfig-get-propergies-from-exec)
+    (editorconfig-core-get-properties-hash)))
+
 (defun editorconfig-apply ()
   (when buffer-file-name
     (let ((props (and (functionp editorconfig-get-properties-function)

Reply via email to