From 40aeba62814a8f28454ee23c6687b5e6dd53aecd Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Tue, 15 Sep 2020 18:51:09 +0100 Subject: 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 --- tools/emacs-pkgs/notable/notable.el | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tools/emacs-pkgs/notable/notable.el b/tools/emacs-pkgs/notable/notable.el index b0b81da21e..d3866bb809 100644 --- a/tools/emacs-pkgs/notable/notable.el +++ b/tools/emacs-pkgs/notable/notable.el @@ -51,14 +51,17 @@ (defvar notable--note-lock (make-mutex "notable-notes") "Exclusive lock for note operations with shared state.") +(defvar notable--note-regexp + (rx "note-" + (group (one-or-more (any num))) + ".json") + "Regular expression to match note file names.") + (defvar notable--next-note - (let ((next 0) - (note-regexp (rx "note-" - (group (one-or-more (any num))) - ".json"))) + (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) -- cgit 1.4.1