Sunday, December 11, 2011

Taking notes using emacs org-mode

After years of using emacs, it's surprising that I got to know org-mode so late. Better late than never. The first thing I did is to switch to org-mode to arrange my notes, on research, computer technology and life.

My criteria for a good note taker is as follows:
  1. Easy to organize topics / create note
  2. Full text search
  3. Sync a copy to internet
  4. Todo list and other tags in note
  5. Mathematics formula support
  6. Simple item folding and expanding
  7. The editor is stable and feature rich
  8. At best plain text, to access anywhere
With the help of Dropbox and some shell scripts, emacs org-mode is good for all the above aspects: (3) is implemented by putting the note folder into Dropbox. (4) - (8) are the advantages of org-mode or emacs. While here I use some simple shell scripts to implement (1) and (2) on command line.

I can roughly classify the notes I am taking. Thus I made several directories: cosmology, computer, etc. Then I put the following line in my .bashrc:

 em () { emacsclient --alternate-editor="" -n -c $1; }  
 takenote () { em /home/wangyi/Dropbox/elite/$1/$2.org; }  
 nc () { takenote cosmology $1; }  
 ncs () { takenote computer $1; }  
 # and a number of other note directories  
 t () { takenote links todo; }  
 d () { takenote diary $(date +'%Y-%m-%d'); }  

To search notes (also in .bashrc): I use "ns keyword" to search the keyword in all note directories, with matched key word highlighted in red; and then"nse keyword number" to open the note with listed number. "nf" lists all available note files and "nfe number" edit the file with listed number.

 RED=`echo -e '\033[31m'`  
 BLUE=`echo -e '\033[34m'`  
 NORMAL=`echo -e '\033[0m'`  
 # replace [number] by the same thing with blue color  
 bluenumber () { sed -e "s/^\[\([0-9]*\)\] .*elite\//$BLUE\[\1\]$NORMAL /g" $1; }  
 ns () { grep --exclude-dir=/home/wangyi/Dropbox/elite/00code -ri $1 /home/wangyi/Dropbox/elite | awk '{print "["NR"] " $0}'|sed -e "s/$1/$RED$1$NORMAL/ig" | bluenumber ; }  
 nse () { em $(grep --exclude-dir=/home/wangyi/Dropbox/elite/00code -ril $1 /home/wangyi/Dropbox/elite/ | awk -v LINENUM="$2" '{if (NR==LINENUM) print $0}'); }  
 nf () { find /home/wangyi/Dropbox/elite/ -name *.org | grep -v diary | awk '{print "["NR"] " $0}' | bluenumber; }  
 nfe () { em $(find /home/wangyi/Dropbox/elite/ -name *.org | awk -v LINENUM="$1" '{if (NR==LINENUM) print $0}'); }  
 nhelp() { cat /home/wangyi/Dropbox/elite/computer/note_commands.org; }  

Sorry the above script is not well structured, but it works for months now...

No comments:

Post a Comment