-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemcn-util.el
35 lines (27 loc) · 1.01 KB
/
emcn-util.el
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
;; emcn-util.el --- Nextcloud Notes Client for Emacs -*- lexical-binding: t; -*-
(defsubst emcn--json-serialize-utf8 (json)
"Serialize a json object and encode the resulting string to UTF-8."
(encode-coding-string
(emcn--json-preset (json-serialize json)) 'utf-8 t))
(defmacro emcn--json-preset (&rest body)
"Define JSON preset to use when marshalling/unmarshalling json"
`(let ((json-array-type 'list)
(json-object-type 'alist)
(json-key-type 'symbol)
(json-false :false))
,@body))
(defsubst emcn--head-file (file &optional end)
"First END characters of file as a string."
(unless end (setq end 130))
(with-temp-buffer
(insert-file-contents file nil 0 end)
(buffer-string)))
(defsubst emcn--file-contents (file)
(with-temp-buffer
(insert-file-contents file)
(buffer-string)))
(defsubst emcn--write-string-to-file (string file)
(with-temp-buffer
(insert string)
(write-region (point-min) (point-max) file nil 'no-message)))
(provide 'emcn-util)