Extension/custom command for comments within lines?


#1

Hi everyone,

I’m having some trouble sorting through the multiple comment packages. I’m looking for something that will let me comment out a block of text within a line when I’m writing prose in markdown. Something like this:

Lorem ipsum dolor sit amet, <!--consectetur adipiscing elit,
sed do eiusmod tempor incididunt--> ut labore et dolore
magna aliqua. Ut enim ad minim veniam, quis nostrud
exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat.

Basically I’d like to highlight text that might be within a line, or might span parts of two or more lines, and have a command that surrounds that text with comment tags.

Is there a package that will do this? Most of the comment packages (like comment) seem to comment out entire lines. If no existing package does this, can someone give me a hint on creating my own custom command that will do this?


#2

Maybe a simple modification of this still works?! Wrap Selected Text - What's the best way?


#3

Brilliant! Thanks @dpo, that worked perfectly.

In case someone else is interested, I just added this to my init.coffee:

wrapSelection = (selection, before, after) ->
  after ?= before
  selectedText = selection.getText()
  selection.insertText("#{before}#{selectedText}#{after}")

atom.commands.add 'atom-text-editor',
  'custom:wrap-html-comment', ->
    editor = @getModel()
    editor.transact ->
      wrapSelection(selection, "<!--", "-->") for selection in editor.getSelections()

#4

:thumbsup: