diff --git a/data/micro.json b/data/micro.json index 63ba098d..49fdc662 100644 --- a/data/micro.json +++ b/data/micro.json @@ -170,10 +170,19 @@ "default": false }, "matchbrace": { - "description": "Whether to underline matching braces\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options", + "description": "Whether to show matching braces\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options", "type": "boolean", "default": true }, + "matchbracestyle": { + "description": "Whether to underline or highlight matching braces\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options", + "type": "string", + "enum": [ + "underline", + "highlight" + ], + "default": "underline" + }, "mkparents": { "description": "Whether to create missing directories\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options", "type": "boolean", diff --git a/internal/action/infocomplete.go b/internal/action/infocomplete.go index 568b6691..e093123d 100644 --- a/internal/action/infocomplete.go +++ b/internal/action/infocomplete.go @@ -216,6 +216,13 @@ func OptionValueComplete(b *buffer.Buffer) ([]string, []string) { if strings.HasPrefix("terminal", input) { suggestions = append(suggestions, "terminal") } + case "matchbracestyle": + if strings.HasPrefix("underline", input) { + suggestions = append(suggestions, "underline") + } + if strings.HasPrefix("highlight", input) { + suggestions = append(suggestions, "highlight") + } } } sort.Strings(suggestions) diff --git a/internal/buffer/buffer.go b/internal/buffer/buffer.go index 7955e0bb..7d7588c1 100644 --- a/internal/buffer/buffer.go +++ b/internal/buffer/buffer.go @@ -1015,7 +1015,7 @@ func (b *Buffer) FindMatchingBrace(braceType [2]rune, start Loc) (Loc, bool, boo leftChar = curLine[start.X-1] } var i int - if startChar == braceType[0] || leftChar == braceType[0] { + if startChar == braceType[0] || (leftChar == braceType[0] && startChar != braceType[1]) { for y := start.Y; y < b.LinesNum(); y++ { l := []rune(string(b.LineBytes(y))) xInit := 0 @@ -1046,24 +1046,24 @@ func (b *Buffer) FindMatchingBrace(braceType [2]rune, start Loc) (Loc, bool, boo l := []rune(string(b.lines[y].data)) xInit := len(l) - 1 if y == start.Y { - if leftChar == braceType[1] { - xInit = start.X - 1 - } else { + if startChar == braceType[1] { xInit = start.X + } else { + xInit = start.X - 1 } } for x := xInit; x >= 0; x-- { r := l[x] - if r == braceType[0] { + if r == braceType[1] { + i++ + } else if r == braceType[0] { i-- if i == 0 { - if leftChar == braceType[1] { - return Loc{x, y}, true, true + if startChar == braceType[1] { + return Loc{x, y}, false, true } - return Loc{x, y}, false, true + return Loc{x, y}, true, true } - } else if r == braceType[1] { - i++ } } } diff --git a/internal/config/settings.go b/internal/config/settings.go index 05a9f8a4..3b9bfaef 100644 --- a/internal/config/settings.go +++ b/internal/config/settings.go @@ -43,17 +43,18 @@ func init() { // Options with validators var optionValidators = map[string]optionValidator{ - "autosave": validateNonNegativeValue, - "clipboard": validateClipboard, - "tabsize": validatePositiveValue, - "scrollmargin": validateNonNegativeValue, - "scrollspeed": validateNonNegativeValue, - "colorscheme": validateColorscheme, - "colorcolumn": validateNonNegativeValue, - "fileformat": validateLineEnding, - "encoding": validateEncoding, - "multiopen": validateMultiOpen, - "reload": validateReload, + "autosave": validateNonNegativeValue, + "clipboard": validateClipboard, + "tabsize": validatePositiveValue, + "scrollmargin": validateNonNegativeValue, + "scrollspeed": validateNonNegativeValue, + "colorscheme": validateColorscheme, + "colorcolumn": validateNonNegativeValue, + "fileformat": validateLineEnding, + "encoding": validateEncoding, + "multiopen": validateMultiOpen, + "reload": validateReload, + "matchbracestyle": validateMatchBraceStyle, } func ReadSettings() error { @@ -274,50 +275,51 @@ func GetGlobalOption(name string) interface{} { } var defaultCommonSettings = map[string]interface{}{ - "autoindent": true, - "autosu": false, - "backup": true, - "backupdir": "", - "basename": false, - "colorcolumn": float64(0), - "cursorline": true, - "diffgutter": false, - "encoding": "utf-8", - "eofnewline": true, - "fastdirty": false, - "fileformat": defaultFileFormat(), - "filetype": "unknown", - "hlsearch": false, - "incsearch": true, - "ignorecase": true, - "indentchar": " ", - "keepautoindent": false, - "matchbrace": true, - "mkparents": false, - "permbackup": false, - "readonly": false, - "reload": "prompt", - "rmtrailingws": false, - "ruler": true, - "relativeruler": false, - "savecursor": false, - "saveundo": false, - "scrollbar": false, - "scrollmargin": float64(3), - "scrollspeed": float64(2), - "smartpaste": true, - "softwrap": false, - "splitbottom": true, - "splitright": true, - "statusformatl": "$(filename) $(modified)($(line),$(col)) $(status.paste)| ft:$(opt:filetype) | $(opt:fileformat) | $(opt:encoding)", - "statusformatr": "$(bind:ToggleKeyMenu): bindings, $(bind:ToggleHelp): help", - "statusline": true, - "syntax": true, - "tabmovement": false, - "tabsize": float64(4), - "tabstospaces": false, - "useprimary": true, - "wordwrap": false, + "autoindent": true, + "autosu": false, + "backup": true, + "backupdir": "", + "basename": false, + "colorcolumn": float64(0), + "cursorline": true, + "diffgutter": false, + "encoding": "utf-8", + "eofnewline": true, + "fastdirty": false, + "fileformat": defaultFileFormat(), + "filetype": "unknown", + "hlsearch": false, + "incsearch": true, + "ignorecase": true, + "indentchar": " ", + "keepautoindent": false, + "matchbrace": true, + "matchbracestyle": "underline", + "mkparents": false, + "permbackup": false, + "readonly": false, + "reload": "prompt", + "rmtrailingws": false, + "ruler": true, + "relativeruler": false, + "savecursor": false, + "saveundo": false, + "scrollbar": false, + "scrollmargin": float64(3), + "scrollspeed": float64(2), + "smartpaste": true, + "softwrap": false, + "splitbottom": true, + "splitright": true, + "statusformatl": "$(filename) $(modified)($(line),$(col)) $(status.paste)| ft:$(opt:filetype) | $(opt:fileformat) | $(opt:encoding)", + "statusformatr": "$(bind:ToggleKeyMenu): bindings, $(bind:ToggleHelp): help", + "statusline": true, + "syntax": true, + "tabmovement": false, + "tabsize": float64(4), + "tabstospaces": false, + "useprimary": true, + "wordwrap": false, } func defaultFileFormat() string { @@ -548,6 +550,22 @@ func validateReload(option string, value interface{}) error { case "prompt", "auto", "disabled": default: return errors.New(option + " must be 'prompt', 'auto' or 'disabled'") + } + + return nil +} + +func validateMatchBraceStyle(option string, value interface{}) error { + val, ok := value.(string) + + if !ok { + errors.New("Expected string type for matchbracestyle") + } + + switch val { + case "underline", "highlight": + default: + return errors.New(option + " must be 'underline' or 'highlight'") } return nil diff --git a/internal/display/bufwindow.go b/internal/display/bufwindow.go index fde20969..bca6bf8e 100644 --- a/internal/display/bufwindow.go +++ b/internal/display/bufwindow.go @@ -407,7 +407,9 @@ func (w *BufWindow) displayBuffer() { if found { matchingBraces = append(matchingBraces, mb) if !left { - matchingBraces = append(matchingBraces, curLoc) + if b.Settings["matchbracestyle"].(string) != "highlight" { + matchingBraces = append(matchingBraces, curLoc) + } } else { matchingBraces = append(matchingBraces, curLoc.Move(-1, b)) } @@ -557,7 +559,15 @@ func (w *BufWindow) displayBuffer() { for _, mb := range matchingBraces { if mb.X == bloc.X && mb.Y == bloc.Y { - style = style.Underline(true) + if b.Settings["matchbracestyle"].(string) == "highlight" { + if s, ok := config.Colorscheme["match-brace"]; ok { + style = s + } else { + style = style.Reverse(true) + } + } else { + style = style.Underline(true) + } } } } diff --git a/runtime/colorschemes/atom-dark.micro b/runtime/colorschemes/atom-dark.micro index 3efd5d4d..d7f8eff6 100644 --- a/runtime/colorschemes/atom-dark.micro +++ b/runtime/colorschemes/atom-dark.micro @@ -28,3 +28,4 @@ color-link color-column "#2D2F31" #No extended types (bool in C, etc.) #color-link type.extended "default" #Plain brackets +color-link match-brace "#1D1F21,#62B1FE" diff --git a/runtime/colorschemes/bubblegum.micro b/runtime/colorschemes/bubblegum.micro index af0dbce6..4c039d4d 100644 --- a/runtime/colorschemes/bubblegum.micro +++ b/runtime/colorschemes/bubblegum.micro @@ -26,3 +26,4 @@ color-link color-column "254" #No extended types (bool in C, &c.) and plain brackets color-link type.extended "241,231" color-link symbol.brackets "241,231" +color-link match-brace "231,28" diff --git a/runtime/colorschemes/cmc-16.micro b/runtime/colorschemes/cmc-16.micro index 44be786d..09ad6eaf 100644 --- a/runtime/colorschemes/cmc-16.micro +++ b/runtime/colorschemes/cmc-16.micro @@ -42,3 +42,4 @@ color-link gutter-warning "red" color-link color-column "cyan" color-link underlined.url "underline blue, white" color-link divider "blue" +color-link match-brace "black,cyan" diff --git a/runtime/colorschemes/cmc-tc.micro b/runtime/colorschemes/cmc-tc.micro index c20e7370..f142210e 100644 --- a/runtime/colorschemes/cmc-tc.micro +++ b/runtime/colorschemes/cmc-tc.micro @@ -38,3 +38,4 @@ color-link color-column "#f26522" color-link constant.bool "bold #55ffff" color-link constant.bool.true "bold #85ff85" color-link constant.bool.false "bold #ff8585" +color-link match-brace "#1e2124,#55ffff" diff --git a/runtime/colorschemes/darcula.micro b/runtime/colorschemes/darcula.micro index f8918160..560ab585 100644 --- a/runtime/colorschemes/darcula.micro +++ b/runtime/colorschemes/darcula.micro @@ -29,3 +29,4 @@ color-link color-column "#2C2C2C" color-link type.extended "default" #color-link symbol.brackets "default" color-link symbol.tag "#AE81FF,#242424" +color-link match-brace "#242424,#7A9EC2" diff --git a/runtime/colorschemes/default.micro b/runtime/colorschemes/default.micro index 27cba2d5..1c3b5eab 100644 --- a/runtime/colorschemes/default.micro +++ b/runtime/colorschemes/default.micro @@ -29,3 +29,4 @@ color-link color-column "#323232" color-link type.extended "default" #color-link symbol.brackets "default" color-link symbol.tag "#AE81FF,#282828" +color-link match-brace "#282828,#AE81FF" diff --git a/runtime/colorschemes/dracula-tc.micro b/runtime/colorschemes/dracula-tc.micro index f87572ff..b242eb6c 100644 --- a/runtime/colorschemes/dracula-tc.micro +++ b/runtime/colorschemes/dracula-tc.micro @@ -43,3 +43,4 @@ color-link cursor-line "#44475A,#F8F8F2" color-link color-column "#44475A" color-link type.extended "default" +color-link match-brace "#282A36,#FF79C6" diff --git a/runtime/colorschemes/dukedark-tc.micro b/runtime/colorschemes/dukedark-tc.micro index 5774468b..54afff60 100644 --- a/runtime/colorschemes/dukedark-tc.micro +++ b/runtime/colorschemes/dukedark-tc.micro @@ -33,3 +33,4 @@ color-link type "bold #3cc83c,#001e28" color-link type.keyword "bold #5aaae6,#001e28" color-link type.extended "#ffffff,#001e28" color-link underlined "#608b4e,#001e28" +color-link match-brace "#001e28,#5aaae6" diff --git a/runtime/colorschemes/dukelight-tc.micro b/runtime/colorschemes/dukelight-tc.micro index d3f492d2..c381f2b1 100644 --- a/runtime/colorschemes/dukelight-tc.micro +++ b/runtime/colorschemes/dukelight-tc.micro @@ -33,3 +33,4 @@ color-link type "bold #004080,#f0f0f0" color-link type.keyword "bold #780050,#f0f0f0" color-link type.extended "#000000,#f0f0f0" color-link underlined "#3f7f5f,#f0f0f0" +color-link match-brace "#f0f0f0,#780050" diff --git a/runtime/colorschemes/dukeubuntu-tc.micro b/runtime/colorschemes/dukeubuntu-tc.micro index 1a14b3f8..7c9f7afb 100644 --- a/runtime/colorschemes/dukeubuntu-tc.micro +++ b/runtime/colorschemes/dukeubuntu-tc.micro @@ -33,3 +33,4 @@ color-link type "bold #3cc83c,#2d0023" color-link type.keyword "bold #5aaae6,#2d0023" color-link type.extended "#ffffff,#2d0023" color-link underlined "#886484,#2d0023" +color-link match-brace "#2d0023,#5aaae6" diff --git a/runtime/colorschemes/geany.micro b/runtime/colorschemes/geany.micro index b6851a20..7333a2a2 100644 --- a/runtime/colorschemes/geany.micro +++ b/runtime/colorschemes/geany.micro @@ -24,3 +24,4 @@ color-link diff-modified "yellow" color-link diff-deleted "red" color-link gutter-error ",red" color-link gutter-warning "red" +color-link match-brace "black,cyan" diff --git a/runtime/colorschemes/gotham.micro b/runtime/colorschemes/gotham.micro index e8dc99c9..600822b6 100644 --- a/runtime/colorschemes/gotham.micro +++ b/runtime/colorschemes/gotham.micro @@ -24,3 +24,4 @@ color-link gutter-warning "#EDB443,#11151C" color-link cursor-line "#091F2E" color-link color-column "#11151C" color-link symbol "#99D1CE,#0C1014" +color-link match-brace "#0C1014,#D26937" diff --git a/runtime/colorschemes/gruvbox-tc.micro b/runtime/colorschemes/gruvbox-tc.micro index e41b1ac2..e6301e67 100644 --- a/runtime/colorschemes/gruvbox-tc.micro +++ b/runtime/colorschemes/gruvbox-tc.micro @@ -24,3 +24,4 @@ color-link cursor-line "#3c3836" color-link color-column "#79740e" color-link statusline "#ebdbb2,#665c54" color-link tabbar "#ebdbb2,#665c54" +color-link match-brace "#282828,#d3869b" diff --git a/runtime/colorschemes/gruvbox.micro b/runtime/colorschemes/gruvbox.micro index 823524ae..a59e99ef 100644 --- a/runtime/colorschemes/gruvbox.micro +++ b/runtime/colorschemes/gruvbox.micro @@ -21,3 +21,4 @@ color-link cursor-line "237" color-link color-column "237" color-link statusline "223,237" color-link tabbar "223,237" +color-link match-brace "235,72" diff --git a/runtime/colorschemes/material-tc.micro b/runtime/colorschemes/material-tc.micro index 7cb30658..561cf81c 100644 --- a/runtime/colorschemes/material-tc.micro +++ b/runtime/colorschemes/material-tc.micro @@ -30,3 +30,4 @@ color-link tabbar "#80DEEA,#3b4d56" color-link todo "bold #C792EA,#263238" color-link type "#FFCB6B,#263238" color-link underlined "underline #EEFFFF,#263238" +color-link match-brace "#263238,#C792EA" diff --git a/runtime/colorschemes/monokai-dark.micro b/runtime/colorschemes/monokai-dark.micro index 3449b305..51174309 100644 --- a/runtime/colorschemes/monokai-dark.micro +++ b/runtime/colorschemes/monokai-dark.micro @@ -23,3 +23,4 @@ color-link gutter-error "#CB4B16" color-link gutter-warning "#E6DB74" color-link cursor-line "#323232" color-link color-column "#323232" +color-link match-brace "#1D0000,#AE81FF" diff --git a/runtime/colorschemes/monokai.micro b/runtime/colorschemes/monokai.micro index 4f93211a..e33cf830 100644 --- a/runtime/colorschemes/monokai.micro +++ b/runtime/colorschemes/monokai.micro @@ -29,3 +29,4 @@ color-link color-column "#323232" color-link type.extended "default" #color-link symbol.brackets "default" color-link symbol.tag "#AE81FF,#282828" +color-link match-brace "#282828,#AE81FF" diff --git a/runtime/colorschemes/one-dark.micro b/runtime/colorschemes/one-dark.micro index c3b0e8cd..b6c96954 100644 --- a/runtime/colorschemes/one-dark.micro +++ b/runtime/colorschemes/one-dark.micro @@ -34,3 +34,4 @@ color-link todo "#8B98AB" color-link type "#66D9EF" color-link type.keyword "#C678DD" color-link underlined "#8996A8" +color-link match-brace "#21252C,#C678DD" diff --git a/runtime/colorschemes/railscast.micro b/runtime/colorschemes/railscast.micro index 3abb1683..61934b94 100644 --- a/runtime/colorschemes/railscast.micro +++ b/runtime/colorschemes/railscast.micro @@ -31,3 +31,5 @@ color-link space "underline #e6e1dc,#2b2b2b" #the Python syntax definition are wrong. This is not how you should do decorators! color-link brightgreen "#edb753,#2b2b2b" + +color-link match-brace "#2b2b2b,#a5c261" diff --git a/runtime/colorschemes/simple.micro b/runtime/colorschemes/simple.micro index 4ee416d4..dc12002e 100644 --- a/runtime/colorschemes/simple.micro +++ b/runtime/colorschemes/simple.micro @@ -27,3 +27,4 @@ color-link type.extended "default" color-link symbol.brackets "default" #Color shebangs the comment color color-link preproc.shebang "comment" +color-link match-brace ",magenta" diff --git a/runtime/colorschemes/solarized-tc.micro b/runtime/colorschemes/solarized-tc.micro index f2840ec3..d68a024a 100644 --- a/runtime/colorschemes/solarized-tc.micro +++ b/runtime/colorschemes/solarized-tc.micro @@ -26,3 +26,4 @@ color-link cursor-line "#003541" color-link color-column "#003541" color-link type.extended "#839496,#002833" color-link symbol.brackets "#839496,#002833" +color-link match-brace "#002833,#268BD2" diff --git a/runtime/colorschemes/solarized.micro b/runtime/colorschemes/solarized.micro index 19b8e2c3..745b46ea 100644 --- a/runtime/colorschemes/solarized.micro +++ b/runtime/colorschemes/solarized.micro @@ -25,3 +25,4 @@ color-link cursor-line "black" color-link color-column "black" color-link type.extended "default" color-link symbol.brackets "default" +color-link match-brace ",blue" diff --git a/runtime/colorschemes/sunny-day.micro b/runtime/colorschemes/sunny-day.micro index f851f318..82e4b8f4 100644 --- a/runtime/colorschemes/sunny-day.micro +++ b/runtime/colorschemes/sunny-day.micro @@ -24,3 +24,4 @@ color-link gutter-warning "88" color-link cursor-line "229" #color-link color-column "196" color-link current-line-number "246" +color-line match-brace "230,22" diff --git a/runtime/colorschemes/twilight.micro b/runtime/colorschemes/twilight.micro index f59d9e41..224fb7fd 100644 --- a/runtime/colorschemes/twilight.micro +++ b/runtime/colorschemes/twilight.micro @@ -35,3 +35,4 @@ color-link todo "#8B98AB" color-link type "#F9EE98" color-link type.keyword "#CDA869" color-link underlined "#8996A8" +color-link match-brace "#141414,#E0C589" diff --git a/runtime/colorschemes/zenburn.micro b/runtime/colorschemes/zenburn.micro index ec8a9580..e4f91175 100644 --- a/runtime/colorschemes/zenburn.micro +++ b/runtime/colorschemes/zenburn.micro @@ -25,3 +25,4 @@ color-link gutter-warning "174,237" color-link cursor-line "238" color-link color-column "238" color-link current-line-number "188,237" +color-link match-brace "237,223" diff --git a/runtime/help/colors.md b/runtime/help/colors.md index ac8b4be3..83800597 100644 --- a/runtime/help/colors.md +++ b/runtime/help/colors.md @@ -194,6 +194,7 @@ Here is a list of the colorscheme groups that you can use: * divider (Color of the divider between vertical splits) * message (Color of messages in the bottom line of the screen) * error-message (Color of error messages in the bottom line of the screen) +* match-brace (Color of matching brackets when `matchbracestyle` is set to `highlight`) Colorschemes must be placed in the `~/.config/micro/colorschemes` directory to be used. diff --git a/runtime/help/options.md b/runtime/help/options.md index 75e877e8..a492bc44 100644 --- a/runtime/help/options.md +++ b/runtime/help/options.md @@ -210,11 +210,19 @@ Here are the available options: default value: `false` -* `matchbrace`: underline matching braces for '()', '{}', '[]' when the cursor - is on a brace character. +* `matchbrace`: show matching braces for '()', '{}', '[]' when the cursor + is on a brace character or next to it. default value: `true` +* `matchbracestyle`: whether to underline or highlight matching braces when + `matchbrace` is enabled. The color of highlight is determined by the `match-brace` + field in the current theme. Possible values: + * `underline`: underline matching braces. + * `highlight`: use `match-brace` style from the current theme. + + default value: `underline` + * `mkparents`: if a file is opened on a path that does not exist, the file cannot be saved because the parent directories don't exist. This option lets micro automatically create the parent directories in such a situation. @@ -495,6 +503,7 @@ so that you can see what the formatting should look like. "linter": true, "literate": true, "matchbrace": true, + "matchbracestyle": "underline", "mkparents": false, "mouse": true, "parsecursor": false,