NAME

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.

__PACKAGE__->install_actions

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

$e->current_line

Convenience :lvalue method to get the current line

$e->docref

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

$e->get_actions

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.

TODO

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.

$e->can_undo

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

$e->can_redo

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

$e->is_changed

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

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

$e->status

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.

$e->vocabulary

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.

$e->dump

Outputs the state of the editor to STDOUT

$e->line_indices

Returns a list of all line indices

This is equivalent to

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

PLUGINS

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.

TODO

AUTHOR

Written by Max Maischein <corion@cpan.org>

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.

SEE ALSO

Zaphod