mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-31 23:27:10 +09:00
Compare commits
5 Commits
better-lua
...
surround
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6f302826c8 | ||
|
|
612658d9c4 | ||
|
|
c31613b2c7 | ||
|
|
d7419d213a | ||
|
|
67a3f86cc9 |
@@ -1852,6 +1852,68 @@ func (v *View) PreviousSplit(usePlugin bool) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (v *View) WrapBracket(usePlugin bool) bool {
|
||||
if v.Cursor.HasSelection() {
|
||||
lockPollEvent = true
|
||||
event := screen.PollEvent()
|
||||
lockPollEvent = false
|
||||
|
||||
ev, ok := event.(*tcell.EventKey)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
if !strings.Contains("()[]{}\"'", string(ev.Rune())) {
|
||||
return false
|
||||
}
|
||||
start := v.Cursor.CurSelection[0]
|
||||
end := v.Cursor.CurSelection[1]
|
||||
if start.Y != end.Y {
|
||||
return false
|
||||
}
|
||||
|
||||
close := map[string]string{
|
||||
")": ")",
|
||||
"]": "]",
|
||||
"}": "}",
|
||||
"(": ")",
|
||||
"[": "]",
|
||||
"{": "}",
|
||||
"\"": "\"",
|
||||
"'": "'",
|
||||
}
|
||||
|
||||
open := map[string]string{
|
||||
")": "(",
|
||||
"]": "[",
|
||||
"}": "{",
|
||||
"(": "(",
|
||||
"[": "[",
|
||||
"{": "{",
|
||||
"\"": "\"",
|
||||
"'": "'",
|
||||
}
|
||||
|
||||
if usePlugin && !PreActionCall("WrapBracket", v) {
|
||||
return false
|
||||
}
|
||||
r := string(ev.Rune())
|
||||
if start.GreaterThan(end) {
|
||||
start, end = end, start
|
||||
v.Buf.Insert(start, open[r])
|
||||
v.Buf.Insert(end.Move(1, v.Buf), close[r])
|
||||
v.Cursor.CurSelection[1] = start
|
||||
} else {
|
||||
v.Buf.Insert(start, open[r])
|
||||
v.Buf.Insert(end.Move(1, v.Buf), close[r])
|
||||
v.Cursor.CurSelection[0] = start
|
||||
}
|
||||
if usePlugin {
|
||||
return PostActionCall("WrapBracket", v)
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
var curMacro []interface{}
|
||||
var recordingMacro bool
|
||||
|
||||
|
||||
@@ -69,6 +69,7 @@ var bindingActions = map[string]func(*View, bool) bool{
|
||||
"PastePrimary": (*View).PastePrimary,
|
||||
"SelectAll": (*View).SelectAll,
|
||||
"OpenFile": (*View).OpenFile,
|
||||
"WrapBracket": (*View).WrapBracket,
|
||||
"Start": (*View).Start,
|
||||
"End": (*View).End,
|
||||
"PageUp": (*View).PageUp,
|
||||
@@ -438,6 +439,7 @@ func DefaultBindings() map[string]string {
|
||||
"Down": "CursorDown",
|
||||
"Right": "CursorRight",
|
||||
"Left": "CursorLeft",
|
||||
"Alt-j": "WrapBracket",
|
||||
"ShiftUp": "SelectUp",
|
||||
"ShiftDown": "SelectDown",
|
||||
"ShiftLeft": "SelectLeft",
|
||||
|
||||
@@ -59,6 +59,9 @@ var (
|
||||
// Event channel
|
||||
events chan tcell.Event
|
||||
autosave chan bool
|
||||
|
||||
// Read events on another thread or wait for a temporary read
|
||||
lockPollEvent bool
|
||||
)
|
||||
|
||||
// LoadInput determines which files should be loaded into buffers
|
||||
@@ -143,6 +146,15 @@ func InitConfigDir() {
|
||||
}
|
||||
configDir = xdgHome + "/micro"
|
||||
|
||||
if len(*flagConfigDir) > 0 {
|
||||
if _, err := os.Stat(*flagConfigDir); os.IsNotExist(err) {
|
||||
TermMessage("Error: " + *flagConfigDir + " does not exist. Defaulting to " + configDir + ".")
|
||||
} else {
|
||||
configDir = *flagConfigDir
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := os.Stat(xdgHome); os.IsNotExist(err) {
|
||||
// If the xdgHome doesn't exist we should create it
|
||||
err = os.Mkdir(xdgHome, os.ModePerm)
|
||||
@@ -240,19 +252,24 @@ func LoadAll() {
|
||||
// Passing -version as a flag will have micro print out the version number
|
||||
var flagVersion = flag.Bool("version", false, "Show the version number and information")
|
||||
var flagStartPos = flag.String("startpos", "", "LINE,COL to start the cursor at when opening a buffer.")
|
||||
var flagConfigDir = flag.String("config-dir", "", "Specify a custom location for the configuration directory")
|
||||
var optionFlagSet = flag.NewFlagSet("option", flag.ExitOnError)
|
||||
|
||||
func main() {
|
||||
flag.Usage = func() {
|
||||
fmt.Println("Usage: micro [OPTIONS] [FILE]...")
|
||||
fmt.Print("Micro's options can be set via command line arguments for quick adjustments. For real configuration, please use the bindings.json file (see 'help options').\n\n")
|
||||
flag.CommandLine.SetOutput(os.Stdout)
|
||||
flag.PrintDefaults()
|
||||
optionFlagSet.SetOutput(os.Stdout)
|
||||
fmt.Print("\n------------------------------------------------------------------\n")
|
||||
fmt.Print("Micro's options can also be set via command line arguments for quick\nadjustments. For real configuration, please use the bindings.json\nfile (see 'help options').\n\n")
|
||||
optionFlagSet.PrintDefaults()
|
||||
}
|
||||
|
||||
optionFlags := make(map[string]*string)
|
||||
|
||||
for k, v := range DefaultGlobalSettings() {
|
||||
optionFlags[k] = flag.String(k, "", fmt.Sprintf("The %s option. Default value: '%v'", k, v))
|
||||
optionFlags[k] = optionFlagSet.String(k, "", fmt.Sprintf("The %s option. Default value: '%v'", k, v))
|
||||
}
|
||||
|
||||
flag.Parse()
|
||||
@@ -405,8 +422,9 @@ func main() {
|
||||
// Here is the event loop which runs in a separate thread
|
||||
go func() {
|
||||
for {
|
||||
if screen != nil {
|
||||
if screen != nil && !lockPollEvent {
|
||||
events <- screen.PollEvent()
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
File diff suppressed because one or more lines are too long
2
cmd/micro/vendor/github.com/zyedidia/tcell
generated
vendored
2
cmd/micro/vendor/github.com/zyedidia/tcell
generated
vendored
Submodule cmd/micro/vendor/github.com/zyedidia/tcell updated: 898883d175...37b78458fe
@@ -147,14 +147,17 @@ The possible methods which you can call using the `messenger` variable are:
|
||||
* `messenger.AddLog(msg ...interface{})`
|
||||
|
||||
## Note
|
||||
`golang` function signatures use `.` and lua uses `:` so
|
||||
Go function signatures use `.` and lua uses `:` so
|
||||
|
||||
```go
|
||||
messenger.Message()
|
||||
```
|
||||
turns to
|
||||
```lua
|
||||
messenger:Message()
|
||||
```
|
||||
|
||||
turns to
|
||||
|
||||
```lua
|
||||
messenger:Message()
|
||||
```
|
||||
|
||||
If you want a standard prompt, just use
|
||||
```lua
|
||||
@@ -165,9 +168,38 @@ Debug or logging your plugin can be done with below lua example code.
|
||||
```lua
|
||||
messenger:AddLog("Message goes here ",pluginVariableToPrintHere)
|
||||
```
|
||||
In Micro Editor to see your plugin logging output press `ctrl E` then type `log`
|
||||
|
||||
In Micro to see your plugin logging output press `CtrlE` then type `log`
|
||||
A logging window will open and any logging sent from your plugin will be displayed here.
|
||||
|
||||
# Accessing the Go standard library
|
||||
|
||||
It is possible for your lua code to access many of the functions in the Go standard library.
|
||||
|
||||
Simply import the package you'd like and then you can use it. For example:
|
||||
|
||||
```lua
|
||||
local ioutil = import("ioutil")
|
||||
local fmt = import("fmt")
|
||||
|
||||
local data, err = ioutil.ReadFile("SomeFile.txt")
|
||||
|
||||
if err ~= nil then
|
||||
messenger:Error("Error reading file: SomeFile.txt")
|
||||
else
|
||||
-- Data is returned as an array of bytes
|
||||
-- Using Sprintf will convert it to a string
|
||||
local str = fmt.Sprintf("%s", data)
|
||||
|
||||
-- Do something with the file you just read!
|
||||
-- ...
|
||||
end
|
||||
```
|
||||
|
||||
For a full list of which packages and functions from the standard library
|
||||
you can access, look at `lua.go` in the source code (it shouldn't be
|
||||
too hard to look through).
|
||||
|
||||
# Adding help files, syntax files, or colorschemes in your plugin
|
||||
|
||||
You can use the `AddRuntimeFile(name, type, path string)` function to add various kinds of
|
||||
|
||||
Reference in New Issue
Block a user