diff --git a/cmd/micro/micro.go b/cmd/micro/micro.go index 1e554c51..396c414a 100644 --- a/cmd/micro/micro.go +++ b/cmd/micro/micro.go @@ -52,8 +52,9 @@ func InitFlags() { optionFlags = make(map[string]*string) for k, v := range config.DefaultGlobalSettings() { - optionFlags[k] = flag.String(k, "", fmt.Sprintf("The %s option. Default value: '%v'", k, v)) + optionFlags[k] = flag.String(k, "", fmt.Sprintf("The %s option. Default value: '%v'.", k, v)) } + optionFlags["filetype"] = flag.String("filetype", "", fmt.Sprintf("The filetype option. Autodetected by default.")) flag.Parse() @@ -153,13 +154,15 @@ func main() { // flag options for k, v := range optionFlags { - if *v != "" { + if *v != "" && k != "filetype" { nativeValue, err := config.GetNativeValue(k, config.GlobalSettings[k], *v) if err != nil { screen.TermMessage(err) continue } config.GlobalSettings[k] = nativeValue + } else if k == "filetype" && *v != "" { + config.GlobalSettings[k] = *v } } @@ -196,6 +199,10 @@ func main() { action.InitTabs(b) action.InitGlobals() + if _, ok := config.GlobalSettings["filetype"]; ok { + delete(config.GlobalSettings, "filetype") + } + // Here is the event loop which runs in a separate thread go func() { events = make(chan tcell.Event) diff --git a/internal/buffer/buffer.go b/internal/buffer/buffer.go index 1a7bf301..5e74ac5f 100644 --- a/internal/buffer/buffer.go +++ b/internal/buffer/buffer.go @@ -155,6 +155,8 @@ func NewBufferFromString(text, path string, btype BufType) *Buffer { // NewBuffer creates a new buffer from a given reader with a given path // Ensure that ReadSettings and InitGlobalSettings have been called before creating // a new buffer +// Places the cursor at startcursor. If startcursor is -1, -1 places the +// cursor at an autodetected location (based on savecursor or :LINE:COL) func NewBuffer(r io.Reader, size int64, path string, startcursor Loc, btype BufType) *Buffer { absPath, _ := filepath.Abs(path) @@ -166,7 +168,7 @@ func NewBuffer(r io.Reader, size int64, path string, startcursor Loc, btype BufT b.Settings[k] = v } } - config.InitLocalSettings(b.Settings, b.Path) + config.InitLocalSettings(b.Settings, path) enc, err := htmlindex.Get(b.Settings["encoding"].(string)) if err != nil { @@ -194,6 +196,12 @@ func NewBuffer(r io.Reader, size int64, path string, startcursor Loc, btype BufT b.EventHandler = NewEventHandler(b.SharedBuffer, b.cursors) } + b.Path = path + b.AbsPath = absPath + + // The last time this file was modified + b.ModTime, _ = GetModTime(b.Path) + switch b.Endings { case FFUnix: b.Settings["fileformat"] = "unix" @@ -201,13 +209,8 @@ func NewBuffer(r io.Reader, size int64, path string, startcursor Loc, btype BufT b.Settings["fileformat"] = "dos" } - b.Path = path - b.AbsPath = absPath - - // The last time this file was modified - b.ModTime, _ = GetModTime(b.Path) - b.UpdateRules() + config.InitLocalSettings(b.Settings, b.Path) if _, err := os.Stat(config.ConfigDir + "/buffers/"); os.IsNotExist(err) { os.Mkdir(config.ConfigDir+"/buffers/", os.ModePerm)