branch: scratch/editorconfig-cc commit 21ea6f23c2e9629dcb45e67a91a5326782464dd9 Author: 10sr <8slashes+...@gmail.com> Commit: Stefan Monnier <monn...@iro.umontreal.ca>
Support charset property --- editorconfig.el | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/editorconfig.el b/editorconfig.el index 9a7be9c969..897ea7e909 100644 --- a/editorconfig.el +++ b/editorconfig.el @@ -193,9 +193,25 @@ NOTE: Only the **buffer local** value of VARIABLE will be set." (when (not (equal size "tab")) (setq size nil))) ) -(defun editorconfig-set-line-ending (end-of-line) - "Set line ending style to CR, LF, or CRLF by END-OF-LINE." - ) +(defun editorconfig-set-coding-system (end-of-line charset) + "Set buffer coding system by END-OF-LINE and CHARSET." + (let ((eol (cond + ((equal end-of-line "lf") 'undecided-unix) + ((equal end-of-line "cr") 'undecided-mac) + ((equal end-of-line "crlf") 'undecided-dos) + (t 'undecided))) + (cs (cond + ((equal charset "latin1") 'iso-latin-1) + ((equal charset "utf-8") 'utf-8) + ((equal charset "utf-8-bom") 'utf-8-with-signature) + ((equal charset "utf-16be") 'utf-16be) + ((equal charset "utf-16le") 'utf-16le) + (t 'undecided)))) + (set-buffer-file-coding-system (merge-coding-systems + cs + eol) + nil t))) + (defun editorconfig-set-line-length (length) "Set the max line length (fill-column) to LENGTH." @@ -234,6 +250,9 @@ It calls `editorconfig-get-properties-from-exec' if (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.")))))