Skip to content

Commit 95992a6

Browse files
committed
Add plugins
0 parents  commit 95992a6

104 files changed

Lines changed: 12257 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.zip

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Micro 2.0 Plugins
2+
3+
This repository contains plugins that have been updated for micro 2.0. The goal is to
4+
have these changes merged back into the original plugin repositories, but in the meantime the updated
5+
versions will be available here.

editorconfig-micro/.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
5+
indent_style = space
6+
indent_size = 4
7+
end_of_line = lf
8+
charset = utf-8
9+
10+
trim_trailing_whitespace = true
11+
insert_final_newline = true
12+
max_line_length = 80
13+
14+
[*.json]
15+
indent_size = 2

editorconfig-micro/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 github.com/10sr + contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

editorconfig-micro/README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# editorconfig-micro
2+
3+
[EditorConfig] plugin for the [`micro`] editor. Works with `micro` v2.
4+
5+
6+
### Prerequisites
7+
8+
You'll need an `editorconfig` core executable, like [EditorConfig C Core], installed and on your PATH.
9+
10+
11+
### Installation
12+
13+
git clone https://github.com/10sr/editorconfig-micro "${XDG_CONFIG_HOME:-~/.config}/micro/plug/editorconfig-micro"
14+
15+
That's all! This plugin will be automatically enabled after you restart [`micro`]. It will automatically apply the appropriate editorconfig properties on files when they are opened or saved.
16+
17+
For more information, use `help editorconfig` in command mode or view `help/editorconfig.md` in this repo.
18+
19+
20+
### Supported Properties
21+
22+
* `root` (only used by EditorConfig Core)
23+
* `indent_style`
24+
* `indent_size`
25+
* `tab_width`
26+
* `charset`
27+
* Currently, [`micro`] only [supports][EditorConfig Options] the `utf-8` charset.
28+
* `end_of_line`
29+
* Currently, [`micro`] only [supports][EditorConfig Options] `lf` and `crlf`.
30+
* `insert_final_newline`
31+
* `trim_trailing_whitespace`
32+
33+
34+
### Unsupported Properties
35+
36+
* `max_line_length`
37+
38+
39+
### License
40+
41+
This software is licensed under MIT License.
42+
See [LICENSE](LICENSE) for details.
43+
44+
[`micro`]: https://micro-editor.github.io
45+
[EditorConfig]: http://editorconfig.org
46+
[EditorConfig Options]: https://github.com/zyedidia/micro/blob/master/runtime/help/options.md
47+
[EditorConfig C Core]: https://github.com/editorconfig/editorconfig-core-c
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
VERSION = "0.3.0"
2+
3+
local micro = import("micro")
4+
local microBuffer = import("micro/buffer")
5+
local config = import("micro/config")
6+
local shell = import("micro/shell")
7+
8+
local verbose = config.GetGlobalOption("editorconfigverbose") or false
9+
10+
local function errlog(msg)
11+
-- TODO: automatically open the log buffer like plugin list
12+
microBuffer.Log(("editorconfig error: %s\n"):format(msg))
13+
end
14+
15+
-- for debugging; use micro -debug, and then inspect log.txt
16+
local function log(msg)
17+
micro.Log(("editorconfig debug: %s"):format(msg))
18+
end
19+
20+
local function setSafely(key, value, buffer)
21+
if value == nil then
22+
-- log(("Ignore nil for %s"):format(key))
23+
else
24+
if config.GetGlobalOption(key) ~= value then
25+
log(("Set %s = %s"):format(key, value))
26+
buffer:SetOptionNative(key, value)
27+
end
28+
end
29+
end
30+
31+
local function setIndentation(properties, buffer)
32+
local indent_size_str = properties["indent_size"]
33+
local tab_width_str = properties["tab_width"]
34+
local indent_style = properties["indent_style"]
35+
36+
local indent_size = tonumber(indent_size_str, 10)
37+
local tab_width = tonumber(tab_width_str, 10)
38+
39+
if indent_size_str == "tab" then
40+
indent_size = tab_width
41+
elseif tab_width == nil then
42+
tab_width = indent_size
43+
end
44+
45+
if indent_style == "space" then
46+
setSafely("tabstospaces", true, buffer)
47+
setSafely("tabsize", indent_size, buffer)
48+
elseif indent_style == "tab" then
49+
setSafely("tabstospaces", false, buffer)
50+
setSafely("tabsize", tab_width, buffer)
51+
elseif indent_style ~= nil then
52+
errlog(("Unknown value for editorconfig property indent_style: %s"):format(indent_style or "nil"))
53+
end
54+
end
55+
56+
local function setEndOfLine(properties, buffer)
57+
local end_of_line = properties["end_of_line"]
58+
if end_of_line == "lf" then
59+
setSafely("fileformat", "unix", buffer)
60+
elseif end_of_line == "crlf" then
61+
setSafely("fileformat", "dos", buffer)
62+
elseif end_of_line == "cr" then
63+
-- See https://github.com/zyedidia/micro/blob/master/runtime/help/options.md for supported runtime options.
64+
errlog(("Value %s for editorconfig property end_of_line is not currently supported by micro."):format(end_of_line))
65+
elseif end_of_line ~= nil then
66+
errlog(("Unknown value for editorconfig property end_of_line: %s"):format(end_of_line))
67+
end
68+
end
69+
70+
local function setCharset(properties, buffer)
71+
local charset = properties["charset"]
72+
if charset ~= "utf-8" and charset ~= nil then
73+
-- TODO: I believe micro 2.0 added support for more charsets, so this is gonna have to be updated accordingly.
74+
-- Also now we need to actually set the charset since it isn't just utf-8.
75+
errlog(("Value %s for editorconfig property charset is not currently supported by micro."):format(charset))
76+
end
77+
end
78+
79+
local function setTrimTrailingWhitespace(properties, buffer)
80+
local val = properties["trim_trailing_whitespace"]
81+
if val == "true" then
82+
setSafely("rmtrailingws", true, buffer)
83+
elseif val == "false" then
84+
setSafely("rmtrailingws", false, buffer)
85+
elseif val ~= nil then
86+
errlog(("Unknown value for editorconfig property trim_trailing_whitespace: %s"):format(val))
87+
end
88+
end
89+
90+
local function setInsertFinalNewline(properties, buffer)
91+
local val = properties["insert_final_newline"]
92+
if val == "true" then
93+
setSafely("eofnewline", true, buffer)
94+
elseif val == "false" then
95+
setSafely("eofnewline", false, buffer)
96+
elseif val ~= nil then
97+
errlog(("Unknown value for editorconfig property insert_final_newline: %s"):format(val))
98+
end
99+
end
100+
101+
local function applyProperties(properties, buffer)
102+
setIndentation(properties, buffer)
103+
setEndOfLine(properties, buffer)
104+
setCharset(properties, buffer)
105+
setTrimTrailingWhitespace(properties, buffer)
106+
setInsertFinalNewline(properties, buffer)
107+
end
108+
109+
function onEditorConfigExit(output, args)
110+
if verbose then
111+
log(("Output: \n%s"):format(output))
112+
end
113+
114+
local properties = {}
115+
for line in output:gmatch('([^\n]+)') do
116+
local key, value = line:match('([^=]*)=(.*)')
117+
if key == nil or value == nil then
118+
errlog(("Failed to parse editorconfig output: %s"):format(line))
119+
return
120+
end
121+
key = key:gsub('^%s(.-)%s*$', '%1')
122+
value = value:gsub('^%s(.-)%s*$', '%1')
123+
properties[key] = value
124+
end
125+
126+
local buffer = args[1]
127+
applyProperties(properties, buffer)
128+
129+
if verbose then
130+
log("Running editorconfig done")
131+
end
132+
end
133+
134+
function getApplyProperties(bufpane)
135+
buffer = bufpane.Buf
136+
if (buffer.Path or "") == "" then
137+
-- Current buffer does not visit any file
138+
return
139+
end
140+
141+
local fullpath = buffer.AbsPath
142+
if fullpath == nil then
143+
messenger:Message("editorconfig: AbsPath is empty")
144+
return
145+
end
146+
147+
if verbose then;
148+
log(("Running editorconfig %s"):format(fullpath))
149+
end
150+
151+
shell.JobSpawn("editorconfig", {fullpath}, "", "", "editorconfig.onEditorConfigExit", buffer)
152+
end
153+
154+
function onBufPaneOpen(bp)
155+
getApplyProperties(bp)
156+
end
157+
158+
function onSave(bp)
159+
getApplyProperties(bp)
160+
return true
161+
end
162+
163+
function init()
164+
config.MakeCommand("editorconfig", getApplyProperties, config.NoComplete)
165+
config.AddRuntimeFile("editorconfig", config.RTHelp, "help/editorconfig.md")
166+
end
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
editorconfig-micro
2+
==================
3+
4+
[EditorConfig][] helps developers define and maintain
5+
consistent coding styles between different editors and IDEs.
6+
This is the EditorConfig plugin for the `micro` editor.
7+
8+
This plugin requires an editorconfig core executable to be installed.
9+
For example, download the [EditorConfig C Core][] and follow the instructions in
10+
the README and INSTALL files to install it.
11+
12+
13+
Usage
14+
-----
15+
16+
Once installed, this plugin will automatically execute `editorconfig.getApplyProperties`
17+
on files when they are opened or saved.
18+
19+
You can also explicitly use the `editorconfig` command in command mode, or bind it to
20+
a keystroke. For example:
21+
22+
```json
23+
{
24+
"Alt-e": "editorconfig.getApplyProperties"
25+
}
26+
```
27+
28+
If any editorconfig properties have been changed, they will be logged, which can be viewed
29+
with `log` in command mode. If you want to see verbose logs, you must manually add `"editorconfigverbose": true,` to your user settings in `~/.config/micro/settings.json`.
30+
31+
32+
[EditorConfig]: http://editorconfig.org
33+
[EditorConfig C Core]: https://github.com/editorconfig/editorconfig-core-c

