Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
#################################### IMPORTS ################################### import sublime import sublimeplugin ############################### HELPER FUNCTIONS ############################### def find_all(view, search, start, end, flags=0): regions = [sublime.Region(start, start)] while True: regions.append(view.find(search, regions[-1].end(), flags)) if not regions[-1] or regions[-1].begin() > end: break return regions[1:-1] ################################### COMMANDS ################################### class BookmarkArea(sublimeplugin.TextCommand): def run(self, view, args): sels = view.sel() start = sels[0].begin() end = sels[-1].end() sels.clear() for pos in (start, end): sels.add(sublime.Region(pos, pos)) view.runCommand('toggleBookmark') sels.clear() sels.add(sublime.Region(start, start)) class SearchBetweenBookmarks(sublimeplugin.TextCommand): def run(self, view, args): if len(view.sel()) == 3: start, search_sel, end = view.sel() else: search_sel = view.sel()[0] view.runCommand('prevBookmark') start = view.sel()[0] view.runCommand('nextBookmark') end = view.sel()[-1] full_word = view.word(search_sel) search_sel = search_sel or full_word search = view.substr(search_sel) if search_sel == full_word: search = r'\b%s\b' % search finds = find_all(view, search, start.begin(), end.end()) view.sel().clear() for sel in [search_sel] + finds: view.sel().add(sel) ################################################################################
This paste will be private.
From the Design Piracy series on my blog: