GNU Emacs on Gentoo

Ulrich Müller  Author
Christian Faulhammer  Author

Updated November 18, 2009

1.  Introduction

What is Emacs?

Emacs is the extensible, customizable, self-documenting real-time display editor. Large parts are written in the Lisp dialect Emacs Lisp, with which extensions can be easily developed. Apart from its editing features, GNU Emacs provides a whole environment to manage your system, mail, IRC chats and texts (be it correspondence or programming).

2.  Maintaining the editor itself

Available versions

Currently the following Emacs versions are available:

Package Version Type SLOT eselect name Remarks
emacs 18.59 released 18 emacs-18
emacs 21.4 released 21 emacs-21
emacs 22.3 released 22 emacs-22
emacs 23.1 released 23 emacs-23
emacs-cvs 23.1.9999 CVS (trunk) 23 emacs-23-cvs

Locations of files

The following files are installed in different locations or under a different name (as compared to vanilla GNU Emacs):

The programs are symlinked to their original names by the Emacs eselect module, apart from ctags and etags which have their own modules.

USE flags

Emacs has many USE flags, most are easy to understand what they are good for, others have some hidden "features" one should know about.

Flag Description Notes
alsa Determine if ALSA should be used Emacs autodetects ALSA. That test is removed by the ebuild if the flag is not set. This is for cases where ALSA is installed but the user does not wish support for it in Emacs.
dbus Make Emacs D-Bus aware (Emacs 23 only).
gconf Use gconf to read the system font name (emacs-cvs only).
gif Support for GIF images.
gpm Support for console-based mouse driver (Emacs 23 only).
gtk Use the GIMP Toolkit (GTK+) as windowing toolkit (menu bar etc.) When this toolkit is activated along with alternative ones (see other USE flags), GTK+ is chosen. This is in sync with upstream's wishes.
gzip-el Zip up all el files. The zip binary is autodetected. So even when this USE flag is disabled but the binary is found, all el files will be compressed. The ebuild takes of that care by confusing the configure script.
hesiod Use the Hesiod name service system.
jpeg Support for JPEG images.
kerberos Support for the Kerberos network authentication protocol.
leim Extended methods for input encodings (Emacs 21 only).
m17n-lib Use the m17n-lib multilingual library for complex text layout, e.g. for Indic scripts (Emacs 23 only). Only available if "xft" is enabled too.
motif A windowing toolkit.
png Support for PNG images.
sendmail Build with support for mail transfer agent (Emacs 21 only).
sound Control the availability of sound support.
source Install the C source files and make them available in the internal documentation system of GNU Emacs.
svg Support for SVG images (Emacs 23 only).
tiff Support for TIFF images.
toolkit-scroll-bars Instead of the internal scroll bars, the ones from the windowing toolkit are used. You will lose some functionality (split windows by clicking on the scroll bar for example).
X Let Emacs use an X session if available. Text mode can always be forced.
Xaw3d A windowing toolkit.
xft Choose an alternative font renderer (Emacs 23 only).
xpm Support for XPM images. If disabled, all logos, icons etc. in Emacs are displayed in grayscale. This flag is forced through EAPI 1 features.

3.  Packages

Depending on a specific Emacs version

Note: The documentation of the functions provided is to be found in the eclasses itself.

If a package needs at least a specific version of GNU Emacs, you can tell the elisp.eclass by giving NEED_EMACS=version_number before the inherit line. Undefined the default dependency is on virtual/emacs-21.

The site-lisp directory and package loading

The regular location for Emacs lisp packages in Gentoo is /usr/share/emacs/site-lisp/package/. All Elisp files (.el) and compiled Elisp files (.elc) should go there.

Emacs packages normally need to be activated or loaded when a certain condition is met (like c-mode for C source files).

In Gentoo every package has a site initialisation file that holds the needed commands. The file is located in ${FILESDIR} and starts with a two-digit number, followed by the package name and -gentoo. The elisp-install function puts this file in the directory /usr/share/emacs/site-lisp/site-gentoo.d/.

When calling elisp-site-regen in an ebuild, the global site file /usr/share/emacs/site-lisp/site-gentoo.el is regenerated, which holds the contents of all individual site init files in one. They are read in alphabetical order, so the numbers determine which comes first, the lowest is to be found at the beginning. That means: Packages depending on each other need to have rising order for site initialisation, too.

Some time ago all those initialisations were added to /usr/share/emacs/site-lisp/site-start.el, which is always loaded at Emacs start-up! Today you can individually control which user will activate all installed Elisp packages by adding a line like

