feat(notable): Add a function for listing existing notes

Change-Id: I23697b4798ee4d4e94d3f7c1a4e4e9abf5115345
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1982
Tested-by: BuildkiteCI
Reviewed-by: tazjin <mail@tazj.in>
This commit is contained in:
Vincent Ambo 2020-09-15 18:51:09 +01:00 committed by tazjin
parent 6b16e5c1ef
commit 40aeba6281

View file

@ -51,14 +51,17 @@
(defvar notable--note-lock (make-mutex "notable-notes")
"Exclusive lock for note operations with shared state.")
(defvar notable--next-note
(let ((next 0)
(note-regexp (rx "note-"
(defvar notable--note-regexp
(rx "note-"
(group (one-or-more (any num)))
".json")))
".json")
"Regular expression to match note file names.")
(defvar notable--next-note
(let ((next 0))
(-each (f-entries notable-note-dir)
(lambda (file)
(when-let* ((match (string-match note-regexp file))
(when-let* ((match (string-match notable--note-regexp file))
(id (string-to-number
(match-string 1 file)))
(larger (> id next)))
@ -100,6 +103,14 @@
(f-write-text (notable--serialize-note note) 'utf-8 path)
(message "Saved note %d" id)))
(defun notable--list-note-ids ()
"List all note IDs (not contents) from `notable-note-dir'"
(cl-loop for file in (f-entries notable-note-dir)
with res = nil
if (string-match notable--note-regexp file)
do (push (string-to-number (match-string 1 file)) res)
finally return res))
;; User-facing functions
(defun notable-take-note (content)