package zed

  1. Overview
  2. Docs
Abstract engine for text edition in OCaml

Install

Dune Dependency

Authors

Maintainers

Sources

3.1.0.tar.gz
sha256=c387b0496c34c7eb680999e751525992e3e636a803297480ef004498887625fd
md5=51e8676ba972e5ad727633c161e404b1

doc/zed/Zed_edit/index.html

Module Zed_editSource

Edition engines

Sourcetype 'a t

Type of edition engines. 'a is the type of custom data attached to the engine in order to extend it.

Sourcetype clipboard = {
  1. clipboard_get : unit -> Zed_rope.t;
    (*

    Returns the current contents of the clipboard.

    *)
  2. clipboard_set : Zed_rope.t -> unit;
    (*

    Sets the contents of the clipboard.

    *)
}

Type of clipboards.

Sourceval new_clipboard : unit -> clipboard

new_clipboard () creates a new clipboard using a reference.

Sourceval regexp_word_core : Zed_re.Core.t

regexp to core-match a word a-z, A-Z, 0-9

Sourceval regexp_word_raw : Zed_re.Raw.t

regexp to raw-match a word a-z, A-Z, 0-9

Sourceval create : ?editable:(int -> int -> bool) -> ?move:(int -> int -> int) -> ?clipboard:clipboard -> ?match_word:(Zed_rope.t -> int -> int option) -> ?locale:string option React.signal -> ?undo_size:int -> unit -> 'a t

create ?editable ?move ?clipboard () creates a new edition engine in the initial state.

editable is used to determine whether the text at given position is editable or not. It takes as argument the position and the length of the text to remove.

move is unused.

clipboard is the clipboard to use for this engine. If none is defined, a new one using a reference is created.

match_word is used to recognize words. It must returns the end of the matched word if any.

locale is the locale of this buffer. It is used for case mapping.

undo_size is the size of the undo buffer. It is the number of state zed will remember. It defaults to 1000.

Sourceval match_by_regexp_core : Zed_re.Core.t -> Zed_rope.t -> int -> int option

match_by_regexp_core re creates a core-word-matching function using a regular expression.

Sourceval match_by_regexp_raw : Zed_re.Raw.t -> Zed_rope.t -> int -> int option

match_by_regexp_raw re creates a raw-word-matching function using a regular expression.

State
Sourceval get_data : 'a t -> 'a

get_data edit returns the custom data attached to the engine. It raises Not_found if no data is attached to the engine.

Sourceval set_data : 'a t -> 'a -> unit

set_data edit data attach data to the engine.

Sourceval clear_data : 'a t -> unit

clear_data edit removes the custom data of engine.

Sourceval text : 'a t -> Zed_rope.t

text edit returns the signal holding the current contents of the buffer.

Sourceval lines : 'a t -> Zed_lines.t

lines edit returns the set of line position of text edit.

Sourceval get_line : 'a t -> int -> Zed_rope.t

get_line edit n returns the rope corresponding to the nth line without the newline character.

changes edit returns an event which occurs with values of the form (start, added, removed) when the contents of the engine changes. start is the start of modifications, added is the number of characters added and removed is the number of characters removed.

Sourceval update : 'a t -> Zed_cursor.t list -> unit React.event

update edit cursors returns an event which occurs each the rendering of the engine should be updated.

Sourceval erase_mode : 'a t -> bool React.signal

erase_mode edit returns the ``erase'' mode of the buffer. In this mode character inserted in the buffer erase existing ones.

Sourceval get_erase_mode : 'a t -> bool

erase_mode edit returns the current erase mode of the buffer.

Sourceval set_erase_mode : 'a t -> bool -> unit

set_erase_mode edit state sets the status of the erase mode for the given engine.

Sourceval mark : 'a t -> Zed_cursor.t

mark edit returns the cursor used to for the mark in the given engine.

Sourceval selection : 'a t -> bool React.signal

selection edit returns the signal holding the current selection state. If true, text is being selectionned.

Sourceval get_selection : 'a t -> bool

selection edit returns the current selection state.

Sourceval set_selection : 'a t -> bool -> unit

set_selection edit state sets the selection state.

Cursors
Sourceval new_cursor : 'a t -> Zed_cursor.t

new_cursor edit creates a new cursor for the given edition engine. The cursor initially points to the beginning of the buffer.

Actions
Sourceexception Cannot_edit

Exception raised when trying to edit a non-editable portion of a buffer.

Sourcetype 'a context

