Refactor and clean up

This commit puts in place the ability for multiple views (splits).
This commit also removes the editor bindings so that all bindings can be
rebound by the user.
I also added some more comments

This fixes #109
This commit is contained in:
Zachary Yedidia
2016-05-28 11:32:09 -04:00
parent d9d0af4a99
commit e8d8da1443
9 changed files with 311 additions and 248 deletions

View File

@@ -21,15 +21,10 @@ You can move the cursor around with the arrow keys and mouse.
These are the default keybindings, along with their actions.
#### Editor bindings
* Ctrl-q: Quit
* Ctrl-e: Execute a command
* Ctrl-g: Toggle help text
* Ctrl-b: Run a shell command
#### Buffer bindings
* Ctrl-s: Save
* Ctrl-o: Open file
* Ctrl-z: Undo
@@ -55,7 +50,7 @@ ctrl up and down move the cursor the start and end of the buffer.
You can hold shift with all of these movement actions to select while moving.
The buffer bindings may be rebound using the `~/.config/micro/bindings.json`
The bindings may be rebound using the `~/.config/micro/bindings.json`
file. Each key is bound to an action.
For example, to bind `Ctrl-y` to undo and `Ctrl-z` to redo, you could put the
@@ -72,52 +67,64 @@ Here are the defaults:
```json
{
"Up": "CursorUp",
"Down": "CursorDown",
"Right": "CursorRight",
"Left": "CursorLeft",
"ShiftUp": "SelectUp",
"ShiftDown": "SelectDown",
"ShiftLeft": "SelectLeft",
"ShiftRight": "SelectRight",
"AltLeft": "WordLeft",
"AltRight": "WordRight",
"AltShiftRight": "SelectWordRight",
"AltShiftLeft": "SelectWordLeft",
"CtrlLeft": "StartOfLine",
"CtrlRight": "EndOfLine",
"CtrlShiftLeft": "SelectToStartOfLine",
"CtrlShiftRight": "SelectToEndOfLine",
"CtrlUp": "CursorStart",
"CtrlDown": "CursorEnd",
"CtrlShiftUp": "SelectToStart",
"CtrlShiftDown": "SelectToEnd",
"Enter": "InsertEnter",
"Space": "InsertSpace",
"Backspace": "Backspace",
"Backspace2": "Backspace",
"Tab": "InsertTab",
"CtrlO": "OpenFile",
"CtrlS": "Save",
"CtrlF": "Find",
"CtrlN": "FindNext",
"CtrlP": "FindPrevious",
"CtrlZ": "Undo",
"CtrlY": "Redo",
"CtrlC": "Copy",
"CtrlX": "Cut",
"CtrlK": "CutLine",
"CtrlD": "DuplicateLine",
"CtrlV": "Paste",
"CtrlA": "SelectAll",
"Home": "Start",
"End": "End",
"PgUp": "PageUp",
"PgDn": "PageDown",
"CtrlU": "HalfPageUp",
"CtrlD": "HalfPageDown",
"CtrlR": "ToggleRuler",
"Delete": "Delete"
"Up": "CursorUp",
"Down": "CursorDown",
"Right": "CursorRight",
"Left": "CursorLeft",
"ShiftUp": "SelectUp",
"ShiftDown": "SelectDown",
"ShiftLeft": "SelectLeft",
"ShiftRight": "SelectRight",
"AltLeft": "WordLeft",
"AltRight": "WordRight",
"AltShiftRight": "SelectWordRight",
"AltShiftLeft": "SelectWordLeft",
"CtrlLeft": "StartOfLine",
"CtrlRight": "EndOfLine",
"CtrlShiftLeft": "SelectToStartOfLine",
"CtrlShiftRight": "SelectToEndOfLine",
"CtrlUp": "CursorStart",
"CtrlDown": "CursorEnd",
"CtrlShiftUp": "SelectToStart",
"CtrlShiftDown": "SelectToEnd",
"Enter": "InsertEnter",
"Space": "InsertSpace",
"Backspace": "Backspace",
"Backspace2": "Backspace",
"Tab": "InsertTab",
"CtrlO": "OpenFile",
"CtrlS": "Save",
"CtrlF": "Find",
"CtrlN": "FindNext",
"CtrlP": "FindPrevious",
"CtrlZ": "Undo",
"CtrlY": "Redo",
"CtrlC": "Copy",
"CtrlX": "Cut",
"CtrlK": "CutLine",
"CtrlD": "DuplicateLine",
"CtrlV": "Paste",
"CtrlA": "SelectAll",
"Home": "Start",
"End": "End",
"PgUp": "PageUp",
"PgDn": "PageDown",
"CtrlG": "ToggleHelp",
"CtrlR": "ToggleRuler",
"CtrlL": "JumpLine",
"Delete": "Delete",
"Esc": "ClearStatus",
"CtrlB": "ShellMode",
"CtrlQ": "Quit",
"CtrlE": "CommandMode",
// Emacs-style keybindings
"Alt-f": "WordRight",
"Alt-b": "WordLeft",
"Alt-a": "StartOfLine",
"Alt-e": "EndOfLine",
"Alt-p": "CursorUp",
"Alt-n": "CursorDown",
}
```
@@ -211,7 +218,7 @@ Here are the options that you can set:
default value: `3`
* `scrollspeed`: amount of lines to scroll
* `scrollspeed`: amount of lines to scroll for one scroll event
default value: `2`

