Monday, December 22, 2014

Gedit as a developer's editor

A good text editor is an essential tool for anyone who writes code. Gedit is okay-ish out of the box, but many nice features are lacking. Here are the plugins I use to make life with Gedit easier:

  1. Gedit Source Code Browser: adds a new side panel that shows symbols (functions, classes, variables, etc.) in the code you're editing. This is a common feature found in virtually any IDE out there.
    Sadly, this plugin didn't work out of the box, so I had to make several modifications to make it:

    Went to ~/.local/share/gedit/plugins/ and in sourcecodebrowser.plugin replaced
    Loader=python
    
    with
    Loader=python3
    

    Because of switch to Python 3, I also had to replace the following line in sourcecodebrowser/ctags.py, in parse(self, command, executable=None:
    symbols = self._parse_text(p.communicate()[0])
    
    with
    symbols = self._parse_text(p.communicate()[0].decode("utf-8"))
    

    I'm not sure if this was really necessary, but it seemed logical to me not to supply 'ctags' executable name in the parameters string (since it's given separately as self.ctags_executable anyway). In sourcecodebrowser/plugin.py:
    command = "ctags -nu --fields=fiKlmnsSzt -f - '%s'" % path
    
    replaced with
    command = "-nu --fields=fiKlmnsSzt -f - '%s'" % path
    
    Once again, not sure this was needed.
  2. Gedit Restore Tabs. Does what it says - Gedit automatically opens all the files you had open in your previous session. Not having to recall where exactly are the files I was editing helps me concentrate on the code.
    Once again had to modify plugin definition file here. In restoretabs.plugin replaced
    Loader=python
    
    with
    Loader=python3
    
    But that was it. No source-code modification was required.

    Important update: I've encountered a text document that somehow causes Restore Tabs to crash Gedit on startup. A workaround is to remove this document from the list of files to be loaded on Gedit startup using dconf-editor tool (if you don't have it, do sudo apt install dconf-editor). To find the list, run dconf-editor and go to org -> gnome -> gedit -> plugins -> restoretabs. Remove the offending file from "uris", or just clear the list if you don't know which file is causing the problem.
  3. gedit-file-search: Gedit plugin to search a text in all files in a directory. No tweaking needed, nice!
  4. Plugins in gedit-plugins package, like Color Scheme Editor, Draw Spaces, File Browser Panel, Smart Spaces, Text Size and even a Python Console!

No comments:

Post a Comment