Type of contexts. Contexts are used to modify an edition buffer.

Sourceval context : ?check:bool -> 'a t -> Zed_cursor.t -> 'a context

context ?check edit cursor creates a new context with given parameters. cursor is the cursor that will be used for all modification of the text. If check is true (the default) then all modification of the text will be checked with the editable function of the engine.

Sourceval edit : 'a context -> 'a t

edit ctx returns the edition engine used by the given context.

Sourceval cursor : 'a context -> Zed_cursor.t

cursor ctx returns the cursor used by this context.

Sourceval check : 'a context -> bool

check ctx returns whether the context has been created with the check flag.

Sourceval with_check : bool -> 'a context -> 'a context

with_check check ctx retuns ctx with the check flag set to check.

Sourceval goto : 'a context -> ?set_wanted_column:bool -> int -> unit

goto ctx ?set_column position moves the cursor to the given position. It raises Zed_cursor.Out_of_bounds if the position is outside the bounds of the text. If set_wanted_column is true, the wanted column of the cursor is set to the new column.

Sourceval move : 'a context -> ?set_wanted_column:bool -> int -> unit

move ctx ?set_wanted_column delta moves the cursor by the given number of characters. It raises Zed_cursor.Out_of_bounds if the current plus delta is outside the bounds of the text.

Sourceval move_line : 'a context -> int -> unit

move_line ctx ?set_wanted_column delta moves the cursor by the given number of lines.

Sourceval position : 'a context -> int

position ctx returns the position of the cursor.

Sourceval line : 'a context -> int

line ctx returns the line of the cursor.

Sourceval column : 'a context -> int

column ctx returns the column of the cursor.

Sourceval column_display : 'a context -> int

column_display ctx returns the display column of the cursor.

Sourceval at_bol : 'a context -> bool

at_bol ctx returns true iff the cursor is at the beginning of the current line.

Sourceval at_eol : 'a context -> bool

at_eol ctx returns true iff the cursor is at the end of the current line.

Sourceval at_bot : 'a context -> bool

at_bot ctx returns true iff the cursor is at the beginning of the text.

Sourceval at_eot : 'a context -> bool

at_eot ctx returns true iff the cursor is at the end of the text.

Sourceval insert : 'a context -> Zed_rope.t -> unit

insert ctx rope inserts the given rope at current position.

Sourceval insert_char : 'a context -> CamomileLibrary.UChar.t -> unit

insert ctx rope inserts the given UChar at current position.

Sourceval insert_no_erase : 'a context -> Zed_rope.t -> unit

insert ctx rope inserts the given rope at current position but do not erase text if the buffer is currently in erase mode.

Sourceval remove_next : 'a context -> int -> unit

remove_next ctx n removes n characters at current position. If there is less than n characters at current position, it removes everything until the end of the text.

Sourceval remove_prev : 'a context -> int -> unit

remove_prev ctx n removes n characters before current position. If there is less than n characters before current position, it removes everything until the beginning of the text.

Sourceval remove : 'a context -> int -> unit

Alias for remove_next

Sourceval replace : 'a context -> int -> Zed_rope.t -> unit

replace ctx n rope does the same as:

  remove ctx n;
  insert_no_erase ctx rope

but in one atomic operation.

Sourceval newline : 'a context -> unit

Insert a newline character.

Sourceval next_char : 'a context -> unit

next_char ctx moves the cursor to the next character. It does nothing if the cursor is at the end of the text.

Sourceval prev_char : 'a context -> unit

prev_char ctx moves the cursor to the previous character. It does nothing if the cursor is at the beginning of the text.

Sourceval next_line : 'a context -> unit

next_line ctx moves the cursor to the next line. If the cursor is on the last line, it is moved to the end of the buffer.

Sourceval prev_line : 'a context -> unit

prev_line ctx moves the cursor to the previous line. If the cursor is on the first line, it is moved to the beginning of the buffer.

Sourceval goto_bol : 'a context -> unit

goto_bol ctx moves the cursor to the beginning of the current line.

Sourceval goto_eol : 'a context -> unit

goto_eol ctx moves the cursor to the end of the current line.

Sourceval goto_bot : 'a context -> unit

goto_bot ctx moves the cursor to the beginning of the text.

Sourceval goto_eot : 'a context -> unit

goto_eot ctx moves the cursor to the end of the text.

Sourceval delete_next_char : 'a context -> unit

delete_next_char ctx deletes the character after the cursor, if any.

Sourceval delete_prev_char : 'a context -> unit

