summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Igne <undyamon@disroot.org>2024-01-11 20:33:01 +0100
committerFederico Igne <undyamon@disroot.org>2024-01-11 20:33:01 +0100
commit235f74aad290186785bf4c66aec805bb4577f7eb (patch)
treea54719a50a866f2f6809cd24ca0cfba55eeed166
parentb177712c7ac2563cbfad48927452d9544cbafd22 (diff)
downloadsandy-235f74aad290186785bf4c66aec805bb4577f7eb.tar.gz
sandy-235f74aad290186785bf4c66aec805bb4577f7eb.zip
fix: open an empty buffer if requested file does not exist.
-rw-r--r--lib/editorBuffer.ml17
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 @@
1open Base 1open Base
2open Stdio
2open Zipper 3open Zipper
3open Util 4open Util
4 5
@@ -48,9 +49,19 @@ module Action = struct
48end 49end
49 50
50let from_file f = 51let 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
56let cursor b = 67let cursor b =