text stringlengths 0 601k |
|---|
let get_data engine = match engine . data with | Some data -> data | None -> raise Not_found |
let set_data engine data = engine . data <- Some data |
let clear_data engine = engine . data <- None |
let text engine = engine . text |
let lines engine = engine . lines |
let changes engine = engine . changes |
let erase_mode engine = engine . erase_mode |
let get_erase_mode engine = S . value engine . erase_mode |
let set_erase_mode engine state = engine . set_erase_mode state |
let mark engine = engine . mark |
let selection engine = engine . selection |
let get_selection engine = S . value engine . selection |
let set_selection engine state = engine . set_selection state |
let get_line e i = let txt = text e in let lines = lines e in let start = Zed_lines . line_start lines i in let stop = Zed_lines . line_stop lines i in Zed_rope . sub txt start ( stop - start ) start |
let update engine cursors = E . select ( E . stamp engine . changes ( ) :: E . stamp ( S . changes engine . selection ) selection ( ) :: E . stamp ( S . changes ( Zed_cursor . position engine . mark ) mark ) mark ( ) :: List . map ( fun cursor -> E . stamp ( S . changes ( Zed_cursor . position cursor ) cursor ) cursor ... |
let new_cursor engine = Zed_cursor . create ( Zed_rope . length engine . text ) text engine . changes ( fun ( ) -> engine . lines ) lines 0 0 |
type ' a context = { edit : ' a t ; cursor : Zed_cursor . t ; check : bool ; } |
let context ( ? check = true ) true edit cursor = { edit ; cursor ; check } |
let edit ctx = ctx . edit |
let cursor ctx = ctx . cursor |
let check ctx = ctx . check |
let with_check check ctx = { ctx with check } |
let goto ctx ? set_wanted_column new_position = Zed_cursor . goto ctx . cursor ? set_wanted_column new_position |
let set_position ctx new_position = Zed_cursor . goto ctx . cursor ~ set_wanted_column : false new_position |
let move ctx ? set_wanted_column delta = Zed_cursor . move ctx . cursor ? set_wanted_column delta |
let next_line_n ctx n = let index = Zed_cursor . get_line ctx . cursor in if index + n > Zed_lines . count ctx . edit . lines then goto ctx ~ set_wanted_column : false ( Zed_rope . length ctx . edit . text ) text else begin let stop = if index + n = Zed_lines . count ctx . edit . lines then Zed_rope . length ctx . edit... |
let prev_line_n ctx n = let index = Zed_cursor . get_line ctx . cursor in if index - n < 0 then begin goto ctx ~ set_wanted_column : false 0 end else begin let stop = Zed_lines . line_start ctx . edit . lines ( index - ( n - 1 ) 1 ) 1 - 1 in let wanted_idx = Zed_lines . get_idx_by_width ctx . edit . lines ( index - n )... |
let move_line ctx delta = match delta with | _ when delta < 0 -> prev_line_n ctx ( - delta ) delta | _ when delta > 0 -> next_line_n ctx delta | _ -> ( ) |
let position ctx = Zed_cursor . get_position ctx . cursor |
let line ctx = Zed_cursor . get_line ctx . cursor |
let column ctx = Zed_cursor . get_column ctx . cursor |
let column_display ctx = Zed_cursor . get_column_display ctx . cursor |
let at_bol ctx = Zed_cursor . get_column ctx . cursor = 0 |
let at_eol ctx = let position = Zed_cursor . get_position ctx . cursor in let index = Zed_cursor . get_line ctx . cursor in if index = Zed_lines . count ctx . edit . lines then position = Zed_rope . length ctx . edit . text else position = Zed_lines . line_start ctx . edit . lines ( index + 1 ) 1 - 1 |
let at_bot ctx = Zed_cursor . get_position ctx . cursor = 0 |
let at_eot ctx = Zed_cursor . get_position ctx . cursor = Zed_rope . length ctx . edit . text |
let modify { edit ; _ } text lines position new_position added removed added_width removed_width = if edit . undo_size > 0 then begin edit . undo ( . edit . undo_index ) undo_index <- ( text , lines , position , new_position , added , removed , added_width , removed_width ) removed_width ; edit . undo_index <- ( edit .... |
let insert ctx rope = let position = Zed_cursor . get_position ctx . cursor in if not ctx . check || ctx . edit . editable position 0 then begin let len = Zed_rope . length rope in let text = ctx . edit . text and lines = ctx . edit . lines in if S . value ctx . edit . erase_mode then begin let text_len = Zed_rope . le... |
let insert_char ctx ch = if Zed_char . is_combining_mark ch then let position = Zed_cursor . get_position ctx . cursor in if not ctx . check || ctx . edit . editable position 0 then begin let text = ctx . edit . text and lines = ctx . edit . lines in try ctx . edit . text <- Zed_rope . insert_uChar ctx . edit . text po... |
let insert_no_erase ctx rope = let position = Zed_cursor . get_position ctx . cursor in if not ctx . check || ctx . edit . editable position 0 then begin let len = Zed_rope . length rope and text = ctx . edit . text and lines = ctx . edit . lines in let width_add = Zed_string . aval_width ( Zed_string . width ( Zed_rop... |
let remove_next ctx len = let position = Zed_cursor . get_position ctx . cursor in let text_len = Zed_rope . length ctx . edit . text in let len = if position + len > text_len then text_len - position else len in if not ctx . check || ctx . edit . editable position len then begin let text = ctx . edit . text and lines ... |
let remove_prev ctx len = let position = Zed_cursor . get_position ctx . cursor in let len = min position len in if not ctx . check || ctx . edit . editable ( position - len ) len len then begin let text = ctx . edit . text and lines = ctx . edit . lines in let width_remove = Zed_string ( . aval_width ( width Zed_rope ... |
let replace ctx len rope = let position = Zed_cursor . get_position ctx . cursor in let text_len = Zed_rope . length ctx . edit . text in let len = if position + len > text_len then text_len - position else len in if not ctx . check || ctx . edit . editable position len then begin let rope_len = Zed_rope . length rope ... |
let newline_rope = Zed_rope . singleton ( Zed_char . unsafe_of_char ' \ n ' ) n ' |
let newline ctx = insert ctx newline_rope |
let next_char ctx = if not ( at_eot ctx ) ctx then move ctx 1 |
let prev_char ctx = if not ( at_bot ctx ) ctx then move ctx ( - 1 ) 1 |
let next_line ctx = let index = Zed_cursor . get_line ctx . cursor in if index = Zed_lines . count ctx . edit . lines then goto ctx ~ set_wanted_column : false ( Zed_rope . length ctx . edit . text ) text else begin let stop = if index + 1 = Zed_lines . count ctx . edit . lines then Zed_rope . length ctx . edit . text ... |
let prev_line ctx = let index = Zed_cursor . get_line ctx . cursor in if index = 0 then begin goto ctx ~ set_wanted_column : false 0 end else begin let stop = Zed_lines . line_start ctx . edit . lines index - 1 in let wanted_idx = Zed_lines . get_idx_by_width ctx . edit . lines ( index - 1 ) 1 ( Zed_cursor . get_wanted... |
let join_line ctx = let is_space uchar = match UCharInfo . general_category uchar with | ` Cc | ` Zs | ` Zl | ` Zp | ` Mn -> true | _ -> false in let is_not_space uchar = not ( is_space uchar ) uchar in let text = ctx . edit . text in let lines = lines ctx . edit in let lines_num = Zed_lines . count lines in let index ... |
let goto_bol ctx = goto ctx ( Zed_lines . line_start ctx . edit . lines ( Zed_cursor . get_line ctx . cursor ) cursor ) cursor |
let goto_eol ctx = let index = Zed_cursor . get_line ctx . cursor in if index = Zed_lines . count ctx . edit . lines then goto ctx ( Zed_rope . length ctx . edit . text ) text else goto ctx ( Zed_lines . line_start ctx . edit . lines ( index + 1 ) 1 - 1 ) 1 |
let goto_bot ctx = goto ctx 0 |
let goto_eot ctx = goto ctx ( Zed_rope . length ctx . edit . text ) text |
let delete_next_chars ctx n = if not ( at_eot ctx ) ctx then begin ctx . edit . set_selection false ; remove_next ctx n ; end |
let delete_prev_chars ctx n = if not ( at_bot ctx ) ctx then begin ctx . edit . set_selection false ; remove_prev ctx n ; end |
let kill_next_chars ctx n = let position = Zed_cursor . get_position ctx . cursor in let end_pos = min ( position + n ) n ( Zed_rope . length ctx . edit . text ) text in let n = end_pos - position in ctx . edit . clipboard . clipboard_set ( Zed_rope . sub ctx . edit . text position n ) n ; ctx . edit . set_selection fa... |
let kill_prev_chars ctx n = let position = Zed_cursor . get_position ctx . cursor in let start = max 0 ( position - n ) n in let n = position - start in ctx . edit . clipboard . clipboard_set ( Zed_rope . sub ctx . edit . text start n ) n ; ctx . edit . set_selection false ; remove_prev ctx n |
let delete_next_char ctx = if not ( at_eot ctx ) ctx then begin ctx . edit . set_selection false ; remove_next ctx 1 end |
let delete_prev_char ctx = if not ( at_bot ctx ) ctx then begin ctx . edit . set_selection false ; remove_prev ctx 1 end |
let delete_next_line ctx = ctx . edit . set_selection false ; let position = Zed_cursor . get_position ctx . cursor in let index = Zed_cursor . get_line ctx . cursor in if index = Zed_lines . count ctx . edit . lines then remove_next ctx ( Zed_rope . length ctx . edit . text - position ) position else remove_next ctx (... |
let delete_prev_line ctx = ctx . edit . set_selection false ; let position = Zed_cursor . get_position ctx . cursor in let start = Zed_lines . line_start ctx . edit . lines ( Zed_cursor . get_line ctx . cursor ) cursor in remove_prev ctx ( position - start ) start |
let kill_next_line ctx = let position = Zed_cursor . get_position ctx . cursor in let index = Zed_cursor . get_line ctx . cursor in if index = Zed_lines . count ctx . edit . lines then begin ctx . edit . clipboard . clipboard_set ( Zed_rope . after ctx . edit . text position ) position ; ctx . edit . set_selection fals... |
let kill_prev_line ctx = let position = Zed_cursor . get_position ctx . cursor in let start = Zed_lines . line_start ctx . edit . lines ( Zed_cursor . get_line ctx . cursor ) cursor in ctx . edit . clipboard . clipboard_set ( Zed_rope . sub ctx . edit . text start ( position - start ) start ) start ; ctx . edit . set_s... |
let switch_erase_mode ctx = ctx . edit . set_erase_mode ( not ( S . value ctx . edit . erase_mode ) erase_mode ) erase_mode |
let set_mark ctx = Zed_cursor . goto ctx . edit . mark ( Zed_cursor . get_position ctx . cursor ) cursor ; ctx . edit . set_selection true |
let goto_mark ctx = goto ctx ( Zed_cursor . get_position ctx . edit . mark ) mark |
let copy ctx = if S . value ctx . edit . selection then begin let a = Zed_cursor . get_position ctx . cursor and b = Zed_cursor . get_position ctx . edit . mark in let a = min a b and b = max a b in ctx . edit . clipboard . clipboard_set ( Zed_rope . sub ctx . edit . text a ( b - a ) a ) a ; ctx . edit . set_selection ... |
let copy_sequence ctx start len = ctx . edit . clipboard . clipboard_set ( Zed_rope . sub ctx . edit . text start len ) len |
let kill ctx = if S . value ctx . edit . selection then begin let a = Zed_cursor . get_position ctx . cursor and b = Zed_cursor . get_position ctx . edit . mark in let a = min a b and b = max a b in ctx . edit . clipboard . clipboard_set ( Zed_rope . sub ctx . edit . text a ( b - a ) a ) a ; ctx . edit . set_selection ... |
let yank ctx = ctx . edit . set_selection false ; insert ctx ( ctx . edit . clipboard . clipboard_get ( ) ) |
let search_word_forward ctx = let len = Zed_rope . length ctx . edit . text in let rec loop idx = if idx = len then None else match ctx . edit . match_word ctx . edit . text idx with | Some idx ' -> Some ( Someidx , idx ' ) idx ' | None -> loop ( idx + 1 ) 1 in loop ( Zed_cursor . get_position ctx . cursor ) cursor |
let search_word_backward ctx = let rec loop idx = if idx = - 1 then None else match ctx . edit . match_word ctx . edit . text idx with | Some idx ' -> loop2 ( idx - 1 ) 1 ( idx , idx ' ) idx ' | None -> loop ( idx - 1 ) 1 and loop2 idx result = if idx = - 1 then Some result else match ctx . edit . match_word ctx . edit... |
let capitalize_word ctx = match search_word_forward ctx with | Some ( Someidx1 , idx2 ) idx2 -> goto ctx idx1 ; if Zed_cursor . get_position ctx . cursor = idx1 && idx1 < idx2 then begin let str = Zed_rope . sub ctx . edit . text idx1 ( idx2 - idx1 ) idx1 in let ch , str ' = Zed_rope . break str 1 in replace ctx ( Zed_... |
let lowercase_word ctx = match search_word_forward ctx with | Some ( Someidx1 , idx2 ) idx2 -> goto ctx idx1 ; if Zed_cursor . get_position ctx . cursor = idx1 then begin let str = Zed_rope . sub ctx . edit . text idx1 ( idx2 - idx1 ) idx1 in replace ctx ( Zed_rope . length str ) str ( CaseMap . lowercase ? locale ( : ... |
let uppercase_word ctx = match search_word_forward ctx with | Some ( Someidx1 , idx2 ) idx2 -> goto ctx idx1 ; if Zed_cursor . get_position ctx . cursor = idx1 then begin let str = Zed_rope . sub ctx . edit . text idx1 ( idx2 - idx1 ) idx1 in replace ctx ( Zed_rope . length str ) str ( CaseMap . uppercase ? locale ( : ... |
let next_word ctx = match search_word_forward ctx with | Some ( Some_idx1 , idx2 ) idx2 -> goto ctx idx2 | None -> goto ctx ( Zed_rope . length ctx . edit . text ) text |
let prev_word ctx = match search_word_backward ctx with | Some ( Someidx1 , _idx2 ) _idx2 -> goto ctx idx1 | None -> goto ctx 0 |
let delete_next_word ctx = let position = Zed_cursor . get_position ctx . cursor in let word_end = match search_word_forward ctx with | Some ( Some_idx1 , idx2 ) idx2 -> idx2 | None -> Zed_rope . length ctx . edit . text in remove ctx ( word_end - position ) position |
let delete_prev_word ctx = let position = Zed_cursor . get_position ctx . cursor in let start = match search_word_backward ctx with | Some ( Someidx1 , _idx2 ) _idx2 -> idx1 | None -> 0 in remove_prev ctx ( position - start ) start |
let kill_next_word ctx = let position = Zed_cursor . get_position ctx . cursor in let word_end = match search_word_forward ctx with | Some ( Some_idx1 , idx2 ) idx2 -> idx2 | None -> Zed_rope . length ctx . edit . text in ctx . edit . clipboard . clipboard_set ( Zed_rope . sub ctx . edit . text position ( word_end - po... |
let kill_prev_word ctx = let position = Zed_cursor . get_position ctx . cursor in let start = match search_word_backward ctx with | Some ( Someidx1 , _idx2 ) _idx2 -> idx1 | None -> 0 in ctx . edit . clipboard . clipboard_set ( Zed_rope . sub ctx . edit . text start ( position - start ) start ) start ; ctx . edit . set... |
let undo { check ; edit ; cursor } = if edit . undo_count > 0 then begin let index = if edit . undo_index = 0 then edit . undo_size - 1 else edit . undo_index - 1 in let text , lines , pos , new_pos , added , removed , added_width , removed_width = edit . undo ( . index ) index in if not check || edit . editable pos ad... |
type action = | Insert of Zed_char . t | Insert_str of Zed_string . t | Newline | Next_char | Prev_char | Next_line | Prev_line | Join_line | Set_pos of int | Goto of int | Goto_bol | Goto_eol | Goto_bot | Goto_eot | Delete_next_chars of int | Delete_prev_chars of int | Kill_next_chars of int | Kill_prev_chars of int |... |
let get_action = function | Insert ch -> ( fun ctx -> if Zed_char . length ch = 1 then insert_char ctx ( Zed_char . core ch ) ch else insert ctx ( Zed_rope . singleton ch ) ch ) ch | Insert_str str -> ( fun ctx -> insert ctx ( Zed_rope . of_string str ) str ) str | Newline -> newline | Next_char -> next_char | Prev_cha... |
let doc_of_action = function | Insert _ -> " insert the given character . " | Insert_str _ -> " insert the given string . " | Newline -> " insert a newline character . " | Next_char -> " move the cursor to the next character . " | Prev_char -> " move the cursor to the previous character . " | Next_line -> " move the cu... |
let actions = [ Newline , " newline " ; Next_char , " next - char " ; Prev_char , " prev - char " ; Next_line , " next - line " ; Prev_line , " prev - line " ; Join_line , " join - line " ; Goto_bol , " goto - bol " ; Goto_eol , " goto - eol " ; Goto_bot , " goto - bot " ; Goto_eot , " goto - eot " ; Delete_next_char ,... |
let actions_to_names = Array . of_list ( List . sort ( fun ( a1 , _ ) _ ( a2 , _ ) _ -> compare a1 a2 ) a2 actions ) actions |
let names_to_actions = Array . of_list ( List . sort ( fun ( _ , n1 ) n1 ( _ , n2 ) n2 -> compare n1 n2 ) n2 actions ) actions |
let parse_insert x = if Zed_utf8 . starts_with x " insert ( insert " && Zed_utf8 . ends_with x ) " " then begin let str = String . sub x 7 ( String . length x - 8 ) 8 in if String . length str = 1 && Char . code str [ . 0 ] 0 < 128 then Insert ( InsertZed_char . unsafe_of_uChar ( UChar . of_char str [ . 0 ] 0 ) 0 ) 0 e... |
let parse_insert_str str = if Zed_utf8 . starts_with str " insert_str ( insert_str " && Zed_utf8 . ends_with str ) " " then let str = String . sub str 11 ( String . length str - 12 ) 12 in try Insert_str ( Zed_string . of_utf8 str ) str with _ -> raise Not_found else raise Not_found |
let parse_action_count action act_name str = let act_len = String . length act_name in if Zed_utf8 . starts_with str ( act_name ^ ( ) " " && Zed_utf8 . ends_with str ) " " then let str = String . sub str ( act_len + 1 ) 1 ( String . length str - ( act_len + 2 ) 2 ) 2 in try action ( int_of_string str ) str with _ -> ra... |
let parse_set_pos = parse_action_count ( fun c -> Set_pos c ) c " set - pos " |
let parse_goto = parse_action_count ( fun c -> Goto c ) c " goto " |
let parse_delete_next_chars = parse_action_count ( fun c -> Delete_next_chars c ) c " delete - next - chars " |
let parse_delete_prev_chars = parse_action_count ( fun c -> Delete_prev_chars c ) c " delete - prev - chars " |
let parse_kill_next_chars = parse_action_count ( fun c -> Kill_next_chars c ) c " kill - next - chars " |
let parse_kill_prev_chars = parse_action_count ( fun c -> Kill_prev_chars c ) c " kill - prev - chars " |
let parse_action_param x = try parse_insert x with Not_found -> try parse_insert_str x with Not_found -> try parse_set_pos x with Not_found -> try parse_goto x with Not_found -> try parse_delete_next_chars x with Not_found -> try parse_delete_prev_chars x with Not_found -> try parse_kill_next_chars x with Not_found -> ... |
let action_of_name x = let rec loop a b = if a = b then parse_action_param x else let c = ( a + b ) b / 2 in let action , name = Array . unsafe_get names_to_actions c in match compare x name with | d when d < 0 -> loop a c | d when d > 0 -> loop ( c + 1 ) 1 b | _ -> action in loop 0 ( Array . length names_to_actions ) ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.