From f94dd5e93243d6894a4cfb2869160bb6f24d173c Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Thu, 17 Sep 2020 12:52:58 +0100 Subject: feat(notable): Add a mode for displaying single notes This mode displays the note's timestamp in its header line, and the content in its body. Some rudimentary key bindings are set up in the list view to view notes in full (RET), and in both modes to quit the current buffer (q). Change-Id: Icb35baec220a9efcfa2b86617b16178669df996f Reviewed-on: https://cl.tvl.fyi/c/depot/+/1985 Tested-by: BuildkiteCI Reviewed-by: tazjin --- tools/emacs-pkgs/notable/notable.el | 49 ++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/tools/emacs-pkgs/notable/notable.el b/tools/emacs-pkgs/notable/notable.el index 4669579ad7..b0cedb3de2 100644 --- a/tools/emacs-pkgs/notable/notable.el +++ b/tools/emacs-pkgs/notable/notable.el @@ -122,6 +122,45 @@ (error "No note with ID %s in note storage!" id)) (notable--deserialize-note (f-read-text path 'utf-8)))) +;; Note view buffer implementation + +(defvar-local notable--buffer-note nil "The note ID displayed by this buffer.") + +(define-derived-mode notable-note-mode fundamental-mode "notable-note" + "Major mode displaying a single Notable note." + (set (make-local-variable 'scroll-preserve-screen-position) t) + (setq truncate-lines t) + (setq buffer-read-only t) + (setq buffer-undo-list t)) + +(setq notable-note-mode-map + (let ((map (make-sparse-keymap))) + (define-key map "q" 'kill-current-buffer) + map)) + +(defun notable--show-note (id) + "Display a single note in a separate buffer." + (check-type id integer) + + (let ((note (notable--get-note id)) + (buffer (get-buffer-create (format "*notable: %d*" id))) + (inhibit-read-only t)) + (with-current-buffer buffer + (notable-note-mode) + (erase-buffer) + (setq notable--buffer-note id) + (setq header-line-format + (format "Note from %s" + (dottime-format + (seconds-to-time (notable--note-time note)))))) + (switch-to-buffer buffer) + (goto-char (point-min)) + (insert (notable--note-content note)))) + +(defun notable--show-note-at-point () + (interactive) + (notable--show-note (get-text-property (point) 'notable-note-id))) + ;; Note list buffer implementation (define-derived-mode notable-list-mode fundamental-mode "notable" @@ -134,11 +173,19 @@ (setq buffer-undo-list t) (hl-line-mode t)) +(setq notable-list-mode-map + (let ((map (make-sparse-keymap))) + (define-key map "q" 'kill-current-buffer) + (define-key map "g" 'notable-list-notes) + (define-key map (kbd "RET") 'notable--show-note-at-point) + map)) + (defun notable--render-note (id note) (check-type id integer) (check-type note notable--note) - (let ((first-line (car (s-lines "foo"))) + (let ((start (point)) + (first-line (car (s-lines (notable--note-content note)))) (date (dottime-format (seconds-to-time (notable--note-time note))))) (insert (propertize (s-concat date " " first-line) -- cgit 1.4.1