Выбрать главу

C++ programmers may want to bind c-forward-into-nomenclature and c-backward-into-nomenclature to the keystrokes normally bound to the standard word motion commands. We show you how to do this in "Customizing Existing Modes" in Chapter 11.

We've covered the main features of C and C++ modes, but actually these modes include many more features, most of them quite obscure or intended only for hardcore Emacs Lisp-adept customizers. Look in the Emacs Lisp package cc-mode.el—and the ever-expanding list of cc- helper packages—for more details.

9.4 Java Support

As we mentioned earlier, recent versions of Emacs come with support for Java built-in (Java mode is based on cc-mode). We'll explore Java mode briefly and then take a more in-depth look at the Java Development Environment for Emacs (JDEE).

9.4.1 Java Mode

Java mode shares all of the formatting and font features mentioned above, but understands the Java language specifically. You get thrown into Java mode when opening any .java file.

When working in Java mode, you have exactly the same features available as you do in C mode. Syntax highlighting handles Java keywords and syntax when font-lock mode is turned on. You can navigate Java commands using M-a and M-e. When commenting out a region, it uses the C++ style // comments.

You'll notice a small augmentation in the indent alignment commands if you choose to spread your throws or extends clauses over multiple lines. For example, consider the following method declaration:

public Object getNetResource(String host, int port, String resName)

throws IllegalArgumentException,

IOException,

SQLException,

FileNotFoundException

{

If you mark the region and run M-C-\ to indent the region, it uses a special alignment for the exception list:

public Object getNetResource(String host, int port, String resName)

        throws IllegalArgumentException,

               IOException,

               SQLException,

               FileNotFoundException

{

It all works like it is supposed to—just with Java as the language at the core of the action. However, for more than casual Java editing, you should read the next section on the JDEE.

9.5 The Java Development Environment for Emacs (JDEE)

While you can certainly get started right away with the built-in Java mode, if you do more than occasional Java programming, you might want to venture into the world of Paul Kinnucan's Java Development Environment for Emacs (JDEE). It takes Emacs into the realm of Java IDE. You won't find a GUI builder, but everything else is in place and ready to roll.

9.5.1 Getting Started

You can pick up the latest version of the JDEE online from http://jdee.sunsite.dk/.[65] This site is essential to getting the JDEE up and running. You'll find all sorts of tips and tricks and full user documentation on all of the bells and whistles is available.

Before you can install the JDEE, you'll need the following components:

Collection of Emacs Development Environment Tools (CEDET)

Available on SourceForge (http://cedet.sourceforge.net/) or by following the links from the JDEE home page. This collection is quite popular as a foundation for more interesting programmer tools. You may already have a sufficient version installed, but it's best to get the latest release.

The JDEE Emacs Lisp library package

Available as a separate download from the JDEE site.

One or more JDKs

While technically not required for editing files in Emacs, a JDK is required to take advantage of any of the compilation or debugging features of the JDEE. You'll also have to register each JDK you plan to use, but more on that later.

9.5.2 Installing CEDET

Installing CEDET is fairly straightforward if you have a make command available. (For Windows users, you'll want to have the Cygnus Unix Distribution installed. It gives you access to a large subset of Unix tools which will come in handy far beyond the installation of the JDEE.)

After you download the CEDET distribution from SourceForge, unpack it wherever you want it to reside. Open a terminal window (or start a Cygwin bash terminal on Windows) and change to the directory where you unpacked the distribution. From there you should be able to run the following command:

shell$ make EMACS=

/path/to/emacs

That process will probably take a few minutes to complete. The Lisp files will be compiled for you.

When the make command completes, you should be in good shape. The last step for CEDET is to update your .emacs file:

;; Turn on CEDET's fun parts

(setq semantic-load-turn-useful-things-on t)

;; Load CEDET

(load-file "/path-to-cedet/common/cedet.el")

9.5.3 Installing the ELisp Library

Installing the ELisp library package from the JDEE site is also straightforward. Unpack the downloaded file wherever you like, but before you run the make command, you'll need to edit the Makefile and configure the entries outlined in Table 9-5 to match your system.

Table 9-5. JDEE Makefile entries

Makefile entry Example Description
prefix /usr/local The top-level directory for any shared or info directories.
datadir $(prefix)/share The directory where your main Emacs directory is located.
locallisppath $(datadir)/emacs/site-lisp The directory where any local Lisp files should be installed.
ELIBDIR $(locallisppath)/elib The directory where the elib Lisp files will go.
EMACS /usr/bin/emacs The command to start Emacs. This can be a fully qualified path or simply "emacs" to reach the default version found on your system.
вернуться

65

Before we take you through the installation process, we should mention two caveats. XEmacs has the JDEE built-in, though it is often out-of-date. TEI-Emacs, an add-on for Linux and Windows described in Chapter 8, also includes the JDEE.