(require 'site-gentoo)

to a file read by Emacs on start-up (usually ~/.emacs).

Historically site-init files were read from the /usr/share/emacs/site-lisp/ directory, which is still supported by the eclasses, but a remerge/update will put them in the site-gentoo.d/ subdirectory. Package app-admin/emacs-updater installs a script that checks for needed rebuilds, called emacs-updater.

Important: A load command for site initialisations is only acceptable for a few packages. If used, it always loads the whole package and makes Emacs start-up really slow, so the autoload mechanism is the preferred way. The elisp-common eclass has functions to generate an autoload file if none is shipped with the package but the functionality is available in the source nonetheless. For more information about the mechanism see the Elisp manual. Also manual keybindings directly in the site-file are discouraged to not disturb the user as he could have bound exactly that keys himself. Keep pollution low but provide sane default settings out of the box so even a novice can start working fast.

Eclasses

Packages that have support for or rely on GNU Emacs can use two eclasses to do some recurring tasks in a simple way. The documentation of the functions are provided in the eclasses, so they are not repeated here! Format of documentation is to allow man-page generation from source with the package app-portage/eclass-manpages.

Name Purpose
elisp-common.eclass Provides functions to handle Elisp files. Compilation, installation and generation of autoloads is covered here in a general way. Packages with optional Emacs support must rely on this eclass.
elisp.eclass The functions from elisp-common.eclass are used to construct the default functions (src_unpack, src_compile and friends) for packages in the app-emacs hierarchy of ebuilds. It pulls in an appropriate version of Emacs (meaning a version of virtual/emacs, controlled by the NEED_EMACS variable) and is not intended for packages with optional (via USE flag) support for GNU Emacs.

Emacs eselect module

Having several Emacs versions simultaneously installed on a system, needs some caution by maintainers. Usual pitfalls are file collisions and installations of one slot using data from another. As described earlier, the executables are suffixed with their corresponding version number. All data files go to similar directories, also distinguished by a version suffix.

To be independent of the installed version, the eselect module from app-admin/eselect-emacs guarantees that /usr/bin/emacs always points to the Emacs you want. All ebuilds for the editor check if the symlink is set, and change it to the highest available in the case where it does not exist. If no GNU Emacs is found, but XEmacs, all helper programs are symlinked to the variants shipped with XEmacs.

The module file has some comments about how the code works. For more information how an eselect module is set up, consult the documentation.

Provided virtuals

Sometimes the same functionality is available through different packages. To not force a subjective choice the maintainer made, virtuals check if one of the alternatives is installed on the user's system.

virtual/editor
Just makes sure you have an editing capability available on your system, Emacs is one choice out of many.
virtual/emacs
This gives you the choice between several version of Emacs. Elisp packages can choose which virtual version is the minimum they need through the elisp.eclass.
virtual/flim
There are several libraries that provide encoding functions for other packages. If they are compatible to app-emacs/flim, they should provide the virtual of the same name.
virtual/gnus
The news reader Gnus is shipped with Emacs (from 21 on) and also available as a separate package. To give users a better choice, all of these ebuilds fullfil the virtual, although it is only valid for version 5.10 or greater of Gnus. So the virtual points to Emacs 22.

Where Emacs team is upstream

Not all packages maintained by the Emacs team are developed by people from outside the Gentoo project (they are usually called upstream). Most of those exceptions are for proper operation of GNU Emacs in the Gentoo environment.

Sources of these packages are kept in the Emacs SVN repository. They are released and brought to the Emacs overlay or to the Portage tree when they have proven stable.

Package name Purpose
app-admin/eselect-emacs Setting the correct man page locations, Info documentation paths and target for /usr/bin/emacs, see the separate section.
app-admin/eselect-ctags There are several implementations of the ctags binary, all with a different feature set. This eselect module lets you choose the variant you need.
app-admin/emacs-updater Ships the emacs-updater script, which makes the transition from the old location of the site-init files to the new one. Another purpose is to byte-compile all installed Emacs support files again, e.g. after a major upgrade of Emacs.
app-emacs/emacs-common-gentoo Installs common files needed by all GNU Emacs versions. These include subdirs.el and a default site-start.el file. With USE=X also desktop files (which provide file associations for many desktop environments) and icons for Emacs and Emacsclient are installed.
app-emacs/emacs-daemon Contains the init script to start Emacs as a background service in server mode. The emacsclient executable then uses this to connect to.
app-emacs/gentoo-syntax A collection of Emacs major modes that help you edit ebuilds and other Gentoo specific files. This is developed in cooperation with the XEmacs team, so we share the same source.

A sample ebuild

We present an ebuild that introduces the canonical form regarding variable ordering in global scope and implementation along an example.

Code Listing 3.1: Sample ebuild

# Copyright 1999-2009 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

inherit elisp

DESCRIPTION="ReStructuredText support for Emacs"
HOMEPAGE="http://www.emacswiki.org/cgi-bin/wiki/reStructuredText"
SRC_URI="mirror://sourceforge/docutils/docutils-${PV}.tar.gz"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="alpha amd64 arm hppa ia64 ppc ppc64 s390 sh sparc ~sparc-fbsd x86 ~x86-fbsd"
IUSE=""

S="${WORKDIR}/docutils-${PV}/tools/editors/emacs"
DOCS="README.txt"
SITEFILE="50${PN}-gentoo.el"
PATCHES=( "${FILESDIR}/${P}-lazy-lock-mode-fix.patch" )

The first lines from inherit to IUSE are standard Gentoo ebuild variables and thus outside the scope of this text.

4.  Resources

Resource Comment
Various authors; Gentoo Developer Handbook First steps as Gentoo developer plus an Ebuild HowTo with a good overview.
Various authors; Gentoo Development Guide Extensive reference about how development is organised in Gentoo, plus style advises for ebuild authors.
Robert J. Chassell; An Introduction to Programming in Emacs Lisp; ISBN 1-882114-56-6; GNU Press A primer on Elisp programming (very basic, but very good).
Richard M. Stallman; GNU Emacs Manual; 16th edition (for version 22); ISBN 1-882114-86-8; GNU Press The official handbook of Emacs, also shipped with the editor. This covers the usage of Emacs, not the programming or deep internals.
Various authors; GNU Emacs Lisp Reference Manual All information needed for Elisp programming, dense and extensive, but not for beginners.
Craig A. Finseth; The Craft of Text Editing: Emacs for the Modern World; ISBN 0-387-97616-7; Springer-Verlag Background information about user interfaces and the ergonomics of text editing.