Sublime Forum

Editing C-style /* */ comments - auto asterisk insert?

#1

How would it be possible to make Sublime to the following.

  • When you are editing C-style comment
/**
  *
  */

… if you add new lines, via Enter key or copy-paste, the comment block would stay closed by automatically inserting * at the beginning of each new line:

/**
  * <-- press enter here
  */

result:

/**
  *
  * <-- automatically inserted, having indent intact
  */

Aptana Studio and other IDEs have had this feature for a long time.

0 Likes

#2

github.com/spadgos/sublime-jsdocs

0 Likes

#3

I use a handful of keybinds that enable this behavior.

[code]// Doc block generation.
{
“keys”: “enter”], “command”: “insert_snippet”,
“args”:
{
“contents”: “\n *$0”
},
“context”:

    { "key": "preceding_text", "operator": "regex_contains", "operand": "/\\*{2}$", "match_all": true },
    { "key": "following_text", "operator": "regex_contains", "operand": "^$", "match_all": true },
    { "key": "selector", "operator": "equal", "operand": "comment.block.documentation.phpdoc.php" }
]

},
{
“keys”: “enter”], “command”: “insert_snippet”,
“args”:
{
“contents”: “*$0\n”
},
“context”:

    { "key": "preceding_text", "operator": "regex_contains", "operand": "^\\s]+$", "match_all": true },
    { "key": "following_text", "operator": "regex_contains", "operand": "^\\*", "match_all": true },
    { "key": "selector", "operator": "equal", "operand": "comment.block.documentation.phpdoc.php" }
]

},
{
“keys”: “enter”], “command”: “insert_snippet”,
“args”:
{
“contents”: “$0\n*”
},
“context”:

    { "key": "preceding_text", "operator": "regex_contains", "operand": "^\\s+\\*$", "match_all": true },
    { "key": "following_text", "operator": "regex_contains", "operand": "^ .+^\\s]$", "match_all": true },
    { "key": "selector", "operator": "equal", "operand": "comment.block.documentation.phpdoc.php" }
]

},
{
“keys”: “enter”], “command”: “insert_snippet”,
“args”:
{
“contents”: “\n*$0”
},
“context”:

    { "key": "preceding_text", "operator": "regex_contains", "operand": "\\s\\* .+^\\s]$", "match_all": true },
    { "key": "following_text", "operator": "regex_contains", "operand": "^$", "match_all": true },
    { "key": "selector", "operator": "equal", "operand": "comment.block.documentation.phpdoc.php" }
]

},
{
“keys”: “enter”], “command”: “insert_snippet”,
“args”:
{
“contents”: “\n*$0”
},
“context”:

    { "key": "preceding_text", "operator": "regex_contains", "operand": "^\\s]+\\*$", "match_all": true },
    { "key": "following_text", "operator": "regex_contains", "operand": "^/$", "match_all": true },
    { "key": "selector", "operator": "equal", "operand": "comment.block.documentation.phpdoc.php" }
]

},
{
“keys”: “enter”], “command”: “insert_snippet”,
“args”:
{
“contents”: “\n*$0”
},
“context”:

    { "key": "preceding_text", "operator": "regex_contains", "operand": "\\s\\*$", "match_all": true },
    { "key": "following_text", "operator": "regex_contains", "operand": "^$", "match_all": true },
    { "key": "selector", "operator": "equal", "operand": "comment.block.documentation.phpdoc.php" }
]

}[/code]

0 Likes

#4

Thanks. Works great.

0 Likes

#5

For anyone else looking, jsdocs is now DocBlockr: sublime.wbond.net/packages/DocBlockr

0 Likes

#6

I am looking for the same behaviour as the original poster. I when I hit enter I would like ‘*’ be inserted in the next line.

I have downloaded DocBlockr. I am wondering if there is a way to enable this behaviour with DocBLockr. Currently it creates the closing / but does not add additional '’.

Thanks

0 Likes

#7

Try this package:
packagecontrol.io/packages/DoxyDoc
It works for me!

0 Likes