Emacs notes

From DiLab
Revision as of 14:48, 10 November 2010 by Leo (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Some emacs lisp examples

Here: http://xahlee.org/emacs/elisp_examples.html

Run lisp in emacs

You can run a builtin or loaded lisp module command in Emacs like this (example - starting the speedbar):

M-x speedbar

You can also try things out in the *scratch* buffer. For example:

  • Bring to front the *scratch* buffer
  • Type your lisp. e.g. (+ 2 3)
  • Press Ctrl+X Crtl+E
  • Watch the result in the bottom (echo) part of the Emacs window/screen

How to open new files in already open Emacs window (using gnuserv)

http://www.debian-administration.org/articles/257

Shortcut:

sudo apt-get install gnuserv emacs-snapshot

Add to your .emacs configuration file the following:

;;
;;  Start GNUServe process when starting up.  This lets us send new files
;; to previously spawned emacs process.
;;
(load "gnuserv-compat")
(load-library "gnuserv")
(gnuserv-start)

;; When loading files reuse existing frames.
(setq gnuserv-frame (car (frame-list)))

;; Stop annoying prompt on kill buffer but member of gnuserv
(setq kill-buffer-query-functions nil)

Create a shortcut script to call emacs and alias emacs command with this:

#!/bin/sh
# ~/bin/emacs

# "apt-get install lsof" - if you're missing "lsof".
lsof /usr/bin/emacs-snapshot | grep $USER >/dev/null 2>&1

if [ "$?" -eq "1" ]; then
    /usr/bin/emacs-snapshot $* &
else
    /usr/bin/gnuclient $* &
fi

Pretty fonts for Emacs editor

How to replace built-in emacs fonts. http://peadrop.com/blog/2007/01/06/pretty-emacs/

Shorcut:

sudo aptitude update
sudo aptitude install emacs-snapshot emacs-snapshot-el

echo "Emacs.font: Monospace-10" >> ~/.Xresources
xrdb -merge ~/.Xresources

Note, if you get the "No fonts match `Monospace-10'" message, make sure you are running the emacs-snapshot and not your previous emacs version.


Emacs and UTF-8

Setting up Emacs to prefer UTF-8 encoding for files: add to .emacs file:

(setq locale-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
(prefer-coding-system 'utf-8)

The command to tell emacs that the file in the buffer is utf-8 instead of latin-1

M-x set-buffer-file-coding-system
(Usually bound to C-x RET f)


How to insert some text in the file (in comments) to tell emacs which encoding to use. Insert the coding File Variable:

Put the following on one of the first two lines:

-*- coding:utf-8; -*-

or put:

Local Variables:
coding: utf-8
End:

in the last 512 bytes of the file.

Useful links: