Skip to content

Instantly share code, notes, and snippets.

@tychobrailleur
Forked from huytd/org-journal-list.el
Last active October 16, 2018 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tychobrailleur/b8c10ba215ed40afe258a8320671b584 to your computer and use it in GitHub Desktop.
Save tychobrailleur/b8c10ba215ed40afe258a8320671b584 to your computer and use it in GitHub Desktop.
(defcustom org-journal-list-default-dir
"~/org/"
"Default location for org files"
:type 'directory)
(defcustom org-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)
(defcustom org-journal-list-preview-size
5
"Number of lines visible in the preview of every org file."
:type 'integer)
(defun org-journal-list--read-journal (path)
(with-temp-buffer
(insert-file-contents (concat org-journal-list-default-dir path))
(split-string (buffer-string) "\n" t)))
(defun org-journal-list--read-first-n-lines (list n)
(cond ((>= (length list) (+ n 1)) (subseq list 1 n))
((>= (length list) 1) (nthcdr 1 list))
(t list)))
(defun org-journal-list--read-journal-heads (path)
(mapconcat (function (lambda (line) (format " %s" line)))
(org-journal-list--read-first-n-lines (org-journal-list--read-journal path)
org-journal-list-preview-size) "\n"))
(defun open-journal-mode ()
(interactive)
(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 org-journal-list-default-dir nil "\\.org$"))
(setq journal-file-list (mapcar (lambda (item)
(format "* [[file:%s/%s][%s]]\n\n #+BEGIN_SRC\n%s\n #+END_SRC\n"
item
org-journal-list-default-dir
item
(org-journal-list--read-journal-heads item)))
journal-file-list))
(insert (mapconcat 'identity journal-file-list "\n"))
(toggle-read-only t)
(goto-char 1))
(display-buffer-in-side-window journal-list-buffer org-journal-list-display-alist))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment