1- VERSION = " 0.1.1 "
1+ VERSION = " 0.2.0 "
22
33local function logger (msg , view )
44 messenger :AddLog ((" EditorConfig <%s>: %s" ):
@@ -40,23 +40,41 @@ local function setIndentation(properties, view)
4040 setSafely (" tabstospaces" , " off" , view )
4141 setSafely (" tabsize" , tab_width , view )
4242 else
43- logger ((" Unknown indent_style: %s" ):format (indent_style or " nil" ), view )
43+ logger ((" Unknown value for editorconfig property indent_style: %s" ):format (indent_style or " nil" ), view )
4444 setSafely (" tabsize" , indent_size , view )
4545 end
4646end
4747
48- local function setCodingSystem (properties , view )
49- -- Currently micro does not support changing coding-systems
50- -- (Always use utf-8 with LF?)
48+ local function setEndOfLine (properties , view )
5149 local end_of_line = properties [" end_of_line" ]
52- local charset = properties [" charset" ]
53- if not (end_of_line == nil or end_of_line == " lf" ) then
54- msg ((" Unsupported end_of_line: %s" ):format (end_of_line ), view )
50+ if end_of_line == " lf" then
51+ setSafely (" fileformat" , " unix" , view )
52+ elseif end_of_line == " crlf" then
53+ setSafely (" fileformat" , " dos" , view )
54+ elseif end_of_line == " cr" then
55+ -- See https://github.com/zyedidia/micro/blob/master/runtime/help/options.md for supported runtime options.
56+ msg ((" Value %s for editorconfig property end_of_line is not currently supported by micro." ):format (end_of_line ), view )
57+ else
58+ msg ((" Unknown value for editorconfig property end_of_line: %s" ):format (end_of_line ), view )
5559 end
56- if not (charset == nil or charset == " utf-8" ) then
57- msg ((" Unsupported charset: %s" ):format (charset ), view )
60+ end
61+
62+ local function setCharset (properties , view )
63+ local charset = properties [" charset" ]
64+ if charset ~= " utf-8" then
65+ msg ((" Value %s for editorconfig property charset is not currently supported by micro." ):format (charset ), view )
5866 end
67+ end
5968
69+ local function setTrimTrailingWhitespace (properties , view )
70+ local val = properties [" trim_trailing_whitespace" ]
71+ if val == " true" then
72+ setSafely (" rmtrailingws" , true , view )
73+ elseif val == " false" then
74+ setSafely (" rmtrailingws" , false , view )
75+ else
76+ logger ((" Unknown value for editorconfig property trim_trailing_whitespace: %s" ):format (val ), view )
77+ end
6078end
6179
6280local function setInsertFinalNewline (properties , view )
@@ -66,16 +84,15 @@ local function setInsertFinalNewline(properties, view)
6684 elseif val == " false" then
6785 setSafely (" eofnewline" , false , view )
6886 else
69- logger ((" Unknown insert_final_newline: %s" ):format (val ), view )
87+ logger ((" Unknown value for editorconfig property insert_final_newline: %s" ):format (val ), view )
7088 end
7189end
7290
7391local function applyProperties (properties , view )
7492 setIndentation (properties , view )
75- setCodingSystem (properties , view )
76- -- `ruler' is not what we want!
77- -- setMaxLineLength(properties, view)
78- -- setTrimTrailingWhitespace(properties, view)
93+ setEndOfLine (properties , view )
94+ setCharset (properties , view )
95+ setTrimTrailingWhitespace (properties , view )
7996 setInsertFinalNewline (properties , view )
8097end
8198
@@ -126,6 +143,7 @@ function onViewOpen(view)
126143end
127144
128145function onSave (view )
146+ getApplyProperties (view )
129147end
130148
131149MakeCommand (" editorconfig" , " editorconfig.getApplyProperties" )
0 commit comments