Permalink
Browse files

Make EditorConfig core function pluggable

Close #41

Squashed commit of the following:

commit e91aca6
Author: 10sr <8slashes+git@gmail.com>
Date:   Sun Oct 25 03:19:26 2015 +0900

    Fix typo in docstring

commit 76ce139
Author: 10sr <8slashes+git@gmail.com>
Date:   Tue Oct 13 13:51:13 2015 +0900

    Implement edconf-get-properties-from-exec

commit 23baf52
Author: 10sr <8slashes+git@gmail.com>
Date:   Mon Oct 12 03:18:54 2015 +0900

    Add variable edconf-get-properties-function
  • Loading branch information...
10sr authored and xuhdev committed Oct 28, 2015
1 parent 9165d10 commit 3835e4b71d17febe7646493465345538b81a0276
Showing with 32 additions and 12 deletions.
  1. +32 −12 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
@@ -276,20 +286,30 @@ NOTE: Only the **buffer local** value of VARIABLE will be set."
(val (mapconcat 'identity (cdr key-val) "")))
(puthash key val properties)))))))
(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))
;;;###autoload
(defun edconf-find-file-hook ()
(if (executable-find edconf-exec-path)
(let ((props (edconf-parse-properties (edconf-get-properties))))
(edconf-set-indentation (gethash 'indent_style props)
(gethash 'indent_size props)
(gethash 'tab_width props))
(edconf-set-line-ending (gethash 'end_of_line props))
(edconf-set-trailing-nl (gethash 'insert_final_newline props))
(edconf-set-trailing-ws (gethash 'trim_trailing_whitespace props))
(edconf-set-line-length (gethash 'max_line_length props))
(dolist (hook edconf-custom-hooks)
(funcall hook props)))
(display-warning :error "Unable to find editorconfig executable. Styles will not be applied.")))
(let ((props (and (functionp edconf-get-properties-function)
(funcall edconf-get-properties-function))))
(if props
(progn
(edconf-set-indentation (gethash 'indent_style props)
(gethash 'indent_size props)
(gethash 'tab_width props))
(edconf-set-line-ending (gethash 'end_of_line props))
(edconf-set-trailing-nl (gethash 'insert_final_newline props))
(edconf-set-trailing-ws (gethash 'trim_trailing_whitespace props))
(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-hook 'find-file-hook 'edconf-find-file-hook)

0 comments on commit 3835e4b

Please sign in to comment.