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

Commit

Permalink
Merge pull request #3 from JoshuaRLi/master
Browse files Browse the repository at this point in the history
The 2018 Update
  • Loading branch information
10sr authored Jan 14, 2018
2 parents a8c9da4 + 4793472 commit 7658b52
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 56 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2016 10sr
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
Expand Down
51 changes: 21 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,48 @@
editorconfig-micro
==================
# editorconfig-micro

[EditorConfig][] Plugin for [micro][] editor
[EditorConfig] Plugin for the [`micro`] editor


Prerequisite
------------
### Prerequisites

* [Micro][micro] editor >= 1.1.3
* An `editorconfig` core executable ([EditorConfig C Core][] for example)
* [`micro`] editor >= 1.3.2
* An `editorconfig` core executable (e.g. [EditorConfig C Core])


Install
-------
### Installation

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

> plugin install editorconfig
`plugin install editorconfig`

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

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

### Supported Properties

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`
* `root` (Only used by EditorConfig Core)
* `trim_trailing_whitespace`

### On the Backlog

* `end_of_line`
* Currently micro supports LF only
* `charset`
* Currently micro supports UTF-8 only
* `trim_trailing_whitespace`
* `max_line_length`
### Unsupported Properties

* `max_line_length`


License
-------
### License

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



[micro]: https://micro-editor.github.io
[`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
48 changes: 33 additions & 15 deletions editorconfig.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = "0.1.1"
VERSION = "0.2.0"

local function logger(msg, view)
messenger:AddLog(("EditorConfig <%s>: %s"):
Expand Down Expand Up @@ -40,23 +40,41 @@ local function setIndentation(properties, view)
setSafely("tabstospaces", "off", view)
setSafely("tabsize", tab_width, view)
else
logger(("Unknown indent_style: %s"):format(indent_style or "nil"), view)
logger(("Unknown value for editorconfig property indent_style: %s"):format(indent_style or "nil"), view)
setSafely("tabsize", indent_size, view)
end
end

local function setCodingSystem(properties, view)
-- Currently micro does not support changing coding-systems
-- (Always use utf-8 with LF?)
local function setEndOfLine(properties, view)
local end_of_line = properties["end_of_line"]
local charset = properties["charset"]
if not (end_of_line == nil or end_of_line == "lf") then
msg(("Unsupported end_of_line: %s"):format(end_of_line), view)
if end_of_line == "lf" then
setSafely("fileformat", "unix", view)
elseif end_of_line == "crlf" then
setSafely("fileformat", "dos", view)
elseif end_of_line == "cr" then
-- See https://github.com/zyedidia/micro/blob/master/runtime/help/options.md for supported runtime options.
msg(("Value %s for editorconfig property end_of_line is not currently supported by micro."):format(end_of_line), view)
else
msg(("Unknown value for editorconfig property end_of_line: %s"):format(end_of_line), view)
end
if not (charset == nil or charset == "utf-8") then
msg(("Unsupported charset: %s"):format(charset), view)
end

local function setCharset(properties, view)
local charset = properties["charset"]
if charset ~= "utf-8" then
msg(("Value %s for editorconfig property charset is not currently supported by micro."):format(charset), view)
end
end

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

local function setInsertFinalNewline(properties, view)
Expand All @@ -66,16 +84,15 @@ local function setInsertFinalNewline(properties, view)
elseif val == "false" then
setSafely("eofnewline", false, view)
else
logger(("Unknown insert_final_newline: %s"):format(val), view)
logger(("Unknown value for editorconfig property insert_final_newline: %s"):format(val), view)
end
end

local function applyProperties(properties, view)
setIndentation(properties, view)
setCodingSystem(properties, view)
-- `ruler' is not what we want!
-- setMaxLineLength(properties, view)
-- setTrimTrailingWhitespace(properties, view)
setEndOfLine(properties, view)
setCharset(properties, view)
setTrimTrailingWhitespace(properties, view)
setInsertFinalNewline(properties, view)
end

Expand Down Expand Up @@ -126,6 +143,7 @@ function onViewOpen(view)
end

function onSave(view)
getApplyProperties(view)
end

MakeCommand("editorconfig", "editorconfig.getApplyProperties")
Expand Down
14 changes: 7 additions & 7 deletions help/editorconfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ editorconfig-micro

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

This plugin requires an editorconfig executable be installed.
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.

Expand All @@ -14,21 +14,21 @@ Usage
-----

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

This plugin also provides one command `editorconfig`.
This plugin also provides one command: `editorconfig`.
You can use this command to explicitly apply properties after updating
`.editorconfig` files.

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

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


[EditorConfig]: http://editorconfig.org
[EditorConfig C Core]: https://github.com/editorconfig/editorconfig-core-c
6 changes: 3 additions & 3 deletions repo.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"Tags": ["editorconfig", "utility", "format"],
"Versions": [
{
"Version": "0.1.1",
"Url": "https://github.com/10sr/editorconfig-micro/archive/v0.1.1.zip",
"Version": "0.2.0",
"Url": "https://github.com/10sr/editorconfig-micro/archive/v0.2.0.zip",
"Require": {
"micro": ">=1.1.3"
"micro": ">=1.3.2"
}
}
]
Expand Down

0 comments on commit 7658b52

Please sign in to comment.