Code Browser plugin

(March 31 2012)

Gerd Knops


Table of Contents

Chapter 1. Description

The Code Browser plugin contains a buffer switcher and a code browser within a split pane. The buffer switcher can be hidden by moving the divider all the way up, or by clicking the small up-handle. The code browser simplifies navigating source code of any programming language supported by the Exuberant C Tags program.

Chapter 2. The Buffer Switcher

The buffer switcher displays the file name of each buffer, and as much of the end of each path as can be fit. The selcted buffer is shown in bold. The file name colors are taken from the File System Browser (See Global Options>File System Browser>Colors). The path of 'dirty' buffers is displayed in in dark red, others in dark gray. Operation of the buffer switcher is straight forward: A mouse click selects a buffer, and a control-click closes a buffer. While the mouse is ofer a buffer switcher entry a tooltip shows the entire path for this entry.

Chapter 3. The Code Browser

The code browser requires Exuberant C Tags version 5.5 or later. You can find it at http://ctags.sourceforge.net. NOTE: The standard ctags program found on many systems is NOT sufficient!!!

The path of the ctags program needs to be set in the Plugin Options for the Code Browser plugin. A typical choice on Unix-like systems is /usr/local/bin/ctags, and on windows systems c:\Apps\ctags51\ctags.exe.

Once the ctags path is set, the code browser plugin will parse a file whenever a buffer displaying the file is selected, or when the current buffer is saved. Please note that only the file on disk is parsed, not the in-memory contents of the buffer.

Simply click on any function, variable declaration etc. displayed in the code browser, and the buffer will be positioned accordingly. As regular expressions are used, code browser will be able to find definitions even in modified files as long as the line on which the definition occured was not changed. Tooltips show the contents of the line, which depending on language and style may include more information.

Right-clicking on any function, variable declaration etc. will bring up a context menu with these choices:

  • Insert at Caret: Inserts the selected term in the current text view.

  • Hypersearch: Perform a hypersearch with this term.

  • Copy to pasteboard: Copies the selected term to the paste board.

  • Append to pasteboard: Appends the selected term to the pasteboard.

The Options menu button above the Code Browser section lets you select a few options:

  • Auto-parse: When checked, buffers are parsed automatically when saved or when you switch to another buffer. When un-checked, buffers will only be parsed when you click on the Parse button. That can be helpful when you work with extremely large files, where parsing requires some time.

  • Sort: When checked, all listed tags will be sorted.

  • Auto-unfold: When checked, any section in the code you jump to will be unfolded automatically.

  • Auto-close dock: After selecting a tag the dock is automatically closed

Chapter 4. Code Browser and Languages/File types not supported by ctags

The ctags program supports many languages, but chances are you might work with a language or file type not supported by ctags. While support built into ctags is the most elegant solution, you can also create some simple regular expression based support for languages not directly supported by ctags.

The following chapter gives some examples. The lines shown need to be added to one of the files ctags reads during startup. On unix-like systems that could be ~/.ctags, and on windows systems that could be a file ctags.cnf in the jEdit directory. Please read the ctags documentation for more info.

Chapter 5. Simple support for XML and HTML

Here is an example for contents of the ctags configuration file mentioned in the previous chapter. The example add simple support for XML files and HTML files (note that HTML is now supported natively in ctags):

--langdef=xml
--langmap=xml:.xml
--regex-xml=/<([^ \t]+)[ \t]*(id|name)[ \t]*=[ \t]*\"([^\"]+)/\1 \3/Named Tags/i

--langdef=html
--langmap=html:.htm.html
--regex-html=/<a[ \t]+href[ \t]*=[ \t]*\"([^\"]+)/\1/HRefs/i
--regex-html=/<img[ \t]+src[ \t]*=[ \t]*\"([^\"]+)/\1/Images/i
--regex-html=/<h([1-6])[^>]*>([^<]*)/\2 (\1)/Headers/i
	

The --langdef lines define the name of the language, the --langmap lines define the extensions of files for this language, and the --regex-html lines define the regular expressions describing the items of a language you want to see in Code Browser. For more info please see the ctags documentation.

Chapter 6. Simple support for Ant build.xml files

build.xml files would normally be governed by the xml entries listed in the previous chapter. ctags does not allow one entry for *.xml and another for build.xml. Code Browser helps out here; Code Browser forces the language used by ctags to ant when the file to be parsed is named build.xml.

