Sublime Forum

DogEars - Named Bookmarks for Sublime Text 2

#1

DogEars allows you to create Bookmarks inside your code, and give them names. It also allows you to search for them using a quick panel (like the Ctrl + P Dialog). Currently it only maintains bookmarks in a particular open view, but I plan to evolve it to become a neat bookmark manager so you can jump to important locations in your project.

[size=120]http://github.com/skyronic/DogEars[/size]

[size=150]What works:[/size]

  • Create a bookmark Ctrl + Shift + B
  • Access a bookmark Ctrl + Shift + M

[size=150]What doesn’t work(yet):
[/size]

  • You can only access bookmarks in the same file for now.
  • The bookmarks aren’t stored on your hard drive. If you close Sublime Text, the bookmarks are lost
  • Deleting bookmarks
  • The bookmarks are still shown in case the section of text containing the bookmark has been deleted
  • A single panel to show all the bookmarks
  • Stability issues

I am not too experienced with python. I would really appreciate any feedback on the code, and suggestions on how I can take this forward.

0 Likes

#2

Thats a pretty neat idea.
I’m not great at python either.
How are you persisting the bookmarks I see BOOKMARS = {} array
I’m wondering if there is something in Sublime for persisting things like this and I’d be really interested in seeing how reopen_last_file command works since it stores a list I would guess of the last opened files and would be the best way to handle storing bookmars as well I assume.

Congratulations on the plugin.

0 Likes

#3

[quote=“atomi”]Thats a pretty neat idea.
I’m not great at python either.
How are you persisting the bookmarks I see BOOKMARS = {} array
I’m wondering if there is something in Sublime for persisting things like this and I’d be really interested in seeing how reopen_last_file command works since it stores a list I would guess of the last opened files and would be the best way to handle storing bookmars as well I assume.

Congratulations on the plugin.[/quote]

Hey! Thanks for checking it out!

I am using BOOKMARKS now because I am still confused about the best way to persist it. Sublime has a neat feature where I can pick out a region (for a bookmark), and ask it to persist across sessions. The best part is that if I add text above or below, the bounds will get re-calculated (like how good bookmarking systems should).

The annoying part is that I will have to keep a list of all the bookmarks in all the files. So when the user searches the global list of bookmarks, it needs to open the appropriate file (if it isn’t opened already) and then move to the correct bookmark.

However, am not sure the best way to persist BOOKMARKS. So I’m just putting it inside a global array. Since the chance of two views writing it simultaneously is none, it shouldn’t have any thread-safety problems. But I’m not sure whether to serialize using CPickle, or JSON, or whatever.

0 Likes

#4

Use CPickle is the fastest way. I use it in github.com/SublimeText/BufferSc … rScroll.py

The problem you will find is that because the application is not sending “on project close/open” and “on application closed” you need to write to that file very often, which is very inefficient.

0 Likes

#5

[quote=“tito”]Use CPickle is the fastest way. I use it in github.com/SublimeText/BufferSc … rScroll.py

The problem you will find is that because the application is not sending “on project close/open” and “on application closed” you need to write to that file very often, which is very inefficient.[/quote]

Hi tito,

yup, I was using the source code of BufferScroll as a reference.

I actually figured out a way to write the bookmarks to disk and keep it efficient.

I maintain one master table containing the global list of bookmarks - which file contains which bookmark, etc. I only write to this on creation of a new bookmark, or deletion of an existing one.

I can use application_close and view_close to pick up the exact caret location of each bookmark inside the open views and store them. It’s going to be a lot more tricky in practice but I think I can pull it off.

0 Likes

#6

A good adition, keep it up. : )

I believe you can just open the file with “sublime.active_window().open_file(path)”, this will refocus the tab if unfocused.

Allow an easy deletion, or save a hash of the content of the line.

[quote]* A single panel to show all the bookmarks

  • Deleting bookmarks[/quote]

There is a tiny example on how to use the panel in this file github.com/weslly/Nettuts-Fetch … r/Fetch.py
You give to the show_quick_panel function a list and the panel will return the index of the selected item.

0 Likes

#7

Just in case, here is the api sublimetext.com/docs/2/api_reference.html

0 Likes

#8

@skyronic or @tito: Any word on merging efforts or updating this plugin for ST3?
It seems that bookmarks are already saved in ST3, but adding the names would be invaluable :smiley:

0 Likes