Sublime Forum

Auto comment closing paranthesis

#1

In Tcl and C and so on there are logical constructs like if/els that look like this (Tcl)

if {test} {
 # do something
}

Suppose I want to comment the “if” sentence out. The steps currently required are:

  1. comment the first line
  2. comment the third line

Would it be cool, if SublimeText would autocomment the third line, after the user comments the first line?
Actually there is already something similar when writing the first line, it adds automatically the closing bracket.

Cheers
Alexandru

0 Likes

#2

I used a macro to do this:
You can use ctrl+m (to jump to the other bracket). You also have to be careful where your cursor is, but again there are keyboard shortcuts to take you to (B)eginning (O)f (L)ine (BOL), EOL etc.

You can write then as well as record the key presses, (ctrl+alt+shift+q to start recording I think), this is what mine looks like (caveat I’m not using ST at the moment, so am probably a bit rusty, and I’m not 100% sure what this does, I’ve saved it as CommentStructure.sublime-macro, so this is just to give you an example)

[
	{
		"args":
		{
			"extend": false,
			"to": "bol"
		},
		"command": "move_to"
	},
	{
		"args":
		{
			"block": false
		},
		"command": "toggle_comment"
	},
	{
		"args":
		{
			"extend": false,
			"to": "bol"
		},
		"command": "move_to"
	},
	{
		"args":
		{
			"by": "lines",
			"forward": true
		},
		"command": "move"
	},
	{
		"args":
		{
			"block": false
		},
		"command": "toggle_comment"
	},
	{
		"args":
		{
			"extend": false,
			"to": "bol"
		},
		"command": "move_to"
	},
	{
		"args":
		{
			"to": "brackets"
		},
		"command": "move_to"
	},
	{
		"args":
		{
			"block": false
		},
		"command": "toggle_comment"
	},
	{
		"args":
		{
			"extend": false,
			"to": "bol"
		},
		"command": "move_to"
	}
]

Hopefully this’ll get you started…

0 Likes

#3

Many thanks. Maybe for others interesting.
For me, I lost interest in customizing software. That’s because I often work on a couple of different computers and the maintanance effort would be to big. I just hope the feature find it’s way into standard.

0 Likes