Zaphod::Editor - document framework for an editor

$e->install_verb $verb => $class

Registers a verb and its handling class by creating a subroutine with the name in $verb which delegates to the class $class. If a subroutine of that name already exists, the method dies.


Installs all verbs from all plugins into the editor class. Inheritance is not really handled.


Convenience :lvalue method to get the current line


Convenience method to get a reference to the current document. This should be moved to Data::Alias maybe, to prevent even further copying of data.

$e->record_action ACTION

Puts an action onto the undo-stack so it can be undone later


Returns a copy of all undoable actions

$e->apply_actions ACTIONS

Apply a list of undoable actions

$e->undo COUNT

Undoes COUNT items in the undo/redo tree.


Change the undo list into a tree so nested calls of the editor unto itself undo intuitively.

When passed an array reference, should undo exactly these actions.

$e->redo COUNT

Redoes COUNT items in the undo/redo tree.

When passed an array reference, should redo exactly these actions.


Returns true if the undo action is available, that is, there are actions that can be undone.


Returns true if the redo action is available, that is, there are actions that can be redone.


Returns true if the document was changed since it was last saved.

Currently, this is identical to the document having undoable actions.


Returns an opaque reference encapsulating the current status of the editor. This is used by the undo facility to record where an action takes place.

Currently, this just means the cursor position.

$e->restore_status STATUS

Restores the status from a previously saved status.


Returns the list of commands understood and undoable by the editor. Mostly convenient for introspection, but it could be convenient to use for scripting as well.

$e->insert_actions FROM,TO,ACTIONS

Replaces the actions in the undo list at the offsets FROM .. TO with the actions in ACTIONS and performs the necessary changes to the document.

$session->adjustment_map CHANGES

Creates the list offset changes that result from applying the given actions.

$e->adjust_change SHIFT_MAP, CHANGES

Adjusts the changes by adjusting their offsets according to the SHIFT_MAP hash reference.

Actions that have no start point anymore are not yet discarded.

$e->adjust_offset SHIFT_MAP, OFFSETS

Adjusts the offsets according to the SHIFT_MAP hash reference.

Offsets that don't exist anymore get moved to their leftmost leftover position.


Outputs the state of the editor to STDOUT


Returns a list of all line indices

This is equivalent to

    0..$#{ $e->document }


All plugins for adding new verbs to the editor are loaded from the Zaphod::Editor::Action:: namespace and are made available directly in the editor as undoable actions.



Written by Max Maischein <>

Copyright Max Maischein 2005,2006; All Rights Reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.