diff options
| -rw-r--r-- | lib/editorBuffer.ml | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/editorBuffer.ml b/lib/editorBuffer.ml index 5104549..715855c 100644 --- a/lib/editorBuffer.ml +++ b/lib/editorBuffer.ml | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | open Base | 1 | open Base |
| 2 | open Stdio | ||
| 2 | open Zipper | 3 | open Zipper |
| 3 | open Util | 4 | open Util |
| 4 | 5 | ||
| @@ -48,9 +49,19 @@ module Action = struct | |||
| 48 | end | 49 | end |
| 49 | 50 | ||
| 50 | let from_file f = | 51 | let from_file f = |
| 51 | let lines = Stdio.In_channel.read_lines f in | 52 | let lines = |
| 52 | let line_to_zipper l = String.to_list l |> Sequence.of_list |> of_seq in | 53 | try |
| 53 | let content = Sequence.(of_list lines |> map ~f:line_to_zipper) |> of_seq in | 54 | let fd = Unix.(openfile f [ O_RDONLY ] 0o640) in |
| 55 | let ic = Unix.in_channel_of_descr fd in | ||
| 56 | let lines = In_channel.input_lines ic in | ||
| 57 | In_channel.close ic; | ||
| 58 | lines | ||
| 59 | with Unix.Unix_error (ENOENT, _, _) -> [] | ||
| 60 | in | ||
| 61 | let content = | ||
| 62 | let line_to_zipper l = String.to_list l |> Sequence.of_list |> of_seq in | ||
| 63 | Sequence.(of_list lines |> map ~f:line_to_zipper) |> of_seq | ||
| 64 | in | ||
| 54 | { kind = File f; content = Ok content } | 65 | { kind = File f; content = Ok content } |
| 55 | 66 | ||
| 56 | let cursor b = | 67 | let cursor b = |
