Sublime Forum

Question(comments): Comments around words

#1

1. Summary

I can’t find, how I can automatically add comment around words.


2. Expected behavior

I wrote Sasha words → I press hotkey → I get:

###############
# Sasha words #
###############

Or another simply actions.


3. Not helped

3.1. Snippet

I try similar snippet as in this answer → I get:

###########################
# Sasha words #
###########################

I get extra # symbols.

3.2. DocBlockr

DocBlockr works only for JavaScript-style comments.

I can’t adapt code fragment for Python-style comments → I get traceback:

Traceback (most recent call last):
  File "D:\Sublime Text 3 x64\sublime_plugin.py", line 818, in run_
    return self.run(edit)
  File "D:\Sublime Text 3 x64\Data\Packages\PaletteMira\BlockComment.py", line 1431, in run
    leadingWS = len(re_whitespace.match(lineText).group(1))
AttributeError: 'NoneType' object has no attribute 'group'

3.3. Another plugins

I can’t find any plugin in Package Control, that can solve this problem.

Thanks.

0 Likes

#2

Hi,

maybe try something like
https://packagecontrol.io/packages/ASCII%20Comment%20Snippets
https://packagecontrol.io/packages/ASCII%20Decorator

1 Like

#3

Yes, I already try these packages, but I don’t find, what I need.

Sorry, that I didn’t point it in the question.

Thanks.

0 Likes

#4

A snippet such as the following seems to do what you want:

<snippet>
    <content><![CDATA[##${0/./#/g}##
# ${0:$SELECTION} #
##${0/./#/g}##
]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <!-- <tabTrigger>hello</tabTrigger> -->
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <!-- <scope>source.python</scope> -->
</snippet>

There may be some extra tweaking involved such as making it python specific and adding a tab trigger if you want to use it as a regular snippet, for example.

2 Likes