From charlesreid1

(Mention how to change Meta key from Esc to Option on Macs)

See also Viper Mode - I'm a vim user at heart, so I need viper mode to use vim shortcuts in the Emacs environment.

See also Aquamacs - version of Emacs using Aqua (native Mac window styling/keyboard functionality).

Installation

Configuring

On the Mac, you can use emacs in several different forms. Your options are:

  • Use the system default emacs, version 22.1.1, which is out of date and command-line-only
  • Use Aquamacs, a really nice port of Emacs that uses Aqua and is already built with many Mac key bindings
  • Use Carbon emacs, another port of Emacs using the Carbon window manager
  • Build your own Emacs (which can be built in the style of command-line-only emacs, xemacs, or Carbon emacs)

I highly recommend Aquamacs for Mac users, but if you're looking for a more universal emacs experience (one that won't leave you confused and looking up keyboard shortcuts when you have to use emacs remotely on a *nix terminal), I would highly recommend building emacs from source. This also allows you to customize it as you see fit, which is appropriate, since emacs is famous for being the world's most customizable text editor.

To build from source, you can build a command-line-only emacs using this configure line:

#!/bin/sh

./configure \
 --prefix=/path/to/your/emacs \
 --without-sound \
 --with-gif=no

The --without-sound argument is a personal preference, as I detest the audible system bell with a passion. Additionally, the --with-gif=no argument was used because I didn't want to bother installing libraries that I will never use.

To build xemacs, which will use X11 (as long as you have it installed), use this configure line:

#!/bin/sh

./configure \
 --prefix=/path/to/your/emacs \
 --with-x \

plus any other arguments you want. Likewise, to create a build of emacs using NextStep, which is another name for the Cocoa window system, use this configure line:

#!/bin/sh

./configure \
 --prefix=/path/to/your/emacs \
 --with-x \
 --with-ns

Another advantage of building from source is, if you wish, you can add CCFLAGS="-g" to make a debug build of emacs and you can run emacs through a debugger.


Modes

Org Mode

Dot Emacs File

If you look around on the web, you can find some very extensive .emacs initialization files - for example,

http://www.sci.utah.edu/~cscheid/software/cscheid.emacs

http://www.stanford.edu/~rgm/comp/dotemacs.html


Some Initial Emacs Settings

; ---------------------------------------
; Emacs startup settings

; Get rid of that annyoing "Welcome" screen
(setq inhibit-startup-screen t)

; Nothing in scratch buffer
(setq initial-scratch-message nil)


Appearance

You can download emacs color themes at the emacs wiki. I use the hober color theme, which looks like this:

The emacs hober color theme.

; ------------------------------------------------
; Color themes
(add-to-list 'load-path "/Users/charles/pkg/emacs/color-theme-6.6.0")
(require 'color-theme)
(eval-after-load "color-theme"
  '(progn
    (color-theme-initialize)
    (color-theme-hober)))

Keyboard Shortcuts

I use Firefox, and like many other programs, it provides a shortcut to page through tabs via Control+Tab.

; ----------------------------------------
; Keyboard settings/shortcuts

; from http://www.sci.utah.edu/~cscheid/software/cscheid.emacs
(global-set-key "\C-x\C-g" 'goto-line)


; cycle through buffers with Ctrl-Tab (like Firefox)
; (If you want a more advanced version that ignores certain buffers, you could take a look at
(global-set-key (kbd "<C-tab>") 'bury-buffer)


; ask for "y/n" instead of "yes/no"
(fset 'yes-or-no-p 'y-or-n-p)
(global-set-key "\C-h" 'backward-delete-char)


Modes, Modules, Extensions

I also include some things in my initialization file for Org Mode (see above section). When I start emacs, I want to start in Org Mode, in the directory ~/org.

; -----------------------------------------
; Emacs Org Mode:
; (see http://orgmode.org/worg/org-tutorials/orgtutorial_dto.php)

; Make sure org mode is loaded!
(message "Adding Org Mode to path...")
    (setq load-path (cons "~/pkg/emacs/org-7.01h/lisp" load-path))
(setq load-path (cons "~/pkg/emacs/org-7.01h/contrib/lisp" load-path))

; Log when tasks are completed
(setq org-log-done t)

; To save clock history across Emacs sessions:
; http://www.gnu.org/software/emacs/manual/html_node/org/Clocking-work-time.html
(setq org-clock-persist 'history)
(org-clock-persistence-insinuate)

; To add a note when you clock out:
(setq org-log-note-clock-out t)

; use CDLaTeX to enter math
; http://www.gnu.org/software/emacs/manual/html_node/org/CDLaTeX-mode.html#CDLaTeX-mode
(setq load-path (cons "~/pkg/emacs" load-path))
(add-hook 'org-mode-hook 'turn-on-org-cdlatex)

; Start emacs in ~/org
;(setq default-directory "~/org")

; Start emacs in org mode
(org-mode)


Another module I use is called icicles, it provides pre-loaded tab-completion that I can move through with arrow-up or arrow-down.

; -------------------------------------------------
; load icicles package for enhanced autocompletion

(add-to-list 'load-path "/Users/charles/pkg/emacs/icicles/")
(require 'icicles)