Add syntax highlighting option

This commit is contained in:
Zachary Yedidia 2016-04-10 18:02:58 -04:00
parent 5330e0e5a5
commit 1331265681
3 changed files with 29 additions and 4 deletions

View file

@ -44,6 +44,9 @@ colorscheme: loads the colorscheme stored in ~/.micro/colorschemes/'option'.micr
tabsize: sets the tab size to 'option'
default value: '4'
syntax: turns syntax on or off
default value: 'on'
`
// DisplayHelp displays the help txt

View file

@ -13,13 +13,14 @@ import (
var settings Settings
// All the possible settings
var possibleSettings = []string{"colorscheme", "tabsize", "autoindent"}
var possibleSettings = []string{"colorscheme", "tabsize", "autoindent", "syntax"}
// The Settings struct contains the settings for micro
type Settings struct {
Colorscheme string `json:"colorscheme"`
TabSize int `json:"tabsize"`
AutoIndent bool `json:"autoindent"`
Syntax bool `json:"syntax"`
}
// InitSettings initializes the options map and sets all options to their default values
@ -61,6 +62,7 @@ func DefaultSettings() Settings {
Colorscheme: "default",
TabSize: 4,
AutoIndent: true,
Syntax: true,
}
}
@ -88,6 +90,17 @@ func SetOption(view *View, args []string) {
settings.Colorscheme = value
LoadSyntaxFiles()
view.buf.UpdateRules()
} else if option == "syntax" {
if value == "on" {
settings.Syntax = true
} else if value == "off" {
settings.Syntax = false
} else {
messenger.Error("Invalid value for " + option)
return
}
LoadSyntaxFiles()
view.buf.UpdateRules()
}
err := WriteSettings(filename)
if err != nil {

View file

@ -548,7 +548,9 @@ func (v *View) HandleEvent(event tcell.Event) {
if relocate {
v.Relocate()
}
if settings.Syntax {
v.matches = Match(v)
}
}
// DisplayView renders the view to the screen
@ -608,12 +610,19 @@ func (v *View) DisplayView() {
// Write the line
tabchars := 0
for colN, ch := range line {
runes := []rune(line)
for colN := v.leftCol; colN < v.leftCol+v.width; colN++ {
if colN >= len(runes) {
break
}
ch := runes[colN]
var lineStyle tcell.Style
// Does the current character need to be syntax highlighted?
// if lineN >= v.updateLines[0] && lineN < v.updateLines[1] {
if settings.Syntax {
highlightStyle = v.matches[lineN][colN]
}
// } else if lineN < len(v.lastMatches) && colN < len(v.lastMatches[lineN]) {
// highlightStyle = v.lastMatches[lineN][colN]
// } else {