)
const (
- synLinesUp = 75 // How many lines up to look to do syntax highlighting
- synLinesDown = 75 // How many lines down to look to do syntax highlighting
doubleClickThreshold = 400 // How many milliseconds to wait before a second click is not a double click
undoThreshold = 500 // If two events are less than n milliseconds apart, undo both of them
autosaveTime = 8 // Number of seconds to wait before autosaving
CommitHash = "Unknown"
CompileDate = "Unknown"
- // L is the lua state
- // This is the VM that runs the plugins
- L *lua.LState
-
// The list of views
tabs []*Tab
// This is the currently open tab
}
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)
screen, err = tcell.NewScreen()
if err != nil {
fmt.Println(err)
+ if err == tcell.ErrTermNotFound {
+ fmt.Println("Micro does not recognize your terminal:", oldTerm)
+ fmt.Println("Please go to https://github.com/zyedidia/mkinfo to read about how to fix this problem (it should be easy to fix).")
+ }
os.Exit(1)
}
if err = screen.Init(); err != nil {
os.Setenv("TERM", oldTerm)
}
+ if GetGlobalOption("mouse").(bool) {
+ screen.EnableMouse()
+ }
+
screen.SetStyle(defStyle)
- screen.EnableMouse()
}
// RedrawAll redraws everything -- all the views and the messenger
}
DisplayTabs()
messenger.Display()
+ if globalSettings["keymenu"].(bool) {
+ DisplayKeyMenu()
+ }
screen.Show()
}
// 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 flagOptions = flag.Bool("options", false, "Show all option help")
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.PrintDefaults()
+ fmt.Println("-config-dir dir")
+ fmt.Println(" \tSpecify a custom location for the configuration directory")
+ fmt.Println("-startpos LINE,COL")
+ fmt.Println(" \tSpecify a line and column to start the cursor at when opening a buffer")
+ fmt.Println("-options")
+ fmt.Println(" \tShow all option help")
+ fmt.Println("-version")
+ fmt.Println(" \tShow the version number and information")
+
+ fmt.Print("\nMicro'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")
+ fmt.Println("-option value")
+ fmt.Println(" \tSet `option` to `value` for this session")
+ fmt.Println(" \tFor example: `micro -syntax off file.c`")
+ fmt.Println("\nUse `micro -options` to see the full list of configuration options")
}
optionFlags := make(map[string]*string)
os.Exit(0)
}
+ if *flagOptions {
+ // If -options was passed
+ for k, v := range DefaultGlobalSettings() {
+ fmt.Printf("-%s value\n", k)
+ fmt.Printf(" \tThe %s option. Default value: '%v'\n", k, v)
+ }
+ os.Exit(0)
+ }
+
// Start the Lua VM for running plugins
L = lua.NewState()
defer L.Close()
// Create a new messenger
// This is used for sending the user messages in the bottom of the editor
messenger = new(Messenger)
- messenger.history = make(map[string][]string)
- InitColorscheme()
+ messenger.LoadHistory()
// Now we load the input
buffers := LoadInput()
L.SetGlobal("Loc", luar.New(L, func(x, y int) Loc {
return Loc{x, y}
}))
+ L.SetGlobal("WorkingDirectory", luar.New(L, os.Getwd))
L.SetGlobal("JoinPaths", luar.New(L, filepath.Join))
L.SetGlobal("DirectoryName", luar.New(L, filepath.Dir))
L.SetGlobal("configDir", luar.New(L, configDir))
L.SetGlobal("AddRuntimeFilesFromDirectory", luar.New(L, PluginAddRuntimeFilesFromDirectory))
L.SetGlobal("AddRuntimeFileFromMemory", luar.New(L, PluginAddRuntimeFileFromMemory))
+ // Access to Go stdlib
+ L.SetGlobal("import", luar.New(L, Import))
+
jobs = make(chan JobFunction, 100)
events = make(chan tcell.Event, 100)
autosave = make(chan bool)
}
}
+ InitColorscheme()
+
// Here is the event loop which runs in a separate thread
go func() {
for {
- events <- screen.PollEvent()
+ if screen != nil {
+ events <- screen.PollEvent()
+ }
}
}()