--langdef=ant
--regex-ant=/<property[ \t]*name[ \t]*=[ \t]*\"([^\"]+)/\1/Properties/i
--regex-ant=/<target[ \t]*name[ \t]*=[ \t]*\"([^\"]+)/\1/Targets/i
--regex-ant=/<path[ \t]*id[ \t]*=[ \t]*\"([^\"]+)/\1/Paths/i
--regex-ant=/<taskdef[ \t]*id[ \t]*=[ \t]*\"([^\"]+)/\1/Taskdefs/i
--regex-ant=/<typedef[ \t]*id[ \t]*=[ \t]*\"([^\"]+)/\1/Typedefs/i
	

Chapter 7. Frequently Asked Questions

Q: I am working on a (shell|perl|python|whatever) script, but CodeBrowser isn't showing anything.

A: Ctags parses files without extensions (like many scripts) only if the executable flag is set AND the magic #!/path/to/interpreter first line can be found. So make sure both those conitions are met, or add a known extension to the script.

Q: Is there support for ActionScript?

A: Check www.ubergeek.tv/jack/hack.php

Chapter 8. License

Feel free to do with the files of this project whatever you want. If they make you filthy rich you should send some bucks my way though.

Chapter 9. Disclaimer

BITart and Gerd Knops make no warranties, representations or commitments with regard to the contents of this software. BITart and Gerd Knops specifically disclaim any and all warranties, wether express, implied or statutory, including, but not limited to, any warranty of merchantability or fitness for a particular purpose, and non-infringement. Under no circumstances will BITart or Gerd Knops be liable for loss of data, special, incidental or consequential damages out of the use of this software, even if those damages were forseeable, or BITart or Gerd Knops was informed of their potential.

Chapter 10. Feedback

You can write to:

Appendix A. Change log

Version 1.4.3. Requires JDK 1.4, jEdit 4.3pre5, ExuberantCtags 5.5.

  • Fixes for change in regexp/search API

  • Sends new CaretChanging editbus message for the benefit of Navigator.

Version 1.4.2. Requires JDK 1.3, jEdit 4.3, ExuberantCtags 5.5.

  • Works with jedit 4.3 API and plugin dynamic loading.

Version 1.4.0. Requires JDK 1.3, jEdit 4.1, ExuberantCtags 5.5.

  • Behavior improved when multiple tags with identical names are found: if you select the n-th one, then CodeBrowser will jump to the n-th occurance in the code.

  • New Options Menu.

  • Moved Sort and Auto buttons into new Options Menu.

  • New option Auto-unfold: When checked and you jump to a folded section of the code that section will be unfolded automatically

  • New option Auto-close Dock: When checked the dock will automatically close after a tag was selected

  • Cleaned up UI

  • Cleaned up code

Version 1.3.1. Requires JDK 1.3, jEdit 4.1, ExuberantCtags 5.5.

  • Updated for jEdit 4.2

Version 1.3.0. Requires JDK 1.3, jEdit 4.1, ExuberantCtags 5.5.

  • Compatible with all languages supported now or in future by ExuberantCtags

  • No longer requires internal tables to determine programming language

  • No longer requires internal tables to translate single letter 'kind' to description

  • Methods, functions etc. now listed with signature

Version 1.2.1. Requires JDK 1.3, jEdit 4.

  • Context menu for items in CodeBrowser (Rudi Widmann)

Version 1.2.0. Requires JDK 1.3, jEdit 4. Code contributed by Rudi Widmann:

  • Manual parsing mode

  • Cache parse results

  • Do not parse when docked but not visible

  • Focus textarea after selecting element in parse tree

Version 1.1.1. Requires JDK 1.3, jEdit 4.

  • Should now work with all kinds of remote files

Version 1.1.0. Requires JDK 1.3, jEdit 4.

  • Added support for FTP plugin

Version 1.0.0. Requires JDK 1.3, jEdit 4.

  • Minor bugfixes

  • First release to plugin central

Version 0.9.2. Requires JDK 1.3, jEdit 4.

  • Improved documentation

  • Now handles multiple/split views better

  • BufferSwitcher now uses colors from File System Browser

Version 0.9.1. Requires JDK 1.3, jEdit 4.

  • Regex bugfix

Version 0.9.0. Requires JDK 1.3, jEdit 4.

  • First beta test version