Skip to content

Instantly share code, notes, and snippets.

@huytd
Last active September 25, 2023 04:18
Show Gist options
  • Save huytd/07e64250d0f52ae81c208a6b6d4e8418 to your computer and use it in GitHub Desktop.
Save huytd/07e64250d0f52ae81c208a6b6d4e8418 to your computer and use it in GitHub Desktop.
(defun read-journal (path)
(with-temp-buffer
(insert-file-contents (concat "~/notes/journal/" path))
(split-string (buffer-string) "\n" t)))
(defun read-first-three-lines (list)
(cond ((>= (length list) 4) (subseq list 1 3))
((>= (length list) 1) (nthcdr 1 list))
(t list)))
(defun read-journal-heads (path)
(mapconcat (function (lambda (line) (format " %s" line)))
(read-first-three-lines (read-journal path)) "\n"))
(defcustom journal-list-display-alist
'((side . left)
(window-width . 40)
(slot . -1))
"Alist used to display notes buffer.
See `display-buffer-in-side-window' for example options."
:type 'alist)
(defun open-journal-mode ()
(interactive)
;(setq split-width-threshold 0)
(setq journal-list-buffer (get-buffer-create (generate-new-buffer-name "journal-list.org")))
(with-current-buffer journal-list-buffer
(org-mode)
(setq journal-file-list (directory-files "~/notes/journal/" nil "\\.org$"))
(setq journal-file-list (mapcar (lambda (item) (format "* %s\n [[file:~/notes/journal/%s][-> jump to file]]\n #+BEGIN_SRC\n%s\n #+END_SRC\n" item item (read-journal-heads item))) journal-file-list))
(insert (mapconcat 'identity journal-file-list "\n"))
(toggle-read-only t)
)
(find-file (concat "~/notes/journal/" (format-time-string "%Y-%m-%d") ".org"))
(display-buffer-in-side-window journal-list-buffer journal-list-display-alist)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment