Sublime Forum

Bookmarking newbie question

#1

another new user here…
I m not really a programmer, I mostly type latex, but I ve fell in love the instant I layed eyes on this beauty!
Quick question:
How difficult is to implement a command that selects from where one is to the next bookmark?
Will I need to know python, or is it dead easy?
I need to restructure a whole book, and after I found about that feature (or was it a plugin…?) that enables one to set bookmarks for a multiple find, I thought I could use it to copy/paste whole sections (= physics problems) fast…

thanks in advance!
sotiris

0 Likes

#2

You’ll need to know a little python to achieve this, but not too much. Doing it should be a matter of copying the current selection, then running the ‘nextBookmark’ command to set the selection to the next bookmark, and then combining the previous selection with the current selection.

Something like this should work:

import sublime, sublimeplugin

class SelectToNextBookmarkCommand(sublimeplugin.TextCommand):
	def run(self, view, args):
		# Copy the current selection
		oldSel = [s for s in view.sel()]
		
		# Go to the next bookmark
		view.runCommand('nextBookmark')
		
		# Combine the selections
		allCover = oldSel[0]
		for i in xrange(1, len(oldSel) - 1):
			allCover = allCover.cover(oldSel*)
		
		for s in view.sel():
			allCover = allCover.cover(s)
		
		# Apply the new selection
		view.sel().clear()
		view.sel().add(allCover)

You can bind this to a key by using the command ‘selectToNextBookmark’.*

0 Likes

#3

thank you so very much for this! :smiley: :smiley: :smiley: :smiley:
For the moment I can’t get it to work, but I guess I must re-read the existing documentation!!

*edit: IT WORKED !!! EXCELLENT !!! thanks again!!

0 Likes