]> git.lizzy.rs Git - micro.git/commitdiff
allow optionally brace matching with the closing brace to the left of the cursor
authorJT Olds <hello@jtolds.com>
Wed, 28 Feb 2018 01:53:04 +0000 (18:53 -0700)
committerJT Olds <hello@jtolds.com>
Wed, 28 Feb 2018 01:53:04 +0000 (18:53 -0700)
this behavior, while slightly less obvious, allows for observing what brace you
just closed. as you write closing braces, the brace you closed gets highlighted

cmd/micro/cellview.go
cmd/micro/settings.go
runtime/help/options.md

index c33d29257b5856e89f12e1b229e92efdb6f83bb2..9c50856e4ab50ac5eefee8ba12c18395d02429d6 100644 (file)
@@ -73,9 +73,20 @@ func (c *CellView) Draw(buf *Buffer, top, height, left, width int) {
        // bracePairs is defined in buffer.go
        if buf.Settings["matchbrace"].(bool) {
                for _, bp := range bracePairs {
-                       r := buf.Cursor.RuneUnder(buf.Cursor.X)
-                       if r == bp[0] || r == bp[1] {
+                       if buf.Cursor.RuneUnder(buf.Cursor.X) == bp[0] {
                                matchingBrace = buf.FindMatchingBrace(bp, buf.Cursor.Loc)
+                               break
+                       }
+                       left := buf.Cursor.Loc.X
+                       if buf.Settings["matchbraceleft"].(bool) {
+                               left -= 1
+                               if left < 0 {
+                                       left = 0
+                               }
+                       }
+                       if buf.Cursor.RuneUnder(left) == bp[1] {
+                               matchingBrace = buf.FindMatchingBrace(
+                                       bp, Loc{X: left, Y: buf.Cursor.Loc.Y})
                        }
                }
        }
index cf1b209316ee5cb02568625e727fdf616317e456..9466227e732e6c26726658443aedc5a9f047ebf0 100644 (file)
@@ -215,6 +215,7 @@ func DefaultGlobalSettings() map[string]interface{} {
                "keepautoindent": false,
                "keymenu":        false,
                "matchbrace":     false,
+               "matchbraceleft": false,
                "mouse":          true,
                "pluginchannels": []string{"https://raw.githubusercontent.com/micro-editor/plugin-channel/master/channel.json"},
                "pluginrepos":    []string{},
@@ -257,6 +258,7 @@ func DefaultLocalSettings() map[string]interface{} {
                "indentchar":     " ",
                "keepautoindent": false,
                "matchbrace":     false,
+               "matchbraceleft": false,
                "rmtrailingws":   false,
                "ruler":          true,
                "savecursor":     false,
index 3ef67a0628ecdc1f9ca35e89158470fa05045542..a767f5bdba983fbd9f4db6cefbea8b78935df718 100644 (file)
@@ -186,6 +186,12 @@ Here are the options that you can set:
 
     default value: `false`
 
+* `matchbraceleft`: when matching a closing brace, should matching match the
+   brace directly under the cursor, or the character to the left? only matters
+   if `matchbrace` is true
+
+    default value: `false`
+
 * `syntax`: turns syntax on or off.
 
        default value: `true`