PRINTSCRIPT; print $script_style; include "/var/www/html/core/partc"; $linkpage = <<< PRINTLINK gfdl homepage > people > cobweb homepage > people > v. balaji homepage > this page PRINTLINK; print $linkpage; // GFDL header include "/var/www/html/core/partd"; $titlepage = <<< TITLEPAGE balaji's emacs setup TITLEPAGE; print $titlepage; // GFDL header include_once( '/var/lib/php/counter.inc' ); error_reporting(E_ERROR); require_once('magpierss/rss_fetch.inc'); require_once('magpierss/rss_utils.inc'); include "/var/www/html/core/parte"; $pagecontent = <<< ENDCONTENT <table> <tr valign="top"> <td class="west"> <table class="linklist"> <tr><th>Links</th></tr> <tr><td>emacs</td></tr> <tr><td>emacswiki</td></tr> <tr><td>emacs-muse: writing for the web</td></tr> <tr><td>emacs auctex: writing LaTeX</td></tr> <tr><td>emacs tramp: reading and writing remote files</td></tr> </table> </td> <td class="centre"> Why would anyone ever do their typing in anything else?

I do still use vi an awful lot, and haven't lost vi finger-memory...

And let's not forget that ed is the standard text editor.


My emacs setup

Here is my emacs setup...

<span class="cobweb"> Users with access to GFDL filesystems can examine or copy my /home/vb/.emacs. </span>

I run emacs in server mode: this means there is a single session running at any time. Anytime I open a new file in emacs from the command line, it's actually a client connecting to a single emacs session. This speeds up emacs startup by a lot. If there is a running emacs in server mode, you can start up emacs with the command emacsclient, which will connect to an existing "server".

These lines in ~/.emacs put emacs in server mode:




(add-hook 'server-visit-hook 'make-frame)

(add-hook 'server-switch-hook
          '(lambda ()
             (server-switch-buffer (other-buffer))))
(server-start)


(setq frame-title-format "%b")		; use buffer name for title
(setq display-buffer-reuse-frames t)    ; no new frame if already open

I use the shell alias:

alias e 'emacsclient -a emacs \!* &'

This always tries to start a client first... emacs is only started when emacsclient is unable to find a server to connect to.

The recommendation in emacs is to attach custom keybindings to the C-c table: for instance I've bound C-c g to the function goto-line. I have many keybindings. You may find these particularly useful:


