Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
[Share Code] Snippet Manager
-
So something I feel has been missing from Pythonista is a snippet manager, so I have created a basic one and it is available on GitHub from here
One you enter a snippet you can currently create a new file from it or copy the contents to the clipboard. I also plan on adding an option to get the contents of the open file of the editor soon via the wrench menu. I have also started to add the ability to tag snippets and hopefully search on that later.
Take a look and let me know what you think.
-
Great idea. I will check it out.
-
@shaun-h , thanks for sharing. I was also doing some work on a snippet manager, but I actually never finish anything😱 I was testing tinydb as the backend rather than SQLite.
But great you have done one. I will use it. I lose code snippets I find all the time.😳I was also working on something with pygments. I just chopped it up and changed the interface a little to be more conducive to if you wanted to call it as an additional view. Good for viewing formatted code, but no editing. Look it's simple, if you can use it or parts of it please feel free to do so. I had implemented a style selection menu for the view as, but as part of a toolbar in the view. I just removed it. In this case would be better done as a menu item. The popup menu I had was trying to be generic. So a lot of crap in there.
I made a gist here.
But again thanks
-
@Phuket2 that pygments thing looks really cool I might have a look at adding that in tomorrow now, as I was wondering how to have syntax highlighting in the view/edit view.
I will let you know how I go.
-
@shaun-h , great. @JonB got me on to that and also helped me getting working. But it also does line hiliting. Probably a lot more. I chopped out quite a lot of stuff as it didn't make sense. I was using Pygments to display a .py file after searching for text in the all the .py file. Lol, because I didn't have a snippet manager, and was constantly looking for code I had already written 😳😱
-
@shaun-h , hey are you ok to receive comments about improving this lib? Maybe it just works as you like it and you don't want to spend any extra time on it. If that's the case I understand.
But I have stored a few things now. For me it needs more.
This is one thing I stored, but I would like to have notes, as well as tags and a field for the origin as I copied it. Also I commented out a line and replaced with my own idea. Also a count of how many times I have copied it from the database, so later the entries could be also sorted by most recent, most popular etc... Just saying, would be nice additions.
But one reason, I looked away from SQLite. I was looking for something that could adapt easily. But not wanting to become a SQL programmer as took me in that direction. Even SqlAlcemy (excuse the spelling) is not that easy unless you are doing it all the time.Anyway, my 2cents worth
def sizeof_fmt(self, num, suffix='B'): # copied from - # http://stackoverflow.com/questions/1094841/reusable-library-to-get-human-readable-version-of-file-size #for unit in ['','Ki','Mi','Gi','Ti','Pi','Ei','Zi']: for unit in ['','K','M','G','T','P','E','Z']: if abs(num) < 1024.0: return "%3.1f%s%s" % (num, unit, suffix) num /= 1024.0 return "%.1f%s%s" % (num, 'Yi', suffix)
-
@Phuket2 I am totally fine with ideas, improvements etc. If you feel like it I am happy for you to submit pull requests on GitHub.
Notes against a snippet sounds like a good idea. I am currently working on tags but I think I will push that back I might restructure it first.
Origin sounds good but I am thinking instead of just origin give the option to put a dictionary of values against so you can have other meta data about the snippet. This dictionary though would be added via a ui though so the user didn't know it was a dictionary.The ordering thing is a good idea as well not sure how I would track the count yet but I'll have a think about it.I did look at SqlAlchemy but I decided I knew how to write SQL and at the time I didn't particularly feel like learning it but I might take a second look at it before I move ahead on this a bit more.