Advertisement
Guest User

Untitled

a guest
May 28th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. # coding: utf-8
  2. #Comment/Uncomment selected lines
  3.  
  4. import editor
  5.  
  6. text = editor.get_text()
  7. selection = editor.get_line_selection()
  8. selected_text = text[selection[0]:selection[1]]
  9. is_comment = selected_text.strip().startswith('#')
  10. replacement = ''
  11. for line in selected_text.splitlines():
  12. if is_comment:
  13. if line.strip().startswith('#'):
  14. replacement += line[line.find('#') + 1:] + '\n'
  15. else:
  16. replacement += line + '\n'
  17. else:
  18. replacement += '#' + line + '\n'
  19.  
  20. editor.replace_text(selection[0], selection[1], replacement)
  21. editor.set_selection(selection[0], selection[0] + len(replacement) - 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement