about summary refs log tree commit diff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/emacs-pkgs/notable/notable.el49
1 files changed, 48 insertions, 1 deletions
diff --git a/tools/emacs-pkgs/notable/notable.el b/tools/emacs-pkgs/notable/notable.el
index 4669579ad73c..b0cedb3de23d 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)