Is there a way to create templates for text files in Eclipse? - eclipse

In Eclipse, I really enjoy being able to create templates for things I commonly write in Java and XML. While there is some room for improvement, templates have proven to be quite the time saver. Today I was documenting some notes in the release notes. We have a specific format that we write said release notes in. I thought it would be handy to write a small template so that I could easily insert most of the boiler plate text when I amend the notes. So I dug around the eclipse settings and didn't see anything for plain text files. I googled around and also didn't see anything.
So is what I'm wanting to do possible in Eclipse? Is there a plugin I would need to enable such a feature?

I assume the closest you can get is using Snippets
Add the view by clicking Window -> Show View -> Snippets. In that view, right-click and select Customizeto create custom snippets. You can now add those snippets in your textfile by double-clicking them.
Maybe there is also some shortcut feature I didn't find yet...

Related

VSCode custom snippets list in activitybar/sidebar - extension recommendation?

Dear fellow VSCode users!
My collection of custom snippets has become rather vast lately, with all of documentation writing that I have to do. And it's becoming kind of difficult to remember all the shortcuts.
I know I can search for snippets and browse their list via the command palette, but it requires quite some extra typing and/or clicking.
Is there an existing extension that would add a new activity bar icon and provide a list of all user-defined snippets in the sidebar, allowing one to simply click on the desired snippet and thus insert it?
I imagine I'm not the only person on the planet to desire such a feature, but I honestly can't seem to be able to find it searching the Marketplace or using Google.
Thanks for all your suggestions.
Just made an extension. Snippets View. Tested only on Windows.
It's not complete yet, but has basic functionality...

how to write notepad++ auto-complete plugin

I'm trying to develop a small plugin that will do a sort-of auto-completion along with some other advanced features in order to create a primitive IDE to use with a custom scripting language we've developed.
So I want to know, how do the auto-complete plugins usually work? I have a basic plugin template that I'm playing around with (the C# one) and I see how the commands work, from a high level anyway, but I'm trying to figure out how I would create my auto-complete feature.
My first guess would be to make a command that spawned a new thread that retrieved the entire contents of the notepad++ text every 100 mills or so and then popped-up a little selector box or directly wrote the auto-complete possibilities when the correct pattern was matched on the newly typed text.
Any wisdom from those who have gone before me on this?
Thanks alot.
Well I figured it out. Apparently there is a "beNotified" method in my project template that I downloaded and it handles all events/notifications from the Scintilla/Notepad++ environment. I will probably be using the SCN_CHARADDED event to check the current line of text each time a character is added to the GUI.

How does Eclipse do code completion specific to third-party frameworks?

How does the Eclipse editor work to enable code completion? For example, within the XML editor for Hibernate property files, if I ctrl-space within a tag, a list of possible value relevant to hibernate will show up.
I understand that the XML editor is pre-configured to understand xml tag, but how about tag specific to a particular framework? How does Eclipse know about that?
I believe that the eclipse XML editor gets the content assist information from any referenced DTDs, or XMLSchema information it associates with the XML file. Try this experiment: Remove the DOCTYPE entry at the beginning of the file and see if content assist still works.
If you're interested in writing your own content assistants, you may want to start by reading the following:
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/editors_contentassist.htm
In a nutshell, like most things in Eclipse, this is a platform hook. When you press the button, it queries all the registered assistants (I'm simplifying here), and they provide suggestions based on the current element or even the current content.
When writing a source editor or viewer for a particular language or document type, it is common to provide at least some rudimentary content assistants.
Removed the DOCTYPE entry at the beginning of the file and im now able to see the commands while typing ctrl+space...
To add to Uri's answer, you can define your own editor for your own language with XText as long as you have a simple EBNF grammar language for your DSL (domain specific language).
You will have:
syntax coloring,
model navigation (F3, etc.),
code completion,
outline view, and
code templates.
Here is a solution you can work. Actually I was facing a same problem with struts.xml file. I was not able to produce tags by cntrl+space
what i did was...
go to Preferences...Java...Editor...Content Assist...Advanced
check all the check-boxes ON and press OK.
sometimes the problem persists due to some false alarming in eclipse. If it happens, just delete your xml file and create a new one in same location.
I hope it will help.
I had the same issue while using the struts.xml file.
I got fix when I tried below...
Go to “Preferences>Java>Editor>Content Assist>Advanced“. Make sure “Java Non Types Proposals” are ticked on both the places as shown in the image below then click Apply and OK button:-

Storing code snippets in eclipse

I'm a recent semi-convert to Eclipse after 20 years of using vi and gvim. One of the things I miss about gvim is that I could cut a bunch of different snippets of code into named buffers, and paste them at will when doing something like repeating a common idiom. For instance I'd have it so "ap would paste
DatabaseHandle handle = null;
try
{
handle = DatabaseConnectionPool.newHandle();
and then "bp would paste
handle.commit();
}
finally
{
handle.rollback();
DatabaseConnectionPool.returnHandle(handle);
}
And I could repeat both of them over and over in the course of a day. In an answer to another question, somebody mentioned that you could "manage code snippets" in Eclipse, but didn't mention how. So now I'm asking: how do you manage code snippets in Eclipse?
You might want to store those two snippets into a code template, as explained in this tutorial.
And do not forget about the possibility to quickly execute any kind of java code snippets in a scrapbook (not exactly what you want, but it can come in handy at times)
Newtopian adds (in the comments)
In fact templates become much more powerful by adding variables and tabstops within, so your example above would become dbHandle ctrl+space. It would copy snippets from both parts and place your cursor right in the middle.
Eclipse also offers something very similar to the templates feature described by VonC called (would you believe) snippets. Window > Show view > Snippets.
To add a new snippet category: Right click in the Snippets window and click Customize...
Click New > New Category. Enter a category name if necessary (e.g. "Java"). Click Apply.
With your chosen category selected, click New > New Item. Enter your snippet.
To use a snippet, put the cursor where you want to insert the snippet, then double click on a snippet in the Snippets window.
I ran into the Snip2Code plugin recently.
It did the job, and I can collect and search snippets in a quick way.
Well a picture worths a thousand words, what about this one?
The question is old but the link of the answere is older ;)
Here is a nice tutorial:
http://www.dansshorts.com/post/creating-snippets-in-eclipse
I have used snippets in some IDEs, like Dreamweaver and Homesite, an old Coldfusion IDE. I also use a lot of snippets in MySQL Workbench - where i type a lot of SQL, very handy there.
I am now using Eclipse Java EE IDE for Web Developers Version Indigo Release and found the snippets panel in Window|Show View|Other...|General|Snippets. I was able to manipulate it and figure out how to add the code I wanted as snippets and how to use it efficiently.
Use Eclipse Snipmatch (Part of Eclipse for Java Developers Package).
Works very well for Java code snippets but also works for any other language like HTML, ABABP, PHP etc.
You can convert any code fragment from your editor directly to a code template. Highlight the code you'd like to convert to a snippet, context menu "create snippet", complete the form and done.
snippets can be shared via Git repositories with your team members
Manual:
https://www.eclipse.org/recommenders/manual/#snipmatch
Installation:
https://marketplace.eclipse.org/content/snipmatch

