Skip to content

Instantly share code, notes, and snippets.

@abdullahkhalids
Created August 8, 2013 22:09
Show Gist options
  • Save abdullahkhalids/6189276 to your computer and use it in GitHub Desktop.
Save abdullahkhalids/6189276 to your computer and use it in GitHub Desktop.
This emacs function helps keep a journal.
;; Pensieve
;; This program helps keep a journal.
;; Last edit: 2012-06-29.
; A journal is simply a list of textfiles, at most one for every
; day.
; Put into your emacs load directory
; Run with M-x pensieve to open a file, ready to write
;Needed features
;* An interactive shell that shows me a list of entries
; from a certain time period.
;The journal folder. This should be set in the .emacs file.
;(setq pensieve-folder "~/Documents/Journal")
;Format for entry filename
(setq pensieve-entry-format "%Y-%m-%d")
;Internal Constants
(setq sep "/")
;; Functions
(defun todays-filename ()
"The last modification time of a file.
Returned in the format YYYYMMDDHHMMSS."
(format-time-string pensieve-entry-format))
(defmacro inc (x)
"increments x by 1."
`(setq ,x (1+ ,x)))
(defmacro remove-starting-char (string char)
"removes a char from the start of a string."
`(if (string= (substring ,string 0 1) ,char)
(setq ,string (substring ,string 1 (length ,string)))))
(defmacro remove-ending-char (string char)
"removes a char from the end of a string."
`(let ((l (length ,string)))
(if (string= (substring ,string (1- l) l)
,char)
(setq ,string (substring ,string 0 (1- l))))))
(defun concat-paths (&rest paths)
"Given a set of paths concats them.
Makes sure that sep are alright."
(let ((n (length paths))
(i 0)
(concated-path "")
(path)
(subpath))
(while (< i n)
(setq subpath (nth i paths))
(if (not (= i 0))
(remove-starting-char subpath sep))
(if (> (length subpath) 0)
(progn
(remove-ending-char subpath sep)
(setq concated-path (concat concated-path
subpath
sep))))
(inc i))
(remove-ending-char concated-path sep)))
(defun pensieve ()
"Create's or appends to today's journal entry."
(interactive)
(let ((file (concat-paths pensieve-folder (todays-filename))))
(find-file file)
(goto-char (point-max))
(message "Write a pensieve entry...")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment