feat(notable): Add note archival function

Archiving notes is done by just changing the filename to an `archive-`
instead of `note-` prefix.

Unarchiving is not yet implemented and should be done by moving the
note to a *new note ID*.

Archiving is bound to 'a' in the note list.

Change-Id: I8c225a25bdac5147a26030f47f24edee497f69df
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1986
Tested-by: BuildkiteCI
Reviewed-by: tazjin <mail@tazj.in>
This commit is contained in:
Vincent Ambo 2020-09-17 13:20:39 +01:00 committed by tazjin
parent f94dd5e932
commit 426a31b7f2

View file

@ -98,6 +98,10 @@
(check-type id integer)
(f-join notable-note-dir (format "note-%d.json" id)))
(defun notable--archive-path (id)
(check-type id integer)
(f-join notable-note-dir (format "archive-%d.json" id)))
(defun notable--add-note (content)
"Add a note with CONTENT to the note store."
(let* ((id (notable--next-id))
@ -108,6 +112,19 @@
(f-write-text (notable--serialize-note note) 'utf-8 path)
(message "Saved note %d" id)))
(defun notable--archive-note (id)
"Archive the note with ID."
(check-type id integer)
(unless (f-exists? (notable--note-path id))
(error "There is no note with ID %d." id))
(when (f-exists? (notable--archive-path id))
(error "Oh no, a note with ID %d has already been archived!" id))
(f-move (notable--note-path id) (notable--archive-path id))
(message "Archived note with ID %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)
@ -161,6 +178,10 @@
(interactive)
(notable--show-note (get-text-property (point) 'notable-note-id)))
(defun notable--archive-note-at-point ()
(interactive)
(notable--archive-note (get-text-property (point) 'notable-note-id)))
;; Note list buffer implementation
(define-derived-mode notable-list-mode fundamental-mode "notable"
@ -175,6 +196,7 @@
(setq notable-list-mode-map
(let ((map (make-sparse-keymap)))
(define-key map "a" 'notable--archive-note-at-point)
(define-key map "q" 'kill-current-buffer)
(define-key map "g" 'notable-list-notes)
(define-key map (kbd "RET") 'notable--show-note-at-point)