How to Change Netbeans Fonts and Colors Preview Document?

Within the Netbeans 6.5's Tools -> Options -> Fonts & Colors -> Syntax dialog, you have the ability to change the look and feel of the Netbeans text editor. When you select a language, you are presented with a preview of your font/color scheme. However, when I preview Java, there are far more options for syntax changes than are being displayed in that preview window. If I were able to view a more robust piece of code, I'd be able to see the immediate effect of more of the options.
How can I supply a preview document to view my font/color changes?
UPDATE:
After looking into this some more, I've been able to narrow down the problem a bit. From what I can tell, everything in Netbeans is considered a plugin. The GUI editor is a plugin, and even the text editor is a plugin. This means that what ever piece of Netbeans that actually analyzes Java code and does syntax highlights is also a plugin (since Java is just one of many languages Netbeans highlights, it makes sense this is a plugin).
I think fromvega is on the right track with his suggestion. The tutorial for creating a manifest file editing plugin pointed me in the right direction. The tutorial eludes to a file used as a sample document used for font/color previews. It tells you how to create one inside this new plugin project. (Located in "Registering the Options in the NetBeans System Filesystem", part 4. About 4/5 of the way down the page.)
My next line of thought was to look for the Java syntax editing mode plugin and find this file and update it with a richer example file. I looked in the installation directory and came up empty, but I found what looks like the appropriate files within my user settings directory. There is a config directory with a lot of subfolders within my user directory (Windows: C:\Documents and Settings\saterus.netbeans\config).
I've been poking around inside this directory a bit, but have only found the xml files the manifest tutorial talks about. I have been unable to find the extensionless sample file for the Java plugin that I believe should be there.
Since I've hit a brick wall for the moment, I thought I'd toss it back to the SO community and see if you guys might make the last leap and find the solution.
Just for anyone who wants to alter this themselves it is possible on a unix machine to use grep to locate the file i.e.
grep -lr "some part of the current sample code" /path/to/netbeans
I used this method to locate the ruby example filename and from that identified that it is kept in org-netbeans-modules-ruby.jar as a file called RubyExample. By simply altering that file I was able to construct a better sample file for my own use.
Hope this helps someone!
The document which is displayed (for each mime type) is specified in a particular folder in the "system file system" (which is a NetBeans concept which is a virtual file system composed from contributions from individual modules; this is how functionality is dynamically registered in NetBeans).
Modules typically specify their system file system contributions in a file named "layer.xml" in the plugin. The create plugin templates typically offer to create this for you.
For example, here's how the Python example is registered:
<filesystem>
...
<folder name="OptionsDialog">
<folder name="PreviewExamples">
<folder name="text">
<file name="x-python" url="PythonExample.py"/>
</folder>
</folder>
...
Here, PythonExample.py is a sample file in the same directory as the layer file.
Therefore, what you need to do is create a plugin which overrides the existing registration(s) for the mime type(s) you care about and provide alternate sample documents. You may need to hide the existing registration first (see the _hidden
part from http://doc.javanb.com/netbeans-api-javadoc-5-0-0/org-openide-filesystems/org/openide/filesystems/MultiFileSystem.html ).
Hopefully this guides you in the right direction.
However, in thinking about it, we probably ought to make the preview area editable - so people can cut & paste whatever codefragment they care about right in there. This wouldn't be persistent, so whenever you change languages you get the original samples back - but it provides a quick way to see your own code. This shouldn't be just for the Fonts & Colors customization, but for the Formatting preview panels as well.
I've filed an issue against NetBeans for this:
http://www.netbeans.org/issues/show_bug.cgi?id=155964
-- Tor
I think you can only accomplish that with a new plugin, since you need somekind of parsing to define what is what.
Give a look a these tutorials, I haven't read them in details but they seem to show you how to do what you want:
http://platform.netbeans.org/tutorials/nbm-mfsyntax.html
http://www.antonioshome.net/kitchen/netbeans/nbms-coloring.php