diff options
author | Vincent Ambo <mail@tazj.in> | 2020-09-17T12·20+0100 |
---|---|---|
committer | tazjin <mail@tazj.in> | 2020-09-18T23·32+0000 |
commit | 426a31b7f2d75eb422a8305b12e3deee403a889e (patch) | |
tree | c795535da67713fe6229b4b3d6005079b20b1555 /tools/emacs-pkgs/notable/notable.el | |
parent | f94dd5e93243d6894a4cfb2869160bb6f24d173c (diff) |
feat(notable): Add note archival function r/1802
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>
Diffstat (limited to 'tools/emacs-pkgs/notable/notable.el')
-rw-r--r-- | tools/emacs-pkgs/notable/notable.el | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tools/emacs-pkgs/notable/notable.el b/tools/emacs-pkgs/notable/notable.el index b0cedb3de23d..d6d2dbe34817 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) |