Add boolean option to actions to disable the lua callback

This commit is contained in:
Zachary Yedidia 2016-08-17 14:16:27 -04:00
parent 8a58506c72
commit d17cc0f628
11 changed files with 395 additions and 250 deletions

File diff suppressed because it is too large Load diff

View file

@ -6,6 +6,11 @@ import (
"strings"
)
// This file is meant (for now) for autocompletion in command mode, not
// while coding. This helps micro autocomplete commands and then filenames
// for example with `vsplit filename`.
// FileComplete autocompletes filenames
func FileComplete(input string) (string, []string) {
dirs := strings.Split(input, "/")
var files []os.FileInfo
@ -41,6 +46,7 @@ func FileComplete(input string) (string, []string) {
return chosen, suggestions
}
// CommandComplete autocompletes commands
func CommandComplete(input string) (string, []string) {
var suggestions []string
for cmd := range commands {
@ -56,6 +62,7 @@ func CommandComplete(input string) (string, []string) {
return chosen, suggestions
}
// HelpComplete autocompletes help topics
func HelpComplete(input string) (string, []string) {
var suggestions []string
@ -73,6 +80,7 @@ func HelpComplete(input string) (string, []string) {
return chosen, suggestions
}
// OptionComplete autocompletes options
func OptionComplete(input string) (string, []string) {
var suggestions []string
for option := range settings {

View file

@ -9,10 +9,10 @@ import (
"github.com/zyedidia/tcell"
)
var bindings map[Key][]func(*View) bool
var bindings map[Key][]func(*View, bool) bool
var helpBinding string
var bindingActions = map[string]func(*View) bool{
var bindingActions = map[string]func(*View, bool) bool{
"CursorUp": (*View).CursorUp,
"CursorDown": (*View).CursorDown,
"CursorPageUp": (*View).CursorPageUp,
@ -221,7 +221,7 @@ type Key struct {
// InitBindings initializes the keybindings for micro
func InitBindings() {
bindings = make(map[Key][]func(*View) bool)
bindings = make(map[Key][]func(*View, bool) bool)
var parsed map[string]string
defaults := DefaultBindings()
@ -314,7 +314,7 @@ modSearch:
}
// findAction will find 'action' using string 'v'
func findAction(v string) (action func(*View) bool) {
func findAction(v string) (action func(*View, bool) bool) {
action, ok := bindingActions[v]
if !ok {
// If the user seems to be binding a function that doesn't exist
@ -335,7 +335,7 @@ func BindKey(k, v string) {
}
actionNames := strings.Split(v, ",")
actions := make([]func(*View) bool, 0, len(actionNames))
actions := make([]func(*View, bool) bool, 0, len(actionNames))
for _, actionName := range actionNames {
actions = append(actions, findAction(actionName))
}

View file

@ -142,7 +142,7 @@ func HSplit(args []string) {
// NewTab opens the given file in a new tab
func NewTab(args []string) {
if len(args) == 0 {
CurView().AddTab()
CurView().AddTab(true)
} else {
filename := args[0]
home, _ := homedir.Dir()
@ -191,13 +191,13 @@ func Run(args []string) {
// Quit closes the main view
func Quit(args []string) {
// Close the main view
CurView().Quit()
CurView().Quit(true)
}
// Save saves the buffer in the main view
func Save(args []string) {
// Save the main view
CurView().Save()
CurView().Save(true)
}
// Replace runs search and replace

View file

@ -55,8 +55,8 @@ func Call(function string, args []string) (lua.LValue, error) {
// and creates a function that will call that lua function
// Specifically it creates a function that can be called as a binding because this is used
// to bind keys to lua functions
func LuaFunctionBinding(function string) func(*View) bool {
return func(v *View) bool {
func LuaFunctionBinding(function string) func(*View, bool) bool {
return func(v *View, _ bool) bool {
_, err := Call(function, nil)
if err != nil {
TermMessage(err)

View file

@ -411,7 +411,7 @@ func runtimeHelpPluginsMd() (*asset, error) {
return a, nil
}
var _runtimePluginsAutocloseAutocloseLua = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xb4\x56\x4d\x6b\xe3\x3c\x10\xbe\xe7\x57\x0c\xee\x21\x36\xb5\x03\x7e\x8f\x05\xbf\xd0\x76\x61\x29\x94\xdd\xa5\x2c\xfb\x41\xdb\x83\x22\x8f\x63\x51\x57\x0a\x23\x29\xe9\x52\xfa\xdf\x17\xd9\x8e\x62\x27\x76\xda\x2c\x6d\x0e\x8a\x6c\xcd\xc7\xf3\xcc\x8c\x66\x5c\x58\xc9\x8d\x50\x12\x78\xc9\xe8\xdc\x84\xda\x50\x0c\x22\x9a\x00\x00\x10\x1a\x4b\x12\xb4\x21\x21\x17\x33\x6d\xe7\xed\x69\x2d\x80\x32\x9f\x4c\x44\x01\x9f\xd1\x7c\x5d\x3a\x0b\x61\xc0\xac\x51\xbc\x52\x1a\x83\x08\xb2\x0c\xa4\xa8\xc0\x94\x28\x6b\x5b\xe7\x79\xbe\x2f\x16\x83\x21\x8b\xad\xad\x4a\x71\x56\x81\x3f\xfc\xc6\x04\x69\xc8\xe0\x39\xb8\x0b\xee\x82\x20\x86\x60\x3a\x75\x6b\x18\xb9\xf5\xf9\xc5\xad\xb7\xf7\xc1\x4b\x47\xef\x0b\xae\x2b\x21\x3b\x9a\x7b\xb2\x13\x4f\x57\xc9\x1b\x2b\x31\xa4\x86\xa9\x28\x40\x2a\x33\xc6\xc5\x93\xd8\x06\xa5\x7e\xac\x61\xbb\x4d\x03\x61\x05\x19\x5c\x5a\xfa\x21\x70\x1d\x36\x66\x0b\x45\x20\x20\x83\x34\x86\x93\x1d\x62\xb9\xf2\x16\x45\x01\xe4\xe2\xd5\x66\xa0\x2f\x78\x2b\xee\x63\xf8\x6f\x07\xc3\xd6\x27\xb7\x74\x2d\x24\x42\x06\xab\xd9\x85\x2d\xce\xdc\x43\xb8\x9a\x5d\x5a\xd2\x8a\x66\xbf\xa3\x49\x4f\x47\x14\x1b\x27\xad\x5e\x0c\x5e\xf6\xd7\x69\x1a\x1d\x8f\xc2\xfd\x56\x67\x17\x8c\x3f\xe8\x25\xe3\xd8\xf2\xee\x9f\x36\x0e\x6e\xc4\xa2\x34\x03\xe7\x73\x42\xf6\xd0\x7b\xeb\xc3\xda\x81\xbd\x85\x09\xff\x43\x0a\x4c\xe6\x10\x5e\xe9\x9f\x8a\xf2\xcb\x92\x51\x38\xce\x2a\x49\xa3\x08\x14\x1d\xe0\x9d\xbc\xc6\xdb\x59\x18\x24\x3e\x0c\x7d\x68\xff\x7a\x8a\xd3\xf7\x4b\x71\x27\x56\x59\x06\x27\x1b\x7d\x45\x75\x8d\xbf\x29\x6a\xa7\xa3\x9c\x93\xc4\xbd\x87\x69\x32\x85\x12\x09\x41\x68\x30\x0a\x72\x24\x2c\x50\x72\xac\x0f\x97\x4a\x48\x83\xe4\x0e\xbc\xc9\x6b\xc5\x61\x5d\x0a\x5e\x3a\x0d\xc7\xff\x91\x19\xc1\x59\x55\xfd\x81\x47\x96\xe3\x90\x9f\x75\x89\x12\xb8\x92\x2b\x24\x23\xe4\x02\x16\xca\xb5\x22\xcb\x4d\xed\xb2\xb2\x6c\x48\xe9\xca\x80\x44\xcc\x6b\x91\x39\xb6\xc0\xc8\x41\xcb\x61\x8e\x9c\x59\xdd\x60\xf4\x8d\x00\x9f\x96\xe8\x4c\x32\x90\x4a\x7a\xe8\x8d\xa3\xfd\x62\xae\x33\x70\x25\x35\x92\x09\x93\x2e\xb9\xf8\xe0\xc5\x79\x6b\xd9\xef\xee\xdd\x7f\x7d\x1d\x3a\x7d\xab\xf1\xde\xf6\xba\xf0\x43\xfb\xd7\x1b\x0b\x70\x2b\x5a\x31\x6d\x0e\xc9\x26\xe9\x8e\x61\xd7\x84\xc1\xdf\x8b\x8d\x7a\x0c\x27\x9b\x6d\x57\x5e\xe2\x93\xe9\x2b\xf8\xd2\x4d\xdb\x6b\xb0\xdb\x71\x7b\x23\xa1\xdf\x73\xbd\xf7\xde\xb5\xec\x2a\x8c\x5e\x4c\x17\x6e\x8f\xe5\xb0\xfa\x78\xd3\x6c\xf2\xf8\x9d\xcd\x87\x9a\xe6\x81\x3a\x0b\xee\x64\x10\xfd\x43\xe5\x2c\x09\x77\xfb\xf4\x07\x94\xcd\x11\x73\xef\x88\xea\x82\xf7\x18\x5e\x6e\x68\x8c\x5b\x78\x75\x08\xec\xe7\x71\x75\xf6\x09\x2b\x34\xdd\xa9\xd7\x0d\x7f\xf7\x1b\xca\x7d\xe7\xd4\xf9\xf8\x1b\x00\x00\xff\xff\xf6\x3c\xc7\xde\x70\x09\x00\x00")
var _runtimePluginsAutocloseAutocloseLua = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xb4\x56\x4d\x6b\xe3\x3c\x10\xbe\xe7\x57\x0c\xee\x21\x36\xb5\x03\x7e\x8f\x01\xbf\xd0\x76\x61\x29\x74\x3f\x28\xcb\x7e\xd0\xf6\xa0\xc8\xe3\x58\xd4\x95\xc2\x48\x4a\xba\x94\xfe\xf7\x45\xb6\xa3\xd8\x49\x9c\x26\xd0\xe6\xa0\xc8\xd6\x33\xdf\x33\x8f\x5c\x58\xc9\x8d\x50\x12\x78\xc9\xe8\xc2\x84\xda\x50\x0c\x22\x1a\x01\x00\x10\x1a\x4b\x12\xb4\x21\x21\xe7\x13\x6d\x67\xed\x69\x0d\x40\x99\x8f\x46\xa2\x80\xcf\x68\xbe\x2d\x9c\x86\x30\x60\xd6\x28\x5e\x29\x8d\x41\x04\x59\x06\x52\x54\x60\x4a\x94\xb5\xae\x8b\x3c\xdf\x85\xc5\x60\xc8\x62\xab\xab\x52\x9c\x55\xe0\x0f\xbf\x33\x41\x1a\x32\x78\x09\xee\x83\xfb\x20\x88\x21\x18\x8f\xdd\x1a\x46\x6e\x7d\x79\x75\xeb\xdd\x43\xf0\xda\x91\xfb\x8a\xab\x4a\xc8\x8e\xe4\x0e\x76\xe4\xc3\x55\xf2\xd6\x4a\x0c\xa9\x89\x54\x14\x20\x95\x19\x8a\xc5\x07\xb1\x49\x4a\xfd\x58\xbb\xed\x36\x8d\x0b\x4b\xc8\xe0\xca\xd2\x4f\x81\xab\xb0\x51\x5b\x28\x02\x01\x19\xa4\x31\x9c\x6d\x05\x96\x2b\xaf\x51\x14\x40\x2e\x5f\x6d\x05\xfa\xc0\x3b\xf1\x10\xc3\x7f\x5b\x3e\x6c\x6c\x72\x4b\x37\x42\x22\x64\xb0\x9c\x5c\xda\x62\xea\x1e\xc2\xe5\xe4\xca\x92\x56\x34\xf9\x13\x8d\x7a\x32\xa2\x58\x1b\x69\xe5\x62\xf0\xd8\xdf\xe7\x69\x74\xba\x17\xee\xb7\x9c\x5e\x32\xfe\xa8\x17\x8c\x63\x58\xb0\x4a\x63\xb4\x07\xd2\x58\xb9\x15\xf3\xd2\x0c\x81\x9e\x50\x6b\x94\x73\xa4\xe9\x17\xd4\x9a\xcd\x31\x0c\x4a\x11\xec\xe2\x66\x84\xec\xb1\xf7\xd6\x17\xa2\x13\xe8\x26\x30\xf8\x1f\x52\x60\x32\x87\xf0\x5a\xff\x52\x94\x5f\x95\x8c\xc2\xe1\x3c\x24\x69\x14\x81\xa2\x03\x99\x4a\xde\xca\x94\xd3\xb0\x37\x55\xfb\x5d\xdf\xb7\x7f\xbb\x29\xd2\xf7\x6b\x8a\x4e\xae\xb2\x0c\xce\xd6\xf2\x8a\xea\xa9\x38\x2a\x6b\xe7\x83\x31\x27\x89\x7b\x0f\xe3\x64\x0c\x25\x12\x82\xd0\x60\x14\xe4\x48\x58\xa0\xe4\x58\x1f\x2e\x94\x90\x06\xc9\x1d\x78\x95\x37\x8a\xc3\xaa\x14\xbc\x74\x12\x2e\xfe\x27\x66\x04\x67\x55\xf5\x17\x9e\x58\x8e\xfb\xec\xac\x4a\x94\xc0\x95\x5c\x22\x19\x21\xe7\x30\x57\x8e\xbc\x2c\x37\xb5\xc9\xca\xb2\x7d\x42\xd7\x06\x24\x62\x5e\x43\x66\xd8\x3a\x46\xce\xb5\x1c\x66\xc8\x99\xd5\x8d\x8f\x9e\x3a\xf0\x79\x81\x4e\x25\x03\xa9\xa4\x77\xbd\x31\xb4\xdb\xf9\x75\x05\xae\xa5\x46\x32\x61\xd2\x0d\x2e\x3e\x38\x6a\xc7\xb6\xfd\xf6\xde\xfd\xd7\xe3\xd0\x61\xba\xc6\x7a\xcb\x8e\xe1\x87\x32\xde\x91\x0d\xb8\x81\x56\x4c\x9b\x43\xd8\x24\xdd\x52\xec\x68\x1b\xfc\x5c\xac\xc5\x63\x38\x5b\x6f\xbb\x78\x89\xcf\xa6\x2f\xe0\x5b\x37\x6d\xc7\x60\x9b\xa3\x7b\x97\x48\x9f\xa5\xbd\xf5\xde\x58\x76\x05\x06\x07\xd3\xa5\xdb\xfb\x72\x58\x7c\x98\x66\x9b\x3a\xfe\x60\xb3\x41\x9a\x3d\xd0\x6c\xc1\xbd\xdc\xe2\xd2\xe3\xda\x67\x41\xb8\xa1\xf7\x0f\xeb\x9d\x13\xae\xcb\x13\x5a\x0c\xde\xe3\xce\x73\x37\xc7\xb0\x86\x37\x6f\x82\xdd\x62\x2e\xa7\x9f\xb0\x42\xb3\x73\x59\x76\x6b\xd0\xfd\xfe\x72\xdf\x48\x75\x51\xfe\x05\x00\x00\xff\xff\xe7\xc9\x08\x65\xac\x09\x00\x00")
func runtimePluginsAutocloseAutocloseLuaBytes() ([]byte, error) {
return bindataRead(
@ -426,12 +426,12 @@ func runtimePluginsAutocloseAutocloseLua() (*asset, error) {
return nil, err
}
info := bindataFileInfo{name: "runtime/plugins/autoclose/autoclose.lua", size: 2416, mode: os.FileMode(420), modTime: time.Unix(1471450014, 0)}
info := bindataFileInfo{name: "runtime/plugins/autoclose/autoclose.lua", size: 2476, mode: os.FileMode(420), modTime: time.Unix(1471457511, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _runtimePluginsGoGoLua = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xa4\x52\x5d\x8b\xd4\x30\x14\x7d\xef\xaf\x38\x04\x84\x44\x3b\xc5\xe7\x81\x3e\xe8\x82\xfb\x24\x2b\xba\xf8\x22\x0a\xb1\xbd\x6d\x83\x69\x52\x92\xdb\x1d\x45\xfc\xef\xd2\x4e\xb6\x33\xed\x8c\x8a\x6c\x5e\x06\xee\x9c\x7b\x3e\x6e\x8f\x69\x70\x4b\x7c\x37\xb0\xf1\x4e\x8a\xd6\x9b\x7e\xf0\x81\xa3\x50\x28\x4b\x38\x63\xc1\x1d\xb9\x0c\x00\x5e\xd5\xf5\x25\x2c\x47\xa3\x6d\x24\x95\x91\xab\xb3\x2d\x57\xd3\xf3\xbf\x78\x26\x48\x0e\x0e\x63\xa2\xc8\xde\xea\x6f\x74\xe3\xfb\x5e\xbb\x7a\xad\x23\x5a\x5f\x44\xfd\x40\x22\xc7\x4b\xb5\x85\x1d\x69\xd6\x90\xac\x19\x5d\x35\xe9\xc0\xbb\x0f\xfa\x81\xa4\x9a\xe5\x4d\x83\x9b\x31\x7c\x34\x74\x90\xaa\x78\x3d\x36\xc5\x1b\x63\xe9\xfe\xc7\x40\x93\x51\x71\xeb\xc5\xc9\x69\x82\xff\xe1\x3e\x2b\xd8\xf4\x96\x3f\x93\xd2\xf4\xc8\x46\xba\x7e\x96\x2b\xeb\x4d\xcf\xe7\xab\xae\xce\x1e\x7f\xe7\xd3\x2c\x79\xce\x91\xd6\x57\xda\xa2\xd3\xae\xb6\x84\x12\xc6\x17\x83\x1f\xe8\x51\x07\xbb\x03\x04\x8a\x62\x13\xf9\x9d\xe6\xee\x7c\x3d\x50\x1c\x2d\xa3\x4c\x3c\xfb\x40\xba\x96\xe2\xb9\x16\x47\x50\x9a\x56\xd6\xc7\xe9\x8a\xf3\x6c\x21\xdc\xbf\xa7\xbb\x49\x50\x5d\x98\x5c\x5f\xe3\x2f\x46\x13\xf0\x7f\xcd\xc6\xc1\x1a\x96\x17\x96\x73\x88\xfd\x53\x8c\xc7\x53\x57\x76\x3b\xdc\x77\x26\xe2\x60\xac\x05\x07\xd3\xb6\x14\x52\x9b\xa0\x5d\x8d\x4a\x8f\x91\x8e\x9f\x03\x3e\x9c\x22\x83\x3d\xc2\xe8\x36\x7a\xa9\x84\x1b\xb5\x39\x44\xe4\x90\x23\xd2\x70\x35\xe7\xcf\x5f\xab\x69\x4b\xdf\x51\x42\x0a\xf9\xe9\xcb\xb3\xf8\xf9\x85\x12\x6a\xdf\xf8\xd0\x6b\x96\x0b\x41\xe3\x03\x48\x57\x1d\x8c\x43\xe4\xb0\x6f\x7b\xcd\x55\x27\xe7\x5d\x85\xda\x2f\x1d\x63\xfd\xd5\x52\x61\x5c\xa4\xc0\xf2\x28\x98\xcf\x9b\x2a\x3b\xaf\x60\x20\x1e\x83\x4b\x8e\xe6\x00\xbf\x03\x00\x00\xff\xff\xe8\x9d\x9e\x71\x37\x04\x00\x00")
var _runtimePluginsGoGoLua = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xa4\x52\xcd\x8a\xd5\x30\x14\xde\xe7\x29\x0e\x01\x21\xd1\x5a\x66\x5d\xe8\x42\x07\x9c\x95\x8c\xa8\xb8\x11\x85\xd8\x9c\xdc\x06\xd3\xa4\x24\xa7\x8e\x22\xbe\xbb\xa4\xcd\xad\x6d\xef\x15\x51\xb3\x69\x9b\x7c\xe7\xfb\x6b\xac\x81\x3b\xa4\xfb\x91\x6c\xf0\x82\x9f\x82\x1d\xc6\x10\x29\x71\x09\x6d\x0b\xde\x3a\xa0\x1e\x3d\x03\x00\x78\xa6\xf5\x25\xac\x02\xa3\x5c\x42\xc9\xd0\x6b\x76\xe4\x32\x03\xfd\x89\x27\x43\x2a\xa0\x38\x15\x0a\xf6\x52\x7d\xc6\xdb\x30\x0c\xca\xeb\xbd\x0e\x3f\x85\x7a\xfb\x7d\x23\x8f\xd8\x85\x6b\xc1\x2d\xef\x37\x92\x31\x33\xf9\x2e\xab\x41\xf0\x6f\xd4\x17\x14\x72\x36\x61\x0d\xdc\x4e\xf1\x9d\xc5\x07\x21\xeb\xe7\x93\xa9\x5f\x58\x87\x6f\xbf\x8d\x98\xed\xf2\xbb\xc0\x7f\xf9\x2d\xf0\xdf\xb4\xb4\x83\xe5\xb5\x1e\x16\xa5\xbc\xd0\x25\xbc\x5e\xce\x95\x71\x33\xd0\x76\xd4\x6b\x76\x7e\xce\x05\xad\x79\xb6\xc8\x35\x4b\x33\x67\x2c\xff\x24\x9f\xb8\xd0\x29\x07\xbd\xf2\xda\x21\xb4\x60\x43\x3d\x86\x11\xcf\x0e\xe0\xe9\x03\x70\xa8\xeb\x43\x19\xaf\x14\xf5\xdb\xf1\x88\x69\x72\x04\x6d\xe1\x69\x22\x2a\x2d\xf8\x63\xc5\x17\x50\xd9\xed\x5c\x48\xb9\xdf\x83\xa3\xd7\x78\x9f\x05\xe5\x85\xfd\x7d\x4f\xff\x14\xa1\x50\xfc\x6d\x8c\x34\x3a\x4b\xe2\x22\x4c\x05\xbc\xf9\x9f\x48\x0b\x6d\xa2\x58\x41\xc2\xf1\xaa\xf2\xf7\x1f\xbb\xdd\x13\x7e\x85\x16\x04\x17\xef\x3f\x3e\x4a\x1f\x9e\x48\x2e\x1b\x13\xe2\xa0\x48\xac\x04\x26\x44\x40\xd5\xf5\x60\x3d\x24\x8a\xcd\x69\x50\xd4\xf5\x62\x9e\x95\xa0\xc3\x7a\x53\x48\x7d\x72\x58\x5b\x9f\x30\x92\x58\x04\xab\x79\x52\xb2\xed\x45\x8a\x48\x53\xf4\xc5\xd1\x1c\xe0\x67\x00\x00\x00\xff\xff\x4a\x0f\xaf\x0f\x03\x04\x00\x00")
func runtimePluginsGoGoLuaBytes() ([]byte, error) {
return bindataRead(
@ -446,12 +446,12 @@ func runtimePluginsGoGoLua() (*asset, error) {
return nil, err
}
info := bindataFileInfo{name: "runtime/plugins/go/go.lua", size: 1079, mode: os.FileMode(420), modTime: time.Unix(1471455442, 0)}
info := bindataFileInfo{name: "runtime/plugins/go/go.lua", size: 1027, mode: os.FileMode(420), modTime: time.Unix(1471457551, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _runtimePluginsLinterLinterLua = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\x8c\x55\xdf\x8f\x9c\x36\x10\x7e\xdf\xbf\x62\x64\x15\xc9\xdc\x01\x27\xe5\x71\x25\x1e\xd2\x6b\x7b\x52\x94\x36\x91\x2e\x6d\x1e\xda\xa6\xf2\xc2\x18\xdc\x18\x1b\xd9\x66\xf7\x56\x55\xff\xf7\xca\x36\xc7\x02\xb7\xe4\x8a\xb4\x62\xd6\xcc\x7c\xdf\xfc\xf8\x18\x04\x87\x07\x74\x1f\x7a\x27\xb4\xa2\x44\x0a\xe5\xd0\x90\x14\xca\x12\x94\x90\xe0\x5a\x54\x3b\x00\x80\xb7\x75\xbd\xf2\xc9\xc0\x99\x01\xd3\x1d\xaa\x7a\xb7\xe3\x83\xaa\xfc\x53\xd0\xea\x91\x1d\x91\xa6\x21\x68\x03\x7b\x02\xf5\x97\xd4\x15\x93\xc0\x1d\x94\x70\x3f\x98\xdf\x04\x9e\x68\x5a\x7c\x3f\xf0\xe2\x27\x21\xf1\xd3\xb9\xc7\xb5\xa7\x90\xf8\xc2\xf7\x23\x73\xed\xca\xaf\xc6\xa3\x1a\xa4\x84\x12\xc8\x5d\x8d\xc7\x3b\xff\x87\x4c\x3e\x82\xc3\x87\x47\x5f\x24\x39\x09\x55\xeb\x93\x25\xcb\xac\xfc\x35\x43\xf8\xe5\xd7\xf7\x97\x58\x5f\xf0\x0c\xc7\xa7\x5e\x02\x79\xd0\x57\x20\x7c\xc9\x94\x34\xfa\x30\x08\x59\x93\x0c\x48\xa3\x21\xd8\x90\x6b\x20\x50\x14\xcf\x24\x19\x90\x84\xef\x13\xb9\x87\xa4\x23\xe9\x55\x0c\x7f\x8f\x10\xde\x8a\xd1\x2f\xbb\x30\x01\x25\xf5\xed\x0a\x0c\xa5\xc5\x4b\xbe\xef\x07\xb6\x99\xb0\x1c\x58\xd5\x62\xf5\xd5\xd3\x3d\xdb\x90\xe7\x4a\xe7\x95\x96\xda\x44\x6e\x3f\x88\xff\xcd\xf6\xf1\xec\x5a\xad\x36\x09\xfb\x33\x97\xec\x2b\x5a\x4f\xf8\x6c\x5f\x61\xf9\x16\xc3\xfd\x76\xfb\xab\x2a\xf4\xad\xaa\x20\xe7\xf6\xac\x1c\x7b\xca\xb5\x92\x67\xc8\x3f\x33\x29\x21\xff\x8c\x4f\xce\xb0\x8d\xa2\x8a\x6f\xd7\xf5\xc3\x26\x6b\xdd\x85\x81\xd7\x5d\x0d\xb1\x6b\xa5\xe6\x1c\x72\x9d\x43\x7e\x82\xfc\x24\x20\xaf\x56\x94\x09\x4d\x64\x92\xbe\xc6\xf8\x8e\x1d\xb7\x07\xf7\x37\x3b\xb2\x50\x6c\x30\xae\x75\x10\x8d\xd1\xe6\x55\x82\xc7\xca\x88\xde\x6d\xd3\xd8\x76\x14\x63\xb4\xd6\x44\xde\x0d\x21\x91\x59\x71\x9b\xad\xa8\xc6\x77\xc7\x53\x4e\x87\x93\x8a\xf7\xf7\x12\x99\x79\x2b\xe5\xc3\xe0\x1c\x9a\x9f\xd1\x5a\xd6\xa0\x1d\xb7\x89\x8f\x5d\x2e\x9b\x90\x4d\x5c\x2b\x19\x54\x5d\x9d\xc5\xf2\xb8\x36\x1d\x73\x31\x68\x85\xbd\x02\x8e\xb1\xe9\x2e\xb8\xbe\xd3\x87\x47\xc7\x8c\xa3\x01\x89\x90\xf1\x17\x7d\x0a\xad\x7e\x7c\x12\xbe\xe6\x67\xbe\x05\xd5\x7a\x09\x7a\x5f\xaa\x07\xd7\x0f\x6e\x23\x02\xa6\x4d\xe5\x9b\x65\xa1\x04\xdb\xcb\x59\x10\xf9\x43\x91\x31\xb1\xe8\x66\xb0\xc1\x27\x28\xe7\x28\xfb\xc6\x0e\x07\x4a\x92\x84\xfb\x44\x69\x71\x9b\x92\x74\x3a\x93\xe1\x2c\xa9\x17\x87\xdd\xc5\x31\x40\x73\x6d\xe0\xaf\x2c\x8c\x4b\x28\x10\x3d\x13\x26\x74\x05\x6d\x0a\xb5\x9e\x26\x94\xe7\xf0\xc9\x88\x0e\x4e\xad\x70\x68\x7b\x56\xcd\xb6\xb2\x8f\x2d\xc3\x6d\xdf\x31\x57\xb5\x94\x7c\x49\xec\x8d\xe7\x48\xec\xcd\x77\xb3\xd9\x0b\x0e\xd6\x19\xa1\x9a\x82\x0b\x55\x07\x96\x2c\x56\x95\x5e\x11\xda\xb4\xec\x43\xff\x30\x83\xce\x36\xbe\x49\x11\x21\x32\xcd\x21\x16\xd1\x82\xc3\x81\x59\x54\xac\x43\xfa\x72\x47\x86\xaf\xdb\xf4\xdc\x73\x5c\x49\x60\x29\x9e\x85\x6e\x26\xc9\x39\xad\x86\xee\x80\x26\x24\x92\x86\x14\x33\x78\xb3\x4c\x65\xfe\xb5\x98\xd4\xff\x42\xc9\x71\xf6\xd6\x99\x0c\x2c\xf6\xe9\x62\xec\x76\x90\xfe\xeb\xf8\xcf\xbf\x57\xc4\x40\x09\xfd\xfd\x4b\x62\xff\x0c\x43\x8e\xa2\xa0\x13\x80\x1f\x2e\xb2\xaa\xf5\xa3\xb5\xce\xec\x9b\xd8\xb5\xb1\xe5\xb3\xf1\x3a\x76\x90\x58\x08\x65\xd1\x38\x1a\x09\xb3\x10\x79\x79\xf1\xfc\xdd\xa0\x1b\x8c\x1a\x33\x5a\x15\xb0\x6c\xe7\x2c\x53\x7f\x78\x99\x5b\xd0\xe1\xb8\x28\x68\x71\x73\x97\xd2\xe2\x26\xf5\x9a\x4c\xde\x8c\x4a\x19\x49\x7c\x58\xa0\xf8\x2f\x00\x00\xff\xff\xa2\xe0\x7e\x83\xa0\x08\x00\x00")
var _runtimePluginsLinterLinterLua = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\x8c\x55\x51\x6f\xdb\x36\x10\x7e\xf7\xaf\x38\x10\x13\x40\xa5\x92\x32\xf4\xd1\x80\x1f\xba\x6c\x0b\x50\xa4\x6b\x81\x74\xeb\xc3\xb6\x0e\xb4\x78\xb4\xb9\x50\xa4\x40\x52\x76\x8c\x61\xff\x7d\x20\x29\xcb\x92\x2c\x17\x0b\x10\xe4\x42\xde\x7d\xdf\xdd\x77\xa7\xa3\x14\xf0\x88\xfe\x63\xeb\xa5\xd1\x94\x28\xa9\x3d\x5a\x92\xc3\x66\x03\x5a\x2a\xf0\x7b\xd4\x2b\x00\x80\x77\x9c\xcf\x7c\x0a\xf0\xb6\xc3\x7c\x85\x9a\xaf\x56\x1f\xd8\x0b\x3e\x98\xa6\x61\x9a\x27\x07\x52\x40\xef\x58\xd9\x4e\x3f\x9d\x43\xbe\xcf\x57\x2b\xd1\xe9\x3a\x20\xc1\x70\x41\xf3\xc8\xf1\xd0\xd9\xdf\x24\x1e\x69\xbe\x7e\x66\x07\xa4\x82\x29\x87\xe9\x46\x99\x9a\x29\x10\x1e\x36\x17\xa7\xea\x87\x4e\x54\x3f\x4b\x85\x9f\x4f\x2d\x8e\xbd\xa4\xc2\x2b\xbf\x4f\xcc\xef\x47\x3e\x1c\x0f\xba\x53\x0a\x36\x40\xee\x39\x1e\xee\xc3\x3f\x24\xde\x4b\x01\x1f\x9f\x43\xf5\xe4\x28\x35\x37\x47\x47\x2e\x1a\x84\x9f\x51\xe4\x2f\xbf\x3e\xa5\x98\xa0\x40\x1f\x1b\x52\xdc\x00\x79\x34\xb3\xb0\x20\x05\x25\x3b\xb3\xed\xa4\xe2\x41\x9b\x9d\x81\x68\x43\x69\x80\x40\x55\x9d\x81\x0b\x20\x99\x58\x67\x6a\x0d\x59\x43\xf2\xab\xf8\xb3\xb4\xc9\x4a\x91\xd7\x95\x0e\x20\x19\x7f\x33\x02\x42\xe5\xf0\x92\xe3\x53\xc7\x16\x93\x54\x1d\xab\xf7\x58\xbf\xc4\x0e\xf6\x36\x94\xa5\x36\x65\x6d\x94\xb1\x89\x33\x88\xfc\xbf\x58\x3e\x9d\xfc\xde\xe8\x45\xa2\xf6\x24\x14\x7b\x41\x17\x88\xce\xf6\x02\xfa\x2d\xe4\x87\x65\x89\xeb\x3a\xea\x53\xd7\x50\x0a\x77\xd2\x9e\xbd\x96\x46\xab\x13\x94\x5f\x98\x52\x50\x7e\xc1\x57\x6f\xd9\x8d\x22\xaa\xdb\x75\xfc\xb8\xc8\xc6\x9b\xd8\x4c\xde\x70\x48\xea\x6c\x8c\x10\x50\x9a\x12\xca\x23\x94\x47\x09\x65\x3d\xa3\xca\x68\xa6\xb2\xfc\x5b\x4c\xef\xd9\x61\xb9\x31\x7f\xb3\x03\x8b\xc5\x45\x63\x49\x29\xb4\xd6\xd8\x6f\x02\x3f\xd7\x56\xb6\x7e\x19\xde\xed\xfb\xe1\x4a\xd6\x9c\x20\xb8\x21\x64\xaa\xa8\xde\x14\x23\x0a\xcd\xd3\x06\x18\xbe\x6a\xa3\xe3\xd7\x9b\x9f\x3f\x89\xa5\xed\x32\xa1\x9f\xaf\x81\x90\xf5\x70\x79\xd9\x09\x0f\x0a\x99\x7d\xa7\xd4\x63\xe7\x3d\xda\x0f\xe8\x1c\xdb\xa1\xa3\xb7\xd2\x88\x45\x25\xc2\x02\xea\x86\x17\x49\x1d\x61\x6c\xc3\xfc\x7c\xdf\x44\xec\x19\x70\x8a\xcd\x57\xd1\xf5\xbd\xd9\x3e\x7b\x66\x3d\x8d\x48\x84\xf4\xbf\xfd\x86\x33\xfa\xa7\x57\x19\xa4\x3b\xf3\x4d\xa8\xe6\xf2\x04\x5f\x6a\x3a\xdf\x76\xfe\x46\xc4\x65\x51\x05\xcd\x1d\x6c\xc0\xb5\x6a\x14\x44\xfe\xd0\xa4\x4f\x2c\xb9\x59\xdc\xe1\x2b\x6c\xc6\x28\xeb\x9d\xeb\xb6\x94\x64\x99\x08\x89\xd2\xea\x4d\x4e\xf2\xe1\x4c\xc5\xb3\x8c\x4f\x0e\x9b\x8b\x63\x84\x16\xc6\xc2\x5f\x45\xec\xba\xd4\x20\x5b\x26\x6d\x54\x05\x5d\x0e\xdc\x0c\x1d\x2a\x4b\xf8\x6c\x65\x03\xc7\xbd\xf4\xe8\x5a\x56\xe3\x78\xb0\xc2\x2a\x0e\x7f\xd6\x0d\xf3\xf5\x9e\x92\xaf\x99\xbb\x0b\x1c\x99\xbb\xfb\x6e\xb4\xdf\xa4\x00\xe7\xad\xd4\xbb\x4a\x48\xcd\x23\x4b\x91\xaa\x9a\x0d\xcb\x74\xcf\x47\xfd\xb0\x80\xc6\xed\x82\x48\x09\x21\x31\x8d\x21\x26\xd1\x52\xc0\x96\x39\xd4\xac\x41\x7a\xbd\x3a\xe3\xcb\x37\xdc\x07\x8e\x85\x04\xa6\xc3\x33\x99\x9b\x61\xe4\xbc\xd1\x5d\xb3\x45\x1b\x13\xc9\x63\x8a\x05\xbc\x9d\xa6\x72\x7e\x38\xc6\xf6\xf5\x24\xa7\xde\x3b\x6f\x0b\x70\xd8\xe6\x93\xb6\xbb\x4e\x85\x47\xf1\x9f\x7f\x17\x86\x81\x12\xfa\xfb\xd7\xcc\xfd\x19\x9b\x9c\x86\x82\x0e\x00\xa1\xb9\xc8\xea\x7d\x68\xad\xf3\x76\xbd\x4b\xaa\xf5\x92\x8f\xda\xeb\xd9\x56\x61\x25\xb5\x43\xeb\x69\x22\x2c\x62\x64\x3e\x79\xfb\x2c\xfa\xce\xea\x3e\xa3\x59\x01\x53\x39\x47\x99\x86\xc3\x4b\xdf\xe2\x1c\xf6\xfb\x86\x56\x77\xf7\x39\xad\xee\xf2\x30\x93\xd9\xdb\x7e\x52\x7a\x92\x10\x16\x29\xfe\x0b\x00\x00\xff\xff\xa1\xcb\xe6\xee\xbc\x08\x00\x00")
func runtimePluginsLinterLinterLuaBytes() ([]byte, error) {
return bindataRead(
@ -466,7 +466,7 @@ func runtimePluginsLinterLinterLua() (*asset, error) {
return nil, err
}
info := bindataFileInfo{name: "runtime/plugins/linter/linter.lua", size: 2208, mode: os.FileMode(420), modTime: time.Unix(1466625633, 0)}
info := bindataFileInfo{name: "runtime/plugins/linter/linter.lua", size: 2236, mode: os.FileMode(420), modTime: time.Unix(1471457560, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}

View file

@ -170,7 +170,7 @@ func (v *View) CanClose(msg string) bool {
if strings.ToLower(quit) == "yes" || strings.ToLower(quit) == "y" {
return true
} else if strings.ToLower(quit) == "save" || strings.ToLower(quit) == "s" {
v.Save()
v.Save(true)
return true
}
}
@ -330,7 +330,7 @@ func (v *View) HandleEvent(event tcell.Event) {
if e.Modifiers() == key.modifiers {
relocate = false
for _, action := range actions {
relocate = action(v) || relocate
relocate = action(v, true) || relocate
}
}
}

View file

@ -48,8 +48,9 @@ value (`interface{}` means any type in Go).
* BindKey(key, action string): binds `key` to `action`.
* MakeCommand(name, function string): creates a command with `name` which will
call `function` when executed.
* MakeCommand(name, function string, completions ...Completion):
creates a command with `name` which will call `function` when executed.
Use 0 for completions to get NoCompletion.
* CurView(): returns the current view
@ -70,8 +71,12 @@ to the background process.
This may seem like a small list of available functions but some of the objects
returned by the functions have many methods. `CurView()` returns a view object
which has all the actions which you can call. For example `CurView():Save()`.
which has all the actions which you can call. For example `CurView():Save(false)`.
You can see the full list of possible actions in the keybindings help topic.
The boolean on all the actions indicates whether or not the lua callbacks should
be run. I would recommend generally sticking to false when making a plugin to
avoid recursive problems, for example if you call `CurView():Save(true)` in `onSave()`.
Just use `CurView():Save(false)` so that it won't call `onSave()` again.
Using the view object, you can also access the buffer associated with that view
by using `CurView().Buf`, which lets you access the `FileType`, `Path`, `Name`...

View file

@ -20,8 +20,8 @@ function onRune(r)
local curLine = v.Buf:Line(v.Cursor.Y)
if charAt(curLine, v.Cursor.X+1) == charAt(autoclosePairs[i], 2) then
v:Backspace()
v:CursorRight()
v:Backspace(false)
v:CursorRight(false)
break
end
@ -57,7 +57,7 @@ function onInsertNewline()
for i = 1, #autoNewlinePairs do
if curRune == charAt(autoNewlinePairs[i], 1) then
if nextRune == charAt(autoNewlinePairs[i], 2) then
v:InsertTab()
v:InsertTab(false)
v.Buf:Insert(-v.Cursor.Loc, "\n")
end
end
@ -74,7 +74,7 @@ function preBackspace()
for i = 1, #autoclosePairs do
local curLine = v.Buf:Line(v.Cursor.Y)
if charAt(curLine, v.Cursor.X+1) == charAt(autoclosePairs[i], 2) and charAt(curLine, v.Cursor.X) == charAt(autoclosePairs[i], 1) then
v:Delete()
v:Delete(false)
end
end

View file

@ -5,8 +5,8 @@ if GetOption("gofmt") == nil then
AddOption("gofmt", true)
end
MakeCommand("goimports", "go.save", 0)
MakeCommand("gofmt", "go.save", 0)
MakeCommand("goimports", "go.goimports", 0)
MakeCommand("gofmt", "go.gofmt", 0)
function onSave()
if CurView().Buf.FileType == "Go" then
@ -19,6 +19,7 @@ function onSave()
end
function gofmt()
CurView():Save(false)
local handle = io.popen("gofmt -w " .. CurView().Buf.Path)
local result = handle:read("*a")
handle:close()
@ -27,6 +28,7 @@ function gofmt()
end
function goimports()
CurView():Save(false)
local handle = io.popen("goimports -w " .. CurView().Buf.Path)
local result = split(handle:read("*a"), ":")
handle:close()
@ -34,11 +36,6 @@ function goimports()
CurView():ReOpen()
end
function save()
-- This will trigger onSave and cause gofmt or goimports to run
CurView():Save()
end
function split(str, sep)
local result = {}
local regex = ("([^%s]+)"):format(sep)

View file

@ -2,30 +2,37 @@ if GetOption("linter") == nil then
AddOption("linter", true)
end
MakeCommand("lint", "linter.runLinter", 0)
function runLinter()
CurView():Save(false)
local ft = CurView().Buf.FileType
local file = CurView().Buf.Path
local devnull = "/dev/null"
if OS == "windows" then
devnull = "NUL"
end
if ft == "Go" then
lint("gobuild", "go build -o " .. devnull, "%f:%l: %m")
lint("golint", "golint " .. CurView().Buf.Path, "%f:%l:%d+: %m")
elseif ft == "Lua" then
lint("luacheck", "luacheck --no-color " .. file, "%f:%l:%d+: %m")
elseif ft == "Python" then
lint("pyflakes", "pyflakes " .. file, "%f:%l: %m")
elseif ft == "C" then
lint("gcc", "gcc -fsyntax-only -Wall -Wextra " .. file, "%f:%l:%d+:.+: %m")
elseif ft == "D" then
lint("dmd", "dmd -color=off -o- -w -wi -c " .. file, "%f%(%l%):.+: %m")
elseif ft == "Java" then
lint("javac", "javac " .. file, "%f:%l: error: %m")
elseif ft == "JavaScript" then
lint("jshint", "jshint " .. file, "%f: line %l,.+, %m")
end
end
function onSave()
if GetOption("linter") then
local ft = CurView().Buf.FileType
local file = CurView().Buf.Path
local devnull = "/dev/null"
if OS == "windows" then
devnull = "NUL"
end
if ft == "Go" then
lint("gobuild", "go build -o " .. devnull, "%f:%l: %m")
lint("golint", "golint " .. CurView().Buf.Path, "%f:%l:%d+: %m")
elseif ft == "Lua" then
lint("luacheck", "luacheck --no-color " .. file, "%f:%l:%d+: %m")
elseif ft == "Python" then
lint("pyflakes", "pyflakes " .. file, "%f:%l: %m")
elseif ft == "C" then
lint("gcc", "gcc -fsyntax-only -Wall -Wextra " .. file, "%f:%l:%d+:.+: %m")
elseif ft == "D" then
lint("dmd", "dmd -color=off -o- -w -wi -c " .. file, "%f%(%l%):.+: %m")
elseif ft == "Java" then
lint("javac", "javac " .. file, "%f:%l: error: %m")
elseif ft == "JavaScript" then
lint("jshint", "jshint " .. file, "%f: line %l,.+, %m")
end
runLinter()
else
CurView():ClearAllGutterMessages()
end