-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemacs_data.ml
94 lines (81 loc) · 2.38 KB
/
emacs_data.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
open Core
type pos = {
begin_: int;
end_: int;
}
[@@deriving show, sexp, equal]
type property = { key: string; value: string; pos: pos}
[@@deriving show, sexp, equal]
type tag = string
[@@deriving show, sexp, equal]
type op = Italic | Strikethrough | Bold | Underline | Subscript | Superscript
[@@deriving show, sexp, equal]
type time = { year: int; month: int; day: int; hour: int option; minute: int option }
[@@deriving show, sexp, equal]
type timestamp = { raw: string; start: time; end_: time; pos: pos }
[@@deriving show, sexp, equal]
let time_to_time_ns ts =
let (let+) x f = Option.bind x ~f in
let+ month = Month.of_int ts.month in
let+ date = try
Some (Date.create_exn ~y:ts.year ~m:month ~d:ts.day)
with Invalid_argument _ -> None in
let time = Time_ns.Ofday.create
~hr:(Option.value ~default:0 ts.hour)
~min:(Option.value ~default:0 ts.minute) () in
Some (Time_ns.of_date_ofday
~zone:(Timezone.utc)
date
time)
type txt =
| Lit of string
| Concat of txt list
| Code of string | Verbatim of string
| Entity of string
| Format of op * txt
| InlineSrcBlock of { language: string; value: string }
| Timestamp of timestamp
| StatisticsCookie of string
[@@deriving show, sexp, equal]
type todo = {
keyword: string;
ty: [`Todo | `Done];
}
[@@deriving show, sexp, equal]
type t =
| Property of property
| Section of { pos: pos; properties: t list}
| Headline of {
raw_value: string;
title: txt;
pos: pos;
level: int;
priority: int option;
tags: tag list;
todo: todo option;
subsections: t list;
closed: timestamp option;
scheduled: timestamp option;
deadline: timestamp option;
}
| Drawer of { name: string; pos: pos; contents: t list }
| Clock of {
status: [`running | `closed ];
value: timestamp;
duration: string option;
pos: pos;
}
| Planning of {
closed: timestamp option;
scheduled: timestamp option;
deadline: timestamp option;
pos: pos;
}
[@@deriving show, sexp, equal]
type buffer_timestamp = { modification_time: int; modification_count: int }
[@@deriving show, sexp, equal]
let buffer_timestamp_gt t1 t2 =
t1.modification_time < t2.modification_time || (
t1.modification_time = t2.modification_time &&
t1.modification_count < t2.modification_count
)