Home Download Buy Blog Forum Support

bookmarking newbie question

bookmarking newbie question

Postby sfranky on Sun Oct 25, 2009 6:55 pm

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!
Posts: 95
Joined: Mon Oct 19, 2009 10:06 pm

Re: bookmarking newbie question

Postby jps on Mon Oct 26, 2009 1:03 pm

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:

Code: Select all
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
      # Combine the selections
      allCover = oldSel[0]
      for i in xrange(1, len(oldSel) - 1):
         allCover = allCover.cover(oldSel[i])
      for s in view.sel():
         allCover = allCover.cover(s)
      # Apply the new selection

You can bind this to a key by using the command 'selectToNextBookmark'.
Site Admin
Posts: 3217
Joined: Wed Mar 19, 2008 12:33 pm

Re: bookmarking newbie question

Postby sfranky on Mon Oct 26, 2009 11:14 pm

thank you so very much for this! :D :D :D :D
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!!
Posts: 95
Joined: Mon Oct 19, 2009 10:06 pm

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 50 guests