Monday, January 16, 2012

Gedit on Windows as a Grails/Groovy editor

I've started using gedit in order to have a common editing environment in both Windows and Linux. In order to make use of the gedit-grails-bundle when using gedit (version 2.30.1) in Windows, the files need to be installed to the following locations:
  • .lang files go in %ProgramFiles%\gedit\share\gtksourceview-2.0\language-specs\ 
  • plugins go in %UserProfile%\AppData\Roaming\gedit\plugins\ 
  • styles go in %UserProfile%\AppData\Roaming\gedit\styles\ 
  • -mime.xml files do not appear to need installation
  • Grails.tags.gz goes in  %ProgramFiles%\gedit\share\plugins\taglist\ (because TagList is one of the plugins shipped with gedit by default)
I amended the instructions on the http://grails.org/Gedit page to include the above.

Of the gedit-grails-bundle plugins only autocomplete and zen coding work unmodified, the rest have unmet dependencies; this could probably be resolved by tracking down and installing those dependencies, but that can be a very slippery slope.


Missing from gedit is built-in "find/replace in files" functionality. None of the plugins I tried worked unmodified; the only one without external dependencies is the one from the Gedit Developer Plugin (GDP) bundle (gedit-developer-plugin-2.28.0). I had to do the following to get it to install and run:

  • Rename gdpfind.gedit-plugin.desktop.in to gdpfind.gedit-plugin
  • Edit gdpfind.gedit-plugin to remove the leading underscores from Name and Description
  • Edit the method in __init__.py as below:

def on_file_lines_row_activated(treeview, path, view_column, plugin):
    """Open the file and jump to the line."""
    treestore = treeview.get_model()
    piter = treestore.get_iter(path)
    base_dir = treestore.get_value(piter, 4)
    path = treestore.get_value(piter, 0)
    if base_dir is None or path is None:
        # There is not enough information to open a document.
        return
    # windows-only hack to strip leading 'file://' which prevents file from opening        
    # uri = 'file://%s' % os.path.abspath(os.path.join(base_dir, path))
    uri = os.path.abspath(os.path.join(base_dir, path))
    line_no = treestore.get_value(piter, 2) - 1
    if line_no < 0:
        line_no = 0
    plugin.activate_open_doc(uri, jump_to=line_no)


Without this change, the URI passed to the new tab has a leading "file://" that will prevent the file from opening properly.

http://projects.gnome.org/gedit/index.html
http://grails.org/Gedit
https://launchpad.net/gdp/incubation/0.2

edit: Changed where the _init_.py fix goes, in the method where the leading 'file://' is added to the URI in the first place; also added install location for Grails.tags.gz file.