emacs-experimentation

My experiences as a [g]vim user trying out emacs.

Day 1:

Emacs commands

Running emacs was no problem, as it was already installed from Fedora’s repository. Reading through some emacs tutorials, I found Emacs For VI Users very helpful.  Probably my most used  vi commands are delete line (dd), yank line (yy), and put (p or P).  Emacs  confusingly uses “yank”  to describe the  vi equivalent “put” command of inserting saved text into the document.  Getting used to the sequences of ctrl / alt + key is strange when I’m used to the efficient vi commands.  ”yy” becomes “Ctrl+a  Ctrl+k Ctrl+k Ctrl+/”.

Tab behavior

Started trying to edit some c++ files using emacs, but found that the default tabbing behavior was messing up my indentation.  The default emacs uses 2 spaces per indentation, and will use the tab key to automatically indent code instead of inserting a tab character.  I like to tab-indent my code and view it as 4 spaces / tab.  This was frustratingly difficult to solve, as emacs has so many options, and many of the emacs options have cryptic names and unclear descriptions.  I finally found some sane lines to put into my ~/.emacs file from Emacs Tips N Tricks For Everybody.  The

(global-set-key "\C-m" 'newline-and-indent)

line is really nice to emulate vi’s autoindent feature. Understanding GNU Emacs and Tabs is also useful for understanding emacs’s special tabbing behavior.

Day 2:

Antialiased fonts

Discovered that emacs 23 supports antialiased fonts, but there’s no stable release yet, and no Fedora 8 rpm.  So, I downloaded the source from cvs and built.  Now running

emacs --font="monospace-10"

works, and emacs looks great.

Start in background

I wrote a bash wrapper to always start emacs in the background (similar to gvim) with the monospace font.

#!/bin/bash
# start emacs in the background with the monospace font
exec emacs-23.0.92.1 --font="monospace-10" "$@" &

My ~/.bashrc has an alias to run this wrapper. (I put the wrapper in ~/bin/emacs)

# .bashrc alias
alias emacs="~/bin/emacs"

Matlab files

Opening a matlab .m file tries to use the ObjC mode. You can add the matlab mode to emacs using the matlab.el file from matlab-emacs. I put the file at ~/.emacs_addons/matlab.el and added these lines to my ~/.emacs file:

; Add addons dir to path
(setq load-path
      (append (list nil "~/.emacs_addons")
              load-path))
; Add matlab.el module
(autoload 'matlab-mode "matlab" "Enter MATLAB mode." t)
(setq auto-mode-alist (cons '("\\.m\\'" . matlab-mode) auto-mode-alist))
(autoload 'matlab-shell "matlab" "Interactive MATLAB mode." t)

Regular expressions

Emacs offers search and replace with regular expressions using the Ctrl-Alt-% command, with some caveats

Tab bar

Opening multiple files in emacs puts each file into a buffer, but there is no [g]vim/firefox-like tab bar which shows the open files. You have to go through the list of buffers or split your window. But at least there is the TabBar mode addon.