Sublime Forum

How does "toggle_bookmark" feature work?

#1

I’d like to understand how toggle_bookmark & next_bookmark work but I don’t know where the code is living. I’ve tried to find it by using “Edit preferences: List plugin commands” plugin but unfortunately is not finding anything. There isn’t any bookmark.py in Default.sublime-package so maybe is not living here?

Anyway, thing is, I understand +/- how toggle_bookmark works, what I don’t understand is the logic when delete text that could contain some bookmarks… It seems the bookmarks will still live after you’ve deleted text that contains them. My question is, how are the new positions of the bookmarks computed after the text has changed (for instance, multiple selected blocks of text deleted).

Thanks.

0 Likes

#2

I don’t think it’s written in Python, so I don’t think the code is available.

AFAIK, it is implemented with add_regions. You can see the regions used by bookmarks with view.get_regions('bookmarks'). Internally Sublime handles when the text surrounding and within a region is modified, at least keeping an empty region when the area around it is deleted.

I’m not sure what you want to know or why. Is there some reason you want to know the particulars of how mutations around regions are handled?

2 Likes

#3

@sapphirehamster Thing is, my favourite text editor for few years has been SublimeText and is the only editor I use to code in a wide variety of languages, if something is missing the first idea it comes to my mind will be adding a plugin.

That said, right now I’m coding some sort of IDE which uses Scintilla behind the curtains, this component is quite nice but the default behaviour is far away of having many of the great features used by SublimeText. So I’m trying to add some of the ST features I use more often to it, one of them is the bookmark feature, problem is I don’t understand the logic behind it, for instance, how the mutations around regions are handled :frowning:

If SublimeText editor was open source or even better, available to be used as a pyside/pyqt pluggable widget I wouldn’t be asking any of this stuff :slight_smile:

NS: Thanks for the hint about view.get_regions('bookmarks'), didn’t know that.

0 Likes

#4

And just for the record, it’s not like I’m trying to create any creepy sublimetext clone (ie: limetext, atom or other slow pseudoclones…), that’s out of scope and it’d take years, SublimeText does the job and it does very well. In this particular case I’m just trying to code a little widget editor based on QScintilla to use it on a custom IDE to code 3d stuff, problem with scintilla is that lacks my favourite SublimeText features so when coding with this QScintilla stuff it feels really weird, ie:

  • toggle_comment
  • find_all_under
  • toogle_bookmark / next_bookmark
  • select_lines

Btw, related to this, how do you know whether a sublime command has the available source code or not? Asking cos I’ve been trying to find select_lines command already for a while (Default.sublime-package, sublime.py, sublime_plugin.py, dir(sublime_api)) and I haven’t found it anywhere

@wbond: Sorry to ping you, would you mind if you can explain me very briefly about the bookmarks logic here so i can give it a shot on QScintilla? Thanks! Hope this question isn’t very offtopic.

Also, if you guys made&sold a SublimeText component/widget ready to be used with pyside/pyqt I’d be more than happy to pay some $$$ for it. Not sure how modular the ST source code you guys got over there is but python wrapping tools nowadays are really friendly ones :wink:

0 Likes