FAFNIR

What is Fafnir?

Fafnir is a text editor written in pure Python. It's main feature is that it's programmable; it comes with a special code editor window for entering commands (= method calls) or general Python code. This makes the editor extremely customizable; people can write their own commands or extensions to make the editor do what they want, then bind the new commands to keys and/or menu items.

Current status

While that may sound good (hey, at least *I* like it <wink>), writing a reasonably complete and useful editor is not a trivial task. I am currently still trying to figure out some design issues. Also, lots of documentation needs to be written; of course, there is always "use the source, Luke", but this will not encourage people to use the editor.

I would like this to be an open source project with contributions from others, but I realize that I won't get many contributors until the editor is relatively stable. (Of course, if you disagree with this, you're free to contribute now. :-) At this point, it's not quite stable yet. I make the source code so far available, though, so people who are interested can shoot at it.

Requirements

  • Python 2.1. It may, or may not, work on 2.0 or even 1.5.2; I haven't tested it. It may work on 2.2 as well; it should, really, although there is a number of small incompatibilities that might affect the code.
  • wxPython 2.3.2.1. Again, any other version may or may not work.

Download

You can download the latest version here. Latest build is 029. Start with fafnir2.py (not fafnir.py, this is a module that implements the Fafnir class).

More info

It's officially called "Fafnir 2.0" (or Fafnir 2) because there was a Fafnir 1, once, for DOS, in the mid-90s, written in Turbo Pascal. The Python-based Fafnir uses some of the ideas of the original, which in turn borrows some ideas from vi.

Fafnir uses wxPython's wxStyledTextCtrl object, which is a wrapper around the Scintilla editor. This allows us to use nifty things like styles (for syntax highlighting), bookmarks, folds, etc. I could have used any old plain vanilla editor control, but this one seemed kinda nice.

The editor as a whole is controlled by the Fafnir object. "Pages" (separate wxStyledTextCtrl instances) are controlled by FafnirPage objects. This allows us to have "commands" (they're really method calls) like
    fafnir.open("myfile.py")
which opens myfile.py in a new window, or
    fafnir.page.save(newname="bla.txt")
to save the current file under a new name.

Of course, lazy as people are <wink>, they will want to press a button like F2 or Ctrl-S to save a document, rather than writing verbose commands. Fortunately, it's easy to add a new key binding. Just add something like
    "Ctrl-S": "fafnir.page.save()"
to the keybindings dictionary in config/editor.py, and you're all set; Ctrl-S now executes the method. Building your own menu structure works in a similar way.

It's easy to see where this leads. You can take existing method calls, or write your own functions/methods, and associate a key or menu binding with them. As everything is pure Python, no recompiling is required, and in many cases, not even restarting the editor. The configuration files are currently at an early stage; they should contain many more goodies in later versions.

Alas, the current editor doesn't support many features taken for granted in modern editors: no word wrap, no auto-indent, no syntax highlighting (although styles were added recently, and a framework for stylesheets will be added soon), no find & replace, no indenting of whole blocks, etc. All this stuff is scheduled for future versions. Sometimes I will have to implement it "by hand", sometimes it's merely a matter of tapping a feature already present in wxStyledTextCtrl or wxPython. Of course, if you want to help and implement some of these (it's not necessarily difficult), you're welcome to do so, and your help would be greatly appreciated.

More news later. Fafnir will be announced on the newsgroup once it is relatively stable and usable.