Skip to content

Commit

Permalink
Add plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
zyedidia committed Feb 10, 2020
0 parents commit 95992a6
Show file tree
Hide file tree
Showing 104 changed files with 12,257 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.zip
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Micro 2.0 Plugins

This repository contains plugins that have been updated for micro 2.0. The goal is to
have these changes merged back into the original plugin repositories, but in the meantime the updated
versions will be available here.
15 changes: 15 additions & 0 deletions editorconfig-micro/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]

indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8

trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 80

[*.json]
indent_size = 2
21 changes: 21 additions & 0 deletions editorconfig-micro/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 github.com/10sr + contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
47 changes: 47 additions & 0 deletions editorconfig-micro/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# editorconfig-micro

[EditorConfig] plugin for the [`micro`] editor. Works with `micro` v2.


### Prerequisites

You'll need an `editorconfig` core executable, like [EditorConfig C Core], installed and on your PATH.


### Installation

git clone https://github.com/10sr/editorconfig-micro "${XDG_CONFIG_HOME:-~/.config}/micro/plug/editorconfig-micro"

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.

For more information, use `help editorconfig` in command mode or view `help/editorconfig.md` in this repo.


### Supported Properties

* `root` (only used by EditorConfig Core)
* `indent_style`
* `indent_size`
* `tab_width`
* `charset`
* Currently, [`micro`] only [supports][EditorConfig Options] the `utf-8` charset.
* `end_of_line`
* Currently, [`micro`] only [supports][EditorConfig Options] `lf` and `crlf`.
* `insert_final_newline`
* `trim_trailing_whitespace`


### Unsupported Properties

* `max_line_length`


### License

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

[`micro`]: https://micro-editor.github.io
[EditorConfig]: http://editorconfig.org
[EditorConfig Options]: https://github.com/zyedidia/micro/blob/master/runtime/help/options.md
[EditorConfig C Core]: https://github.com/editorconfig/editorconfig-core-c
166 changes: 166 additions & 0 deletions editorconfig-micro/editorconfig.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
VERSION = "0.3.0"

local micro = import("micro")
local microBuffer = import("micro/buffer")
local config = import("micro/config")
local shell = import("micro/shell")

local verbose = config.GetGlobalOption("editorconfigverbose") or false

local function errlog(msg)
-- TODO: automatically open the log buffer like plugin list
microBuffer.Log(("editorconfig error: %s\n"):format(msg))
end

-- for debugging; use micro -debug, and then inspect log.txt
local function log(msg)
micro.Log(("editorconfig debug: %s"):format(msg))
end

local function setSafely(key, value, buffer)
if value == nil then
-- log(("Ignore nil for %s"):format(key))
else
if config.GetGlobalOption(key) ~= value then
log(("Set %s = %s"):format(key, value))
buffer:SetOptionNative(key, value)
end
end
end

local function setIndentation(properties, buffer)
local indent_size_str = properties["indent_size"]
local tab_width_str = properties["tab_width"]
local indent_style = properties["indent_style"]

local indent_size = tonumber(indent_size_str, 10)
local tab_width = tonumber(tab_width_str, 10)

if indent_size_str == "tab" then
indent_size = tab_width
elseif tab_width == nil then
tab_width = indent_size
end

if indent_style == "space" then
setSafely("tabstospaces", true, buffer)
setSafely("tabsize", indent_size, buffer)
elseif indent_style == "tab" then
setSafely("tabstospaces", false, buffer)
setSafely("tabsize", tab_width, buffer)
elseif indent_style ~= nil then
errlog(("Unknown value for editorconfig property indent_style: %s"):format(indent_style or "nil"))
end
end

local function setEndOfLine(properties, buffer)
local end_of_line = properties["end_of_line"]
if end_of_line == "lf" then
setSafely("fileformat", "unix", buffer)
elseif end_of_line == "crlf" then
setSafely("fileformat", "dos", buffer)
elseif end_of_line == "cr" then
-- See https://github.com/zyedidia/micro/blob/master/runtime/help/options.md for supported runtime options.
errlog(("Value %s for editorconfig property end_of_line is not currently supported by micro."):format(end_of_line))
elseif end_of_line ~= nil then
errlog(("Unknown value for editorconfig property end_of_line: %s"):format(end_of_line))
end
end

