func (b *Buffer) ClearMatches() {
	for i := range b.lines {
		b.SetMatch(i, nil)
		b.SetState(i, nil)
	}
}
ClearMatches clears all of the syntax highlighting for this buffer
package editor
import (
	"io"
	"strings"
	"unicode/utf8"
	"github.com/askovpen/gossiped/pkg/highlight"
)
const LargeFileThreshold = 50000
var (
	fileformat = 0
)
type Buffer struct {
	*EventHandler
	*LineArray
	Path string
	Cursor    Cursor
	cursors   []*Cursor  
	curCursor int        
	name string
	IsModified bool
	NumLines int
	syntaxDef   *highlight.Def
	highlighter *highlight.Highlighter
	Settings map[string]interface{}
}
func NewBufferFromString(text string) *Buffer {
	return NewBuffer(strings.NewReader(text), int64(len(text)), "1.msg", nil)
}
func NewBuffer(reader io.Reader, size int64, path string, cursorPosition []string) *Buffer {
	b := new(Buffer)
	b.LineArray = NewLineArray(size, reader)
	b.Settings = DefaultLocalSettings()
	if fileformat == 1 {
		b.Settings["fileformat"] = "unix"
	} else if fileformat == 2 {
		b.Settings["fileformat"] = "dos"
	}
	b.Path = path
	b.EventHandler = NewEventHandler(b)
	b.update()
	b.Cursor = Cursor{
		Loc: Loc{0, 0},
		buf: b,
	}
	b.cursors = []*Cursor{&b.Cursor}
	return b
}
func (b *Buffer) GetName() string {
	return b.name
}
func (b *Buffer) updateRules() {
	ryaml := `
filetype: msg
detect:
  filename: "\\.msg$"
rules:
- comment: ".*\\>+.*$"
- icomment: ".*[^>](>>)+[^>].*$"
- tagline: "^\\.\\.\\..*$"
- origin: "^ \\* Origin:.*$"
- tearline: "^--- .*$"
- kludge: "^@.*$"
- kludge: "^SEEN-BY: .*$"
`
	file, err := highlight.ParseFile([]byte(ryaml))
	if err != nil {
		return
	}
	ftdetect, err := highlight.ParseFtDetect(file)
	if err != nil {
		return
	}
	header := new(highlight.Header)
	header.FileType = file.FileType
	header.FtDetect = ftdetect
	b.syntaxDef, err = highlight.ParseDef(file, header)
	if err != nil {
		return
	}
	if b.syntaxDef != nil {
		b.Settings["filetype"] = b.syntaxDef.FileType
		b.highlighter = highlight.NewHighlighter(b.syntaxDef)
		b.highlighter.HighlightStates(b)
	}
}
func (b *Buffer) FileType() string {
	return b.Settings["filetype"].(string)
}
func (b *Buffer) IndentString() string {
	if b.Settings["tabstospaces"].(bool) {
		return Spaces(int(b.Settings["tabsize"].(float64)))
	}
	return "\t"
}
func (b *Buffer) update() {
	b.NumLines = len(b.lines)
}
func (b *Buffer) MergeCursors() {
	var cursors []*Cursor
	for i := 0; i < len(b.cursors); i++ {
		c1 := b.cursors[i]
		if c1 != nil {
			for j := 0; j < len(b.cursors); j++ {
				c2 := b.cursors[j]
				if c2 != nil && i != j && c1.Loc == c2.Loc {
					b.cursors[j] = nil
				}
			}
			cursors = append(cursors, c1)
		}
	}
	b.cursors = cursors
	for i := range b.cursors {
		b.cursors[i].Num = i
	}
	if b.curCursor >= len(b.cursors) {
		b.curCursor = len(b.cursors) - 1
	}
}
func (b *Buffer) UpdateCursors() {
	for i, c := range b.cursors {
		c.Num = i
	}
}
func (b *Buffer) Modified() bool {
	return b.IsModified
}
func (b *Buffer) insert(pos Loc, value []byte) {
	b.IsModified = true
	b.LineArray.insert(pos, value)
	b.update()
}
func (b *Buffer) remove(start, end Loc) string {
	b.IsModified = true
	sub := b.LineArray.remove(start, end)
	b.update()
	return sub
}
func (b *Buffer) Start() Loc {
	return Loc{0, 0}
}
func (b *Buffer) End() Loc {
	return Loc{utf8.RuneCount(b.lines[b.NumLines-1].data), b.NumLines - 1}
}
func (b *Buffer) RuneAt(loc Loc) rune {
	line := b.LineRunes(loc.Y)
	if len(line) > 0 {
		return line[loc.X]
	}
	return '\n'
}
func (b *Buffer) LineBytes(n int) []byte {
	if n >= len(b.lines) {
		return []byte{}
	}
	return b.lines[n].data
}
func (b *Buffer) LineRunes(n int) []rune {
	if n >= len(b.lines) {
		return []rune{}
	}
	return toRunes(b.lines[n].data)
}
func (b *Buffer) Line(n int) string {
	if n >= len(b.lines) {
		return ""
	}
	return string(b.lines[n].data)
}
func (b *Buffer) LinesNum() int {
	return len(b.lines)
}
func (b *Buffer) Lines(start, end int) []string {
	lines := b.lines[start:end]
	slice := make([]string, len(lines))
	for _, line := range lines {
		slice = append(slice, string(line.data))
	}
	return slice
}
func (b *Buffer) Len() (n int) {
	for _, l := range b.lines {
		n += utf8.RuneCount(l.data)
	}
	if len(b.lines) > 1 {
		n += len(b.lines) - 1  
	}
	return
}
func (b *Buffer) MoveLinesUp(start int, end int) {
	if start < 1 || start >= end || end > len(b.lines) {
		return  
	}
	if end == len(b.lines) {
		b.Insert(
			Loc{
				utf8.RuneCount(b.lines[end-1].data),
				end - 1,
			},
			"\n"+b.Line(start-1),
		)
	} else {
		b.Insert(
			Loc{0, end},
			b.Line(start-1)+"\n",
		)
	}
	b.Remove(
		Loc{0, start - 1},
		Loc{0, start},
	)
}
func (b *Buffer) MoveLinesDown(start int, end int) {
	if start < 0 || start >= end || end >= len(b.lines)-1 {
		return  
	}
	b.Insert(
		Loc{0, start},
		b.Line(end)+"\n",
	)
	end++
	b.Remove(
		Loc{0, end},
		Loc{0, end + 1},
	)
}