emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] scratch/editorconfig-cc a4b8e55bf4 032/351: Make EditorConfig c


From: Stefan Monnier
Subject: [nongnu] scratch/editorconfig-cc a4b8e55bf4 032/351: Make EditorConfig core function pluggable
Date: Thu, 13 Jun 2024 18:38:38 -0400 (EDT)

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

    Make EditorConfig core function pluggable
    
    Close #41
    
    Squashed commit of the following:
    
    commit e91aca6f38d9c42be19cc49aafc75ac086907b00
    Author: 10sr <8slashes+git@gmail.com>
    Date:   Sun Oct 25 03:19:26 2015 +0900
    
        Fix typo in docstring
    
    commit 76ce139cd0a0ff6bc250615ca7bb94868c85c41d
    Author: 10sr <8slashes+git@gmail.com>
    Date:   Tue Oct 13 13:51:13 2015 +0900
    
        Implement edconf-get-properties-from-exec
    
    commit 23baf520c83a7cb68634cd173ce28f9a6842f593
    Author: 10sr <8slashes+git@gmail.com>
    Date:   Mon Oct 12 03:18:54 2015 +0900
    
        Add variable edconf-get-properties-function
---
 editorconfig.el | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/editorconfig.el b/editorconfig.el
index 6f5ce71cff..f362ea7061 100644
--- a/editorconfig.el
+++ b/editorconfig.el
@@ -44,6 +44,16 @@
   :type 'string
   :group 'editorconfig)
 
+(defcustom edconf-get-properties-function
+  'edconf-get-properties-from-exec
+  "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.
+The hash object should have symbols of property names as keys and strings of
+property values as values."
+  :type 'function
+  :group 'editorconfig)
+
 (defcustom edconf-custom-hooks ()
   "A list of custom hooks after loading common EditorConfig settings
 
@@ -104,10 +114,24 @@ property emacs_linum to decide whether to show line 
numbers on the left
 (defun edconf-parse-properties (props-string)
   )
 
+(defun edconf-get-properties-from-exec ()
+  "Get EditorConfig properties of current buffer by calling 
`edconf-exec-path'."
+  (if (executable-find edconf-exec-path)
+    (edconf-parse-properties (edconf-get-properties))
+    (display-warning :error
+      "Unable to find editorconfig executable.")
+    nil))
+
 (defun edconf-find-file-hook ()
+  (let ((props (and (functionp edconf-get-properties-function)
+                 (funcall edconf-get-properties-function))))
+    (if props
+      (progn
       (edconf-set-line-length (gethash 'max_line_length props))
       (dolist (hook edconf-custom-hooks)
         (funcall hook props)))
+      (display-warning :error "EditorConfig core program is not available.  
Styles will not be applied."))))
+
 
 ;;;###autoload
 (add-to-list 'auto-mode-alist '("/\\.editorconfig\\'" . conf-unix-mode))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]