local function setCharset(properties, buffer)
local charset = properties["charset"]
if charset ~= "utf-8" and charset ~= nil then
-- TODO: I believe micro 2.0 added support for more charsets, so this is gonna have to be updated accordingly.
-- Also now we need to actually set the charset since it isn't just utf-8.
errlog(("Value %s for editorconfig property charset is not currently supported by micro."):format(charset))
end
end

local function setTrimTrailingWhitespace(properties, buffer)
local val = properties["trim_trailing_whitespace"]
if val == "true" then
setSafely("rmtrailingws", true, buffer)
elseif val == "false" then
setSafely("rmtrailingws", false, buffer)
elseif val ~= nil then
errlog(("Unknown value for editorconfig property trim_trailing_whitespace: %s"):format(val))
end
end

local function setInsertFinalNewline(properties, buffer)
local val = properties["insert_final_newline"]
if val == "true" then
setSafely("eofnewline", true, buffer)
elseif val == "false" then
setSafely("eofnewline", false, buffer)
elseif val ~= nil then
errlog(("Unknown value for editorconfig property insert_final_newline: %s"):format(val))
end
end

local function applyProperties(properties, buffer)
setIndentation(properties, buffer)
setEndOfLine(properties, buffer)
setCharset(properties, buffer)
setTrimTrailingWhitespace(properties, buffer)
setInsertFinalNewline(properties, buffer)
end

function onEditorConfigExit(output, args)
if verbose then
log(("Output: \n%s"):format(output))
end

local properties = {}
for line in output:gmatch('([^\n]+)') do
local key, value = line:match('([^=]*)=(.*)')
if key == nil or value == nil then
errlog(("Failed to parse editorconfig output: %s"):format(line))
return
end
key = key:gsub('^%s(.-)%s*$', '%1')
value = value:gsub('^%s(.-)%s*$', '%1')
properties[key] = value
end

local buffer = args[1]
applyProperties(properties, buffer)

if verbose then
log("Running editorconfig done")
end
end

function getApplyProperties(bufpane)
buffer = bufpane.Buf
if (buffer.Path or "") == "" then
-- Current buffer does not visit any file
return
end

local fullpath = buffer.AbsPath
if fullpath == nil then
messenger:Message("editorconfig: AbsPath is empty")
return
end

if verbose then;
log(("Running editorconfig %s"):format(fullpath))
end

shell.JobSpawn("editorconfig", {fullpath}, "", "", "editorconfig.onEditorConfigExit", buffer)
end

function onBufPaneOpen(bp)
getApplyProperties(bp)
end

function onSave(bp)
getApplyProperties(bp)
return true
end

function init()
config.MakeCommand("editorconfig", getApplyProperties, config.NoComplete)
config.AddRuntimeFile("editorconfig", config.RTHelp, "help/editorconfig.md")
end
33 changes: 33 additions & 0 deletions editorconfig-micro/help/editorconfig.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
editorconfig-micro
==================

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

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


Usage
-----

Once installed, this plugin will automatically execute `editorconfig.getApplyProperties`
on files when they are opened or saved.

You can also explicitly use the `editorconfig` command in command mode, or bind it to
a keystroke. For example:

```json
{
"Alt-e": "editorconfig.getApplyProperties"
}
```

If any editorconfig properties have been changed, they will be logged, which can be viewed
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`.


[EditorConfig]: http://editorconfig.org
[EditorConfig C Core]: https://github.com/editorconfig/editorconfig-core-c
22 changes: 22 additions & 0 deletions editorconfig-micro/repo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[{
"Name": "editorconfig",
"Description": "EditorConfig plugin for micro",
"Tags": ["editorconfig", "utility", "format"],
"Website": "https://github.com/10sr/editorconfig-micro",
"Versions": [
{
"Version": "0.3.0",
"Url": "https://github.com/10sr/editorconfig-micro/archive/v0.3.0.zip",
"Require": {
"micro": ">=2.0.0-1"
}
},
{
"Version": "0.2.3",
"Url": "https://github.com/10sr/editorconfig-micro/archive/v0.2.3.zip",
"Require": {
"micro": ">=1.3.2"
}
}
]
}]
17 changes: 17 additions & 0 deletions filemanager-plugin/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
charset = utf-8
end_of_line = lf
indent_style = tab
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

# Ignore .md files, because 2 spaces at end-of-line has meaning
[*.md]
trim_trailing_whitespace = false
Loading

0 comments on commit 95992a6

Please sign in to comment.