Spyder: Add support for text snippets

Created on 17 Feb 2015  Â·  27Comments  Â·  Source: spyder-ide/spyder

_From [email protected] on 2011-03-16T11:31:10Z_

Spyder absolutely rocks but it has one glaring omission -- no support for text snippets. Please, please, please add this functionality.

_Original issue: http://code.google.com/p/spyderlib/issues/detail?id=588_

11–20 stars Editor Enhancement

All 27 comments

_From [email protected] on 2011-03-16T10:56:52Z_

You assume everyone knows what a text snippet is. Can you link to a definition of this functionality?

_From [email protected] on 2011-03-16T11:27:32Z_

Thank you for pointing that out to me. What I mean by code snippets is the functionality included by both gEdit and TextMate where you can type a short string and then hit tab (or some other keyboard shortcut) which will replace the string with some user defined text. For example, in my TextMate I have the following snippet:

pdb ==> hit tab (cursor is at the end of "pdb") ==> pdb replaced with import pdb; pdb.set_trace();

Another example from TextMate (or gEdit for that matter) is when you type "class" and hit tab, an outline of a generic class will be created:

class ==> hitting tab (cursor is at the end of "class") results in,

class MyClass(object):
"""docstring"""
def init(self, arg):
pass

I think the TextMate/gEdit model is really good -- a user creates a small template or outline of the text they want to insert and sets an option specifying the input text and a keyboard trigger. Just like TextMate/gEdit there should be a way of navigating through the various parts of a snippet via the keyboard, specifying some transformation to occur as the user types. To give an example of what this would look like, in gEdit, the template for the "class" example is:

class ${1:ClassName}(${2:object}):
def init(self${3:,}):
${4:pass}
$0

Without knowing any of the particulars, it is reasonably clear what the above template is trying to accomplish. For a more detailed explanation of what I mean by snippets, check out gEdit or TextMate. A good link is for an introduction to gEdit snippets is http://www.tuxradar.com/content/save-time-gedit-snippets If its not already apparent TextMate (on the mac) and gEdit (on linux) are my two primary editors. I think Spyder has a lot of promise and would like to switch to it, but without some of the basic, indispensable tools of modern text editors (like snippets) I am hesitant to make the switch. Please add in this functionality. Thank you all in the Spyder community for your time.

_From [email protected] on 2011-03-16T13:37:53Z_

I'm not a dev on this project, but that does seem like a handy feature. It gets my vote!

_From pierre.raybaut on 2011-03-16T15:11:26Z_

That is an interesting idea indeed.

But note that implementing such feature requires some work.
I'll think about it.

Summary: Add support for text snippets
Status: Accepted
Labels: -Type-Defect Type-Enhancement

_From [email protected] on 2011-03-18T00:15:49Z_

I posted a similar issue with the same idea some time ago https://code.google.com/p/spyderlib/issues/detail?id=235

_From pierre.raybaut on 2011-03-18T02:08:35Z_

issue #235 has been merged into this issue.

_From [email protected] on 2011-03-28T08:35:28Z_

Definitely a must have feature; it is boring having to repeat the same code over and over again when you want to define new functions, classes, methods, etc.
This way, you don't need to worry about typos, when you're typing in a hurry or when you are not focused; it saves time.

_From pierre.raybaut on 2011-05-16T01:29:31Z_

Labels: Cat-Editor

_From pierre.raybaut on 2011-05-18T00:31:48Z_

Status: ContributorNeeded

_From [email protected] on 2012-01-01T17:47:48Z_

Why re-implement the same functionality in every text editor when you can just implement it for ALL text inputs with something like AutoHotkey?

_From [email protected] on 2012-02-19T17:04:07Z_

Would love to see the feature in this IDE ... really usefull and time saver.

_From pierre.raybaut on 2012-03-18T14:12:23Z_

Status: HelpNeeded
Labels: -Type-Enhancement Type-Enh

_From [email protected] on 2012-07-26T21:43:03Z_

or even as komodo-edit does with a tools menu, that you can create/edit your own snippets that can be clicked to insert that text snippet (or dialog script getting some variables for the text) at the cursor's current location. and "built-in" variables could be called on in the snippets (such as current time/date, username, ect) for filling out your shebang/title/comments/license

i think clickable snippets (even of complex scripts) would be easier to program in without needing to monitor every typed character and matching to a dictionary... (although, i like that functionality too...

a tip to perhaps help development, parts of autokey (automation for linux desktops) has examples of matching text-typed and trigger characters to insert snippets (it uses Xlib, but only because it must interact with other windows)...

for now, anyone else looking to add such functionality themselves (using software outside the IDE) can use snippet/automation scripts such as:

for windows:
texter http://lifehacker.com/software/texter/lifehacker-code-texter-windows-238306.php autohotkey (texter is written in this lang) http://www.autohotkey.com/ autoit (similar split project. free but not open source.) http://www.autoitscript.com/site/autoit/ for linux - there are a few, but the best i have seen is autokey: https://code.google.com/p/autokey/ mac - sorry, i dont know a free version but there is the following commercial ones: http://www.ettoresoftware.com/products/typeit4me/ http://www.ergonis.com/products/typinator/

_From [email protected] on 2014-02-27T04:32:01Z_

I'd also love to see this feature and have implemented a simple hacked editor such that widgets.editor.trigger_code_completion will also look through a dict of snippets.
In principle the dict can be loaded from a separate .py, .json, .xml or whatever format is deemed most suitable for storing snippets...

It seems to work well for me though it's probably a bit rough around the edges.

_From [email protected] on 2014-02-27T04:33:36Z_

This issue is over a year old - is there any interest in this functionality or has it been superseded?

_From ccordoba12 on 2014-02-28T05:16:03Z_

I'm very interested to see this in Spyder, It'd be really cool to have it! :)

