UP | HOME

Class 7: Emacs and org-mode (DRAFT)

Table of Contents

Reminder to log in to the IRC    irc

Please only use the Ubuntu virtual machine in class today. There is too much confusion when switching between Windows and Ubuntu.

Make sure to not use "researchtools" as your login name for the IRC channel!

Introduction

Today, we will start off with a little more background on where to find material. We will look at man pages online and the Safari Technical Books. Last time, the question was asked how to find out about what software is available and which is already installed. There is a section on that, but I will leave it to you to read outside of class.

Next, we will dive into taking notes with emacs org-mode. I take most of my work notes in org-mode and some students use it to keep track of the their research and draft material for their thesis. All of the lecture notes for this class and the homework assignments are written in org-mode format.

HOMEWORK: The end of this document links to homework due on Thursday. Please pay close attention to detail when doing the homework.

Emacs and org-mode reference cards

Print these double sided:

In the virtual machine, you can open either of these links:

Or run these commands:

xdg-open /usr/share/emacs/23.2/etc/refcards/refcard.pdf
xdg-open /usr/share/doc/org-mode/org.pdf.gz

Ubuntu man pages online    man

Sometimes you have a second computer next to you when working. One of the many ways that you can take advantage of that computer by using it to view "man pages". Ubuntu has the man pages online. We are using "Ubuntu 11.04" during this class, but man pages for other versions should be very similar.

http://manpages.ubuntu.com/

Try searching for minmax. If you use the search box in the top left, you will be taken to a menu of Ubuntu versions. Select 11.04 and you will be taken to this page:

http://manpages.ubuntu.com/manpages/natty/en/man1/minmax.1gmt.html

Technical/Computer Online Books at UNH - Safari

Safari Books Online provides technical books online. UNH has a subscription, so if you are a student, staff or faculty at UNH, you can get access to a wide range of technical books. If you are not at UNH and your job does not provide the service, you can sign up for a personal account. This can save you a lot of money over buying a large number of books. However, I do not think that you can take these with you off line and I still like "dead tree" books (aka the real thing).

You should now be able to get access to a very large number of books. Some books that might be useful for this lecture '''NOTE:''' I have not necessarily read these books.

./figures/safari-books.jpg

A quick look at Ubuntu and Software    ubuntu sysadmin

There have been questions in class as to how to find out which software is installed. I'll give you a quick intruduction here.

Which version of Linux?

First, how do you find out which version of linux you are using? Most linux systems have a file that describes the version of linux. It's usually a "release" file in the /etc directory. "etc" is a directory tree that contains most of the system wide settings. On Redhat and CentOS Linux systems, there is a /etc/redhad-release file:

