Create large commented headings in code

When writing code, I usually divide my code into sections with large headings like this

# ==========================================
#         Utility Methods
# ==========================================

Currently I create blocks like this manually. Is there a plugin in atom that allows one to do this by just selecting the text, and possibly also detects the comment character for the programming language.

You could always request the style of comment you want in a package like this one, however this wold be a perfect use for your own custom snippet!

Or you can use a custom command in your init script:

atom.commands.add 'atom-workspace', 
 'misc:titleize': ->
    editor = atom.workspace.getActiveTextEditor()

    selection = editor.getLastSelection()
    {start, end} = selection.getBufferRange()

    scope = editor.scopeDescriptorForBufferPosition([start.row, 0])
    {commentStartString, commentEndString} = editor.languageMode.commentStartAndEndStringsForScope(scope)

    separator = '=============================='

    if commentStartString?
      if commentEndString?
        tpl = "#{commentStartString}#{separator}\n  #{editor.getTextInRange([start, end])}\n#{separator}#{commentEndString}"
        tpl = """
        #{commentStartString}  #{editor.getTextInRange([start, end])}

      editor.setTextInBufferRange([start, end], tpl)

It’s a quick and dirty version that don’t consider indent and al but it still do the job:

1 Like