]> git.lizzy.rs Git - micro.git/blobdiff - internal/buffer/buffer.go
Don't block when redraw channel becomes full
[micro.git] / internal / buffer / buffer.go
index 98fdfd6cfcc679c6572b7e158a1439ab5d84ef45..c3b8fa85ef7812b5231eee363dcc17fedd6f6643 100644 (file)
@@ -1,11 +1,13 @@
 package buffer
 
 import (
+       "bufio"
        "bytes"
        "crypto/md5"
        "errors"
        "io"
        "io/ioutil"
+       "log"
        "os"
        "path/filepath"
        "strconv"
@@ -16,6 +18,7 @@ import (
 
        luar "layeh.com/gopher-luar"
 
+       dmp "github.com/sergi/go-diff/diffmatchpatch"
        "github.com/zyedidia/micro/internal/config"
        ulua "github.com/zyedidia/micro/internal/lua"
        "github.com/zyedidia/micro/internal/screen"
@@ -24,7 +27,6 @@ import (
        "golang.org/x/text/encoding/htmlindex"
        "golang.org/x/text/encoding/unicode"
        "golang.org/x/text/transform"
-       dmp "github.com/sergi/go-diff/diffmatchpatch"
 )
 
 const backupTime = 8000
@@ -225,7 +227,7 @@ func NewBuffer(r io.Reader, size int64, path string, startcursor Loc, btype BufT
                b.Settings["encoding"] = "utf-8"
        }
 
-       reader := transform.NewReader(r, enc.NewDecoder())
+       reader := bufio.NewReader(transform.NewReader(r, enc.NewDecoder()))
 
        found := false
        if len(path) > 0 {
@@ -270,8 +272,8 @@ func NewBuffer(r io.Reader, size int64, path string, startcursor Loc, btype BufT
        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)
+       if _, err := os.Stat(filepath.Join(config.ConfigDir, "buffers")); os.IsNotExist(err) {
+               os.Mkdir(filepath.Join(config.ConfigDir, "buffers"), os.ModePerm)
        }
 
        if startcursor.X != -1 && startcursor.Y != -1 {
@@ -413,7 +415,7 @@ func (b *Buffer) ReOpen() error {
                return err
        }
 
-       reader := transform.NewReader(file, enc.NewDecoder())
+       reader := bufio.NewReader(transform.NewReader(file, enc.NewDecoder()))
        data, err := ioutil.ReadAll(reader)
        txt := string(data)
 
@@ -543,6 +545,7 @@ func (b *Buffer) UpdateRules() {
        if syntaxFile == "" {
                // search for the syntax file in the user's custom syntax files
                for _, f := range config.ListRealRuntimeFiles(config.RTSyntax) {
+                       log.Println("real runtime file", f.Name())
                        data, err := f.Data()
                        if err != nil {
                                screen.TermMessage("Error loading syntax file " + f.Name() + ": " + err.Error())
@@ -556,7 +559,7 @@ func (b *Buffer) UpdateRules() {
                                continue
                        }
 
-                       if (ft == "unknown" || ft == "" && highlight.MatchFiletype(header.FtDetect, b.Path, b.lines[0].data)) || header.FileType == ft {
+                       if ((ft == "unknown" || ft == "") && highlight.MatchFiletype(header.FtDetect, b.Path, b.lines[0].data)) || header.FileType == ft {
                                syndef, err := highlight.ParseDef(file, header)
                                if err != nil {
                                        screen.TermMessage("Error parsing syntax file " + f.Name() + ": " + err.Error())
@@ -641,7 +644,7 @@ func (b *Buffer) UpdateRules() {
                        go func() {
                                b.Highlighter.HighlightStates(b)
                                b.Highlighter.HighlightMatches(b, 0, b.End().Y)
-                               screen.DrawChan <- true
+                               screen.Redraw()
                        }()
                }
        }
@@ -905,6 +908,7 @@ func (b *Buffer) Retab() {
 
                l = bytes.TrimLeft(l, " \t")
                b.lines[i].data = append(ws, l...)
+               b.Modifications = append(b.Modifications, Loc{i, i})
                dirty = true
        }
 
@@ -1029,7 +1033,7 @@ func (b *Buffer) SetDiffBase(diffBase []byte) {
                b.diffBaseLineCount = strings.Count(string(diffBase), "\n")
        }
        b.UpdateDiff(func(synchronous bool) {
-               screen.DrawChan <- true
+               screen.Redraw()
        })
 }