ls -l /etc/*release
# -rw-r--r-- 1 root root 27 Apr 25  2010 /etc/redhat-release

cat /etc/redhat-release 
CentOS release 5.5 (Final)

cat /etc/issue
CentOS release 5.5 (Final)
Kernel \r on an \m

Ubuntu and any other system that follows the Linux Standard Base (LSB) guidelines for Linux have one or both of two files named /etc/lsb-release and /etc/issue that document the version of the system:

cat /etc/issue
Ubuntu 11.04

cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=11.04
DISTRIB_CODENAME=natty
DISTRIB_DESCRIPTION="Ubuntu 11.04"

Command line exploration of software on the system and available for install

There are many different ways to look at the software on a Ubuntu computer, but this is the way that I go about it.

First, what is installed?

researchtools@ubuntu:~$ dpkg --get-selections | wc -l
1789

dpkg --get-selections | head
adduser                                         install
apel                                            install
apparmor                                        install
apparmor-utils                                  install
apport                                          install
apport-symptoms                                 install
apt                                             install
apt-transport-https                             install
apt-utils                                       install
apt-xapian-index                                install

dpkg --get-selections | grep emacs
emacs                                           install
emacs-jabber                                    install
emacs23                                         install
emacs23-bin-common                              install
emacs23-common                                  install
emacsen-common                                  install
python-ropemacs                                 install

If you want to read through them all, use a pager (e.g. more, less or most):

dpkg --get-selections | less

If you know a package that is installed, you can use listfiles option to dpkg. A common task is to list the programs available in a package.

dpkg --listfiles gmt | grep bin | head
/usr/bin
/usr/bin/GMT
/usr/lib/gmt/bin
/usr/lib/gmt/bin/gmt_shell_functions.sh
/usr/lib/gmt/bin/gmtget
/usr/lib/gmt/bin/gmtlogo
/usr/lib/gmt/bin/isogmt
/usr/lib/gmt/bin/psbbox.sh
/usr/lib/gmt/bin/blockmean
/usr/lib/gmt/bin/blockmedian

If you would like to know which package a file belongs to, you can ask the system. We can combine that with the command type that tells you where in your path a program is located. For example, the sudo command that gives you access to administrator capabilities (aka "root"). The "hashed" means that the shell has an internal table of commands to speed up searching.

type sudo
sudo is hashed (/usr/bin/sudo)

dpkg --search /usr/bin/sudo
sudo: /usr/bin/sudo

There are also an interactive text based program to examine packages without a full graphical interface:

http://wiki.debian.org/Aptitude

Graphical software management - Synaptic

./figures/synaptic-package-manager.png

Introduction to Emacs    emacs orgmode

Emacs is a very powerful text editing environment. It is the editor that I use for writing this class, for programming, and many other tasks. As you use emacs, you will discover that that many of the shortcuts in emacs have been adopted by other programs (especially bash).

I got started in seriously using an electronic work log in 2004 at the suggestion of Anne Wright, while I was working at NASA JPL. Paper logs are really helpful, but they are hard to search.

We will start out jumping right into writing a log in emacs. I use emacs org-mode to keep most of my work logs. I don't use as many features of org-mode as I would like, but it really pushes me to take better notes. I started using org-mode for my work log in 2010 (I found some old notes files and have since converted them into org mode. e.g. 1998, 2000, and 2001).

From the number of lines of log files, you can see that I take electronic logs very seriously.

wc -l kurt-????.{txt,org}
     192 kurt-1998.org
     149 kurt-2000.org
     327 kurt-2001.org
      62 kurt-2002.txt
     475 kurt-2003.txt
   12139 kurt-2004.txt
    6644 kurt-2005.txt
   19332 kurt-2006.txt
   28292 kurt-2007.txt
   28746 kurt-2008.txt
   18740 kurt-2009.txt
   30945 kurt-2010.org
   21929 kurt-2011.org

Org-mode is much more useful than just straight text. It can produce a table of contents and helps me keep a much more organized log.

./figures/org-mode-contents.png

./figures/org-mode-example-entry.png

Initial setup

I missed one emacs package that we need for today in the Virtual Machine. Without a package called htmlize, org-mode output will not have code colored. It is a part of the emacs goodies package. texlive is used to produce PDF documents.

sudo apt-get install emacs-goodies-el
sudo apt-get install texlive
sudo apt-get install texlive-latex-extra

Opening files

I will give an introduction to using emacs for basic files here. This really needs a video of the section to show what I'm doing.

  • opening a directory
  • searching with C-s

Basic org-mode - outlining

The format for org-mode is very similar to Mediawiki. However, the characters used to mark up the text are slightly different. There are large numbers of markup languages, but we will ignore the others right now.

Start by opening a new org mode file. Org-mode starts by default if the file name ends in ".org". "File" -> "Visit New File" and pick type in "example.org".

An alternative approach is to use the keyboard shortcut:

C-x C-f example.org

At the bottom of the window, you will see:

--:--- example.org All L1 (Org)------------

You are staring at a blank page, but there are helpers under the "Org" and "Tbl" (meaning table) menus that just appeared at the top of the Window. Select Org -> New Heading. You will see a "*" appear. Headings are made up of 1 or more "*" characters followed by the text.

* Introduction

Sub-headings have two like this:

** This is a sub heading

You can type paragraphs in any heading or sub-heading.

Lists start with "-". A list looks like this:

- first item
- another item
- yet another

The list will look like this:

  • first item
  • another item
  • yet another

Seeing the results?

But how do we see what the results are??? We have to "publish" or "export" the document. There are many formats, but we will start with HTML.

"Org" -> "Export/Publish"

You will now see lots of options for the output. Start off by trying "export as HTML and open in browser".

Press the letter "b"

You now should see Firefox open up and show the file "example.html".

You can also export to a pdf:

"Org" -> "Export/Publish" -> press "d"

Tables

Tables are built with the vertical "|" character. Entries with all "—" characters create horizontal rulers.

| Column header  | something else           |
|----------------+--------------------------|
| hello          | world                    |
| a second entry | what do you want to say? |

Would look like this:

Column headersomething else
helloworld
a second entrywhat do you want to say?

Examples and source code

You can also create example blocks and source code blocks. Inside of an example, it will not show the normal formatting. Try this:

#+BEGIN_EXAMPLE 
* This is a heading
#+END_EXAMPLE

Alternative strategies for note taking

See also: Comparison of Notetaking Software and Comparison of Wiki Software

TODO HOMEWORK - shell and org-mode

Author: Kurt Schwehr

Date: <2011-09-20 Tue>

HTML generated by org-mode 7.4 in emacs 23