-
-
Save vrotaru/2faa768296bb3830f0eb8da45057f4ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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