From 426a31b7f2d75eb422a8305b12e3deee403a889e Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Thu, 17 Sep 2020 13:20:39 +0100 Subject: 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 --- tools/emacs-pkgs/notable/notable.el | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tools/emacs-pkgs/notable/notable.el b/tools/emacs-pkgs/notable/notable.el index b0cedb3de2..d6d2dbe348 100644 --- a/tools/emacs-pkgs/notable/notable.el +++ b/tools/emacs-pkgs/notable/notable.el @@ -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) -- cgit 1.4.1