Charles' Emacs Page

Useful Links


Having a good .emacs files is very useful. If you can't find one anywhere else, please grab mine.

Note You may have to comment out (using ; characters) parts relating to Tramp and html-helper-mode if you do not have these packages installed.


Here are a few useful things you can add to your .emacs file. Here are some random commands to run in emacs

Tramp and Hobo


Tramp is a very useful package that lets you use a local version of emacs and edit remote files. Please visit the Tramp homepage for more details. Tramp is installed as part of the base package for Emacs 22.

Once you have tramp installed, the usage is pretty easy. You use <ctrl>-x <ctrl>-f as normal and find the file using

<ctrl>-x <ctrl>-f /[]localpath
<ctrl>-x <ctrl>-f /[]/absolute/path

Do not forget the / at the beginning of the filename.

Tramp and AutoSave

The autosave feature in emacs can be quite annoying when using tramp (this can take 20 seconds and you will not be able to use Emacs while this is happening). I recommend one of two things: either turning off autosave in buffers you are editting with tramp or telling emacs to autosave tramp files in a local directory.

To turn off autosave in a buffer, You can do <alt>-x auto-save-mode (or by typing <F11> if you are using my .emacs file).

To autosave tramp files in a local directory, add similar lines to your .emacs file:

 (setq tramp-auto-save-directory "~/emacs/tramp-autosave")

I wrote a perl script called that you run on a remote string to edit a particular file:

cplager@fcdflnx4> ~/.emacs


Hobo is a similar package to tramp that is less flexible (i.e., always uses scp), but faster and easier to install (see hobo.el for details; Joseph Casadonte has this and other emacs information here). Here's what I did to get hobo up and running
;; Hobo
(setq load-path (cons "/home/cplager/emacs" load-path))
;; hobo.el is in /home/cplager/emacs
(require 'hobo)
(setq hobo-use-agent nil)
(global-set-key [f10] 'hobo-find-file) ;; use [f10] key to load new file

Note: I have found that if I load a file with hobo and then change the mode (e.g., change to html_helper_mode), emacs forgets that the buffer is a hobo buffer and doesn't push the changes back onto the original server.

Auto time stamps for HTML files

Here's a useful function for auto-time-stamping html files. After grabbbing d a copy of html-helper-mode.el (if you don't already have it installed) and adding
;; Auto dating for html files
(setq load-path (cons "/cdf/home/cplager/emacs" load-path)) ;;html-helper-mode.el is saved in /cdf/home/cplager/emacs
(autoload 'html-helper-mode "html-helper-mode" "Yay HTML" t)
(setq auto-mode-alist (cons '("\\.html$" . html-helper-mode) auto-mode-alist))
(setq html-helper-do-write-file-hooks t)
to my .emacs file, I add following lines:
<!-- hhmts start -->
Last modified: Fri Apr 15 14:06:28 CDT 2005
<!-- hhmts end -->

Rectangle functions

To do rectangles in emacs, you set your mark (C- usually) at one corner of the rectangle and the point at the other (or left-click one corner and right-click the other) and enter a rectangle command such as: C-h a rectangle gives you help on rectangle functions


There is a most recently-recorded macro, which I use a lot, and also I think named macros, which I haven't used yet. C-h a macro gives you help on macros, and you can also look up the subject in the emacs info browser (C-h i). To record a macro: I often perform a search in a simple emacs macro to put my cursor at the next appropriate spot. This works nicely because I often want to run the macro many times until the end of the document. The search will fail, which makes a beep, which stops the macro from running. Also, if you're recording a macro and make a mistake, as I often do, hitting C-g a time or two will get you out of macro record mode.

Running shell commands on selected text

Personally, I find Perl's syntax for making substitutions much more powerful than what's built-in to emacs. What emacs let you do is run a script command on part of an emacs buffer.

To do this:

Last modified: Wed Jul 6 10:02:13 EDT 2011