I’m trying to write a small plugin that loops over each paragraph in the view (it’s a prose file, not code) and add a tab to the first line if it isn’t already present.
This is what I have so far, but the results are quite odd… I get tabs in the middle of paragraphs after the first.
import sublime
import sublime_plugin
class TabAllParagraphsCommand(sublime_plugin.TextCommand):
def run(self, edit):
doc = sublime.Region(0, self.view.size())
regions = self.view.lines(doc);
for region in regions:
if not region.empty():
_region = self.view.substr(region)
if not _region.startswith('\t'):
_region = '\t' + _region
self.view.replace(edit, region, _region)
Clearly, I’m missing a key concept or two here. Would someone be kind enough to clue me in?