Skip to content

Instantly share code, notes, and snippets.

@vrotaru
Created Aug 24, 2021
Embed
What would you like to do?
#use "topfind";;
#thread;;
#require "ocp-indent.lib";;
#require "cmdliner";;
#require "lablgtk3";;
#require "lablgtk3-sourceview3";;
let x = {|let pr_string output block text usr =
begin match output.kind with
| Numeric _ -> usr
| Print f -> f text usr
| Extended f ->
f block (Text text) usr
end
|};;
let man = IndentConfig.man;;
#show Cmdliner.Term;;
let info = Cmdliner.Term.info ~man "HO-HO" ;;
let ns = Nstream.of_string x;;
let init = IndentBlock.empty;;
let buffer = Buffer.create 64;;
let print s () = Buffer.add_string buffer s;;
let output = IndentPrinter.{
debug = false;
config = IndentConfig.default;
in_lines = Fun.const true;
indent_empty = false;
adaptive = false;
kind = Print print
};;
let text_buffer = GText.buffer ();;
let view = GText.view
~editable: true
~accepts_tab: false
~border_width: 5
~width: 640
~height: 480
;;
let _ = GMain.init ();;
let window = GWindow.window;;
let window = window ();;
let view = view ~buffer: text_buffer ~packing: window#add ();;
let _ = view#misc#modify_font_by_name "Fira Code 12";;
let _ = GtkThread.start ();;
let _ = window#show () ;;
text_buffer#set_text x;;
let reident () =
let text = text_buffer#get_text
~start: text_buffer#start_iter ~stop: text_buffer#end_iter
() in
let ns = Nstream.of_string text in
let () = Buffer.clear buffer in
let () = IndentPrinter.proceed output ns init () in
text_buffer#set_text @@ Buffer.contents buffer
;;
reident ();;
let offsets file =
let output = IndentPrinter.{
debug = false;
config = IndentConfig.default;
in_lines = Fun.const true;
indent_empty = false;
adaptive = false;
kind = Numeric
(fun n () -> Format.printf "%d\n" n)
} in
let ch = open_in_bin file in
Fun.protect
~finally: (fun () -> close_in_noerr ch)
(fun () ->
let ns = Nstream.of_channel ch in
IndentPrinter.proceed output ns init ()
)
;;
offsets "tools/mkicons.ml";;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment