Snippets (?) using lenght of arguments - Dynamic content



I would like to have snippets producing “pretty” comments like the two above.

# ----------------- #
# -- 1st example -- #
# ----------------- #

The size of the dash lines must be adapted to the content of the single line of text:

# ---------------------------- #
# -- Another example larger -- #
# ---------------------------- #

Typically I would like to use a snippet showing

# ------------------- #
# -- Short_comment -- #
# ------------------- #

where Short_comment is a $1 argument regarding to the syntax used for defining snippets.

My problem is to adapt the size of the dash line regarding to the value of $1. Is this possible or not ?


It’s not possible to do this with snippets right now. But you could do this with a bit of code or the snippets package could be enhanced.


Thanks. Is there some easy to read package where to start to do my first atom package ?


There’s the Your First Package document in the docs:


Until you get the new feature you should use this package for that example …


Thanks a lot for the two lats advices. The tiny package is a good example of a very simple package.


Hi, @projetmbc I’ve made the wrap selection package so if you have any questions of things which you want to me to add please let me know. Its fresh new package and there are few simple things I am planning to add.

PS: Thanks @mark_hahn for recommending my package. Always happy to see that other find it useful too.


Thanks for the help, I will take a look at the code as soon as possible (I have a lot of work for the moment).


@Trudko; I’ve just took a look and this sounds like black magic for me for the moment.

wrapWithText: ->
    editor = atom.workspace.getActiveEditor()
    selections = editor.getSelections()
    for selection in selections
        if not selection.isEmpty()
            range = selection.getBufferRange()

In this lines, could I go trough each single selection such as to find the width of this selection ? Can I remove the text of a selection and replace it by another ?


@projetmbc of course it sounds like black magic because it is! :smiley:

What I am doing here is I go through each selection finds where it start(range variable) and I put one cursor at the start of selection and one at the end. What you could do is in for loop:

width = selection.getText().length
selection.insertText(“Text to replace the text in selection”)


Thanks a lot for your help mister black magician. :wink: I will try to find 5 min to play with atom packages… As soon as I made something usable, I will add it to my user’s profile.

Last question, but not the least. Is there an easy way to know a language associated to a file from a package point of view ?


For the file currently active:

editor = atom.workspace.getActiveEditor()
grammarName = editor.getGrammar().name


So cute. :slight_smile: I love that !