[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

16. Compiling Files According to Major-Mode

The compile command is very rudimentary in its creation of its compilation command, using "make -k" by default. This package provides an intelligent replacement for the compile command. See section `Compilation' in The XEmacs Editor., for details.

The mode-compile command functions as a layer above compile. Its purpose is mainly to build a smarter compile command for compile to execute. This compile command is built according to number of parameters:

Most of these parameters are highly customizable through Emacs Lisp variables (to be set in your user-init-file or through the Customization menu). Running mode-compile after a universal-argument (C-u) allows remote compilations; the user is prompted for the host name to execute the compilation command. The mode-compile-kill function terminates a running compilation session launched by mode-compile.

By default, mode-compile is very verbose and waits a user-specified number of seconds after displaying each message to give the user time to read it. The variables mode-compile-expert-p and mode-compile-reading-time can be used to change this behaviour. On Windows-based systems, the variable mode-compile-other-frame-p will create a new frame and launch the compilation command in it.

16.1 Customization  
16.2 compilation-mode  
16.3 makefile-mode  
16.4 emacs-lisp-mode, lisp-interaction-mode  
16.5 dired-mode  
16.6 sh-mode, csh-mode, zsh-mode  
16.7 c?perl-mode  
16.8 tcl-mode  
16.9 c-mode, c++-mode  
16.10 ada-mode  
16.11 fortran-mode  
16.12 java-mode  
16.13 python-mode  
16.14 message-mode  
16.15 Miscellaneous Modes  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

16.1 Customization

This section explains how the compile-command is built according to the major-mode and how to customize it. The major modes currently supported are:

ada-mode c++-mode c-mode
c?perl-mode compilation-mode csh-mode
dired-mode emacs-lisp-mode fortran-mode
fundamental-mode indented-text-mode java-mode
lisp-interaction-mode makefile-mode python-mode
sh-mode tcl-mode text-mode
zsh-mode

For other modes a default behaviour is provided.

When running mode-compile or mode-compile-kill the hooks mode-compile-(before|after)-(compile|kill)-hook are executed. The current buffer can be automatically saved if mode-compile-always-save-buffer-p is set to t. All the modified buffers can be automatically saved if mode-compile-save-all-p is set to t.

To configure this package, type:

 
  M-x customize-group RET compilation RET


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

16.2 compilation-mode

Calls compile with the last compile command.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

16.3 makefile-mode

The makefile is run with make through compile (user is prompted for the rule to run, see variable mode-compile-preferred-default-makerule to see how a default choice could be selected).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

16.4 emacs-lisp-mode, lisp-interaction-mode

If the buffer is a `.el' file we byte-compile it to produce a `.elc' file. Otherwise, just byte-compile the buffer (this does not use compile but byte-compile).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

16.5 dired-mode

Find a `makefile' in the directory and run make with it (like in makefile-mode), else try to byte-recompile all `.el' files older than their associated `.elc' files (unlike byte-recompile-directory this is not recursive), finally if no `.el' files are present ask compilation command to user by calling default-compile. To find a `makefile' a regexp is provided which name is mode-compile-makefile-regexp.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

16.6 sh-mode, csh-mode, zsh-mode

Run "[cz]?sh" with debugging arguments as specified in [cz]?sh-dbg-flags on the currently edited file.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

16.7 c?perl-mode

Run file with "perl -w" (can step through errors with compile's next-error command).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

16.8 tcl-mode

Run file with "wish" (can step through errors with compile's next-error command).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

16.9 c-mode, c++-mode

First it tries to see if there is a `makefile' in the directory. Makefiles to look for are specified by the variable mode-compile-makefile-regexp. If yes two cases could happen: there is only one makefile so use it, or there is more than one (sometimes when you need to write portable soft you could have some makefiles by system: SunOs.make, HP.make ...), in that case prompt to user for choice (with smart completion). Once the makefile has been selected it extract the rules from it and ask to user to choose a rule to make (with smart completion, see variable mode-compile-preferred-default-makerule to see how a default choice could be selected).

There are some cases where no makefiles are present (YES I KNOW this is bad practice but you sometimes have no need to write a Makefile). In that case the function tries to build the most intelligent compilation command by using the favourite user C/C++ compiler: value of environment variable "CC" or "CXX" or first found, in the PATH, of compilers specified in variable cc-compilers-list or c++-compilers-list. Then it looks for the environment variable "CFLAGS" of "CXXFLAGS" to append to the compiler command, finds the file to compile: <name-of-the-file-to-compiled>.(c|cc|C|cpp) (see *) and asks for confirmation. If you really trust mode-compile will build the correct command and want to bypass confirmation you could set the variable mode-compile-never-edit-command-p to t.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

16.10 ada-mode

Same as c/c++-mode but run Ada compiler on the Ada file. There are no companion file and no way to find a main function in Ada.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

16.11 fortran-mode

Same as c-mode but run Fortran compiler on .[Ff](or)? files.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

16.12 java-mode

Same as c-mode but call "javac" without the -o option on .java files


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

16.13 python-mode

Run file with "python" (can step through errors with compile's next-error command).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

16.14 message-mode

Run message-send.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

16.15 Miscellaneous Modes

This handles fundamental-mode, text-mode, indented-text-mode and any unknown modes.

Try to guess what the file is by

The kill-compile command is then bound dynamically (buffer-local).


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by XEmacs shared group account on December, 19 2009 using texi2html 1.65.