Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit 7658b52

Browse files
author
10sr
authored
Merge pull request #3 from JoshuaRLi/master
The 2018 Update
2 parents a8c9da4 + 4793472 commit 7658b52

5 files changed

Lines changed: 65 additions & 56 deletions

File tree

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2016 10sr
3+
Copyright (c) 2018 github.com/10sr + contributors
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,48 @@
1-
editorconfig-micro
2-
==================
1+
# editorconfig-micro
32

4-
[EditorConfig][] Plugin for [micro][] editor
3+
[EditorConfig] Plugin for the [`micro`] editor
54

65

7-
Prerequisite
8-
------------
6+
### Prerequisites
97

10-
* [Micro][micro] editor >= 1.1.3
11-
* An `editorconfig` core executable ([EditorConfig C Core][] for example)
8+
* [`micro`] editor >= 1.3.2
9+
* An `editorconfig` core executable (e.g. [EditorConfig C Core])
1210

1311

14-
Install
15-
-------
12+
### Installation
1613

17-
Once you installed a core program, this plugin can be
18-
installed via micro plugin system:
14+
While in micro's command mode (default keybinding: <kbd>CtrlE</kbd>):
1915

20-
> plugin install editorconfig
16+
`plugin install editorconfig`
2117

22-
(Type <kbd>CtrlE</kbd> `plugin install editorconfig` <kbd>Enter</kbd>)
18+
That's all! This plugin will be automatically enabled after you restart [`micro`].
2319

24-
This plugin will be automatically enabled after you restart micro editor.
2520

21+
### Supported Properties
2622

27-
Supported Properties
28-
--------------------
29-
23+
* `root` (only used by EditorConfig Core)
3024
* `indent_style`
3125
* `indent_size`
3226
* `tab_width`
27+
* `charset`
28+
* Currently, [`micro`] only [supports][EditorConfig Options] the UTF-8 charset.
29+
* `end_of_line`
30+
* Currently, [`micro`] only [supports][EditorConfig Options] LF and CRLF.
3331
* `insert_final_newline`
34-
* `root` (Only used by EditorConfig Core)
32+
* `trim_trailing_whitespace`
3533

36-
### On the Backlog
3734

38-
* `end_of_line`
39-
* Currently micro supports LF only
40-
* `charset`
41-
* Currently micro supports UTF-8 only
42-
* `trim_trailing_whitespace`
43-
* `max_line_length`
35+
### Unsupported Properties
4436

37+
* `max_line_length`
4538

4639

47-
License
48-
-------
40+
### License
4941

5042
This software is licensed under MIT License.
5143
See [LICENSE](LICENSE) for details.
5244

53-
54-
55-
[micro]: https://micro-editor.github.io
45+
[`micro`]: https://micro-editor.github.io
5646
[EditorConfig]: http://editorconfig.org
47+
[EditorConfig Options]: https://github.com/zyedidia/micro/blob/master/runtime/help/options.md
5748
[EditorConfig C Core]: https://github.com/editorconfig/editorconfig-core-c

editorconfig.lua

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION = "0.1.1"
1+
VERSION = "0.2.0"
22

33
local 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
4646
end
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
6078
end
6179

6280
local 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
7189
end
7290

7391
local 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)
8097
end
8198

@@ -126,6 +143,7 @@ function onViewOpen(view)
126143
end
127144

128145
function onSave(view)
146+
getApplyProperties(view)
129147
end
130148

131149
MakeCommand("editorconfig", "editorconfig.getApplyProperties")

help/editorconfig.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ editorconfig-micro
33

44
[EditorConfig][] helps developers define and maintain
55
consistent coding styles between different editors and IDEs.
6-
This is the EditorConfig plugin for micro editor.
6+
This is the EditorConfig plugin for the `micro` editor.
77

8-
This plugin requires an editorconfig executable be installed.
8+
This plugin requires an editorconfig core executable to be installed.
99
For example, download the [EditorConfig C Core][] and follow the instructions in
1010
the README and INSTALL files to install it.
1111

@@ -14,21 +14,21 @@ Usage
1414
-----
1515

1616
Once installed, this plugin will automatically execute `editorconfig` for
17-
current files and apply properties when opening buffers for them.
17+
current files and apply properties when opening buffers for them. `editorconfig`
18+
will also be executed upon every file save.
1819

19-
This plugin also provides one command `editorconfig`.
20+
This plugin also provides one command: `editorconfig`.
2021
You can use this command to explicitly apply properties after updating
2122
`.editorconfig` files.
2223

23-
By default there is no keybindings for this command, but you can bind a key to
24-
this command in you `bindings.json`:
24+
By default there are no keybindings for this command, but you can bind a key to
25+
this command in your `bindings.json`. For example:
2526

2627
``` json
2728
{
2829
"Alt-e": "editorconfig.getApplyProperties"
2930
}
3031
```
3132

32-
3333
[EditorConfig]: http://editorconfig.org
3434
[EditorConfig C Core]: https://github.com/editorconfig/editorconfig-core-c

repo.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
"Tags": ["editorconfig", "utility", "format"],
55
"Versions": [
66
{
7-
"Version": "0.1.1",
8-
"Url": "https://github.com/10sr/editorconfig-micro/archive/v0.1.1.zip",
7+
"Version": "0.2.0",
8+
"Url": "https://github.com/10sr/editorconfig-micro/archive/v0.2.0.zip",
99
"Require": {
10-
"micro": ">=1.1.3"
10+
"micro": ">=1.3.2"
1111
}
1212
}
1313
]

0 commit comments

Comments
 (0)