editorconfig-micro/repo.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[{
2+
"Name": "editorconfig",
3+
"Description": "EditorConfig plugin for micro",
4+
"Tags": ["editorconfig", "utility", "format"],
5+
"Website": "https://github.com/10sr/editorconfig-micro",
6+
"Versions": [
7+
{
8+
"Version": "0.3.0",
9+
"Url": "https://github.com/10sr/editorconfig-micro/archive/v0.3.0.zip",
10+
"Require": {
11+
"micro": ">=2.0.0-1"
12+
}
13+
},
14+
{
15+
"Version": "0.2.3",
16+
"Url": "https://github.com/10sr/editorconfig-micro/archive/v0.2.3.zip",
17+
"Require": {
18+
"micro": ">=1.3.2"
19+
}
20+
}
21+
]
22+
}]

filemanager-plugin/.editorconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# EditorConfig is awesome: http://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
# Unix-style newlines with a newline ending every file
7+
[*]
8+
charset = utf-8
9+
end_of_line = lf
10+
indent_style = tab
11+
indent_size = 2
12+
insert_final_newline = true
13+
trim_trailing_whitespace = true
14+
15+
# Ignore .md files, because 2 spaces at end-of-line has meaning
16+
[*.md]
17+
trim_trailing_whitespace = false

0 commit comments

Comments
 (0)