From ea6a87d41a9fcaa9fff81c1a5310726b1e15c548 Mon Sep 17 00:00:00 2001 From: JT Olds Date: Tue, 27 Feb 2018 18:53:04 -0700 Subject: [PATCH 1/3] allow optionally brace matching with the closing brace to the left of the cursor 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 | 15 +++++++++++++-- cmd/micro/settings.go | 2 ++ runtime/help/options.md | 6 ++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/cmd/micro/cellview.go b/cmd/micro/cellview.go index c33d2925..9c50856e 100644 --- a/cmd/micro/cellview.go +++ b/cmd/micro/cellview.go @@ -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}) } } } diff --git a/cmd/micro/settings.go b/cmd/micro/settings.go index cf1b2093..9466227e 100644 --- a/cmd/micro/settings.go +++ b/cmd/micro/settings.go @@ -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, diff --git a/runtime/help/options.md b/runtime/help/options.md index 3ef67a06..a767f5bd 100644 --- a/runtime/help/options.md +++ b/runtime/help/options.md @@ -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` From b12eca0a98419eaca06e268a5c9915cbc763fa59 Mon Sep 17 00:00:00 2001 From: sum01 Date: Thu, 8 Mar 2018 11:28:38 -0500 Subject: [PATCH 2/3] Fix #1066 php syntax --- runtime/syntax/php.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/syntax/php.yaml b/runtime/syntax/php.yaml index bd0c5395..b3f2dc4b 100644 --- a/runtime/syntax/php.yaml +++ b/runtime/syntax/php.yaml @@ -18,7 +18,7 @@ rules: - comment: "" - default: "<\\?(php|=)\" end=\"\\?>" - identifier.class: "([a-zA-Z0-9_-]+)\\(" - - preproc: "(require|include|require_once|include_once)" + - preproc: "\\b(require|include)(_once)?)\\b" - type: "\\b(var|class|extends|function|echo|case|default|exit|switch|extends|as|define|do|declare|in|trait|interface|[E|e]xception|array|int|string|bool|iterable|void)\\b" - identifier.class: "[a-zA-Z\\\\]+::" - identifier: "([A-Z][a-zA-Z0-9_]+)\\s" From 41bae11c1e5e2cceaa6f13723fac30936b3e9b6c Mon Sep 17 00:00:00 2001 From: Velocet Date: Wed, 21 Mar 2018 03:58:04 +0100 Subject: [PATCH 3/3] Create PowerShell.yaml --- runtime/syntax/PowerShell.yaml | 129 +++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 runtime/syntax/PowerShell.yaml diff --git a/runtime/syntax/PowerShell.yaml b/runtime/syntax/PowerShell.yaml new file mode 100644 index 00000000..7a45e426 --- /dev/null +++ b/runtime/syntax/PowerShell.yaml @@ -0,0 +1,129 @@ +# PowerShell syntax highlighting file for micro - https://micro-editor.github.io/ +# PowerShell syntax taken from: https://github.com/PowerShell/EditorSyntax + +filetype: powershell + +detect: + filename: "\\.ps(1|m1|d1)$" + #header: "" + +rules: + # - comment.block: # Block Comment + # - comment.doc: # Doc Comment + # - comment.line: # Line Comment + # - comment.shebang: # Shebang Line + + # - constant: # Constant + # - constant.bool: # Constant (true, false) + # - constant.interpolation: + # - constant.number: # Constant (null) + # - constant.specialChar: + # - constant.string: # String + # - constant.string.char: + # - constant.string.url: # Uri + # - constant.unicode: + + # - identifier: # Also used for functions + # - identifier.class: # Also used for functions + # - identifier.macro: + # - identifier.var: + + # - preproc: # Preprocessor + # - preproc.DebugIdentifier: # Preprocessor + # - preproc.shebang: # The #! at the beginning of a file that tells the os what script interpreter to use + + # - special: # Special (global|local|private|script|using|workflow) + + # - statement: # Statements Keywords + # - statement.built_in: + # - statement.declaration: # Declaration Keywords + # - statement.meta: # Meta + # - statement.reserved: # Reserved Keywords + + # - symbol + # - symbol.brackets: # {}()[] and sometimes <> + # - symbol.operator: # Operators + # - symbol.tag: # For html tags, among other things + + # - type + # - type.collections: # Collections (array, hashtable) + # - type.ctypes: # CTypes (CBool, CChar, etc.) + # - type.keyword: # If you want a special highlight for keywords like 'private' + # - type.storage: # Storage Types (int, uint, string, etc.) + + # Class + - identifier.class: "class +[A-Za-z0-9]+ *((:) +[A-Za-z0-9.]+)?" + - identifier.class: "(function)(?:([[:space:]][A-Za-z0-9]+[[:space:]]*))" + + # Verbs taken from PwSh 6.0.2 + - identifier: "(Add|Approve|Assert|Backup|Block|Build|Checkpoint|Clear|Close|Compare|Complete|Compress|Confirm|Connect|Convert|ConvertFrom|ConvertTo|Copy)[-][A-Za-z0-9]+" + - identifier: "(Debug|Deny|Deploy|Disable|Disconnect|Dismount|Edit|Enable|Enter|Exit|Expand|Export|Find|Format|Get|Grant|Group|Hide)[-][A-Za-z0-9]+" + - identifier: "(Import|Initialize|Install|Invoke|Join|Limit|Lock|Measure|Merge|Mount|Move|New|Open|Optimize|Out|Ping|Pop|Protect|Publish|Push)[-][A-Za-z0-9]+" + - identifier: "(Read|Receive|Redo|Register|Remove|Rename|Repair|Request|Reset|Resize|Resolve|Restart|Restore|Resume|Revoke)[-][A-Za-z0-9]+" + - identifier: "(Save|Search|Select|Send|Set|Show|Skip|Split|Start|Step|Stop|Submit|Suspend|Switch|Sync|Test|Trace)[-][A-Za-z0-9]+" + - identifier: "(Unblock|Undo|Uninstall|Unlock|Unprotect|Unpublish|Unregister|Update|Use|Wait|Watch|Write)[-][A-Za-z0-9]+" + - identifier.var: "\\$(?i)((Global|Local|Private|Script|Using|Workflow)[:])?[A-Za-z0-9]*" + + + # Expression and types + - type: "\\[\\b([A-Za-z]+|[A-Za-z]+[0-9]+)\\b\\]" + + # Keywords + - statement: "\\b(alias|as|begin|break|catch|continue|data|default|define|do|dynamicparam)\\b" + - statement: "\\b(else|elseif|end|exit|finally|for|foreach|foreach-object|from|if|in|inlinescript)\\b" + - statement: "\\b(parallel|param|process|return|switch|throw|trap|try|until|using|var|where|where-object|while)\\b" + + # Special Keywords + - special: "\\b(break|continue|exit)\\b" + + - symbol.brackets: "(\\{|\\})" + - symbol.brackets: "(\\(|\\))" + - symbol.brackets: "(\\[|\\])" + - symbol.operator: "[\\-+/*=<>?:!~%&|]" + - symbol.operator: "[[:space:]][-](ne|eq|gt|ge|lt|le|like|notlike|match|notmatch|contains|notcontains|in|notin|replace|is|isnot)[[:space:]]" + + # Constants + - constant.bool: "\\b\\$(true|false|null)\\b" + - constant.number: "\\b([0-9._]+|0x[A-Fa-f0-9_]+|0b[0-1_]+)[FL]?\\b" + + # Expression Mode String + - constant.string: + start: "\"" + end: "\"" + #skip: "\\\\." + rules: + - constant.specialChar: "\\\\([btnfr]|'|\\\"|\\\\)" + - constant.specialChar: "\\\\u[A-Fa-f0-9]{4}" + + # Argument Mode String + - constant.string: + start: "'" + end: "'" + #skip: "\\\\." + rules: + - constant.specialChar: "\\\\([btnfr]|'|\\\"|\\\\)" + - constant.specialChar: "\\\\u[A-Fa-f0-9]{4}" + + # Line Comment + - comment: + start: "#" + end: "$" + rules: + - todo: "(TODO|XXX|FIXME|BUG):?" + + # Block Comment + - comment: + start: "<#" + end: "#>" + rules: + - todo: "(TODO|XXX|FIXME|BUG):?" + + # Embedded C# + - default: + start: "@\"" + end: "\"@" + rules: + - include: "csharp" + + # Todo + - todo: "(TODO|XXX|FIXME|BUG):?"