diff options
author | Vincent Ambo <mail@tazj.in> | 2020-09-15T17·51+0100 |
---|---|---|
committer | tazjin <mail@tazj.in> | 2020-09-17T10·51+0000 |
commit | 40aeba62814a8f28454ee23c6687b5e6dd53aecd (patch) | |
tree | f9e4f82a39cd20fbadfec929cec69369dee1ff29 /tools/emacs-pkgs/notable/notable.el | |
parent | 6b16e5c1efb5688b32899693eaf5467988f479a7 (diff) |
feat(notable): Add a function for listing existing notes r/1797
Change-Id: I23697b4798ee4d4e94d3f7c1a4e4e9abf5115345 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1982 Tested-by: BuildkiteCI Reviewed-by: tazjin <mail@tazj.in>
Diffstat (limited to 'tools/emacs-pkgs/notable/notable.el')
-rw-r--r-- | tools/emacs-pkgs/notable/notable.el | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/tools/emacs-pkgs/notable/notable.el b/tools/emacs-pkgs/notable/notable.el index b0b81da21ecc..d3866bb80916 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) |