(global-set-key (read-kbd-macro "RET") 'newline-and-indent)
(global-set-key (read-kbd-macro "LFD") 'newline)

Auto-indentation works very well for typing code, bulleted lists, and so on.

If you have a mouse with a scroll wheel, you may like these:

;; Wheel-mouse actions, from http://koala.ilog.fr/colas/mouse-wheel-scroll/
(defun up-slightly () (interactive) (scroll-up 5))
(defun down-slightly () (interactive) (scroll-down 5))
(global-set-key [mouse-4] 'down-slightly)
(global-set-key [mouse-5] 'up-slightly)

(defun up-one () (interactive) (scroll-up 1))
(defun down-one () (interactive) (scroll-down 1))
(global-set-key [S-mouse-4] 'down-one)
(global-set-key [S-mouse-5] 'up-one)

(defun up-a-lot () (interactive) (scroll-up))
(defun down-a-lot () (interactive) (scroll-down))
(global-set-key [C-mouse-4] 'down-a-lot)
(global-set-key [C-mouse-5] 'up-a-lot)

"Font-locking" is the emacs way of higlighting keywords based on the major mode of the file you're editing: there are modes for most languages including the C family, various fortrans, scripting languages like perl, python, and the various shells, text-processing modes like LaTeX, and so on. You turn on keyword highlighting with:

(global-font-lock-mode t)		; use font-lock to highlight all modes

flyspell-mode is an on-the-fly spell-checker, which will catch and highlight words it thinks you've misspelled, as you're typing. It's pretty useful and not too obtrusive or intrusive.

(require 'flyspell-mode nil t)          ; won't fail if no flyspell

turns this on, if it exists on the system. You can then choose when flyspell-mode is invoked. For example,

(add-hook 'text-mode-hook '(lambda ()
 			     (flyspell-mode t)
			     (auto-fill-mode t)))

turns it on for plain text mode. (auto-fill-mode is another minor mode, which automatically adds linefeeds while you type continuously, and always at a word boundary. You can also fill paragraphs by hand, by hitting M-q while the cursor is inside the paragraph you want formatted).

eshell-mode is a powerful interactive shell, invoked with M-x eshell. Among the useful settings for eshell mode:

(setq eshell-rm-interactive-query t)    ; like rm -i

woman is a nice mode for looking at manpages. Set it up with:

(autoload 'woman "woman" "Decode and browse a UN*X man page." t)
(autoload 'woman-find-file "woman"
  "Find, decode and browse a specific UN*X man-page file." t)

then, when you want to look at a manpage, type M-x woman.

I used to use ange-ftp for looking at remote files (which were transparently fetched by ftp). As ftp becomes obsolescent, it's been replaced by tramp, which does the same using ssh and scp.

This sets up tramp, and also sets up emacs to beep when it has finished importing or exporting a remote file.


(require 'tramp nil t)			; won't fail if tramp missing

(setq tramp-verbose 0)			; set to 10 when debugging
(setq tramp-default-method "scp")
(setq tramp-auto-save-directory "/tmp")
(defadvice tramp-handle-write-region (after make-tramp-beep activate)
  " beep after tramping."
  (interactive)
  (beep))
(defadvice tramp-handle-do-copy-or-rename-file (after make-tramp-beep activate)
  " beep after tramping."
  (interactive)
  (beep))
(defadvice tramp-handle-insert-file-contents (after make-tramp-beep activate)
  " beep after tramping."
  (interactive)
  (beep))

With tramp correctly installed, user foo can edit files on the remote machine bar.edu, where she has ssh access, as follows:

C-x C-f /foo@bar.edu:/a/b/c

and it will be as though she were editing the file /a/b/c locally. All the normal keybindings will work, e.g C-x C-s will save the file to the remote machine transferring it via scp. With a properly configured ssh connection (using keypairs) she'll never even type any passwords.


Using emacs tags to navigate a source tree

Modern editors such as emacs and vi have many features built upon some ability to parse the syntax of the file that's being edited. For instance, syntax highlighting of source code is a great editing aid. Another feature of syntax-sensitive editors is to enable the traversal of a complex source tree. This is done by generating a set of tags that bookmark key spots in the code, such as the first line of every procedure. Thus if you find call foo() while editing Fortran source, and would like to examine subroutine foo but have no idea which source file it's found in, the editor would use its tag or bookmark for foo to open the right source file and take you there.

Tags for emacs are generated by running etags <list of source files>. This creates a file called TAGS containing a complete list of cross-references and bookmarks across the entire source tree in the list you gave it. (The equivalent feature in vi is a file called tags (lowercase) which is generated by running ctags <list of source files>. I'm told that other editors like nedit also understand vi's tags file, but can't vouch for it.)

If you used mkmf to generate your Makefile, you can just type make TAGS to create the TAGS file: mkmf is tags-aware. (Similarly, make tags for vi tags.)

Once you have a valid TAGS file, here's how you use it.

There are many more tags-related emacs commands, but these are the basic ones, and the most useful. You'll never be cd'ing up and down your source tree again.

I'm not exactly sure how to achieve the same functionality in vi or nedit but I'm sure the same set of functions exists.

A good place to begin exploring these issues at GFDL might be at the vim wikipage. There also appears to be a mailing list for vim users at oar.gfdl.vim@noaa.gov.


The LaTeX Beamer class is a spectacular method for producing presentation material. Please don't use PowerPoint anymore!

I've structured my beamer example in the form of a presentation. Here's the associated LaTeX source, and you may also need to download this example movie.

</td> ENDCONTENT; print $pagecontent; $url = 'http://www.emacswiki.org/emacs/full.rss'; $rss = fetch_rss($url); if( $rss ) { echo '\n"; foreach ($rss->items as $item) { $href = $item['link']; $title = $item['title']; echo "\n"; } } $url = '0http://groups.google.com/group/gnu.emacs.help/feed/rss_v2_0_topics.xml'; $rss = fetch_rss($url); if( $rss ) { echo '\n"; foreach ($rss->items as $item) { $href = $item['link']; $title = $item['title']; echo "\n"; } } $url = '0http://groups.google.com/group/comp.emacs/feed/rss_v2_0_topics.xml'; $rss = fetch_rss($url); if( $rss ) { echo '\n"; foreach ($rss->items as $item) { $href = $item['link']; $title = $item['title']; echo "\n"; } } $pagecontent = <<< ENDCONTENT </table> </td> </tr> </table>
emacs-muse-mode created by v. balaji (balaji@princeton.edu) in emacs using the emacs-muse mode.
ENDCONTENT; print $pagecontent; print "last modified: ". date( "d F Y", getlastmod() ); print "
this page visited: ".getCount(). " times "; include "/var/www/html/core/partf"; include "/var/www/html/core/partg";