Project:Emacs/GNU Emacs developer guide

From Gentoo Wiki
< Project:Emacs
Revision as of 19:45, 14 July 2013 by Ulm (Talk | contribs)

Jump to: navigation, search
Summary
This document describes how GNU Emacs and associated packages are made available in Gentoo. These guidelines also describe the philosophy how the packages are maintained.

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).

Maintaining the editor itself

Available versions

Currently the following Emacs versions are available:

Package Version Type SLOT eselect name Remarks
app-editors/emacs 18.59 released 18 emacs-18 Not covered by virtual/emacs, for quick editing purposes
app-editors/emacs 21.4 released 21 emacs-21 deprecated
app-editors/emacs 22.3 released 22 emacs-22 deprecated
app-editors/emacs 23.4 released 23 emacs-23
app-editors/emacs 24.3 released 24 emacs-24
app-editors/emacs-vcs 24.3.9999 Bazaar (trunk) 24 emacs-24-vcs

Locations of files

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

  • Emacs executable: /usr/bin/emacs-suffix, where suffix is normally equal to the Emacs major version
  • Auxiliary programs (e.g., ctags): /usr/bin/ctags-emacs-suffix
  • Man pages are named accordingly
  • Info files of Emacs are installed in directory /usr/share/info/emacs-suffix/

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. The slot for version 18 has no USE flags at all, so if nothing else is noted, version 21 onwards is described.

Flag Description Notes
acl Include support for Access Control Lists (Emacs 24.4 and above).
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.
aqua Include support for the Aqua/Cocoa GUI. Only available under Prefix on Max OS X.
athena Use the MIT Athena widget set as windowing toolkit.
dbus Make Emacs D-Bus aware (Emacs 23 and above).
games Support shared score files for games. This flag is passed on to app-emacs/emacs-common-gentoo which will create the games user and install score files.
gconf Use gconf to read the system font name (Emacs 23 and above).
gfile Use gfile (glib) for file notification (Emacs 24.4 and above). This takes precedence over the inotify flag. Note that glib file notification on Linux uses inotify internally.
gif Support for GIF images.
gnutls Support GnuTLS for secure session initiation (Emacs 24 and above).
gpm Support for console-based mouse driver (Emacs 23 and above).
gsettings Use gsettings (glib) to read the system font name (Emacs 24 and above).
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.
gtk3 Link against GTK+ version 3 instead of version 2 (Emacs 24 and above).
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 care of that by confusing the configure script.
hesiod Use the Hesiod name service system.
imagemagick Use the imagemagick toolset for enhanced image manipulation (Emacs 24 and above).
inotify Enable inotify file change notification support (Emacs 24.4 and above).
jpeg Support for JPEG images.
kerberos Support for the Kerberos network authentication protocol.
leim Extended methods for input encodings (Emacs 21 only).
libxml2 Parse XML with libxml2 instead of built-in Elisp functions which gives a substantial speed-up (Emacs 24 and above).
livecd Force the /usr/bin/emacs symlink to be set during livecd building. Internal use, not intended to be set by users.
m17n-lib Use the m17n-lib multilingual library for complex text layout, e.g. for Indic scripts (Emacs 23 and above). Only available if xft is enabled too.
motif Use Motif as windowing toolkit.
pax_kernel Enable building under a PaX enabled kernel.
png Support for PNG images.
selinux Support the SELinux security extensions (Emacs 24 and above).
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 and above).
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).
wide-int Prefer wide Emacs integers, typically 62-bit (Emacs 24 and above). This option has an effect only on architectures where long and long long types have different size.
X Let Emacs use an X session if available. Text mode can always be forced.
Xaw3d Use the 3D Athena widget set as windowing toolkit.
xft Choose an alternative font renderer (Emacs 23 and above).
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.

Packages

Depending on a specific Emacs version

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

A minimum version of GNU Emacs required by a package can be specified by assigning NEED_EMACS=version_number before inheriting elisp.eclass. The given version number must be available as an ebuild in virtual/emacs. Without such an assignment, the package will by default depend on >=virtual/emacs-21. Packages that have optional support for GNU Emacs (via USE flags) can check for a minimum version of GNU Emacs at build time with the elisp-need-emacs() function.

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.

Formerly, all those initialisations were directly added to site-start.el, which is executed at Emacs start-up. Today there is another level of indirection, i.e. initialisations are in /usr/share/emacs/site-lisp/site-gentoo.el which can either be loaded from /etc/emacs/site-start.el (the default), or it can be individually loaded from users’ ~/.emacs files by adding a line like:

Code

(require 'site-gentoo)

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
Site initialisation means that the package should be ready for use, but not that the package should be imposed on all users by loading or even starting it at Emacs startup time. (Think of systems with multiple users.) 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 eselect developer guide.

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/emacs-cedet
The Collection of Emacs Development Environment Tools was traditionally available as a separate package app-emacs/cedet. It is also shipped with Emacs versions from 23.2 on.
virtual/emacs-flim
There are several libraries that provide encoding functions for other packages. If they are compatible to app-emacs/flim, they should provide the emacs-flim virtual.

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-Tools Git 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/ebuild-mode 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.
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.

A sample ebuild

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

Code

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

EAPI=5

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"

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

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

Resources

Resource Comment
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. Revised 3rd edition. GNU Press, ISBN 1-882114-43-3. A primer on Elisp programming (very basic, but very good).
Richard M. Stallman: GNU Emacs Manual. 17th edition (updated for Emacs version 24.3). GNU Press, ISBN 978-0-9831592-4-7. 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. Springer-Verlag, New York 1991, ISBN 0-387-97616-7. Background information about user interfaces and the ergonomics of text editing.