X

Geertjan's Blog

  • March 10, 2014

EditorConfig and NetBeans IDE (Part 1)

Geertjan Wielenga
Product Manager

I made the first steps into EditorConfig support for NetBeans IDE.

Put a file named ".editorconfig" somewhere, e.g., the root folder, open a file, click the EditorConfig button (the mouse is the logo of EditorConfig) in the toolbar, which you can see below next to the Cut button, and then the Output window shows the parsed EditorConfig file, applied based on which type of file is currently selected.

However, I had assumed that the properties in the EditorConfig file would automatically be applied to the current file by EditorConfig. But that doesn't appear to be the case. So, for each property in EditorConfig (of which there are not many), I need to figure out how to map them to functionality in NetBeans IDE. In some cases, I guess there will not be APIs and I'll need to figure out on a case by case basis how to implement the property for the file in question.

The sources are here:

https://java.net/projects/nb-api-samples/sources/api-samples/show/versions/8.0/nb-editorconfig

The related issue:

https://netbeans.org/bugzilla/show_bug.cgi?id=240398

And here's all the code.

@ActionID(
        category = "Tools",
        id = "org.netbeans.ec.RunEditorconfigAction"
)
@ActionRegistration(
        iconBase = "org/netbeans/ec/editorconfig.png",
        displayName = "#CTL_RunEditorconfigAction"
)
@ActionReferences({
    @ActionReference(path = "Menu/Source", position = 200),
    @ActionReference(path = "Toolbars/Clipboard", position = 0)
})
@Messages("CTL_RunEditorconfigAction=Run EditorConfig")
public final class RunEditorconfigAction implements ActionListener {
    private final DataObject dobj;
    public RunEditorconfigAction(DataObject dobj) {
        this.dobj = dobj;
    }
    @Override
    public void actionPerformed(ActionEvent e) {
        InputOutput io = IOProvider.getDefault().getIO("EditorConfig", true);
        io.select();
        OutputWriter writer = io.getOut();
        StatusDisplayer.getDefault().setStatusText(dobj.getPrimaryFile().getPath());
        EditorConfig ec;
        try {
            ec = new EditorConfig();
            List<EditorConfig.OutPair> l = null;
            l = ec.getProperties(dobj.getPrimaryFile().getPath());
            for (int i = 0; i < l.size(); ++i) {
                writer.println(l.get(i).getKey() + "=" + l.get(i).getVal());
            }
            writer.close();
        } catch (PythonException ex) {
            Exceptions.printStackTrace(ex);
        } catch (EditorConfigException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
}

Join the discussion

Comments ( 6 )
  • guest Thursday, March 13, 2014

    Right on! Keep going - thanks for this.


  • guest Monday, March 17, 2014

    Can`t wait to use this!


  • Benny Neugebauer Tuesday, March 18, 2014

    I am pleased to read that. Once there is a plugin for it, I'll download it immediately. This is a huge step forward for the unification of team collaboration. Thank you for working on that, Geertjan.


  • Michael Robinson Wednesday, March 19, 2014

    Thank you very much for your efforts!


  • sni Monday, May 5, 2014

    In France, there is a lot of disdain toward Netbeans (don't ask me why...)

    My current employer is currently evaluating several Front-End editors for future developments, and I'm pushing netbeans. "Does it support editorconfig ?" someone asked me today "Because webstorm, notepad++, etc.. support it."

    Since I really want Netbeans to be choosen, please consider finishing this plugin so I could answer "Yes !" ;)


  • Geertjan Monday, May 5, 2014

    Sure, working on it. About France -- I can point you to lots of NetBeans users, if you want. Also, I can give an overview to your employer, in person or via Skype, about the key NetBeans features. Just let me know (geertjan dot wielenga at oracle dot com).


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.