View File

@@ -6,25 +6,25 @@ if GetOption("gofmt") == nil then
end
function go_onSave()
if view.Buf.FileType == "Go" then
if views[mainView+1].Buf.FileType == "Go" then
if GetOption("goimports") then
go_goimports()
elseif GetOption("gofmt") then
go_gofmt()
end
view:ReOpen()
views[mainView+1]:ReOpen()
end
end
function go_gofmt()
local handle = io.popen("gofmt -w " .. view.Buf.Path)
local handle = io.popen("gofmt -w " .. views[mainView+1].Buf.Path)
local result = handle:read("*a")
handle:close()
end
function go_goimports()
local handle = io.popen("goimports -w " .. view.Buf.Path)
local handle = io.popen("goimports -w " .. views[mainView+1].Buf.Path)
local result = go_split(handle:read("*a"), ":")
handle:close()
end

View File

@@ -4,15 +4,15 @@ end
function linter_onSave()
if GetOption("linter") then
local ft = view.Buf.FileType
local file = view.Buf.Path
local ft = views[mainView+1].Buf.FileType
local file = views[mainView+1].Buf.Path
local devnull = "/dev/null"
if OS == "windows" then
devnull = "NUL"
end
if ft == "Go" then
linter_lint("gobuild", "go build -o " .. devnull, "%f:%l: %m")
linter_lint("golint", "golint " .. view.Buf.Path, "%f:%l:%d+: %m")
linter_lint("golint", "golint " .. views[mainView+1].Buf.Path, "%f:%l:%d+: %m")
elseif ft == "Lua" then
linter_lint("luacheck", "luacheck --no-color " .. file, "%f:%l:%d+: %m")
elseif ft == "Python" then
@@ -27,12 +27,12 @@ function linter_onSave()
linter_lint("jshint", "jshint " .. file, "%f: line %l,.+, %m")
end
else
view:ClearAllGutterMessages()
views[mainView+1]:ClearAllGutterMessages()
end
end
function linter_lint(linter, cmd, errorformat)
view:ClearGutterMessages(linter)
views[mainView+1]:ClearGutterMessages(linter)
local handle = io.popen("(" .. cmd .. ")" .. " 2>&1")
local lines = linter_split(handle:read("*a"), "\n")
@@ -44,8 +44,8 @@ function linter_lint(linter, cmd, errorformat)
line = line:match("^%s*(.+)%s*$")
if string.find(line, regex) then
local file, line, msg = string.match(line, regex)
if linter_basename(view.Buf.Path) == linter_basename(file) then
view:GutterMessage(linter, tonumber(line), msg, 2)
if linter_basename(views[mainView+1].Buf.Path) == linter_basename(file) then
views[mainView+1]:GutterMessage(linter, tonumber(line), msg, 2)
end
end
end