Emacs diary additional functionality

On my another posting about Everyday Text File and emacs LISP Customization, I made a fast way to make a text file every day for diary. Also, there was a way to find information from diaries. However, sometimes, I want to see yesterday’s diary, and previous/next day’s diary of current diary file. To make this, I wrote a bash script and LISP functions.

Bash script that opens previous/next file


fname=$(basename $2)

if [ "$1" == "next" ]
    a=$(ls /diary | grep -C1 $fname | tail -1)
    echo "/diary/"$a
elif [ "$1" == "prev" ]
    b=$(ls /diary | grep -C1 $fname | head -1)
    echo "/diary/"$b

This script gets a file name and return previous file or next file. In this case it returns previous day’s file or next day’s file when I run like this :

np.sh prev diary2015_04_20.md

When there is diary2015_04_21.md file it opens it. If now, it opens a previous file that there is.

LISP functions for emacs

(defun prevfile ()
  (find-file (substring (shell-command-to-string (format "~/sh/np.sh prev %s" (current-buffer)))0 -1) )

(defun nextfile ()
  (find-file (substring (shell-command-to-string (format "~/sh/np.sh next %s" (current-buffer)))0 -1) )

(global-set-key (kbd "C-S-<prior>") 'prevfile)
(global-set-key (kbd "C-S-<next>") 'nextfile)

M-x prevfile takes current buffer name, which is the file name, and open previous file in the diary directory. I set short cuts using global-set-key.
Ctrl+Shift+PageUp opens previous day’s diary
Ctrl+Shift+PageDown opens next day’s diary
and in my case, Ctrl+PageUp/PageDown opens previous/next buffer in emacs.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s