Finally, both C and C++ mode contain the commands c-forward-into-nomenclatureand c-backward-into-nomenclature, which aren't bound to any keystrokes by default. These are like forward-wordand backward-word, respectively, but they treat capital letters in the middle of words as if they were starting new words. For example, they treat ThisVariableName as if it were three separate words while the standard forward-wordand backward-wordcommands treat it as one word. ThisTypeOfVariableName is a style used by C++ programmers, as opposed to this_type_of_variable_name , which is somehow more endemic to old-school C code.
C++ programmers may want to bind c-forward-into-nomenclatureand c-backward-into-nomenclatureto 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.
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).
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-aand 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 throwsor extendsclauses 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.
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.
Installing CEDET is fairly straightforward if you have a makecommand 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 makecommand 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 makecommand, you'll need to edit the Makefile and configure the entries outlined in Table 9-5to 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. |
Run the makecommand with the installoption to get everything set up:
shell$ make install
The last step for the ELisp library is to make sure the Emacs defaults acknowledge the new package. You simply need to add the new directory to your load-pathvariable, as described next.
The ELisp library actually provides a simple template file that matches where you installed the package. After the makeprocess completes, you should have an elib_startup.el file in the directory where you ran the makecommand. That file contains the line you'll need to add to your .emacs file or you can merge it with the system default.el file for everyone to use. (The default.el file is often found in your site-lisp directory. Chapter 11has more details.)
Читать дальше