Please send us a pull request against our bitbucket repo https://bitbucket.org/spyder-ide/spyderlib/ so we can what you've done and start give you feedback.

By the way, what format are using for snippets, texmate one?

_From [email protected] on 2014-02-28T14:32:05Z_

Hi I just submitted my pull request - as I mentioned the approach is still
very rough and seems hackish to me, so all feedback and suggestions on how
to fit in better with the current spyderlib framework are much appreciated.

My pull request has two commits; the first is the very simple snippet
functionality such that pressing tab after entering a snippet keyword
expands the snippet at that point.

Today I worked on adding in simple token support (using basic vim snipmate
i.e.~ texmate syntax), such that e.g. {1:some text} will be replaced by
some text by default, but the editor will also be in "snippet mode" that
allows the user to cycle through tokens in the snippet and change the
default values.

@rlaverde do you have some ideas here?

Should we close this @ccordoba12 @andfoy ?

We still have to implement code snippets (right now we only have completion snippets).

@ccordoba12 Was the snippet feature not part of the Spyder 4.0.0 release?

It's interesting.

I mistakenly thought that code snippets is a basic feature in most modern IDEs.

We added completion snippets to Spyder 4, not code snippets, sorry.

Any plans with code snippetting?

On Tue, 18 Feb 2020 at 17:26, Carlos Cordoba notifications@github.com
wrote:

We added completion snippets to Spyder 4, not code snippets, sorry.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/spyder-ide/spyder/issues/588?email_source=notifications&email_token=ABCYONE3XUTOBQLZRAL7TTDRDPV27A5CNFSM4A4E7VA2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMCFFHA#issuecomment-587485852,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ABCYONBSFNHBY6NLXJJBDGDRDPV27ANCNFSM4A4E7VAQ
.

--
Lukio Olweny
Data Scientist, NAIROBI
Phone: +254 0718 480 030/+254729642561
Email: lukio.[email protected]
Skype id: lukio.olweny

Support for PyMOL code snippets

It was great to discuss today via the SciPy2020 sprint-spyder your plans for accommodating libraries of code snippets. I have a library of about 200 code snippets in pml for PyMOL, called pymolsnips, that I would like to make available to the users of spyder.

Hey @MooersLab, we'll have support for snippets in our next version (4.2.0), to be released next weekend.

Hi Carlos,

This is great news!! Congratulations on the progress of your team!!

Best regards,

Blaine

On Sat, Oct 31, 2020 at 2:01 PM Carlos Cordoba notifications@github.com
wrote:

Hey @MooersLab https://github.com/MooersLab, we'll have support for
snippets in our next version (4.2.0), to be released next weekend.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/spyder-ide/spyder/issues/588#issuecomment-719974119,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ADTZEC7D3NN43DPPJN5BWPTSNRNHXANCNFSM4A4E7VAQ
.

--
Best regards,

Blaine

Blaine Mooers, Ph.D.
Associate Professor
Department of Biochemistry and Molecular Biology
College of Medicine
University of Oklahoma Health Sciences Center
S.L. Young Biomedical Research Center Rm. 466
975 NE 10th Street
https://maps.google.com/?q=975+NE+10th+Street&entry=gmail&source=g, BRC
466
Oklahoma City, OK 73104-5419

office: (405) 271-8300 lab: (405) 271-8313

Faculty webpage
http://basicsciences.ouhsc.edu/biochemmolbiol/Faculty/bio_details/TabId/11753/ArtMID/30702/ArticleID/6430/Mooers-Blaine-HM-PhD.aspx
X-ray lab (LBSF)
http://research.ouhsc.edu/CoreFacilities/LaboratoryofBiomolecularStructureandFunction.aspx
SSRL
UEC
https://www-ssrl.slac.stanford.edu/content/about-ssrl/advisory-panels/ssrl-users-organization/members/ssrluo-2016-executive-committee-members
SSURF
EasyPyMOL https://github.com/MooersLab/EasyPyMOL Molecular Graphics
https://www.oumedicine.com/docs/default-source/ad-biochemistry-workfiles/moleculargraphicslinks.html

https://www.oumedicine.com/docs/default-source/ad-biochemistry-workfiles/MolecularGraphicsLinks.html
Small
Angle Scattering
http://www.oumedicine.com/docs/default-source/ad-biochemistry-workfiles/small-angle-scattering-links-27aug2014.html?sfvrsn=0
office: (405) 271-8300 lab: (405) 271-8313
e-mail: [email protected] (or [email protected])

Was this page helpful?
0 / 5 - 0 ratings