Sublime Forum

[Closed] Detect semicolon at end of line

#1

Hi, I’m trying to get a key binding to only add a semicolon to the end of the line when it there isn’t one there already. I’m playing around with detection and I have something like

{ "keys": ["ctrl+shift+enter"], "command": "insert", "args": {"characters": "hi"}, "context": [
			{"key": "preceding_text", "operator": "regex_match", "operand": "^.*", "match_all": true},
			{"key": "following_text", "operator:": "regex_match", "operand": ".*;$", "match_all": true}
		]
	},

Based off of the regex, it should only insert “hi” when there is a semicolon at the end, but it doesn’t seem to be working and defaults to the original command. I’m not sure what I am doing wrong, unless “following_text” doesn’t match up until the end of the line.

0 Likes

#2

you have a colon inside the JSON key for operator, which shouldn’t be there:

{"key": "following_text", "operator:": "regex_match", "operand": ".*;$", "match_all": true}
                                   ^

should be

{"key": "following_text", "operator": "regex_match", "operand": ".*;$", "match_all": true}
                                   ^
2 Likes

#3

That was very silly of me, I honestly thought I checked everything. Thank you so much!

0 Likes

#4

it took me a while to find it too, don’t worry about it!

0 Likes