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 <mail@tazj.in>
This commit is contained in:
parent
781870f288
commit
f94dd5e932
1 changed files with 48 additions and 1 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue