From 1331265681a7e2330dcf43c97a23126ab512a05b Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Sun, 10 Apr 2016 18:02:58 -0400 Subject: [PATCH] Add syntax highlighting option --- src/help.go | 3 +++ src/settings.go | 15 ++++++++++++++- src/view.go | 15 ++++++++++++--- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/help.go b/src/help.go index 1edfa79e..27051986 100644 --- a/src/help.go +++ b/src/help.go @@ -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 diff --git a/src/settings.go b/src/settings.go index b4755e67..106fe8c4 100644 --- a/src/settings.go +++ b/src/settings.go @@ -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 { diff --git a/src/view.go b/src/view.go index d06df9cf..c8e172f6 100644 --- a/src/view.go +++ b/src/view.go @@ -548,7 +548,9 @@ func (v *View) HandleEvent(event tcell.Event) { if relocate { v.Relocate() } - v.matches = Match(v) + 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] { - highlightStyle = v.matches[lineN][colN] + 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 {