]> git.lizzy.rs Git - micro.git/blobdiff - cmd/micro/highlighter.go
make undothresthold a setting (part 2)
[micro.git] / cmd / micro / highlighter.go
index 18cf01d8d370b7f6e5a1090e7aa1e7923f29990a..8ec16de37f9fd274d7eb1af4fb5f4d4e26019859 100644 (file)
@@ -1,7 +1,7 @@
 package main
 
 import (
-       "github.com/gdamore/tcell"
+       "github.com/zyedidia/tcell"
        "io/ioutil"
        "path/filepath"
        "regexp"
@@ -93,6 +93,7 @@ var preInstalledSynFiles = []string{
        "privoxy-filter",
        "puppet",
        "python",
+       "r",
        "reST",
        "rpmspec",
        "ruby",
@@ -362,10 +363,10 @@ func LoadRulesFromFile(text, filename string) []SyntaxRule {
 // and returns them. It also returns the filetype of the file
 func GetRules(buf *Buffer) ([]SyntaxRule, string) {
        for r := range syntaxFiles {
-               if r[0] != nil && r[0].MatchString(buf.path) {
+               if r[0] != nil && r[0].MatchString(buf.Path) {
                        // Check if the syntax statement matches the extension
                        return LoadRulesFromFile(syntaxFiles[r].text, syntaxFiles[r].filename), syntaxFiles[r].filetype
-               } else if r[1] != nil && r[1].MatchString(buf.lines[0]) {
+               } else if r[1] != nil && r[1].MatchString(buf.Lines[0]) {
                        // Check if the header statement matches the first line
                        return LoadRulesFromFile(syntaxFiles[r].text, syntaxFiles[r].filename), syntaxFiles[r].filetype
                }
@@ -377,30 +378,19 @@ func GetRules(buf *Buffer) ([]SyntaxRule, string) {
 // so map[3] represents the style of the third character
 type SyntaxMatches [][]tcell.Style
 
-// Match takes a buffer and returns the syntax matches a map specifying how it should be syntax highlighted
-// We need to check the start-end regexes for the entire buffer every time Match is called, but for the
-// non start-end rules, we only have to update the updateLines provided by the view
+// Match takes a buffer and returns the syntax matches: a 2d array specifying how it should be syntax highlighted
+// We match the rules from up `synLinesUp` lines and down `synLinesDown` lines
 func Match(v *View) SyntaxMatches {
-       buf := v.buf
-       rules := v.buf.rules
+       buf := v.Buf
+       rules := v.Buf.rules
 
-       viewStart := v.topline
-       viewEnd := v.topline + v.height
-       if viewEnd > len(buf.lines) {
-               viewEnd = len(buf.lines)
+       viewStart := v.Topline
+       viewEnd := v.Topline + v.height
+       if viewEnd > buf.NumLines {
+               viewEnd = buf.NumLines
        }
 
-       // updateStart := v.updateLines[0]
-       // updateEnd := v.updateLines[1]
-       //
-       // if updateEnd > len(buf.lines) {
-       //      updateEnd = len(buf.lines)
-       // }
-       // if updateStart < 0 {
-       //      updateStart = 0
-       // }
-       lines := buf.lines[viewStart:viewEnd]
-       // updateLines := buf.lines[updateStart:updateEnd]
+       lines := buf.Lines[viewStart:viewEnd]
        matches := make(SyntaxMatches, len(lines))
 
        for i, line := range lines {
@@ -408,19 +398,19 @@ func Match(v *View) SyntaxMatches {
        }
 
        // We don't actually check the entire buffer, just from synLinesUp to synLinesDown
-       totalStart := v.topline - synLinesUp
-       totalEnd := v.topline + v.height + synLinesDown
+       totalStart := v.Topline - synLinesUp
+       totalEnd := v.Topline + v.height + synLinesDown
        if totalStart < 0 {
                totalStart = 0
        }
-       if totalEnd > len(buf.lines) {
-               totalEnd = len(buf.lines)
+       if totalEnd > buf.NumLines {
+               totalEnd = buf.NumLines
        }
 
-       str := strings.Join(buf.lines[totalStart:totalEnd], "\n")
-       startNum := ToCharPos(0, totalStart, v.buf)
+       str := strings.Join(buf.Lines[totalStart:totalEnd], "\n")
+       startNum := ToCharPos(0, totalStart, v.Buf)
 
-       toplineNum := ToCharPos(0, v.topline, v.buf)
+       toplineNum := ToCharPos(0, v.Topline, v.Buf)
 
        for _, rule := range rules {
                if rule.startend {
@@ -432,7 +422,7 @@ func Match(v *View) SyntaxMatches {
                                                if i < toplineNum {
                                                        continue
                                                }
-                                               colNum, lineNum := FromCharPosStart(toplineNum, 0, v.topline, i, buf)
+                                               colNum, lineNum := FromCharPosStart(toplineNum, 0, v.Topline, i, buf)
                                                if lineNum == -1 || colNum == -1 {
                                                        continue
                                                }
@@ -448,7 +438,6 @@ func Match(v *View) SyntaxMatches {
                                if indicies := rule.regex.FindAllStringIndex(line, -1); indicies != nil {
                                        for _, value := range indicies {
                                                for i := value[0]; i < value[1]; i++ {
-                                                       // matches[lineN+updateStart][i] = rule.style
                                                        matches[lineN][i] = rule.style
                                                }
                                        }