Tips & Tricks for the Emacs editor
Location : Lennart's TikiWiki > Emacs
Emacs
Table of contents
Emacs is a versatile text editor available for Unix/Linux. EMACS stands for Escape Meta Alt Control Shift.
It supports many things, including syntax highlighting (for C/C++, IDL, LaTeX, HTML and others) and an interface to RCS (the revision control system). My .emacs file with some customisations is attached to this wiki page.
I recently bought the book Learning GNU Emacs 3rd ed. by Cameron et al. It's a great book, easy to read and even though I've been using Emacs for more than five years now I still learned a lot from it. It's also great as a reference.
These are the basic commands for Emacs:
exit Ctrl-x Ctrl-c save Ctrl-x Ctrl-s save as Ctrl-x Ctrl-w undo Ctrl-Shift-_ search Ctrl-s search-replace Alt-Shift-5
Caps-lock vs. Ctrl
Emacs relies heavily on shortcuts using the Ctrl key, which is quite awkwardly positioned on standard keyboards. You'll find yourself folding your pinky to reach it. On oldskool keyboards (like the one I have for Vitamientje), the Ctrl key was placed where Caps-lock resides these days. But who needs Caps-lock anyway? It usually only there to annoy you when you're logging in and you password doesn't seem to work. So let's just replace it with the control key. The easisest way to do that is to put the line Option "XkbOptions" "ctrl:nocaps" in the InputDevice section for your keyboad in the /etc/X11/xorg.conf file. Furthermore, when using Gnome go to the System menu -> Preferences -> Keyboard and in the Layout Options tab Change the Ctrl key position.IDL
At http://www.idlwave.org you can find out all about the IDLWave mode for Emacs. This is a great mode to use when programming and running IDL.LaTeX
Several shortcuts exist when using Emacs to edit LaTeX files. See the LaTeX page.Maxima
Maxima is a Computer Algebra System, much like Mathematica. And, good thing, there's a maxima-mode in Emacs. Even better is the imaxima-mode available here. It formats maxima's output using LaTeX!The maxima-mode is available in the UbuntuLinux repositories, but the imaxima-mode has to be installed by hand (pretty simple using configure, make, make install). The add these lines to your .emacs file:
;; Autoload the imaxima files from /usr/local/
(autoload 'imaxima "imaxima" "Image support for Maxima." t)
(autoload 'imath-mode "imath" "Interactive Math minor mode." t)
(setq imaxima-fnt-size "Large")
(setq imaxima-use-maxima-mode-flag t)
Using RCS or SVN from Emacs
If you use the emacs editor to edit a file registered with RCS, you can give emacs commands to perform the necessary co -l and ci -u operations and thus avoid using separate shell commands. The commands you give to emacs are nicely listed at http://www.credmp.org/2007/12/08/emacs-hidden-gems-version-control/. See also the EmacsWiki entry.Running make from Emacs
When working on programming projects for example, Emacs can call the make utility (M-x compile) to build your project. It captures the output in an Emacs window and using C-x ` (Ctrl-X followed by the back tick you can parse through the errors while emacs tries to look up the line where the error was produced. In my personal .emacs file (the first of the links below) I bound the key C-x m to this command to save some typing.Emacs shell
In order to make the emacs shell print the colored output of e.g. the ls command right (i.e. without showing the ANSI excape sequences) use the foloowing command: M-x ansi-color-for-comint-mode-on.These are the sheel cusomisations I have in my .emacs:
;; Interpret and use ansi color codes in shell output windows
(ansi-color-for-comint-mode-on)
(setq comint-scroll-to-bottom-on-input t) ; always insert at the bottom
(setq comint-scroll-to-bottom-on-output t) ; always add output at the bottom
(setq comint-scroll-show-maximum-output t) ; scroll to show max possible output
(setq comint-completion-autolist t) ; show completion list when ambiguous
(setq comint-input-ignoredups t) ; no duplicates in command history
(setq comint-completion-addsuffix t) ; insert space/slash after file completion
;; Hide passwords in Emacs shell
(add-hook 'comint-output-filter-functions 'comint-watch-for-password-prompt)
;; make completion buffers disappear after 3 seconds.
(add-hook 'completion-setup-hook
(lambda () (run-at-time 3 nil
(lambda () (delete-windows-on "*Completions*")))))
Emacs RegExps
Regular expressions in Emacs are a bit different from the ones in e.g. Perl or grep. For example there are no POSIX compliant constructions like :digit: .Stevey's blog on Emacs RegExps shows some examples.
To insert the newline character in RegExp searches use: C-q C-j.
A table of the special RegExp characters can be found here at 3monkeyweb.com's Emacs tutorial.
Links
- My personal .emacs file can be found here.
- The Emacs Reference Card at refcards.com.
- Emacs Reference Chart
- The Emacs Wiki at emacswiki.org.
- Sams Teach Yourself Emacs in 24 Hours, the full text of the book (1999).
- On-the-fly spell checking in Emacs
- Check out http://tulrich.com/geekstuff/emacs.html and this linux journal article for tips on using etags to navigate through source code.
- Minor emacs wizardry, a blog.
- M-x all-things-emacs, another blog.
Created by lennart. Last Modification: Thursday 14 of August, 2008 13:31:08 CEST by lennart.
Sidebar
Sidebar
Last articles
-
Some notes on installing Debian Etch on an SGI O2 machine
Recently I helped a friend to install Debian 4.0 (Etch) on an old SGI O2 MIPS machine. This article lists some notes I made during this process.
-
Notes on getting a Tektronix XP217C X-terminal to work with my Linux server
These are some notes of the steps I took to get my Tektronix XP217C X-terminal Vitamientje to connect to my Linux server Jerom.
-
Setting up WebDAV with Apache
This article shows which steps I took to setup a webDAV share on my Apache webserver
-
Making a Pundit-R into a MythTV frontend with Gentoo
This article lists the steps I took to make Lambik, an Asus Pundit-R into an HTPC with the mythTV software. It's not too fancy, but it'll help me retrace my steps in case of a crash or some other evil.
-
Some notes on installing openVPN
Some notes on installing openVPN on my server Jerom.






