package chamo

  1. Overview
  2. Docs

Misc functions.

val map_opt : ('a -> 'b) -> 'a option -> 'b option
val my_int_of_string : string -> int

Same as int_of_string but support strings beginning with '+'.

val add_shortcut : Stk.Widget.widget -> (string * ((unit -> bool) option * (unit -> unit))) list -> (Stk.Key.keystate * string) -> unit
val remove_char : string -> char -> string

remove_char s c returns a copy of the given string s without character c.

val line_of_char : string -> int -> int

line_of_char file char gets the line number (0-based) in a file from a character number.

val char_of_line : string -> int -> int

char_of_line file line returns the offset of the first character of the given line of the give file. Line number are zero-based, as the returned character number.

val escape_menu_label : string -> string

escape_menu_label string returns a the string where all '_' have been escaped to be displayed correctly in Lablgtk menus.

val mod_date_of_file : string -> float

mod_date_of_file file returns the Unix last modification date of the given file, or 0.0 if the date could not be obtained.

val string_of_bool : bool -> string
val bool_of_string : string -> bool
val date_of_file : string -> float option

date_of_file file returns the unix date of the last modification of the file, is the file can be accessed.

val catch_print_exceptions : ('a -> unit) -> 'a -> unit

catch_print_exception f v applies f to v and catch and print any raised exception to stderr.

val to_utf8 : ?coding:string -> string -> string

Encode the given string to UTF-8, using the default charset Core_rc.encoding or the given coding.

val pp_to_utf8 : Format.formatter -> string -> unit
val of_utf8 : ?coding:string -> string -> string

Decode the given string from UTF-8, using the default charset Core_rc.encoding or the given coding.

val filename_to_utf8 : string -> string

Convert filename from locale encoding to UTF-8.

val filename_from_utf8 : string -> string

Convert filename from UTF-8 to locale encoding.

val same_files : string -> string -> bool

Return whether the two given filename identifies the same file (same device and inode).

  • raises Failure

    if information about a file cannot be accessed.

val safe_same_files : string -> string -> bool

Same as same_files but returns false instead of raising an exception if information about one file could not be retrieved.

val set_active_state_message : string -> unit

This function calls the "set_active_state_message" command with the given utf-8 string.

val set_active_action_message : string -> unit

This function calls the "set_active_action_message" command with the given utf-8 string.

val display_message : string -> unit

This function displays the given message with Log.app and calls the "set_active_action_message" command with the given utf-8 string.

val warning_message : string -> unit

This function displays the given message with Log.warn and calls the "set_active_action_message" command with the given utf-8 string.

val error_message : string -> unit

This function displays the given message with Log.err and calls the "set_active_action_message" command with the given utf-8 string.

val fail_if_unix_error : ('a -> 'b) -> 'a -> 'b

fail_if_unix_error f x applies f to x and catches only exception Unix.Unix_error. If such an exception is raised by f, create a message string and raise Failure message.

val is_prefix : string -> string -> bool

is_prefix s1 s2 returns whether s2 is a prefix of s1.

val dir_entries : ?prefix:string -> string -> string list

dir_entries dir return the list of entries in directory dir.

  • parameter prefix

    can be used to filter only entries with the given prefix.

val max_common : string list -> string option

max_common strings return the longest string common to all the given strings or None if strings is the empty list.

val chop_n_char : int -> string -> string

chop_n_char n s returns the given string where characters after position n are replaced by "...".

val list_remove_doubles : ?pred:('k -> 'k -> bool) -> 'k list -> 'k list

list_remove_doubles ?pred l remove doubles in the given list l, according to the optional equality function pred. Default equality function is (=).

val subdirs : string -> string list

subdirs path returns the list of subdirectories of the given directory name. Returned names are relative to the given path. Raises Unix_error if an error occurs.

val replace_in_string : pat:string -> subs:string -> s:string -> string

replace_in_string ~pat ~subs ~s replaces all occurences of pattern pat by subs in string s.

val string_of_file : string -> string

string_of_file filename returns the content of filename in the form of one string. Raises Sys_error if the file could not be open.

val file_of_string : file:string -> string -> unit

file_of_string ~file str creates a file named filename whose content is str. Raises Sys_error if the file could not be open.

val split_string : ?keep_empty:bool -> string -> char list -> string list

Separate the given string according to the given list of characters. keep_empty is false by default. If set to true, the empty strings between separators are kept.

val safe_remove_file : string -> unit

Remove the given file, and ignore the error if the file does not exist (catch Sys_error).

val make_list : int -> 'i -> 'i list

make_list n ele builds a list of n elements ele.

val no_blanks : string -> string

no_blanks s returns the given string without any blank characters, i.e. '\n' '\r' ' ' '\t'.

val try_finalize : ('l -> 'm) -> 'l -> ('n -> unit) -> 'n -> 'm

try_finalize f x g y applies f to x and return the result or raises an exception, but in all cases g is applied to y before returning or raising the exception.

Input functions

The strings given in parameter to the following input functions must be utf-8 encoded; the strings passed to the given callback function is decoded from utf-8 before.

val select_file_history : Minibuffer.minibuffer_history

The minibuffer history used in function select_file.

val select_file : Minibuffer.minibuffer -> title:string -> string -> (string -> unit Lwt.t) -> unit Lwt.t

select_file mb ~title default_text f makes the user select a file in the minibuffer and calls f with the selected file when user validates.

val select_string : ?history:Minibuffer.minibuffer_history -> Minibuffer.minibuffer -> title:string -> choices:string list -> string -> (string -> unit Lwt.t) -> unit Lwt.t

select_string mb ~title ~choice default_text f makes the user choose a string among the given choices and then calls f with the choices when the user validates.

  • parameter a

    minibuffer history can be given to use.

val input_string : ?history:Minibuffer.minibuffer_history -> Minibuffer.minibuffer -> title:string -> string -> (string -> unit Lwt.t) -> unit Lwt.t

input_string mb ~title default_text f makes the user enter a text and calls f on that text when the user validates.

val input_command_arg : Minibuffer.minibuffer -> ?history:Minibuffer.minibuffer_history -> title:string -> (string -> unit Lwt.t) -> string -> string array -> unit Lwt.t

FIXME: explain this

val confirm : Minibuffer.minibuffer -> string -> (unit -> unit Lwt.t) -> unit Lwt.t

confirm mb question f makes the user answer to the given question and calls f if the response is "yes"

OCaml

Innovation. Community. Security.