]> git.lizzy.rs Git - micro.git/commitdiff
Don't display the tab bar if only one tab is open
authorZachary Yedidia <zyedidia@gmail.com>
Wed, 8 Jun 2016 17:29:24 +0000 (13:29 -0400)
committerZachary Yedidia <zyedidia@gmail.com>
Wed, 8 Jun 2016 17:29:24 +0000 (13:29 -0400)
cmd/micro/tab.go
cmd/micro/view.go
runtime/plugins/go/go.lua
runtime/plugins/linter/linter.lua

index ddf8efd7894fde0cee02ea0b7c81eb0f47419b25..d4d4d498fd8046b82891966afd1d6b6ae4325264 100644 (file)
@@ -31,6 +31,9 @@ func CurView() *View {
 }
 
 func DisplayTabs() {
+       if len(tabs) <= 1 {
+               return
+       }
        str := ""
        for i, t := range tabs {
                if i == curTab {
index 612dd6a49083cb7928434f5f1f1283a52051632b..6ecce7c94208789685c95ff8ffaf5eb522441da6 100644 (file)
@@ -99,7 +99,7 @@ func NewView(buf *Buffer) *View {
 func NewViewWidthHeight(buf *Buffer, w, h int) *View {
        v := new(View)
 
-       v.x, v.y = 0, 1
+       v.x, v.y = 0, 0
 
        v.widthPercent = w
        v.heightPercent = h
@@ -123,8 +123,11 @@ func NewViewWidthHeight(buf *Buffer, w, h int) *View {
 func (v *View) Resize(w, h int) {
        // Always include 1 line for the command line at the bottom
        h--
-       // Include one line for the tab bar at the top
-       h--
+       if len(tabs) > 1 {
+               // Include one line for the tab bar at the top
+               h--
+               v.y = 1
+       }
        v.width = int(float32(w) * float32(v.widthPercent) / 100)
        // We subtract 1 for the statusline
        v.height = int(float32(h) * float32(v.heightPercent) / 100)
index 6ea14cd07165af6f0d9d4d0a3ec446083812d57a..094fb653b81469fcdc4a3f8b4aabd27c3274229b 100644 (file)
@@ -9,7 +9,7 @@ MakeCommand("goimports", "go_goimports")
 MakeCommand("gofmt", "go_gofmt")
 
 function go_onSave()
-    if views[mainView+1].Buf.FileType == "Go" then
+    if CurView().Buf.FileType == "Go" then
         if GetOption("goimports") then
             go_goimports()
         elseif GetOption("gofmt") then
@@ -19,21 +19,21 @@ function go_onSave()
 end
 
 function go_gofmt()
-    views[mainView+1]:Save()
-    local handle = io.popen("gofmt -w " .. views[mainView+1].Buf.Path)
+    CurView():Save()
+    local handle = io.popen("gofmt -w " .. CurView().Buf.Path)
     local result = handle:read("*a")
     handle:close()
 
-    views[mainView+1]:ReOpen()
+    CurView():ReOpen()
 end
 
 function go_goimports()
-    views[mainView+1]:Save()
-    local handle = io.popen("goimports -w " .. views[mainView+1].Buf.Path)
+    CurView():Save()
+    local handle = io.popen("goimports -w " .. CurView().Buf.Path)
     local result = go_split(handle:read("*a"), ":")
     handle:close()
 
-    views[mainView+1]:ReOpen()
+    CurView():ReOpen()
 end
 
 function go_split(str, sep)
index 9767da5d80c816562678b15617c21f02870bb8fb..be7fe76fa24e5569bb41015bd36c31e14936972e 100644 (file)
@@ -4,15 +4,15 @@ end
 
 function linter_onSave()
     if GetOption("linter") then
-        local ft = views[mainView+1].Buf.FileType
-        local file = views[mainView+1].Buf.Path
+        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
             linter_lint("gobuild", "go build -o " .. devnull, "%f:%l: %m")
-            linter_lint("golint", "golint " .. views[mainView+1].Buf.Path, "%f:%l:%d+: %m")
+            linter_lint("golint", "golint " .. CurView().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
-        views[mainView+1]:ClearAllGutterMessages()
+        CurView():ClearAllGutterMessages()
     end
 end
 
 function linter_lint(linter, cmd, errorformat)
-    views[mainView+1]:ClearGutterMessages(linter)
+    CurView():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(views[mainView+1].Buf.Path) == linter_basename(file) then
-                views[mainView+1]:GutterMessage(linter, tonumber(line), msg, 2)
+            if linter_basename(CurView().Buf.Path) == linter_basename(file) then
+                CurView():GutterMessage(linter, tonumber(line), msg, 2)
             end
         end
     end