This is Anupam’s personal page.
These tips and tricks have been tested on plain-vanilla CarbonEmacs version 22.1 on OS X. YMMV on other versions.
In addition to the tips below, tons of other OS X tips can be found at:
Emacs comes with a
‘locate’ command that uses the
locate system command to find files within your system. On OS X, it is easier to use Spotlight, which is trivial to enable in Emacs.
.emacs file, add the following code:
(setq locate-command "mdfind")
M-x locate enter your search here
Your search results will be populated in a new Window.
Traditionally, mice on Macs have had just one button (including the iBook/Powerbook trackpads) - even through Mac OS (including OS X) can accept 2 or 3 button input without any problems.
If you want to emulate a three button mouse in Emacs on OS X, a simple customization option will do the trick.
M-x customize-group and enter
mac. Navigate to the “Mac Emulate Three Button Mouse” and select option 2 or option 3. Voila!
This is an absolute must, unless you like contorting your fingers and risk RSI. It is also an easy thing to do on OS X.
You need to bring up the System preferences → Keyboard & Mouse
and then click the “Modifier Keys” to remap the Capslock to Control.
This is available on OS X 10.4 and later versions.
The standard key-binding for moving to the other frame (
‘other-frame’) is C-x 5 o. That’s quite a few key-strokes, and also does not match with the standard OS X key-mapping for switching windows, which is Command-`. On OS X, the
Command key maps to
However, this is easy to fix. Put the following code-fragment into your
(define-key icicle-mode-map [?\M-`] nil) # Only needed if you use Icicles (global-set-key [?\M-`] 'other-frame) # This sets the key binding
Note that by default
‘tmm-menubar’ which can also be accessed via
[f10]. Also, you do not need the first line (to undefine the key binding in Icicles if you do not use that package.
Emacs is a great editor, but has one setback - it is slow to startup if you have loads of packages to load. On my G4 iBook, it takes around 45 seconds before Emacs becomes usable (OK - I use lots of packages).
However, Emacs is not meant to be restarted every so often. The canonical usage is to start Emacs once, start the server mode (see EmacsClient) and then use the emacsclient from the command line to invoke the editor instance when needed.
On my system, I have aliased the
‘emacsclient’ binary to be
‘ec’, which is much simpler to type.
I.e., in my `.bashrc’, I have
alias ec emacsclient
I have also defined
$EDITOR to use
‘emacsclient’ when possible, and
‘vi’ otherwise. However, instead of directly assigning to the
$EDITOR environment variable, I have a small shell-script to define the default editor I want to use. This script is then assigned to the
The code for the default-editor shell-script (named
#!/bin/bash # Set up a default editor for the shell # Use Emacs if already open, and vi in other cases (including fallback) EMACS_EDITOR=`which emacsclient` if [ -x "$EMACS_EDITOR" ]; then $EMACS_EDITOR -a vi "$@" else vi "$@" # Never fails! fi
And then, in the
.bashrc file, I have:
if [ -x $HOME/bin/default_editor ]; then export EDITOR=$HOME/bin/default_editor else export EDITOR=`which vi` fi
BTW, the code above assumes that you use bash as the primary shell in your terminal. You can however trivially modify the scripts above for your specific shell.
Very useful for OS X, where the default path is set by plists.
;;; Define a function to setup additional path (defun my-add-path (path-element) "Add the specified path element to the Emacs PATH" (interactive "DEnter directory to be added to path: ") (if (file-directory-p path-element) (setenv "PATH" (concat (expand-file-name path-element) path-separator (getenv "PATH")))))
and use it as:
;;; Set localized PATH for OS X (if (fboundp 'my-add-path) (let ((my-paths (list "/opt/local/bin" "/usr/local/bin" "/usr/local/sbin" "/usr/local/mysql/bin" "~/bin"))) (dolist (path-to-add my-paths (getenv "PATH")) (my-add-path path-to-add))))
Icicles has quite a few files (Icicles - Libraries) that form the package, and LeWang has provided a shell script at get-icicles.sh to conveniently download all the required files. However, on Windows, unless you have Cygwin (http://www.cygwin.com/), it is difficult to run this script.
The ELPA package system by TomTromey provides an elegant mechanism to download packages from within Emacs itself, using the UrlPackage. The code below allows you to use a similar mechanism to download Icicles.
To use, please select the code snippet below and paste it in the
*scratch* buffer, move your cursor to the last closing parenthesis, and hit C-x C-e
The download may take some time - be patient!
;; Evaluate this code in a scratch buffer to download all Icicles files. (let ((buffer (url-retrieve-synchronously "http://www.emacswiki.org/cgi-bin/emacs/download/download-icicles.el"))) (save-excursion (set-buffer buffer) (goto-char (point-min)) (re-search-forward "^$" nil 'move) (eval-region (point) (point-max)) (kill-buffer (current-buffer)))) ;; ---------------------------------^ ;; Place your cursor HERE and hit C-x C-e
The actual lisp file which downloads rest of Icicles is at: download-icicles.el
After discussions with DrewAdams, I created an alternate mechanism to download Icicles from within Emacs. You need to perform the following steps:
(load "~/<dirname>/icicles-install")(Note: Adjust the directory name for your local download directory.)
C-x C-eto load the file.
~/icicles) by running
‘icicle-download-wizard’from the mini-buffer. I.e., run
This will run a prompt-based wizard which will guide you through the download and optional byte-compile steps.