delete_prev_char ctx delete the character before the cursor.

Sourceval delete_next_line : 'a context -> unit

delete_next_line ctx delete everything until the end of the current line.

Sourceval delete_prev_line : 'a context -> unit

delete_next_line ctx delete everything until the beginning of the current line.

Sourceval kill_next_line : 'a context -> unit

kill_next_line ctx delete everything until the end of the current line and save it to the clipboard.

Sourceval kill_prev_line : 'a context -> unit

kill_next_line ctx delete everything until the beginning of the current line and save it to the clipboard.

Sourceval switch_erase_mode : 'a context -> unit

switch_erase_mode ctx switch the current erase mode.

Sourceval set_mark : 'a context -> unit

set_mark ctx sets the mark at current position.

Sourceval goto_mark : 'a context -> unit

goto_mark ctx moves the cursor to the mark.

Sourceval copy : 'a context -> unit

copy ctx copies the current selectionned region to the clipboard.

Sourceval copy_sequence : 'a context -> int -> int -> unit

copy_sequence ctx start len copies len characters start from start to the clipboard.

Sourceval kill : 'a context -> unit

kill ctx copies the current selectionned region to the clipboard and remove it.

Sourceval yank : 'a context -> unit

yank ctx inserts the contents of the clipboard at current position.

Sourceval capitalize_word : 'a context -> unit

capitalize_word ctx capitalizes the first word after the cursor.

Sourceval lowercase_word : 'a context -> unit

lowercase_word ctx converts the first word after the cursor to lowercase.

Sourceval uppercase_word : 'a context -> unit

uppercase_word ctx converts the first word after the cursor to uppercase.

Sourceval next_word : 'a context -> unit

next_word ctx moves the cursor to the end of the next word.

Sourceval prev_word : 'a context -> unit

prev_word ctx moves the cursor to the beginning of the previous word.

Sourceval delete_next_word : 'a context -> unit

delete_next_word ctx deletes the word after the cursor.

Sourceval delete_prev_word : 'a context -> unit

delete_prev_word ctx deletes the word before the cursor.

Sourceval kill_next_word : 'a context -> unit

kill_next_word ctx deletes the word after the cursor and save it to the clipboard.

Sourceval kill_prev_word : 'a context -> unit

kill_prev_word ctx deletes the word before the cursor and save it to the clipboard.

Sourceval undo : 'a context -> unit

undo ctx reverts the last performed action.

Action by names
Sourcetype action =
  1. | Insert of Zed_char.t
  2. | Insert_str of Zed_string.t
  3. | Newline
  4. | Next_char
  5. | Prev_char
  6. | Next_line
  7. | Prev_line
  8. | Join_line
  9. | Set_pos of int
  10. | Goto of int
  11. | Goto_bol
  12. | Goto_eol
  13. | Goto_bot
  14. | Goto_eot
  15. | Delete_next_chars of int
  16. | Delete_prev_chars of int
  17. | Kill_next_chars of int
  18. | Kill_prev_chars of int
  19. | Delete_next_char
  20. | Delete_prev_char
  21. | Delete_next_line
  22. | Delete_prev_line
  23. | Kill_next_line
  24. | Kill_prev_line
  25. | Switch_erase_mode
  26. | Set_mark
  27. | Goto_mark
  28. | Copy
  29. | Kill
  30. | Yank
  31. | Capitalize_word
  32. | Lowercase_word
  33. | Uppercase_word
  34. | Next_word
  35. | Prev_word
  36. | Delete_next_word
  37. | Delete_prev_word
  38. | Kill_next_word
  39. | Kill_prev_word
  40. | Undo

Type of actions.

Sourceval get_action : action -> 'a context -> unit

get_action action returns the function associated to the given action.

Sourceval actions : (action * string) list

List of actions with their names, except Insert.

Sourceval doc_of_action : action -> string

doc_of_action action returns a short description of the action.

Sourceval action_of_name : string -> action

action_of_name str converts the given action name into an action. Action name are the same as function name but with '_' replaced by '-', number parameter replaced with "(number)". It raises Not_found if the name does not correspond to an action.

Insert ch is represented by "insert(<char>)" where <char> is:

  • a literal ascii character, such as "a", "b", ...
  • a unicode character, written "U+< code >", such as "U+0041"

Insert_str str is represented by "insert-str(<str>)" where <str> is raw utf8 string.

Sourceval name_of_action : action -> string

name_of_action act returns the name of the given action.

OCaml

Innovation. Community. Security.