Chamo.Misc
Misc functions.
remove_char s c
returns a copy of the given string s
without character c
.
line_of_char file char
gets the line number (0-based) in a file from a character number.
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.
escape_menu_label string
returns a the string where all '_' have been escaped to be displayed correctly in Lablgtk menus.
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.
date_of_file file
returns the unix date of the last modification of the file, is the file can be accessed.
catch_print_exception f v
applies f
to v
and catch and print any raised exception to stderr.
Encode the given string to UTF-8, using the default charset Core_rc.encoding
or the given coding
.
Decode the given string from UTF-8, using the default charset Core_rc.encoding
or the given coding
.
Return whether the two given filename identifies the same file (same device and inode).
Same as same_files
but returns false
instead of raising an exception if information about one file could not be retrieved.
This function calls the "set_active_state_message" command with the given utf-8 string.
This function calls the "set_active_action_message" command with the given utf-8 string.
This function displays the given message with Log.app
and calls the "set_active_action_message" command with the given utf-8 string.
This function displays the given message with Log.warn
and calls the "set_active_action_message" command with the given utf-8 string.
This function displays the given message with Log.err
and calls the "set_active_action_message" command with the given utf-8 string.
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
.
dir_entries dir
return the list of entries in directory dir
.
max_common strings
return the longest string common to all the given strings or None if strings
is the empty list.
chop_n_char n s
returns the given string where characters after position n are replaced by "..."
.
list_remove_doubles ?pred l
remove doubles in the given list l
, according to the optional equality function pred
. Default equality function is (=)
.
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.
replace_in_string ~pat ~subs ~s
replaces all occurences of pattern pat
by subs
in string s
.
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.
file_of_string ~file str
creates a file named filename
whose content is str
. Raises Sys_error
if the file could not be open.
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.
Remove the given file, and ignore the error if the file does not exist (catch Sys_error
).
no_blanks s
returns the given string without any blank characters, i.e. '\n' '\r' ' ' '\t'.
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.
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.
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"