Initial Commit
[temp.git] / site-lisp / includes / mode-compile.el
blobaca776fea01fc7fa2d2ea170561cb821ac941e47
1 ;;; mode-compile.el --- Smart command for compiling files
2 ;; according to major-mode.
3 ;;
4 ;; Copyright (c) 1994 - 2006 heddy Boubaker C.E.N.A.
5 ;;
6 ;; Author: Heddy Boubaker <heddy.Boubaker@cena.fr>
7 ;; Maintainer: Heddy Boubaker <heddy.Boubaker@cena.fr>
8 ;; Created: June 1994
9 ;; Last modified: 2006/12/01 13:52:47
10 ;; Version: 2.29
11 ;; Keywords: compile, compilation, modes, languages
12 ;; Tested for:
13 ;; XEmacs (Lucid GNU Emacs) >= 19.10
14 ;; Must work with FSF GNU Emacs > 19.31 ;-)
15 ;; Do not work anymore for Emacses <= 18
16 ;; Ftp access:
17 ;; archive.cis.ohio-state.edu:pub/gnu/emacs/elisp-archive/misc/mode-compile.el.Z
18 ;; WWW access:
19 ;; <URL http://www.tls.cena.fr/~boubaker/Emacs/>
21 ;; LCD Archive Entry:
22 ;; mode-compile|Heddy Boubaker|boubaker@cena.fr|
23 ;; Smart command for compiling files according to major-mode and more.|
24 ;; 2003/04/01 13:52:47|2.28|~/misc/mode-compile.el.Z|
26 ;;; This file is NOT part of GNU Emacs but the same permissions apply.
28 ;; GNU Emacs is free software; you can redistribute it and/or modify it under
29 ;; the terms of the GNU General Public License as published by the Free
30 ;; Software Foundation; either version 2, or (at your option) any later
31 ;; version.
33 ;; GNU Emacs is distributed in the hope that it will be useful, but WITHOUT
34 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
35 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
36 ;; more details.
38 ;; You should have received a copy of the GNU General Public License along
39 ;; with GNU Emacs; see the file COPYING. If not, write to the Free Software
40 ;; Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
42 ;; @ Purpose:
43 ;; ==========
45 ;; Provide `mode-compile' function as a replacement for the use of `compile'
46 ;; command which is very dumb for creating it's compilation command (use
47 ;; "make -k" by default). `mode-compile' is a layer above `compile'; Its
48 ;; purpose is mainly to build a smart compile-command for `compile' to
49 ;; execute it. This compile-command is built according to number of
50 ;; parameters:
51 ;; - the major-mode.
52 ;; - presence or not of a makefile in current directory.
53 ;; - the buffer-file-name and extension.
54 ;; - what is in the current buffer (`main' function,"#!/path/shell", ...).
55 ;; - and more ... (see Commentary section below).
56 ;; Most of these parameters are higly customizable throught Emacs Lisp
57 ;; variables (to be set in your .emacs or through Customization menu).
58 ;; Running mode-compile after an universal-argument (C-u) allows remote
59 ;; compilations, user is prompted for a host name to run the compilation
60 ;; command on. Another function provided is `mode-compile-kill' which
61 ;; terminate a running compilation session launched by `mode-compile'.
63 ;; @ Installation:
64 ;; ===============
66 ;; Byte compile this file (*) somewhere in your `load-path' and add in
67 ;; your .emacs:
68 ;; (autoload 'mode-compile "mode-compile"
69 ;; "Command to compile current buffer file based on the major mode" t)
70 ;; (global-set-key "\C-cc" 'mode-compile)
71 ;; (autoload 'mode-compile-kill "mode-compile"
72 ;; "Command to kill a compilation launched by `mode-compile'" t)
73 ;; (global-set-key "\C-ck" 'mode-compile-kill)
75 ;; By default mode-compile is very verbose and waits a few seconds (1 by
76 ;; default) after each message for the user to have time to read it. You
77 ;; could set variables `mode-compile-expert-p' and
78 ;; `mode-compile-reading-time' to change this behaviour. On X-Windows
79 ;; systems setting the variable `mode-compile-other-frame-p' will create a
80 ;; new frame and launch the compilation command in it.
82 ;; (*) Don't take care of messages:
83 ;; ** reference to free variable efs-remote-shell-file-name
84 ;; This is perfectly normal ;-}. But if you know a way to avoid it let me
85 ;; know.
87 ;; @ Bug Reports:
88 ;; ==============
90 ;; To report a bug please use function `mode-compile-submit-bug-report'
91 ;; Please note that this bug-report facility uses Barry Warsaw's reporter.el
92 ;; which is part of GNU Emacs v19 and bundled with many other packages. If
93 ;; needed, you can obtain a copy of reporter.el at the elisp-archive.
95 ;; @ Documentation:
96 ;; ================
98 ;; This section will explain how the `compile-command' are built according to
99 ;; the `major-mode' and how to customize it. The major modes `mode-compile'
100 ;; currently known are:
101 ;; - c-mode, c++-mode, makefile-mode, dired-mode, ada-mode, emacs-lisp-mode,
102 ;; lisp-interaction-mode, sh-mode, csh-mode, fundamental-mode, text-mode,
103 ;; indented-text-mode compilation-mode, fortran-mode, c?perl-mode,
104 ;; zsh-mode java-mode, tcl-mode, python-mode, ruby-mode
105 ;; For other modes a default behaviour is provided.
107 ;; When running `mode-compile' or `mode-compile-kill' the hooks
108 ;; `mode-compile-(before|after)-(compile|kill)-hook' are executed. The
109 ;; current buffer could be automaticaly saved if variable
110 ;; `mode-compile-always-save-buffer-p' is set to `t'. ALL the modified
111 ;; buffers could be automaticaly saved if variable `mode-compile-save-all-p'
112 ;; is set to `t'.
114 ;; @@ fundamental-mode, text-mode, indented-text-mode & UNKNOWN MODES:
115 ;; *** THIS IS TOO THE DEFAULT BEHAVIOR FOR UNKNOWN MODES ***
116 ;; Try to guess what the file is by:
117 ;; - 1st looking at it's name and extension (see variable
118 ;; `mode-compile-filename-regexp-alist').
119 ;; - 2nd looking at string "#!/path/shell" at first line to extract shell
120 ;; to run the script with (see variable `mode-compile-shell-alist').
121 ;; - 3rd looking at a makefile in current directory.
122 ;; - then calling `compile' with the last compile command which is
123 ;; asked to be edited by user ...
124 ;; The `kill-compile' command is then bound dynamically (buffer-local).
126 ;; @@ compilation-mode:
127 ;; Call `compile' with the last compile command.
129 ;; @@ makefile-mode:
130 ;; The makefile is run with make throught `compile' (user is prompted
131 ;; for the rule to run, see variable
132 ;; `mode-compile-prefered-default-makerule' to see how a default choice
133 ;; could be selected).
135 ;; @@ emacs-lisp-mode, lisp-interaction-mode:
136 ;; If the buffer is a .el file byte-compile it to produce a .elc file,
137 ;; else just byte-compile the buffer (this don't use `compile' but
138 ;; `byte-compile').
140 ;; @@ dired-mode:
141 ;; Find a makefile in the directory and run make with it (like in
142 ;; makefile-mode), else try to byte-recompile all .el files olders than
143 ;; their associated .elc files (unlike `byte-recompile-directory' this is
144 ;; not recursive), finally if no .el files are present ask compilation
145 ;; command to user by calling `default-compile'. To find a makefile a
146 ;; regexp is provided which name is `mode-compile-makefile-regexp'.
148 ;; @@ sh-mode, csh-mode, zsh-mode:
149 ;; Run "[cz]?sh" with debugging arguments as specified in
150 ;; `[cz]?sh-dbg-flags' on the currently edited file.
152 ;; @@ c?perl-mode:
153 ;; Run file with "perl -w" (can step throught errors with compile's
154 ;; `next-error' command).
156 ;; @@ tcl-mode:
157 ;; Run file with "wish" (can step throught errors with compile's
158 ;; `next-error' command).
160 ;; @@ c-mode, c++-mode:
161 ;; First it try to see if there is a makefile in the directory, makefiles to
162 ;; look for are specified by the variable `mode-compile-makefile-regexp'.
163 ;; If yes two cases could happen: there is only one makefile so use it, or
164 ;; there is more than one (sometimes when you need to write portable soft
165 ;; you could have some makefiles by system: SunOs.make, HP.make ...), in
166 ;; that case prompt to user for choice (with smart completion). Once the
167 ;; makefile has been selected it extract the rules from it and ask to user
168 ;; to choose a rule to make (with smart completion, see variable
169 ;; `mode-compile-prefered- default-makerule' to see how a default choice
170 ;; could be selected).
172 ;; There are some cases where no makefiles are presents (YES I KNOW this is
173 ;; bad practice but you sometimes have no needs to write a Makefile). In
174 ;; that case the function try to build the most intelligent compilation
175 ;; command by using the favourite user C/C++ compiler: value of environment
176 ;; variable "CC" or "CXX" or first found, in the PATH, of compilers
177 ;; specified in variable `cc-compilers-list' or `c++-compilers-list'. Then
178 ;; it look for the varenv "CFLAGS" of "CXXFLAGS" to append to the compiler
179 ;; command, find the file to compile:
180 ;; <name-of-the-file-to-compiled>.(c|cc|C|cpp) (see *) and ask for
181 ;; confirmation. If you really trust mode-compile will build the right
182 ;; command and want to bypass confirmation you could set the variable
183 ;; `mode-compile-never-edit-command-p' to t.
185 ;; (*) How to find <name-of-the-file-to-compiled>:
186 ;; In both case the command try to guess which file has to be compiled:
187 ;; It's a trivial choice when current buffer file is a
188 ;; .(c|C|cc|cpp... -any file with extension specified in
189 ;; `cc-source-file-ext-list' or `c++-source-file-ext-list') file but
190 ;; when it's a .(h|H|hh) file what to do? The variable
191 ;; `cc-companion-file-regexp' or `c++-companion-file-regexp' specify
192 ;; how to find a .(c|C|cc|cpp...) file from a .(h|H|hh...); This is
193 ;; done by appending .(c|C|cc|cpp) to
194 ;; <filename-without-matching-regexp>. In c-mode with default value
195 ;; it produce:
196 ;; file.h, file_[Pp].h -> file.c
197 ;; I sometimes use files _p.h to indicate that the file is a private header
198 ;; file for a .c file.
199 ;; In c++-mode with default value it produce:
200 ;; file.hh, file_[Pp].hh -> file.cc
201 ;; I sometimes use files _p.cc to indicate that the file is a private header
202 ;; file for a .cc file.
203 ;; The output of compilation will be a
204 ;; <name-of-the-file-to-compiled>.o file if no `main' function is
205 ;; found inside or a <name-of-the-file-to-compiled> EXECUTABLE file
206 ;; if `main' function found.
208 ;; @@ ada-mode:
209 ;; Same as c/c++-mode but run Ada compiler on the Ada file. There are no
210 ;; companion file and no way to find a main function in Ada.
212 ;; @@ fortran-mode:
213 ;; Same as c-mode but run Fortran compiler on .[Ff](or)? files.
215 ;; @@ java-mode:
216 ;; Same as c-mode but call "javac" without the -o option on .java files
218 ;; @@ python-mode:
219 ;; Run file with "python" (can step throught errors with compile's
220 ;; `next-error' command).
222 ;; @@ ruby-mode:
223 ;; Run file with "ruby" (can step throught errors with compile's
224 ;; `next-error' command).
226 ;; @@ message-mode:
227 ;; Run `message-send'.
229 ;; @ WhatsNew:
230 ;; ===========
232 ;; Support for ruby-mode
234 ;; @ Contributors/Helpers:
235 ;; =======================
237 ;; Adrian Aichner <aichner@ecf.teradyne.com>
238 ;; "William A. Perkins" <wa_perkins@pnl.gov>
239 ;; Bin Mu <mubin@DerivaTech.COM>
240 ;; Gael MARZIOU <Gael_Marziou@grenoble.hp.com>
241 ;; Christian Motschke <motschke@prosun.first.gmd.de>
242 ;; boris <boris@cs.rochester.edu>
243 ;; Edward Hartnett <ejh@larry.gsfc.nasa.gov>.
244 ;; Hartmut MANZ <manz@intes-stuttgart.de>.
245 ;; Henry Guillaume <henryg@tusc.com.au>.
246 ;; Ian Young <imy@wcl-rs.bham.ac.uk>
247 ;; Ilya Zakharevich <ilya@math.ohio-state.edu>.
248 ;; Kevin Broadey <KevinB@bartley.demon.co.uk>.
249 ;; Lawrence R. Dodd <dodd@roebling.poly.edu>.
250 ;; Martin Jost <asictest@ztivax.zfe.siemens.de>.
251 ;; Michael Welsh Duggan <md5i+@andrew.cmu.edu>.
252 ;; Rolf EBERT <rolf@gundog.lbl.gov>.
253 ;; Scott Hofmann <scotth@visix.com>.
254 ;; Stefan Schoef <Stefan.Schoef@arbi.informatik.uni-oldenburg.de>.
255 ;; John W. Harwell <ccjohnh@showme.missouri.edu> - JWH.
256 ;; Charles L.G. Comstock <dgtized@gmail.com> - CLGC
258 ;; @ ToDo:
259 ;; =======
261 ;; Extending this to some others programming languages (modes).
262 ;; Writting an Info documentation.
263 ;; Contributors are greatly accepted (send me diffs and don't forget to
264 ;; update documentation and all comments too please).
265 ;; Maybe Using ange-ftp parse .netrc utilities for remote host and
266 ;; user infos.
268 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
271 ;; @ Requirements ;;;
273 ;; mode-compile is not a replacement for compile
274 ;; it is just a layer above it.
275 (require 'compile)
276 ;;; For Emacs-Lisp files compilations
277 (require 'byte-compile "bytecomp")
278 ;;; For easy macros
279 (require 'backquote)
280 (require 'cl)
281 (load-library "cl-macs")
282 ;; Pretty print elisp
283 (require 'pp)
284 ;;; Setting obsolete vars
285 (eval-and-compile
286 (condition-case ()
287 (require 'obsolete)
288 (error nil))
289 (if (and (featurep 'obsolete) (fboundp 'define-obsolete-variable-alias))
290 nil ;; We've got what we needed
291 (defmacro define-obsolete-variable-alias (old new)
292 (` (progn (defalias (, old) (, new))
293 (put (, old) 'byte-obsolete-variable (, new)))
294 ))))
295 ;;; For using custom - stolen from w3-cus.el -
296 (eval-and-compile
297 (condition-case ()
298 (require 'custom)
299 (error nil))
300 (if (and (featurep 'custom) (fboundp 'custom-declare-variable))
301 nil ;; We've got what we needed
302 ;; We have the old custom-library, hack around it!
303 (defmacro defgroup (&rest args)
304 nil)
305 (defmacro defcustom (var value doc &rest args)
306 (` (defvar (, var) (, value) (, doc))))))
308 ;; Custom groups
309 (defgroup compilation nil
310 "Compilations from within Emacs variables."
311 :link '(url-link :tag "Author's Emacs Page"
312 "http://www.tls.cena.fr/~boubaker/Emacs/")
313 :group 'tools
314 :group 'development)
315 (defgroup compilation-lang nil
316 "Language specific compilation options."
317 :group 'languages
318 :group 'compilation)
319 (defgroup compilation-script nil
320 "Scripts compilation options."
321 :group 'compilation)
322 (defgroup compilation-elisp nil
323 "Emacs developpement compilation options."
324 :group 'lisp
325 :group 'compilation)
327 ;; @ User variables ;;;
328 ;; @@ Common variables to mode-compile for all modes ;;;
330 (defcustom mode-compile-modes-alist
331 '((c-mode . (cc-compile kill-compilation))
332 (java-mode . (java-compile kill-compilation))
333 (c++-mode . (c++-compile kill-compilation))
334 (ada-mode . (ada-compile kill-compilation))
335 (fortran-mode . (f77-compile kill-compilation))
336 (dired-mode . (dired-compile kill-compilation))
337 (emacs-lisp-mode . (elisp-compile keyboard-quit)) ; I'm SURE IT'S NOT the best way
338 (lisp-interaction-mode . (elisp-compile keyboard-quit)) ; to kill a byte-compilation.
339 (makefile-mode . (makefile-compile kill-compilation))
340 (sh-mode . (sh-compile kill-compilation))
341 (csh-mode . (csh-compile kill-compilation))
342 (zsh-mode . (zsh-compile kill-compilation))
343 (perl-mode . (perl-compile kill-compilation))
344 (cperl-mode . (perl-compile kill-compilation))
345 (tcl-mode . (tcl-compile kill-compilation)) ; JWH
346 (python-mode . (python-compile kill-compilation)) ; BM
347 (ruby-mode . (ruby-compile kill-compilation)) ; CLGC
348 ;(message-mode . (message-compile kill-compilation))
349 (fundamental-mode . (guess-compile nil)) ; bound dynamically
350 (text-mode . (guess-compile nil)) ; itou
351 (indented-text-mode . (guess-compile nil)) ; itou
352 (compilation-mode . (default-compile kill-compilation)))
353 "Assoc list of compile/kill functions for some known modes.
355 Each element look like (MODE . (COMPILE-FUNCTION KILL-FUNCTION))
356 `mode-compile' will call COMPILE-FUNCTION and `mode-compile-kill'
357 KILL-FUNCTION if current major-mode is MODE.
359 If you want to add or modify a COMPILE-FUNCTION and it's associated
360 KILL-FUNCTION for MODE and don't want to hack `mode-compile' you could
361 do the following (it exists however a more subtle method for
362 modifying, this is left as an exercice for the reader :-):
363 (defun my-mode-compile() ...)
364 (defun my-mode-compile-kill() ...)
365 (setq mode-compile-modes-alist
366 (append '((my-mode . (my-mode-compile my-mode-compile-kill)))
367 mode-compile-modes-alist))"
368 :type '(repeat
369 (cons :tag "Association: mode/compilation functions"
370 (function :tag "Mode")
371 (list :tag "Compilation functions"
372 (choice :tag "Function to run the compilation"
373 (function-item :tag "Default" :value default-compile)
374 (function-item :tag "Guess" :value guess-compile)
375 (function-item :tag "Emacs lisp byte compilation" :value elisp-compile)
376 (function :tag "Your choice, take care..."))
377 (choice :tag "Function to kill a running compilation"
378 (function-item :tag "Just kill" :value kill-compilation)
379 (const :tag "Nothing -- use with guess-compile --" :value nil)
380 (function-item :tag "To use with elisp-compile" :value keyboard-quit)
381 ;; This item could not be selected due to a custom (hum) feature ...
382 (function :tag "Your choice, take care..." :value nil)))))
383 :group 'compilation)
385 (defcustom mode-compile-filename-regexp-alist
386 ;; These could be in auto-mode-alist. But if you are like me
387 ;; and don't like these modes (prefear to edit these kind of
388 ;; files in text-mode) this is a nice way to compile them
389 ;; without to be bored with their associated modes.
390 '((mode-compile-makefile-regexp . makefile-mode)
391 ("\\.sh$" . sh-mode)
392 ("\\.csh$" . csh-mode)
393 ("\\.zsh$" . zsh-mode))
394 "Assoc list of major-modes for some filenames regexp.
396 Each element look like (REGEXP . MODE) This variable is really similar
397 to `auto-mode-alist' in the fact that it associate a MODE to a REGEXP
398 matching a filename. The only differences is that you are not obliged
399 to have the specified MODE available to use it (`guess-compile' use
400 it), the MODE is only a pointer to an assoq in
401 `mode-compile-modes-alist' to get the COMPILE-FUNCTION and the
402 KILL-FUNCTION. The REGEXP could be a form wich evaluate to a string.
404 To add a new filename regexp do the following:
405 (setq mode-compile-filename-regexp-alist
406 (append '((my-filename-regexp . some-mode-mode-compile-know)
407 mode-compile-modes-alist))"
408 :type '(repeat
409 (cons :tag "Association: filename/mode"
410 (choice :tag "Filename regexp match"
411 (regexp :tag "Regexp as a string")
412 (symbol :tag "Variable containing the regexp")
413 (sexp :tag "Form wich evaluate to a string"))
414 ;; I need to bind dynamicaly this with const, ideas??
415 ;;`(choice
416 ;; ,@(mapcar (lambda (x) `(const ,(car x))) mode-compile-modes-alist))))
417 (function :tag "Mode to use -- should be a valid assoq in mode-compile-modes-alist --")))
418 :group 'compilation)
420 (defcustom mode-compile-shell-alist
421 '(("sh" . sh-mode)
422 ("csh" . csh-mode)
423 ("zsh" . zsh-mode)
424 ("perl" . perl-mode)
425 ("tcl" . tcl-mode) ; JWH
426 ("python" . python-mode) ; BM
427 ("ruby" . ruby-mode)) ; CLGC
428 "Assoc list of compile function for some known shells.
430 Each element look like (SHELL . MODE) This variable look like
431 `auto-mode-alist' in the fact that it associate a MODE to a name; A
432 SHELL name here. The main difference is that you are not obliged to
433 have the specified MODE available to use it (`guess-compile' use it),
434 the MODE is only a pointer to an assoq in `mode-compile-modes-alist'
435 to get the COMPILE-FUNCTION and the KILL-FUNCTION.
437 To add a new shell do the following:
438 (setq mode-compile-filename-shell-alist
439 (append '((my-shell-name . some-mode-mode-compile-know)
440 mode-compile-modes-alist))"
441 :type '(repeat
442 (cons :tag "Association: shell name/mode"
443 (string :tag "Shell name")
444 ;; I need to bind dynamicaly this with const, ideas??
445 ;;`(choice
446 ;; ,@(mapcar (lambda (x) `(const ,(car x))) mode-compile-modes-alist))))
447 (function :tag "Mode to use -- should be a valid assoq in mode-compile-modes-alist --")))
448 :group 'compilation)
450 ;;;###autoload
451 (defcustom mode-compile-make-program "make"
452 "*The `make' program used to process makefiles.
454 If you have GNU make installed with name \"gmake\" use it."
455 :type 'string
456 :group 'compilation)
458 (defcustom mode-compile-makefile-regexp
459 "\\(^[Mm]akefile\\|.*\\.[mM][aA]?[kK][eE]?\\.?.*$\\)"
460 "Regexp matching 'could be' makefiles filenames."
461 :type 'regexp
462 :group 'compilation)
464 (defcustom mode-compile-makefile-backups-regexp
465 "\\(\\(~\\|\\.[bB][aA][cC]?[kK]\\)$\\)\\|\\(\\(^\\|/\\)[.,][^/]+$\\)"
466 "Regexp to find if a Makefile is a backup or not"
467 :type 'regexp
468 :group 'compilation)
470 ;;;###autoload
471 (defcustom mode-compile-ignore-makefile-backups t
472 "*Tell mode compile to ignore makefiles backup files when selecting the Makefile to use."
473 :type 'boolean
474 :group 'compilation)
476 ;;;###autoload
477 (defvar mode-compile-default-make-options "-k"
478 "Default options to give to `make'.")
479 ;;;###autoload
480 (defcustom mode-compile-make-options (eval mode-compile-default-make-options)
481 "*Options to give to `make'.
482 This could be any form evaluating to a string.
484 Some people asked me a way to modify the make options everytime a
485 compilation command is launched, do that:
486 (defun my-mode-compile-ask-make-options()
487 \"*Hook called by mode-compile, asking for make options.\"
488 (interactive)
489 (read-string \"Make options: \"
490 mode-compile-default-make-options))
491 (setq mode-compile-make-options
492 'my-mode-compile-ask-make-options)"
493 :type '(choice
494 string
495 (sexp :tag "Form evaluating to a string"))
496 :group 'compilation)
498 ;;;###autoload
499 (defcustom mode-compile-prefered-default-makerule 'none
500 "*Default makerule you would like to see in minibuffer as a default choice
501 when selecting the make rule to build.
503 Possible values are:
504 'none -- let mode-compile deciding for you.
505 'all -- try hard to show you the \"all\" rule.
506 'default -- try hard to show you the \"default\" rule.
507 'file -- try to show you the name of the file which will be
508 result of compilation.
509 The 'none action is taken as default is something fail."
510 :type '(radio :tag "Symbol"
511 (const :tag "None - Let mode compile made the choice" :value none)
512 (const :tag "All - Show the \"all\" rule" :value all)
513 (const :tag "Default - Show the \"default\" rule" :value default)
514 (const :tag "File - Show the \"result file name\" rule" :value file))
515 :group 'compilation)
517 ;;;###autoload
518 (defcustom mode-compile-ignore-makerule-regexp nil
519 "*Makefile rules which must be ignored when building completion list.
521 For example if you want to remove all `files rules' set
522 it to: \"\\\\.\\\\([aoc]\\\\|s[ao][.0-9]*\\\\)\". "
523 :type '(choice (const :tag "none" :value nil)
524 (const :tag "The `all files' rule" :value "\\.\\([aoc]\\|s[ao][.0-9]*\\)")
525 regexp)
526 :group 'compilation)
528 ;;;###autoload
529 (defcustom mode-compile-save-all-p nil
530 "*Non-nil means save ALL the modified buffers without asking
531 before launching compilation command."
532 :type 'boolean
533 :group 'compilation)
535 ;;;###autoload
536 (defcustom mode-compile-always-save-buffer-p nil
537 "*Non-nil means save the current buffer without asking
538 before launching compilation command."
539 :type 'boolean
540 :group 'compilation)
542 ;;;###autoload
543 (defcustom mode-compile-never-edit-command-p nil
544 "*Non-nil means never ask to user to edit the compile command."
545 :type 'boolean
546 :group 'compilation)
548 ;; @@ Compilation in other frame vars ;;;
549 (defgroup compilation-frame nil
550 "Compile in another frame variables."
551 :group 'frames
552 :group 'compilation)
554 ;;;###autoload
555 (defcustom mode-compile-other-frame-p nil
556 "*Non-nil means compile in another frame.
558 A new Emacs FRAME is created and the compilation command is executed
559 in this other frame. To specify the frame parameters see also
560 variable `mode-compile-frame-parameters-alist'."
561 :type 'boolean
562 :group 'compilation-frame)
564 (defcustom mode-compile-other-frame-name "COMPILATION"
565 "Name of mode-compile's other frame.
567 This name could be used in your .Xdefault or .Xresources file as:
568 Emacs.MODE-COMPILE-OTHER-FRAME-NAME.resource_to_be_set: ..."
569 :type 'string
570 :group 'compilation-frame)
572 (defconst mode-compile-default-frame-parameters
573 (list
574 (cons 'name mode-compile-other-frame-name)
575 (cons 'width 85) ; columns
576 (cons 'height 30)) ; lines
577 "Default parameters for mode-compile's other frame.")
579 (defvar mode-compile-frame-parameters-alist
580 (purecopy mode-compile-default-frame-parameters)
581 "Parameters for the new Compilation Screen created
582 if variable `mode-compile-other-frame-p' is non nil..
584 See also variable `mode-compile-default-frame-parameters' and
585 `mode-compile-other-frame-name'.
587 For informations about Screen/Frame parameters see:
588 - Info, Nodes: Lispref::Screen::Screen Parameters
589 - GNU Emacs Lisp Reference Manual, chapter 26 p375: Frames.")
591 ;; @@ Hooks ;;;
593 ;;;###autoload
594 (defcustom mode-compile-before-compile-hook nil
595 "Hook to be run before compile command is executed
596 when `mode-compile' is invoked."
597 :type 'hook
598 :group 'compilation)
600 ;;;###autoload
601 (defcustom mode-compile-after-compile-hook nil
602 "Hook to be run after compile command is executed
603 when `mode-compile' is invoked."
604 :type 'hook
605 :group 'compilation)
607 ;;;###autoload
608 (defcustom mode-compile-before-kill-hook nil
609 "Hook to be run before killing compile command is executed
610 when `mode-compile-kill' is invoked."
611 :type 'hook
612 :group 'compilation)
614 ;;;###autoload
615 (defcustom mode-compile-after-kill-hook nil
616 "Hook to be run after killing compile command is executed
617 when `mode-compile-kill' is invoked."
618 :type 'hook
619 :group 'compilation)
621 ;; @@ System dependencies ;;;
623 (defvar mode-compile-exe-file-ext
624 (cond
625 ((memq system-type '(ms-dos emx windows-95 windows-98 windows-nt)) ".exe")
626 (t ""))
627 "*Extension of executable files (with dot included)")
629 (defvar mode-compile-dir-separator-char
630 (cond
631 ;; MSDOSish file systems
632 ((memq system-type '(ms-dos emx windows-95 windows-98 windows-nt)) "\\")
633 ;; Unixish file systems
634 (t "/"))
635 "*Separator char between directories")
637 ;; @@ Facilities variables ;;;
639 ;;;###autoload
640 (defvar mode-compile-choosen-compiler nil
641 "*Global variable containing the name of the compiler
642 which will be used for compiling without makefile.
644 Could be used in combination with
645 (cc|c++|ada|f77)-default-compiler-options
646 to automaticaly choose the compiler specific options.
648 example:
649 (defun my-compiler-get-options()
650 (cond
651 ((string= mode-compile-choosen-compiler \"gcc\")
652 \"-Wall -pedantic-errors\")
653 ((string= mode-compile-choosen-compiler \"cc\")
654 \"cc options whatever they are...\")
656 (message \"Don't know this compiler: %s\" mode-compile-choosen-compiler)
657 (read-string
658 (format \"Options for %s compiler: \" mode-compile-choosen-compiler)))))
660 (setq cc-default-compiler-options 'my-compiler-get-options)")
662 ;; @@ User level ;;;
664 ;;;###autoload
665 (defcustom mode-compile-expert-p nil
666 "*Non nil means `mode-compile' will not speaks too much.
668 See also variable variable mode-compile-reading-time."
669 :type 'boolean
670 :group 'compilation)
672 ;;;###autoload
673 (defcustom mode-compile-reading-time 1
674 "*Seconds to wait in verbose mode after printing a message.
676 In verbose mode mode-compile print too much messages that it is
677 allmost impossible to read them. Just setting this delay leave you the
678 time to read all the messages. If you don't want any delay set it to
679 `0'.
681 See also function sit-for."
682 :type 'integer
683 :group 'compilation)
686 ;; @@ Remote compilation vars ;;;
687 (defgroup compilation-remote nil
688 "Remote compilations options."
689 :group 'compilation)
691 (defcustom mode-compile-remote-hosts-alist '()
692 "Alist of favourites hosts names and the username
693 to use to log on (HOSTNAME . USERNAME).
695 If USERNAME is a function it will be called with HOSTNAME as argument
696 and should return an USERNAME string (for example you could use
697 something like efs-get-user - not tested -), if it is nil the function
698 user-login-name will be used."
699 :type '(repeat
700 (cons
701 (string :tag "Hostname")
702 (choice
703 (const :tag "We'll use \'user-login-name" :value nil)
704 (string :tag "Username")
705 (function :tag "Function which return USERNAME given a HOSTNAME" :value efs-get-user))))
706 :group 'compilation-remote)
708 (defcustom mode-compile-remote-execute-command "rsh"
709 "The shell command used to run a command remotely.
710 \"rsh\" is the only choice I know but I'm far to know everything...
712 This variable is set automaticaly with the value of
713 remote-shell-program or efs-remote-shell-file-name at load time."
714 :type 'string
715 :group 'compilation)
716 (eval-when 'load
717 (cond
718 ((not (string= mode-compile-remote-execute-command "rsh"))
719 ;; user changed default
720 nil)
721 ;; Try to not multiply definitions of the same stuff
722 ;; in too many emacs lisp packages ...
723 ((and (boundp 'remote-shell-program) remote-shell-program)
724 (setq mode-compile-remote-execute-command remote-shell-program))
725 ((and (boundp 'efs-remote-shell-file-name) efs-remote-shell-file-name)
726 (setq mode-compile-remote-execute-command efs-remote-shell-file-name))
729 (defcustom mode-compile-remote-execute-set-host-arg ""
730 "Argument To set the remote host name to the
731 mode-compile-remote-execute-command,
733 None is required for \"rsh\"."
734 :type 'string
735 :group 'compilation-remote)
737 (defcustom mode-compile-remote-execute-set-command-arg ""
738 "Argument to set the command to be run remotely to the
739 mode-compile-remote-execute-command.
741 None is required for \"rsh\"."
742 :type 'string
743 :group 'compilation-remote)
745 (defcustom mode-compile-remote-execute-set-username-arg "-l"
746 "Argument to set the username under which we will log on
747 on the remote host, to give to mode-compile-remote-execute-command."
748 :type 'string
749 :group 'compilation-remote)
751 (defcustom mode-compile-remote-execute-misc-args ""
752 "Misc additionnals arguments to give to the
753 mode-compile-remote-execute-command."
754 :type 'string
755 :group 'compilation-remote)
759 ;; @@ c-mode compile variables ;;;
760 (defgroup compile-c nil
761 "C Compilation options."
762 :group 'c
763 :group 'compilation-lang)
765 (defcustom cc-compilers-list '( "gcc" "c89" "acc" "cc" )
766 "List of user's favourites C compilers in order of preferencies."
767 :type '(repeat (string :tag "C Compiler name"))
768 :group 'compile-c)
770 (defcustom cc-companion-file-regexp "\\(_[Pp]\\)?\\.[pP]?h"
771 "Regexp to find associated .c file from a .h."
772 :type 'regexp
773 :group 'compile-c)
775 (defcustom cc-default-compiler "cc"
776 "*Default C compiler to use when everything else fails.
778 This could be any form evaluating to a string, so you could map it to
779 a function asking you interactively to choose the compiler.
781 example:
782 (defun my-choose-compiler()
783 (read-string \"C compiler: \"))
784 (setq cc-compilers-list '()
785 cc-default-compiler 'my-choose-compiler)"
786 :type '(choice string function)
787 :group 'compile-c)
789 (defcustom cc-compiler-varenv "CC"
790 "Varenv indicating the C compiler to use."
791 :type 'string
792 :group 'compile-c)
794 (defcustom cc-cflags-varenv "CFLAGS"
795 "Varenv indicating the C compiler flags to use."
796 :type 'string
797 :group 'compile-c)
799 (defcustom cc-source-ext-list '( "c" )
800 "Extensions for C compileable source files."
801 :type '(repeat string)
802 :group 'compile-c)
804 (defcustom cc-headers-ext-list '( "h" )
805 "Extensions for C headers source files."
806 :type '(repeat string)
807 :group 'compile-c)
809 (defcustom cc-default-compiler-options "-g"
810 "*Default options to give to the C compiler.
812 This could be any form evaluating to a string.
813 See `mode-compile-choosen-compiler' variable."
814 :type '(choice
815 string
816 (sexp :tag "Form evaluating to a string"))
817 :group 'compile-c)
819 (defcustom cc-source-file-ext-regexp "\\.c"
820 "Regexp to find, from it's name, if a C file is compileable."
821 :type 'string
822 :group 'compile-c)
824 (defcustom cc-build-output-args t
825 "Build output-args for c-mode."
826 :type 'boolean
827 :group 'compile-c)
829 (defcustom cc-object-file-ext "o"
830 "Extension of objects file (result of compilation)
831 in c mode."
832 :type 'string
833 :group 'compile-c)
837 ;; @@ java-mode compile variables ;;;
838 (defgroup compile-java nil
839 "Java compilation options."
840 :group 'compilation-lang)
842 (defcustom java-compilers-list '( "javac" )
843 "List of user's favourites java compilers in order of preferencies."
844 :type '(repeat (string :tag "Java Compiler name"))
845 :group 'compile-java)
847 (defcustom java-companion-file-regexp ""
848 "Regexp to find associated compileable Java companion file.
850 This is useless in Java because there do not exists uncompileable files."
851 :type 'regexp
852 :group 'compile-java)
854 (defcustom java-default-compiler "javac"
855 "*Default C compiler to use when everything else fails.
857 This could be any form evaluating to a string, so you could map it to
858 a function asking you interactively to choose the compiler.
860 example:
861 (defun my-choose-compiler()
862 (read-string \"Java compiler: \"))
863 (setq java-default-compiler 'my-choose-compiler)."
864 :type '(choice string function)
865 :group 'compile-java)
867 (defcustom java-compiler-varenv "JAVAC"
868 "Varenv indicating the C compiler to use."
869 :type 'string
870 :group 'compile-java)
872 (defcustom java-cflags-varenv "JAVAC_FLAGS"
873 "Varenv indicating the C compiler flags to use."
874 :type 'string
875 :group 'compile-java)
877 (defcustom java-source-ext-list '( "java" )
878 "Extensions for Java compileable source files."
879 :type '(repeat string)
880 :group 'compile-java)
882 (defcustom java-headers-ext-list '( "java" )
883 "Extensions for Java source files."
884 :type '(repeat string)
885 :group 'compile-java)
887 (defcustom java-default-compiler-options "-O"
888 "*Default options to give to the Java compiler.
890 This could be any form evaluating to a string. See
891 `mode-compile-choosen-compiler' variable."
892 :type '(choice
893 string
894 (sexp :tag "Form evaluating to a string"))
895 :group 'compile-java)
897 (defcustom java-source-file-ext-regexp "\\.java"
898 "Regexp to find, from it's name, if a Java file is compileable."
899 :type 'regexp
900 :group 'compile-java)
902 (defcustom java-build-output-args nil
903 "Dont build output-args for Java-mode."
904 :type 'boolean
905 :group 'compile-java)
907 (defcustom java-object-file-ext "class"
908 "Extension of objects file (result of compilation)
909 in java mode."
910 :type 'string
911 :group 'compile-java)
915 ;; @@ c++-mode compile variables ;;;
916 (defgroup compile-c++ nil
917 "C++ compilation options"
918 :group 'compilation-lang)
920 (defcustom c++-compilers-list '( "g++" "gcc" "CC" )
921 "List of user's favourites C++ compilers in order of preferencies."
922 :type '(repeat (string :tag "C++ Compiler name"))
923 :group 'compile-c++)
925 (defcustom c++-companion-file-regexp "\\(_[Pp]\\)?\\.\\([pP]?[Hh][Hh]?\\|[Hh]\\+\\+?\\)"
926 "Regexp to find associated compileable C++ companion file
927 from a header file."
928 :type 'regexp
929 :group 'compile-c++)
931 (defcustom c++-default-compiler "CC"
932 "*Default C++ compiler to use when everything else fails..
934 This could be any form evaluating to a string, so you could map it to
935 a function asking you interactively to choose the compiler.
937 example:
938 (defun my-choose-compiler()
939 (read-string \"C++ compiler: \"))
940 (setq c++-default-compiler 'my-choose-compiler)"
941 :type '(choice string function)
942 :group 'compile-c++)
944 (defcustom c++-compiler-varenv "CXX"
945 "Varenv indicating the C++ compiler to use."
946 :type 'string
947 :group 'compile-c++)
949 (defcustom c++-cflags-varenv "CXXFLAGS"
950 "Varenv indicating the C++ compiler flags to use."
951 :type 'string
952 :group 'compile-c++)
954 (defcustom c++-source-ext-list '( "cc" "C" "CC" "cpp" "cxx" "c++" "c+" )
955 "Extensions for C++ compileable source files."
956 :type '(repeat string)
957 :group 'compile-c++)
959 (defcustom c++-headers-ext-list '( "H" "hh" "HH" "h++" "h+" "h" "hpp" "hxx" )
960 "Extensions for C++ headers source files."
961 :type '(repeat string)
962 :group 'compile-c++)
964 (defcustom c++-default-compiler-options "-g"
965 "*Default options to give to the C++ compiler.
966 This could be any form evaluating to a string. See
967 `mode-compile-choosen-compiler' variable."
968 :type '(choice
969 string
970 (sexp :tag "Form evaluating to a string"))
971 :group 'compile-c++)
973 (defcustom c++-source-file-ext-regexp "\\.\\(cc\\|CC?\\|c\\+\\+?\\|cpp\\|cxx\\)"
974 "Regexp to find, from it's name, if a C++ file is compileable."
975 :type 'regexp
976 :group 'compile-c++)
978 (defcustom c++-build-output-args t
979 "Build output-args for c++-mode."
980 :type 'boolean
981 :group 'compile-c++)
983 (defcustom c++-object-file-ext "o"
984 "Extension of objects file (result of compilation)
985 in c++ mode."
986 :type 'string
987 :group 'compile-c++)
991 ;; @@ ada-mode compile variables ;;;
992 (defgroup compile-ada nil
993 "Ada compilation options"
994 :group 'compilation-lang)
996 (defcustom ada-compilers-list
997 '( "gcc" "gnat" "ada" )
998 "List of user's favourites Ada compilers in order of preferencies."
999 :type '(repeat (string :tag "Ada Compiler name"))
1000 :group 'compile-ada)
1002 (defcustom ada-companion-file-regexp ""
1003 "Regexp to find associated compileable Ada companion file from a spec file.
1005 This is useless in Ada because there do not exists uncompileable files."
1006 :type 'regexp
1007 :group 'compile-ada)
1009 (defcustom ada-default-compiler "ada"
1010 "*Default Ada compiler to use when everything else fails.
1012 This could be any form evaluating to a string, so you could map it to
1013 a function asking you interactively to choose the compiler.
1015 example:
1016 (defun my-choose-compiler()
1017 (read-string \"Ada compiler: \"))
1018 (setq ada-default-compiler 'my-choose-compiler)"
1019 :type '(choice string function)
1020 :group 'compile-ada)
1022 (defcustom ada-compiler-varenv "ADA"
1023 "Varenv indicating the Ada compiler to use."
1024 :type 'string
1025 :group 'compile-ada)
1027 (defcustom ada-aflags-varenv "AFLAGS"
1028 "Varenv indicating the Ada compiler flags to use."
1029 :type 'string
1030 :group 'compile-ada)
1032 (defcustom ada-source-ext-list '( "ads" "adb" "ada" "a" )
1033 "Extensions for Ada compileable source files."
1034 :type '(repeat string)
1035 :group 'compile-ada)
1037 (defcustom ada-headers-ext-list '( "ads" "ada" "a" )
1038 "Extensions for Ada spec source files."
1039 :type '(repeat string)
1040 :group 'compile-ada)
1042 (defcustom ada-default-compiler-options "-g"
1043 "*Default options to give to the Ada compiler.
1045 This could be any form evaluating to a string. See
1046 `mode-compile-choosen-compiler' variable."
1047 :type '(choice
1048 string
1049 (sexp :tag "Form evaluating to a string"))
1050 :group 'compile-ada)
1052 (defcustom ada-source-file-ext-regexp "\\.\\(ad[abs]\\|a\\)"
1053 "Regexp to find, from it's name, if an Ada file is compileable.
1055 This is useless in Ada because there do not exists uncompileable files."
1056 :type 'regexp
1057 :group 'compile-ada)
1059 (defcustom ada-build-output-args t
1060 "Build output-args for ada-mode."
1061 :type 'boolean
1062 :group 'compile-ada)
1064 (defcustom ada-object-file-ext "o"
1065 "Extension of objects file (result of compilation)
1066 in ada mode."
1067 :type 'string
1068 :group 'compile-ada)
1072 ;; @@ fortran-mode compile variables ;;;
1073 (defgroup compile-fortran nil
1074 "Fortran compilation options"
1075 :group 'compilation-lang)
1077 (defcustom f77-compilers-list '( "f77" "fc" )
1078 "List of user's favourite Fortran compilers in order of preferencies."
1079 :type '(repeat (string :tag "C Compiler name"))
1080 :group 'compile-fortran)
1082 (defcustom f77-companion-file-regexp "\\(_[Pp]\\)?\\.[pP]?inc"
1083 "Regexp to find associated .f file from a .inc."
1084 :type 'regexp
1085 :group 'compile-fortran)
1087 (defcustom f77-default-compiler "f77"
1088 "*Default fortran compiler to use when everything else fails..
1090 This could be any form evaluating to a string, so you could map it to
1091 a function asking you interactively to choose the compiler.
1093 example:
1094 (defun my-choose-compiler()
1095 (read-string \"Fortran compiler: \"))
1096 (setq f77-default-compiler 'my-choose-compiler)"
1097 :type '(choice string function)
1098 :group 'compile-fortran)
1100 (defcustom f77-compiler-varenv "F77"
1101 "Varenv indicating the fortran compiler to use."
1102 :type 'string
1103 :group 'compile-fortran)
1105 (defcustom f77-cflags-varenv "FCOPTS"
1106 "Varenv indicating the fortran compiler flags to use."
1107 :type 'string
1108 :group 'compile-fortran)
1110 (defcustom f77-source-ext-list '( "f" "F" "for" "For" )
1111 "Extensions for fortran compileable source files."
1112 :type '(repeat string)
1113 :group 'compile-fortran)
1115 (defcustom f77-headers-ext-list '( "inc" "h")
1116 "Extensions for fortran include files."
1117 :type '(repeat string)
1118 :group 'compile-fortran)
1120 (defcustom f77-default-compiler-options "-w66 -a"
1121 "*Default options to give to the fortran compiler.
1123 This could be any form evaluating to a string. See
1124 `mode-compile-choosen-compiler' variable."
1125 :type '(choice
1126 string
1127 (sexp :tag "Form evaluating to a string"))
1128 :group 'compile-fortran)
1130 (defcustom f77-source-file-ext-regexp "\\.\\([Ff]\\|for\\)"
1131 "Regexp to find, from it's name, if a fortran file is compileable."
1132 :type 'regexp
1133 :group 'compile-fortran)
1135 (defcustom f77-build-output-args t
1136 "Build output-args for f77-mode."
1137 :type 'boolean
1138 :group 'compile-fortran)
1140 (defcustom f77-object-file-ext "o"
1141 "Extension of objects file (result of compilation)
1142 in Fortran mode."
1143 :type 'string
1144 :group 'compile-fortran)
1148 ;; @@ sh-mode compile variables ;;;
1149 (defgroup compile-sh nil
1150 "Sh (Bourne Shell scripts) compilation options"
1151 :group 'compilation-script)
1153 (defcustom sh-command "sh"
1154 "Command to run sh scripts"
1155 :type 'string
1156 :group 'compile-sh)
1158 (defcustom sh-dbg-flags "-fvx"
1159 "*Flags to give to sh for debugging a Bourne Shell script.
1161 The -f flag must always be present."
1162 :type 'string
1163 :group 'compile-sh)
1165 (defvar sh-compilation-error-regexp-alist nil
1166 ;; I'd never seen a Bourne shell returning file+line where a syntax
1167 ;; error occured.
1168 "Alist that specifies how to match errors in sh output.
1170 See variable compilation-error-regexp-alist for more details.")
1173 ;; @@ csh-mode compile variables ;;;
1174 (defgroup compile-csh nil
1175 "Csh (C Shell) compilation options"
1176 :group 'compilation-script)
1178 (defcustom csh-command "csh"
1179 "Command to run csh scripts"
1180 :type 'string
1181 :group 'compile-csh)
1183 (defcustom csh-dbg-flags "-fVX"
1184 "*Flags to give to csh for debugging a C Shell script.
1186 The -f flag must always be present."
1187 :type 'string
1188 :group 'compile-csh)
1190 (defvar csh-compilation-error-regexp-alist nil
1191 ;; I'd never seen a C shell returning file+line where a syntax
1192 ;; error occured.
1193 "Alist that specifies how to match errors in csh output.
1195 See variable compilation-error-regexp-alist for more details.")
1198 ;; @@ zsh-mode compile variables ;;;
1199 (defgroup compile-zsh nil
1200 "Zsh (Z Shell scripts) compilation options"
1201 :group 'compilation-script)
1203 (defcustom zsh-command "zsh"
1204 "Command to run zsh scripts"
1205 :type 'string
1206 :group 'compile-zsh)
1208 (defcustom zsh-dbg-flags "-nCvx"
1209 "*Flags to give to zsh for debugging a Z Shell script."
1210 :type 'string
1211 :group 'compile-zsh)
1213 (defvar zsh-compilation-error-regexp-alist nil
1214 ;; I'd never seen a Z shell returning file+line where a syntax
1215 ;; error occured.
1216 "Alist that specifies how to match errors in csh output.
1218 See variable compilation-error-regexp-alist for more details.")
1221 ;; @@ tcl-mode compile variables - JWH ;;;
1222 (defgroup compile-tcl nil
1223 "Tcl compilation options"
1224 :group 'compilation-script)
1226 (defcustom tcl-command "wish"
1227 "Command to run tcl scripts"
1228 :type 'string
1229 :group 'compile-tcl)
1231 (defcustom tcl-dbg-flags ""
1232 "*Flags to give to tcl -- none."
1233 :type 'string
1234 :group 'compile-tcl)
1236 (defvar tcl-compilation-error-regexp-alist
1237 ;; TK (file "/directory-path/filename.tcl" line XY)
1239 ("file \"\\([^ ]+\\)\" line \\([0-9]+\\)[)]" 1 2)
1241 "Alist that specifies how to match errors in tcl output.
1243 See variable compilation-error-regexp-alist for more details.")
1246 ;; @@ python-mode compile variables - BM ;;;
1247 (defgroup compile-python nil
1248 "Python compilation options"
1249 :group 'compilation-script)
1251 (defcustom python-command "python"
1252 "Command to run python scripts"
1253 :type 'string
1254 :group 'compile-python)
1256 (defcustom python-dbg-flags ""
1257 "*Flags to give to python -- none."
1258 :type 'string
1259 :group 'compile-python)
1261 (defvar python-compilation-error-regexp-alist
1262 ;; TK (file "/directory-path/filename.tcl" line XY in ZZZ)
1264 ("File \"\\([^ ]+\\)\", line \\([0-9]+\\).*" 1 2)
1266 "Alist that specifies how to match errors in python output.
1268 See variable compilation-error-regexp-alist for more details.")
1271 ;; @@ perl-mode compile variables ;;;
1272 (defgroup compile-perl nil
1273 "Perl compilation options"
1274 :group 'compilation-script)
1276 (defcustom perl-command "perl"
1277 "Command to run perl."
1278 :type 'string
1279 :group 'compile-perl)
1281 (defcustom perl-dbg-flags "-w"
1282 "*Flags to give to perl for debugging a Perl script."
1283 :type 'string
1284 :group 'compile-perl)
1286 (defvar perl-compilation-error-regexp-alist
1287 ;; Contributed by Martin Jost
1289 ;; PERL 4
1290 ("in file \\([^ ]+\\) at line \\([0-9]+\\).*" 1 2)
1291 ;; PERL 5 Blubber at FILE line XY, <XY> line ab.
1292 ("at \\([^ ]+\\) line \\([0-9]+\\)," 1 2)
1293 ;; PERL 5 Blubber at FILE line XY.
1294 ("at \\([^ ]+\\) line \\([0-9]+\\)." 1 2)
1296 ;; This look like a paranoiac regexp: could anybody find a better one? (which WORK).
1297 ;;'(("^[^\n]* \\(file\\|at\\) \\([^ \t\n]+\\) [^\n]*line \\([0-9]+\\)[\\.,]" 2 3))
1298 "Alist that specifies how to match errors in perl output.
1300 See variable compilation-error-regexp-alist for more details.")
1303 ;; @@ ruby-mode compile variables ;;;
1304 (defgroup compile-ruby nil
1305 "Ruby compilation options"
1306 :group 'compilation-script)
1308 (defcustom ruby-command "ruby"
1309 "Command to run ruby"
1310 :type 'string
1311 :group 'compile-ruby)
1313 (defcustom ruby-dbg-flags "-w"
1314 "Flags to give ruby for catching warnings"
1315 :type 'string
1316 :group 'compile-ruby)
1318 (defvar ruby-compilation-error-regexp-alist
1320 ;; Unit Tests
1321 ("test[a-zA-Z0-9_]*([A-Z][a-zA-Z0-9_]*) \\[\\(.*\\):\\([0-9]+\\)\\]:" 1 2)
1322 ;; Errors and Warnings
1323 ("\\(.*?\\)\\([0-9A-Za-z_./\:-]+\\.rb\\):\\([0-9]+\\)" 2 3))
1324 "Alist that specifies how to match errors in ruby output.
1326 See variable compilation-error-regexp-alist for more details.")
1329 ;; @@ emacs lisp compile variables ;;;
1331 ;;;###autoload
1332 (defcustom emacs-lisp-byte-compile-dir-interactive-p t
1333 "*Non-nil means when byte-compiling a directory ask for each file
1334 needing to be recompiled or not."
1335 :type 'boolean
1336 :group 'compilation-elisp)
1337 (define-obsolete-variable-alias
1338 'mode-compile-byte-compile-dir-interactive-p
1339 'emacs-lisp-byte-compile-dir-interactive-p)
1341 (defcustom emacs-lisp-sources-regexp
1342 (cond
1343 ((boundp 'emacs-lisp-file-regexp)
1344 emacs-lisp-file-regexp)
1346 "\\.el$"))
1347 "Regexp to find emacs lisp sources files."
1348 :type 'regexp
1349 :group 'compilation-elisp)
1351 (defcustom emacs-lisp-bytecomp-ext "c"
1352 "Extension added to byte-compiled emacs sources files."
1353 :type 'string
1354 :group 'compilation-elisp)
1357 ;; @@ Misc declarations ;;;
1359 ;;;###autoload
1360 (defconst mode-compile-version "2.28"
1361 "Current version of mode-compile package.
1363 mode-compile.el,v 2.28 2003/04/01 13:52:47 boubaker Exp
1364 Please send bugs-fixes/contributions/comments to boubaker@cena.fr")
1366 (defconst mode-compile-help-address "heddy.Boubaker@cena.fr"
1367 "E-Mail address of mode-compile maintainer.")
1370 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1371 ;; @ No user modifiable stuff below this line ;;;
1372 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1374 ;; Save old compile function. In case someone will bound
1375 ;; mode-compile on 'compile.
1376 (or (fboundp 'mc--compile-sav)
1377 (if (fboundp 'compile)
1378 (progn
1379 (fset 'mc--compile-sav (symbol-function 'compile))
1380 (put 'compile 'compile-saved-on-mc--compile-sav t))
1381 (error "`compile' function not known to be defined...")))
1383 ;; @@ Internals variables and constants ;;;
1385 ;; Mode specific
1386 (defvar mc--comp-lst nil) ; c-mode,c++-mode,ada-mode,fortran-mode
1387 (defvar mc--def-comp nil) ; itou
1388 (defvar mc--compfile-regexp nil) ; itou
1389 (defvar mc--comp-varenv nil) ; itou
1390 (defvar mc--comp-options nil) ; itou
1391 (defvar mc--cflags-varenv nil) ; itou
1392 (defvar mc--source-ext-lst nil) ; itou
1393 (defvar mc--head-ext-lst nil) ; itou
1394 (defvar mc--source-ext-regexp nil) ; itou
1395 (defvar mc--build-op-args nil) ; itou
1396 (defvar mc--outfile-ext nil) ; itou
1398 ;; remote stuff
1399 (defvar mc--efs-path-list nil)
1400 (defvar mc--remote-host nil)
1401 (defvar mc--remote-host-history nil)
1402 (defvar mc--remote-username nil)
1403 (defvar mc--remote-command nil)
1404 (defvar mc--remote-pathname nil)
1406 ;; Frames/Windows stuff
1407 (defvar mc--other-frame nil)
1408 (defvar mc--ws (or
1409 (and (fboundp 'console-type) (console-type))
1410 (and (fboundp 'device-type) (device-type))
1411 window-system))
1413 (defvar mc--compile-command nil)
1414 ;; Compile command used when no makefile has been found.
1415 ;; This variable is buffer local to keep history for read-string.
1416 ;; Unfortunately not a real history, keep only memory of
1417 ;; the last compile command used.
1418 (make-variable-buffer-local 'mc--compile-command)
1420 (defvar mc--kill-compile nil)
1421 ;; kill-compile command bound dynamically by `guess-compile'.
1422 (make-variable-buffer-local 'mc--kill-compile)
1424 (defvar mc--selected-makefile nil)
1425 (defvar mc--selected-makefile-history nil)
1426 ;; User selected makefile among the list, to run make with.
1427 ;; This variable is buffer local to keep history for completing-read
1428 ;; Unfortunately not a real history, keep only memory of
1429 ;; the last makefile used.
1430 (make-variable-buffer-local 'mc--selected-makefile)
1432 (defvar mc--selected-makerule nil)
1433 (defvar mc--selected-makerule-history nil)
1434 ;; User selected make rule to rebuild.
1435 ;; This variable is buffer local to keep history for completing-read
1436 ;; Unfortunately not a real history, keep only memory of
1437 ;; the last makerule used.
1438 (make-variable-buffer-local 'mc--selected-makerule)
1440 (defconst mc--find-C-main-regexp
1441 "^[ \t]*\\(int\\|void\\)?[ \t\n]*main[ \t\n]*\(+" )
1442 ;; Regexp to find the main() function in a C/C++ file
1444 (defconst mc--makefile-rules-regexp
1445 "^\n*\\([^.$ \t#\n][^$ \t#\n:]*\\)[ \t]*:")
1446 ;; Regexp to extract makefiles rules.
1447 ;; But only those not containing references to $(VARIABLES)
1448 ;; and not starting with `.'
1450 (defvar mc--makefile-rules nil)
1451 ;; List of all rules extracted from makefile
1452 (make-variable-buffer-local 'mc--makefile-rules)
1454 (defvar mc--mkfl-buffer-tick nil)
1455 ;; Tick counter for the buffer at the time of the rules extraction.
1456 (make-variable-buffer-local 'mc--mkfl-buffer-tick)
1458 (defvar mc--shell-args nil)
1459 ;; Shell arguments for the script to debug.
1460 ;; This variable is buffer local to keep history for read-string.
1461 ;; Unfortunately not a real history, keep only memory of
1462 ;; the last shell arguments used.
1463 (make-variable-buffer-local 'mc--shell-args)
1465 ;; nil in GNU FSF Emacs, >= 0 in GNU Lucid Emacs/XEmacs
1466 (defconst mc--lucid-emacs-p (or (string-match "Lucid" emacs-version)
1467 (string-match "XEmacs" emacs-version)))
1469 ;; @@ Internals functions and macros ;;;
1471 (if (not (fboundp 'defsubst))
1472 ;; Emacs 18
1473 (fset 'defsubst (symbol-function 'defun)))
1475 (defun mc--compile (compile-command)
1476 ;; Call compile with the compile command
1477 ;; but append the remote-command before
1478 (if (null mc--remote-command)
1479 ;; local compile
1480 (mc--compile-sav compile-command)
1481 ;; remote compile
1482 (let ((thisdir (expand-file-name (or default-directory "~"))))
1483 (mc--compile-sav
1484 (concat
1485 ;; The command to lauch remote commands
1486 mc--remote-command
1487 ;; Change to this buffer directory ...
1488 "'( cd " thisdir " ; "
1489 ;; then run the compile command
1490 compile-command " )'")))))
1492 (defsubst mc--msg (msg &rest args)
1493 ;; Print MSG with ARGS and wait to let time to user
1494 ;; to read the message in minibuffer.
1495 (cond ((not mode-compile-expert-p)
1496 (apply 'message (concat "mode-compile: " msg) args)
1497 (sit-for mode-compile-reading-time))))
1499 (cond
1500 ;; Check availaibles frames functions
1501 ((fboundp 'make-frame)
1502 ;; GNU Emacs
1503 (fset 'mc--make-frame (symbol-function 'make-frame))
1504 (fset 'mc--select-frame (symbol-function 'select-frame))
1505 (fset 'mc--frame-live-p (symbol-function 'frame-live-p))
1506 (fset 'mc--make-frame-visible (symbol-function 'make-frame-visible))
1507 (fset 'mc--raise-frame (symbol-function 'raise-frame)))
1508 ((fboundp 'make-screen)
1509 ;; XEmacs
1510 (fset 'mc--make-frame (symbol-function 'make-screen))
1511 (fset 'mc--select-frame (symbol-function 'select-screen))
1512 (fset 'mc--frame-live-p (symbol-function 'screen-live-p))
1513 (fset 'mc--make-frame-visible (symbol-function 'make-screen-visible))
1514 (fset 'mc--raise-frame (symbol-function 'raise-screen)))
1515 ((fboundp 'new-screen)
1516 ;; Lucid Emacs/obsolete
1517 (fset 'mc--make-frame (symbol-function 'new-screen))
1518 (fset 'mc--select-frame (symbol-function 'select-screen))
1519 (fset 'mc--frame-live-p (symbol-function 'screen-live-p))
1520 (fset 'mc--make-frame-visible (symbol-function 'make-screen-visible))
1521 (fset 'mc--raise-frame (symbol-function 'raise-screen))))
1523 (defsubst mc--funcall (command &rest params)
1524 ;; Run command with params in another frame or not:
1525 ;; only if user ask for it and if window system is X
1526 ;; (maybe test window-system is set will be enought?).
1527 (cond ((and (eq mc--ws 'x)
1528 mode-compile-other-frame-p)
1529 ;; switch to another frame
1530 (mc--msg "Switching to another frame to compile...")
1531 (let ((buffer (current-buffer))
1532 (win-attr (or mode-compile-frame-parameters-alist
1533 mode-compile-default-frame-parameters))
1534 (frame (cond ((fboundp 'mc--frame-live-p)
1535 (if (mc--frame-live-p mc--other-frame)
1536 mc--other-frame
1537 nil))
1539 (mc--msg "Don't know how to check frame existence.")
1540 nil))))
1541 (cond ((fboundp 'mc--make-frame)
1542 (mc--select-frame (or frame
1543 (setq mc--other-frame
1544 (mc--make-frame win-attr))))
1545 ;; I really don't understand why the 3 following
1546 ;; are necessary (raise-frame must be enought?).
1547 (mc--make-frame-visible mc--other-frame)
1548 (mc--raise-frame mc--other-frame)
1549 (switch-to-buffer buffer))
1551 (mc--msg "Don't know how to create a new frame."))))))
1552 ;; Just run the command with it's parameters
1553 (apply command params))
1555 (defun mc--byte-compile-buffer()
1556 (if (fboundp 'byte-compile-buffer) (byte-compile-buffer)
1557 ;; No byte-compile-buffer
1558 ;; Save current-buffer in a temporary file and byte-compile it.
1559 (let ((tmp-file (concat (or (getenv "TMPDIR")
1560 (concat mode-compile-dir-separator-char "tmp"))
1561 mode-compile-dir-separator-char (make-temp-name "mc--"))))
1562 (save-restriction
1563 (widen)
1564 (write-region (point-min) (point-max) tmp-file)
1565 (condition-case err
1566 (byte-compile-file tmp-file)
1567 ;; handler
1568 (error (mc--msg "Failing to byte-compile %s, #error %s"
1569 (buffer-name) err)))
1570 (delete-file tmp-file)
1571 (let ((elc-file (concat tmp-file emacs-lisp-bytecomp-ext)))
1572 (if (file-writable-p elc-file)
1573 (condition-case err
1574 (delete-file elc-file)
1575 ;; handler
1576 (error (mc--msg "Failing to delete %s, #error %s"
1577 elc-file err)))))
1578 (message nil))))) ; to clean minibuffer
1580 (fset 'mc--member
1581 (if (fboundp 'member)
1582 (symbol-function 'member)
1583 ;; No member function
1584 (function
1585 (lambda (elt list)
1586 (catch 'elt-is-member
1587 (while list
1588 (if (equal elt (car list))
1589 (throw 'elt-is-member list))
1590 (setq list (cdr list))))))))
1592 (fset 'mc--run-hooks
1593 (if (fboundp 'run-hooks)
1594 (symbol-function 'run-hooks)
1595 ;; No run-hooks
1596 (function
1597 (lambda (hooklist)
1598 (mapcar '(lambda (x)
1599 ;; report an error if x not a function
1600 (funcall x))
1601 hooklist)))))
1603 (defsubst mc--read-string (prompt &optional initial-contents)
1604 ;; On Lucid Emacs I use compile-history as 3rd argument but
1605 ;; no history is possible with GNU emacs.
1606 (if mc--lucid-emacs-p
1607 (read-string prompt initial-contents 'compile-history)
1608 (read-string prompt initial-contents)))
1610 (defmacro mc--eval (sym &optional arg)
1611 ;; Evaluate symbol
1612 (` (cond
1613 ((and (symbolp (, sym))
1614 (fboundp (, sym)))
1615 (funcall (, sym) (, arg)))
1617 (eval (, sym))))))
1619 (defmacro mc--common-completion (alist)
1620 ;; Return the greatest common string for all
1621 ;; possible completions in alist.
1622 (` (try-completion "" (, alist))))
1624 (defun mc--byte-recompile-files (files)
1625 ;; Byte recompile all FILES which are older than their
1626 ;; .elc files in the current directory
1627 (let ((tmp-fl files))
1628 (while (car-safe tmp-fl)
1629 (let* ((el-file (car tmp-fl))
1630 (elc-file (concat el-file emacs-lisp-bytecomp-ext)))
1631 (mc--msg "Checking file %s ..." el-file)
1632 ;; is el-file newer than elc-file (if exists)
1633 (if (and (file-newer-than-file-p el-file elc-file)
1634 (or (not emacs-lisp-byte-compile-dir-interactive-p)
1635 (y-or-n-p (format "byte-recompile file %s? " el-file))))
1636 (condition-case err
1637 (byte-compile-file el-file)
1638 ;; handler
1639 (error (mc--msg "Failing to byte-compile %s, #error %s"
1640 el-file err))))
1641 (setq tmp-fl (cdr-safe tmp-fl))))
1642 (mc--msg "All files processed")))
1644 (defun mc--which (file)
1645 ;; Find an executable FILE in exec-path
1646 (if (not (stringp file))
1647 (error "mc--which: nil FILE arg"))
1648 (if mc--lucid-emacs-p
1649 ;; Some emacses don't have locate-file some have...
1650 ;; Lucid have it in standard, some others (GNU) have it
1651 ;; (add-on pkg) but the syntax is not always consistent...
1652 ; (locate-file file exec-path nil 1)
1653 (locate-file file exec-path mode-compile-exe-file-ext 1)
1654 (let ((tmp-p-lst exec-path)
1655 (found nil)
1656 (file-found nil))
1657 (while (and (car-safe tmp-p-lst)
1658 (not (setq found
1659 (file-executable-p
1660 (setq file-found
1661 (concat (car tmp-p-lst)
1662 mode-compile-dir-separator-char
1663 file
1664 mode-compile-exe-file-ext))))))
1665 (setq tmp-p-lst (cdr-safe tmp-p-lst)))
1666 (if found file-found nil))))
1668 (defun mc--find-compiler ()
1669 ;; Find user's favourite mode compiler
1670 (mc--msg "Searching for your favourite %s compiler ..." mode-name)
1671 (let ((tmp-comp-lst mc--comp-lst)
1672 (compiler nil))
1673 (or (getenv mc--comp-varenv)
1674 (progn
1675 (while (and tmp-comp-lst
1676 (not (setq compiler
1677 (mc--which (car tmp-comp-lst)))))
1678 (setq tmp-comp-lst (cdr tmp-comp-lst)))
1679 (file-name-nondirectory (or compiler (mc--eval mc--def-comp)))))))
1681 (defun mc--find-to-compile-file (&optional fname)
1682 ;; Find the name of the file to compile.
1683 (let ((file-name (or fname
1684 (buffer-file-name)
1685 (error "Compilation abort: Buffer %s has no filename."
1686 (buffer-name))))
1687 (assoc-file nil)
1688 (found nil)
1689 (pos 0))
1690 (cond
1691 ((string-match mc--source-ext-regexp file-name)
1692 ;; buffer is a compileable file
1693 (file-name-nondirectory file-name))
1695 ((setq pos (string-match mc--compfile-regexp file-name))
1696 ;; Buffer is not a compileable file, try to find associated
1697 ;; compileable file.
1698 (let ((tmp-ext-lst mc--source-ext-lst))
1699 (mc--msg "Looking for a compileable companion file for %s..."
1700 (file-name-nondirectory file-name))
1701 (while (and tmp-ext-lst
1702 (not (setq found
1703 (file-readable-p
1704 (setq assoc-file
1705 (concat
1706 (substring file-name 0 pos)
1707 "." (car tmp-ext-lst)))))))
1708 (setq tmp-ext-lst (cdr tmp-ext-lst))))
1709 (if found
1710 ;; A compileable companion source file found
1711 (file-name-nondirectory assoc-file)
1712 ;; No compileable companion source file found
1713 (mc--msg "Couldn't find any compileable companion file for %s ..."
1714 (file-name-nondirectory file-name))
1715 nil))
1718 ;; Buffer has an unknown file extension
1719 ;; Could I be more cool?
1720 (error "Compilation abort: Don't know how to compile %s."
1721 (file-name-nondirectory file-name))))))
1723 (defun mc--guess-compile-result-fname (infile)
1724 ;; Try to guess if outfile will be an object file or
1725 ;; an executable file by grepping for `main()' in INFILE.
1726 (let ((base-fname
1727 (substring infile 0
1728 (string-match mc--source-ext-regexp infile))))
1729 (save-excursion
1730 ;; Create a temporary buffer containing infile contents
1731 (set-buffer (find-file-noselect infile))
1732 (save-excursion
1733 (save-restriction
1734 (widen)
1735 (goto-char (point-min))
1736 ;; Grep into tmp buffer for main function
1737 ;; THIS WILL NOT WORK FOR PROGRAMMING LANGAGES
1738 ;; WHICH ARE NOT C DIALECTS:
1739 ;; In non C-ish modes I hope this regexp will never be found :-(
1740 (if (re-search-forward mc--find-C-main-regexp (point-max) t)
1741 (concat base-fname mode-compile-exe-file-ext)
1742 (concat base-fname "." mc--outfile-ext)))))))
1744 (defun mc--build-output-args (infile)
1745 ;; Build output arguments for compile command by scanning INFILE.
1746 (mc--msg "Looking into %s to build compile command ..." infile)
1747 (let ((out-file (mc--guess-compile-result-fname infile)))
1748 (concat (if (string-match
1749 (concat "\\." mc--outfile-ext "$")
1750 out-file)
1751 ;; outfile will be an object file
1752 " -c "
1753 ;; outfile will be an executable file
1754 " ")
1755 infile " -o " out-file )))
1757 (defun mc--set-remote-cmd (remote-host &optional username pathname)
1758 ;; Check validity of remote-host or ask one to user
1759 ;; Then build the first part of the remote command
1760 (if (stringp remote-host)
1761 ;; Arg is the remote host name
1762 (let ((host-infos (assoc remote-host
1763 mode-compile-remote-hosts-alist)))
1764 (setq mc--remote-host
1765 remote-host)
1766 (setq mc--remote-username
1767 (or username
1768 (let ((usrnam (cdr host-infos)))
1769 (if usrnam
1770 (cond
1771 ((stringp usrnam)
1772 usrnam)
1773 ((functionp usrnam)
1774 ;; usrnam is a function call it with hostname arg
1775 (funcall usrnam mc--remote-host))
1777 ;; What's that??
1778 (mc--msg "%s is not a valid option using user-login-name" (pp-to-string usrnam))
1779 (user-login-name)))
1780 (user-login-name)))))
1781 (setq mc--remote-pathname pathname)
1782 ;; Add host to the user's list
1783 (or host-infos
1784 (setq mode-compile-remote-hosts-alist
1785 (append (list (list remote-host))
1786 mode-compile-remote-hosts-alist)))
1787 ;; Prepare the command
1788 (setq mc--remote-command
1789 (concat
1790 ;; "rsh host -l username"
1791 mode-compile-remote-execute-command " "
1792 mode-compile-remote-execute-set-host-arg " "
1793 mc--remote-host " "
1794 mode-compile-remote-execute-set-username-arg " "
1795 mc--remote-username " "
1796 mode-compile-remote-execute-misc-args " "
1797 mode-compile-remote-execute-set-command-arg " "
1799 ;; Arg is: Ask to user then check
1800 (let ((rhost (completing-read
1801 "Remote host to compile to: "
1802 mode-compile-remote-hosts-alist
1803 nil nil
1804 ;; Initial contents
1805 (or mc--remote-host
1806 (car-safe (car-safe mode-compile-remote-hosts-alist)))
1807 mc--remote-host-history)))
1808 (or (string= rhost "")
1809 (mc--set-remote-cmd rhost)))))
1811 ;(defmacro mc--makefile-test-p (makefile)
1812 ; (` (and (, makefile)
1813 ; (not (string-equal (, makefile) ""))
1814 ; (not (file-directory-p (, makefile)))
1815 ; (file-readable-p (, makefile)))))
1816 (defun mc--makefile-test-p (makefile)
1817 (cond
1818 ((or (not makefile)
1819 (string-equal makefile ""))
1820 (mc--msg "Empty makefile selection")
1821 nil)
1822 ((file-directory-p makefile)
1823 (mc--msg "Makefile selection %s is a directory !!" makefile)
1824 nil)
1825 ((not (file-readable-p makefile))
1826 (mc--msg "Makefile %s unreadable" makefile)
1827 nil)
1828 (t)))
1831 (if (not (fboundp 'buffer-modified-tick))
1832 (fset 'buffer-modified-tick
1833 ;; allways indicate modified
1834 (function
1835 (lambda()
1836 (if mc--mkfl-buffer-tick
1837 (+ mc--mkfl-buffer-tick 1)
1838 1)))))
1840 (defun mc--get-makefile-rules (makefile)
1841 ;; Try to find if makefile's buffer has been modified
1842 ;; since last rule extraction
1843 (if (or (not mc--mkfl-buffer-tick)
1844 (not (equal mc--mkfl-buffer-tick
1845 (buffer-modified-tick))))
1846 (save-excursion
1847 (save-restriction
1848 (widen)
1849 (goto-char (point-min))
1850 (setq mc--mkfl-buffer-tick (buffer-modified-tick))
1851 (setq mc--makefile-rules nil)
1852 (mc--msg "Extracting rules from %s ..." makefile)
1853 ;; Grep into tmp buffer for makefile rules
1854 (while (re-search-forward mc--makefile-rules-regexp nil t)
1855 (let ((rule (buffer-substring
1856 (match-beginning 1)
1857 (match-end 1))))
1858 ;; add rule to list if it don't match the ignore regexp
1859 ;; and if not allready in rules list.
1860 (if (and
1861 (or (not mode-compile-ignore-makerule-regexp)
1862 (not (string-match
1863 mode-compile-ignore-makerule-regexp
1864 rule)))
1865 (not (mc--member rule mc--makefile-rules)))
1866 (setq mc--makefile-rules
1867 (append mc--makefile-rules
1868 (list rule))))))))
1869 (mc--msg "Rules had already been extracted from %s ..." makefile))
1870 ;; Always add an empty rule to allow `default' choice.
1871 (append mc--makefile-rules '([])))
1873 (defun mc--makerule-completion (alist outfile &optional pref)
1874 ;; Return the makerule completion according to the prefered
1875 ;; default makerule
1876 (let ((preference (or pref
1877 mode-compile-prefered-default-makerule)))
1878 (mc--msg "Prefered makerule choice is '%s" preference)
1879 (cond
1880 ((eq preference 'none)
1881 ;; Just show max common completion string to user
1882 (or (mc--common-completion alist) ""))
1884 ((eq preference 'all)
1885 ;; Find the all rule or 'none
1886 (if (assoc "all" alist) "all"
1887 (mc--makerule-completion alist outfile 'none)))
1889 ((eq preference 'file)
1890 ;; The out file is prefered or 'none
1891 (or outfile (mc--makerule-completion alist outfile 'none)))
1893 ((eq preference 'default)
1894 ;; Find the default rule or ""
1895 (if (assoc "default" alist) "default" ""))
1898 ;; Invalid preference return 'none
1899 (mc--msg "Invalid `mode-compile-prefered-default-makerule': '%s"
1900 mode-compile-prefered-default-makerule)
1901 (mc--makerule-completion alist outfile 'none)))))
1903 (defun mc--choose-makefile-rule (makefile &optional outfile)
1904 ;; Choose the makefile rule and set it makefile local
1905 (save-excursion
1906 ;; Switch to makefile buffer
1907 (set-buffer (find-file-noselect makefile))
1908 (setq mc--selected-makerule
1909 ;; Add the name of the out file to the makefile
1910 ;; rules list if not allready in.
1911 (let* ((mk-rules-alist (mc--get-makefile-rules makefile))
1912 (choices (mapcar '(lambda (x) (list x))
1913 (if (or (not outfile)
1914 (mc--member outfile
1915 mk-rules-alist))
1916 mk-rules-alist
1917 (append mk-rules-alist
1918 (list outfile))))))
1919 (completing-read
1920 (if mode-compile-expert-p
1921 "Make rule: "
1922 "Using `make', enter rule to rebuild ([TAB] to complete): ")
1923 choices
1924 nil nil
1925 ;; initial contents
1926 (or mc--selected-makerule
1927 (mc--makerule-completion choices outfile
1928 (if outfile 'file)))
1929 mc--selected-makerule-history
1930 )))))
1932 (defmacro mc--cleanup-makefile-list (makefile-list)
1933 ;; Remove unusable and/or backups makefiles from list
1934 (` (let ((newlist))
1935 (mapcar
1936 '(lambda (x)
1937 (if (and (mc--makefile-test-p x)
1938 (or (not mode-compile-ignore-makefile-backups)
1939 (not (string-match
1940 mode-compile-makefile-backups-regexp
1941 x))))
1942 (setq newlist (cons x newlist))
1943 (mc--msg "Removing makefile \"%s\" from completion list"
1944 x)))
1945 (, makefile-list))
1946 newlist)))
1948 (defun mc--makefile-to-use (&optional directory)
1949 ;; Find the makefile to use in the current directory
1950 (let ((makefile-list (mc--cleanup-makefile-list
1951 (directory-files
1952 ;; I do not use the 5th parameter in Lucid Emacs
1953 ;; to be compatible with GNU Emacs which accept
1954 ;; only 4 parameters - no NOSORT -.
1955 (or directory default-directory)
1956 nil mode-compile-makefile-regexp t))))
1957 (cond
1958 ((not makefile-list)
1959 ;; No makefile found
1960 nil)
1962 ((and (not (cdr-safe makefile-list))
1963 (mc--makefile-test-p (car makefile-list)))
1964 ;; Only one valid makefile
1965 (car makefile-list))
1968 ;; Many makefiles in directory ask user to select one
1969 (let ((choices (mapcar
1970 '(lambda (x) (list x))
1971 makefile-list))
1972 (makefile nil))
1973 (while
1974 ;; While the makefile do not pass the test.
1975 (not (mc--makefile-test-p
1976 (setq makefile
1977 (completing-read
1978 (if mode-compile-expert-p
1979 "Makefile: "
1980 "Using `make', select makefile to use ([TAB] to complete): ")
1981 choices
1982 nil t
1983 ;; initial contents
1984 (or mc--selected-makefile
1985 (mc--common-completion choices))
1986 mc--selected-makefile-history
1987 )))))
1988 makefile)))))
1990 (defun mc--set-command (&optional file)
1991 ;; Return a compilation command, built according to the existence
1992 ;; of a makefile or not, to compile FILE .
1993 (setq completion-ignore-case nil) ; let completion be case sensitive
1994 (let ((to-compile-fname (or file (mc--find-to-compile-file))))
1995 (if (setq mc--selected-makefile (mc--makefile-to-use))
1996 (progn
1997 ;; A makefile found in the directory:
1998 ;; using make to compile
1999 (let ((out-fname (if to-compile-fname
2000 (mc--guess-compile-result-fname
2001 to-compile-fname)
2002 nil)))
2003 ;; build make command by asking rule to user
2004 (concat mode-compile-make-program " "
2005 (or (mc--eval mode-compile-make-options) "")
2006 " -f " mc--selected-makefile " "
2007 (mc--choose-makefile-rule
2008 mc--selected-makefile out-fname))))
2009 ;; else
2010 ;; No makefile: build compile command asking for confirmation to user.
2011 ;; Should this be replaced by the creation of a makefile (and then
2012 ;; running it) as rms proposed me?
2013 (or mc--compile-command
2014 (setq mc--compile-command
2015 (concat (setq mode-compile-choosen-compiler
2016 (mc--find-compiler)) " "
2017 (or (getenv mc--cflags-varenv)
2018 (mc--eval mc--comp-options))
2019 (if to-compile-fname
2020 (if mc--build-op-args
2021 (mc--build-output-args to-compile-fname)
2022 (concat " " to-compile-fname)
2024 " "))))
2025 (if (not mode-compile-never-edit-command-p)
2026 (setq mc--compile-command
2027 (mc--read-string
2028 (if mode-compile-expert-p
2029 "Compile command: "
2030 (if to-compile-fname
2031 (format "Edit command to compile %s: "
2032 to-compile-fname)
2033 "Edit compile command: " ))
2034 mc--compile-command))
2035 mc--compile-command))))
2037 (defun mc--shell-compile (shell dbgflags &optional errors-regexp-alist)
2038 ;; Run SHELL with debug flags DBGFLAGS on current-buffer
2039 (let* ((shcmd (or (mc--which shell)
2040 (error "Compilation abort: command %s not found" shell)))
2041 (shfile (or mc--remote-pathname (buffer-file-name)
2042 (error "Compilation abort: Buffer %s has no filename"
2043 (buffer-name))))
2044 (run-cmd (concat shcmd " " dbgflags " " shfile " "
2045 (setq mc--shell-args
2046 (read-string (if mode-compile-expert-p
2047 "Argv: "
2048 (format "Arguments to %s %s script: "
2049 shfile shell))
2050 mc--shell-args)))))
2051 ;; Modify compilation-error-regexp-alist if needed
2052 (if errors-regexp-alist
2053 (progn
2054 ;; Set compilation-error-regexp-alist from compile
2055 (or (listp errors-regexp-alist)
2056 (error "Compilation abort: In mc--shell-compile errors-regexp-alist not a list."))
2057 ;; Add new regexp alist to compilation-error-regexp-alist
2058 (mapcar '(lambda(x)
2059 (if (mc--member x compilation-error-regexp-alist) nil
2060 (setq compilation-error-regexp-alist
2061 (append (list x)
2062 compilation-error-regexp-alist))))
2063 errors-regexp-alist)))
2064 ;; Run compile with run-cmd
2065 (mc--compile run-cmd)))
2067 (defmacro mc--assq-get-fcomp (asq)
2068 ;; Return compile-function associated to ASQ
2069 (` (let* ((mode (cdr (, asq)))
2070 (massq (assq mode mode-compile-modes-alist)))
2071 (if massq (car-safe (cdr massq))))))
2073 (defmacro mc--assq-get-fkill (asq)
2074 ;; Return kill-compile-function associated to ASQ
2075 (` (let* ((mode (cdr (, asq)))
2076 (massq (assq mode mode-compile-modes-alist)))
2077 (if massq (car-safe (cdr-safe (cdr massq)))))))
2079 (defun mc--lookin-for-shell ()
2080 ;; Look into current-buffer to see if it is a shell script
2081 ;; and return function to compile it or nil.
2082 (mc--msg "Looking if buffer %s is a shell script..." (buffer-name))
2083 (save-excursion
2084 (save-restriction
2085 (widen)
2086 (goto-char (point-min))
2087 (if (looking-at "#![ \t]*/\\([^ \t\n]+/\\)\\([^ \t\n]+\\)")
2088 (let* ((shell-name (buffer-substring (match-beginning 2)
2089 (match-end 2)))
2090 (shell-assq (assoc shell-name mode-compile-shell-alist)))
2091 (if shell-assq
2092 (progn
2093 (mc--msg "Buffer is a %s script" shell-name)
2094 (setq mc--kill-compile (mc--assq-get-fkill shell-assq))
2095 (mc--assq-get-fcomp shell-assq))
2096 nil))))))
2098 (defun mc--lookat-name ()
2099 ;; Lookat buffer file name to see if it can return a function
2100 ;; to compile it or nil.
2101 (mc--msg "Trying to guess compile command from buffer %s file name..."
2102 (buffer-name))
2103 (let ((fname (buffer-file-name)))
2104 (if (not fname) nil
2105 ;; try regexp from mode-compile-filename-regexp-alist
2106 (let ((tmp-al mode-compile-filename-regexp-alist)
2107 (found nil))
2108 (while (and tmp-al (car tmp-al) (not found))
2109 ;; evaluate to string
2110 (let ((regxp (mc--eval (car (car tmp-al)))))
2111 (if (string-match regxp fname)
2112 (setq found (car tmp-al)))
2113 (setq tmp-al (cdr tmp-al))))
2114 (if (not found)
2116 (mc--msg "File %s matches regexp %s" fname (car found))
2117 (setq mc--kill-compile (mc--assq-get-fkill found))
2118 (mc--assq-get-fcomp found))))))
2121 ;; @ mode specific functions ;;;
2123 (defun cc-compile ()
2124 "Run `compile' with a dynamically built command for `c-mode'.
2126 The command is built depending of the existence of a makefile (which could
2127 be specified by changing value of variable mode-compile-makefile-regexp) in
2128 the current directory or not.
2129 If no makefile is found try to run a C compiler on the file or it's companion.
2131 See also variables:
2132 -- cc-compilers-list
2133 -- cc-default-compiler
2134 -- cc-companion-file-regexp
2135 -- cc-compiler-varenv
2136 -- cc-cflags-varenv
2137 -- cc-source-ext-list
2138 -- cc-headers-ext-list
2139 -- cc-source-file-ext-regexp"
2140 (setq
2141 mc--comp-lst cc-compilers-list
2142 mc--def-comp cc-default-compiler
2143 mc--compfile-regexp cc-companion-file-regexp
2144 mc--comp-varenv cc-compiler-varenv
2145 mc--comp-options cc-default-compiler-options
2146 mc--cflags-varenv cc-cflags-varenv
2147 mc--source-ext-lst cc-source-ext-list
2148 mc--head-ext-lst cc-headers-ext-list
2149 mc--source-ext-regexp cc-source-file-ext-regexp
2150 mc--build-op-args cc-build-output-args
2151 mc--outfile-ext cc-object-file-ext
2153 (mc--compile (mc--set-command)))
2155 (defun java-compile ()
2156 "Run `compile' with a dynamically built command for `java-mode'.
2158 The command is built depending of the existence of a makefile (which could
2159 be specified by changing value of variable mode-compile-makefile-regexp) in
2160 the current directory or not.
2161 If no makefile is found try to run a Java compiler on the file or it's
2162 companion.
2164 See also variables:
2165 -- java-compilers-list
2166 -- java-default-compiler
2167 -- java-companion-file-regexp
2168 -- java-compiler-varenv
2169 -- java-cflags-varenv
2170 -- java-source-ext-list
2171 -- java-headers-ext-list
2172 -- java-source-file-ext-regexp"
2173 (setq
2174 mc--comp-lst java-compilers-list
2175 mc--def-comp java-default-compiler
2176 mc--compfile-regexp java-companion-file-regexp
2177 mc--comp-varenv java-compiler-varenv
2178 mc--comp-options java-default-compiler-options
2179 mc--cflags-varenv java-cflags-varenv
2180 mc--source-ext-lst java-source-ext-list
2181 mc--head-ext-lst java-headers-ext-list
2182 mc--source-ext-regexp java-source-file-ext-regexp
2183 mc--build-op-args java-build-output-args
2184 mc--outfile-ext java-object-file-ext
2186 (mc--compile (mc--set-command)))
2188 (defun c++-compile ()
2189 "Run `compile' with a dynamically built command for `c++-mode'.
2191 The command is built depending of the existence of a makefile (which could
2192 be specified by changing value of variable mode-compile-makefile-regexp) in
2193 the current directory or not.
2194 If no makefile is found try to run a C++ compiler on the file or it's companion.
2196 See also variables:
2197 -- c++-compilers-list
2198 -- c++-default-compiler
2199 -- c++-companion-file-regexp
2200 -- c++-compiler-varenv
2201 -- c++-cflags-varenv
2202 -- c++-source-ext-list
2203 -- c++-headers-ext-list
2204 -- c++-source-file-ext-regexp"
2205 (setq
2206 mc--comp-lst c++-compilers-list
2207 mc--def-comp c++-default-compiler
2208 mc--compfile-regexp c++-companion-file-regexp
2209 mc--comp-varenv c++-compiler-varenv
2210 mc--comp-options c++-default-compiler-options
2211 mc--cflags-varenv c++-cflags-varenv
2212 mc--source-ext-lst c++-source-ext-list
2213 mc--head-ext-lst c++-headers-ext-list
2214 mc--source-ext-regexp c++-source-file-ext-regexp
2215 mc--build-op-args c++-build-output-args
2216 mc--outfile-ext c++-object-file-ext
2218 (mc--compile (mc--set-command)))
2221 (defun ada-compile ()
2222 "Run `compile' with a dynamically built command for `ada-mode'.
2224 The command is built depending of the existence of a makefile (which could
2225 be specified by changing value of variable mode-compile-makefile-regexp) in
2226 the current directory or not.
2227 If no makefile is found try to run an Ada compiler on the file.
2229 See also variables:
2230 -- ada-compilers-list
2231 -- ada-default-compiler
2232 -- ada-companion-file-regexp
2233 -- ada-compiler-varenv
2234 -- ada-aflags-varenv
2235 -- ada-source-ext-list
2236 -- ada-headers-ext-list
2237 -- ada-source-file-ext-regexp)"
2238 (setq
2239 mc--comp-lst ada-compilers-list
2240 mc--def-comp ada-default-compiler
2241 mc--compfile-regexp ada-companion-file-regexp
2242 mc--comp-varenv ada-compiler-varenv
2243 mc--comp-options ada-default-compiler-options
2244 mc--cflags-varenv ada-aflags-varenv
2245 mc--source-ext-lst ada-source-ext-list
2246 mc--head-ext-lst ada-headers-ext-list
2247 mc--source-ext-regexp ada-source-file-ext-regexp
2248 mc--build-op-args ada-build-output-args
2249 mc--outfile-ext ada-object-file-ext
2251 (mc--compile (mc--set-command)))
2254 (defun f77-compile ()
2255 "Run `compile' with a dynamically built command for `fortran-mode'.
2257 The command is built depending of the existence of a makefile (which could
2258 be specified by changing value of variable mode-compile-makefile-regexp) in
2259 the current directory or not.
2260 If no makefile is found try to run a Fortran compiler on the file or it's companion..
2262 See also variables:
2263 -- f77-compilers-list
2264 -- f77-default-compiler
2265 -- f77-companion-file-regexp
2266 -- f77-compiler-varenv
2267 -- f77-cflags-varenv
2268 -- f77-source-ext-list
2269 -- f77-headers-ext-list
2270 -- f77-source-file-ext-regexp)"
2271 (setq
2272 mc--comp-lst f77-compilers-list
2273 mc--def-comp f77-default-compiler
2274 mc--compfile-regexp f77-companion-file-regexp
2275 mc--comp-varenv f77-compiler-varenv
2276 mc--cflags-varenv f77-cflags-varenv
2277 mc--comp-options f77-default-compiler-options
2278 mc--source-ext-lst f77-source-ext-list
2279 mc--head-ext-lst f77-headers-ext-list
2280 mc--source-ext-regexp f77-source-file-ext-regexp
2281 mc--build-op-args f77-build-output-args
2282 mc--outfile-ext f77-object-file-ext
2284 (mc--compile (mc--set-command)))
2287 (defun elisp-compile ()
2288 "Run `byte-compile' on the current Emacs lisp buffer.
2289 For `emacs-lisp-mode' and `lisp-interaction-mode'.
2291 Produce a `.elc' file if possible or `byte-compile' only the buffer."
2292 (let ((comp-file (or (buffer-file-name) "")))
2293 (if (string-match emacs-lisp-sources-regexp comp-file)
2294 (progn
2295 (mc--msg "Byte compiling file %s ..." comp-file)
2296 (byte-compile-file comp-file))
2297 (mc--msg "Byte compiling buffer %s #No .elc produced ..." (buffer-name))
2298 (mc--byte-compile-buffer))))
2301 (defun makefile-compile (&optional makefile)
2302 "Run `make' on the current-buffer (`makefile-mode').
2304 The user is prompted for a selection of make rules to build."
2305 (let ((mkfile (or makefile (buffer-file-name)
2306 (error
2307 "Compilation abort: buffer %s has no file name"
2308 (buffer-name)))))
2309 (setq mc--selected-makefile mkfile)
2310 (setq mc--compile-command
2311 (concat mode-compile-make-program " "
2312 (or (mc--eval mode-compile-make-options) "")
2313 " -f " mkfile " "
2314 (mc--choose-makefile-rule mkfile))))
2315 (mc--compile mc--compile-command))
2318 (defun dired-compile ()
2319 "Run `make' if a Makefile is present in current directory (`dired-mode').
2321 The user is prompted for a selection of a makefile to choose if many
2322 matching `mode-compile-makefile-regexp' are present in the directory and
2323 for the make rules to build. If directory contain no makefile the function
2324 try to find if there are some un-byte-compiled .el files and recompile them
2325 if needed.
2326 Ask for the complete `compile-command' if no makefile and no .el files found."
2327 (let ((makefile (mc--makefile-to-use)))
2328 (if makefile
2329 ;; Makefile exists compile with it
2330 (makefile-compile makefile)
2331 ;; No makefile found look for some .el files
2332 (mc--msg "No makefile found, looking for .el files ...")
2333 (let ((el-files (directory-files
2334 default-directory nil emacs-lisp-sources-regexp)))
2335 (if el-files
2336 ;; Some .el files found byte-recompile them
2337 (mc--byte-recompile-files el-files)
2338 ;; No .el files ask compile command to user
2339 (mc--msg "No .el files found in directory %s" default-directory)
2340 (default-compile))))))
2343 (defun sh-compile ()
2344 "Run `sh-command' (Bourne Shell) with `sh-dbg-flags' on current-buffer (`sh-mode').
2346 User is prompted for arguments to run his sh program with.
2347 If you want to step throught errors set the variable `sh-compilation-error-regexp-alist'
2348 to a value understandable by compile's `next-error'.
2349 See variables compilation-error-regexp-alist or sh-compilation-error-regexp-alist."
2350 (mc--shell-compile sh-command sh-dbg-flags sh-compilation-error-regexp-alist))
2353 (defun csh-compile ()
2354 "Run `csh-command' (C Shell) with `csh-dbg-flags' on current-buffer (`csh-mode').
2356 User is prompted for arguments to run his csh program with.
2357 If you want to step throught errors set the variable `csh-compilation-error-regexp-alist'
2358 to a value understandable by compile's `next-error'.
2359 See variables compilation-error-regexp-alist or csh-compilation-error-regexp-alist."
2360 (mc--shell-compile csh-command csh-dbg-flags csh-compilation-error-regexp-alist))
2363 (defun zsh-compile ()
2364 "Run `zsh-command' (Z Shell) with `zsh-dbg-flags' on current-buffer (`zsh-mode').
2366 User is prompted for arguments to run his zsh program with.
2367 If you want to step throught errors set the variable `zsh-compilation-error-regexp-alist'
2368 to a value understandable by compile's `next-error'.
2369 See variables compilation-error-regexp-alist or zsh-compilation-error-regexp-alist."
2370 (mc--shell-compile zsh-command zsh-dbg-flags zsh-compilation-error-regexp-alist))
2373 (defun perl-compile ()
2374 "Run Perl with `perl-dbg-flags' on current-buffer (`perl-mode').
2376 User is prompted for arguments to run his perl program with.
2377 If you want to step throught errors set the variable `perl-compilation-error-regexp-alist'
2378 to a value understandable by compile's `next-error'.
2379 See variables compilation-error-regexp-alist or perl-compilation-error-regexp-alist."
2380 (mc--shell-compile perl-command perl-dbg-flags perl-compilation-error-regexp-alist))
2383 (defun tcl-compile ()
2384 ;; JWH
2385 "Run `tcl-command' with `tcl-dbg-flags' on current-buffer (`tcl-mode').
2387 User is prompted for arguments to run his Tcl/Tk program with.
2388 If you want to step throught errors set the variable `tcl-compilation-error-regexp-alist'
2389 to a value understandable by compile's `next-error'.
2390 See variables compilation-error-regexp-alist or tcl-compilation-error-regexp-alist."
2391 (mc--shell-compile tcl-command tcl-dbg-flags tcl-compilation-error-regexp-alist))
2394 (defun python-compile ()
2395 ;; BM
2396 "Run `python-command' with `python-dbg-flags' on current-buffer (`python-mode').
2398 User is prompted for arguments to run his Python program with.
2399 If you want to step throught errors set the variable `python-compilation-error-regexp-alist'
2400 to a value understandable by compile's `next-error'.
2401 See variables compilation-error-regexp-alist or python-compilation-error-regexp-alist."
2402 (mc--shell-compile python-command python-dbg-flags python-compilation-error-regexp-alist))
2404 (defun ruby-compile ()
2405 ;; CLGC
2406 "Run `ruby-command' with `ruby-dbg-flags' on current-buffer (`ruby-mode').
2408 User is prompted for arguments to run their ruby program with.
2409 If you want to step throught errors set the variable `ruby-compilation-error-regexp-alist'
2410 to a value understandable by compile's `next-error'.
2411 See variables compilation-error-regexp-alist or ruby-compilation-error-regexp-alist."
2412 (mc--shell-compile ruby-command ruby-dbg-flags ruby-compilation-error-regexp-alist))
2414 (defun default-compile ()
2415 "Default function invoked by `mode-compile' (\\[mode-compile])
2416 when everything else failed.
2418 Ask to user to edit `compile-command' and run `compile' (\\[compile]) with it."
2419 (setq mc--compile-command
2420 (mc--read-string
2421 (if mode-compile-expert-p
2422 "Compile command: "
2423 (format "Edit command to compile %s : " (buffer-name)))
2424 (or mc--compile-command compile-command)))
2425 (mc--compile mc--compile-command))
2427 (defvar mc--makefile) ;; Just to avoid compiler warning
2428 (defun guess-compile ()
2429 "Try to guess how to compile current-buffer.
2431 When the compile command could not be extrapolated from major-mode this function
2432 is called which try to guess from number of parameters which command to build.
2433 The steps to guess which command to use to compile are:
2434 1st : Look into the file to check if it is a shell script
2435 See variable mode-compile-shell-alist
2436 2nd : Try to guess from the file name
2437 See variable mode-compile-filename-regexp-alist
2438 3rd : Look for a makefile in the current directory
2439 See variable mode-compile-makefile-regexp
2440 Last: Give up and ask user for the command to use
2441 See function default-compile"
2442 (mc--msg "Trying to guess how to compile buffer %s ..." (buffer-name))
2443 (let ((mc--makefile))
2444 (funcall
2446 ;; step 1
2447 (mc--lookin-for-shell)
2448 ;; step 2
2449 (mc--lookat-name)
2450 ;; step 3
2451 (progn
2452 (mc--msg "Looking for a makefile in current directory...")
2453 (if (setq mc--makefile (mc--makefile-to-use
2454 (and (buffer-file-name)
2455 (file-name-directory (buffer-file-name)))))
2456 (progn
2457 (setq mc--kill-compile 'kill-compilation)
2458 ;; Byte-compiling says `makefile' is not referenced.
2459 '(lambda () (makefile-compile mc--makefile)))))
2460 ;; step 4
2461 (progn
2462 (mc--msg "Don't know how to compile %s, giving up..."
2463 (buffer-name))
2464 (setq mc--kill-compile 'kill-compilation)
2465 'default-compile)))))
2468 ;; @ user accessible/exported function ;;;
2470 ;; get reporter-submit-bug-report when byte-compiling
2471 (and (fboundp 'eval-when-compile)
2472 (eval-when-compile (require 'reporter)))
2474 ;;;###autoload
2475 (defun mode-compile-submit-bug-report ()
2476 "*Submit via mail a bug report on mode-compile v2.27."
2477 (interactive)
2478 (and
2479 (y-or-n-p "Do you REALLY want to submit a report on mode-compile? ")
2480 (require 'reporter)
2481 (reporter-submit-bug-report
2482 mode-compile-help-address
2483 (concat "mode-compile " mode-compile-version)
2484 (list
2485 ;; Interesting mode-compile variables
2486 'mode-compile-modes-alist
2487 'mode-compile-filename-regexp-alist
2488 'mode-compile-shell-alist
2489 'mode-compile-makefile-regexp
2490 'mode-compile-make-program
2491 'mode-compile-default-make-options
2492 'mode-compile-make-options
2493 'mode-compile-reading-time
2494 'mode-compile-expert-p
2495 'mode-compile-never-edit-command-p
2496 'mode-compile-save-all-p
2497 'mode-compile-always-save-buffer-p
2498 'mode-compile-before-compile-hook
2499 'mode-compile-after-compile-hook
2500 'mode-compile-before-kill-hook
2501 'mode-compile-after-kill-hook
2502 'mode-compile-other-frame-p
2503 'mode-compile-other-frame-name
2504 'mode-compile-frame-parameters-alist
2505 'mode-compile-prefered-default-makerule
2506 'emacs-lisp-byte-compile-dir-interactive-p
2507 ;; others variables
2508 'features
2509 'compilation-error-regexp-alist
2510 'compile-command
2514 "Dear Heddy,")))
2517 ;;;###autoload
2518 (defun mode-compile (&optional remote-host)
2519 "*Compile the file in the current buffer with a dynamically built command.
2521 The command is built according to the current major mode the function
2522 was invoked from.
2524 Running this command preceded by universal-argument (\\[universal-argument])
2525 allows remote compilation, the user is prompted for a host name to run the
2526 compilation command on.
2528 Currently know how to compile in:
2529 `c-mode' , -- function cc-compile.
2530 `java-mode' , -- function java-compile.
2531 `c++-mode', -- function c++-compile.
2532 `ada-mode', -- function ada-compile.
2533 `fortran-mode', -- function f77-compile.
2534 `emacs-lisp-mode' -- function elisp-compile.
2535 `lisp-interaction-mode' -- function elisp-compile.
2536 `makefile-mode' -- function makefile-compile.
2537 `dired-mode' -- function dired-compile.
2538 `sh-mode' -- function sh-compile.
2539 `csh-mode' -- function csh-compile.
2540 `zsh-mode' -- function zsh-compile.
2541 `perl-mode' -- function perl-compile.
2542 `cperl-mode' -- function perl-compile.
2543 `tcl-mode' -- function tcl-compile.
2544 `python-mode' -- function python-compile.
2545 `ruby-mode' -- function ruby-compile.
2546 `fundamental-mode' -- function guess-compile.
2547 `text-mode' -- function guess-compile.
2548 `indented-text-mode' -- function guess-compile.
2549 `compilation-mode' -- function default-compile.
2550 The function `guess-compile' is called when mode is unknown.
2552 The variable `mode-compile-modes-alist' contain description of known
2553 modes. The hooks variables `mode-compile-before-compile-hook' and
2554 `mode-compile-after-compile-hook' are run just before and after
2555 invoking the compile command of the mode.
2557 Use the command `mode-compile-kill' (\\[mode-compile-kill]) to abort a
2558 running compilation.
2560 Bound on \\[mode-compile]."
2561 (interactive "P")
2562 ;; reinit
2563 (setq
2564 mc--efs-path-list nil
2565 mc--remote-command nil)
2566 (if remote-host
2567 ;; Remote compilation asked
2568 ;; prepare remote command
2569 (mc--set-remote-cmd remote-host)
2570 ;; Not asked but check buffer-file-name to see
2571 ;; if it is not an efs file
2572 (setq mc--efs-path-list (and (fboundp 'efs-ftp-path)
2573 (buffer-file-name)
2574 (efs-ftp-path (buffer-file-name))))
2575 (and mc--efs-path-list (mc--set-remote-cmd
2576 (car mc--efs-path-list)
2577 (nth 1 mc--efs-path-list)
2578 (nth 2 mc--efs-path-list))))
2579 (if (and mode-compile-always-save-buffer-p
2580 (buffer-file-name))
2581 ;; save-buffer allready check if buffer had been modified
2582 (save-buffer))
2583 (if mode-compile-save-all-p (save-some-buffers t))
2584 ;; Check if compile-command set as local variable
2585 (if (and
2586 (boundp 'compile-command)
2587 (local-variable-p 'compile-command (current-buffer))
2588 compile-command ; not null
2589 (if mc--compile-command
2590 (equal compile-command mc--compile-command)
2593 ;; Just ask user and go
2594 (progn
2595 (mc--run-hooks 'mode-compile-before-compile-hook)
2596 (default-compile)
2597 (mc--run-hooks 'mode-compile-after-compile-hook)
2599 ;; Here is the real work
2600 (let ((mode-elem (assq major-mode mode-compile-modes-alist)))
2601 (if mode-elem
2602 ;; known mode
2603 (progn
2604 (mc--msg (substitute-command-keys
2605 "Compiling in %s mode ... \\[mode-compile-kill] to kill.")
2606 mode-name)
2607 (mc--run-hooks 'mode-compile-before-compile-hook)
2608 ;; mc--funcall can launch the compilation
2609 ;; in another frame.
2610 (mc--funcall (car (cdr mode-elem)))
2611 (mc--run-hooks 'mode-compile-after-compile-hook))
2612 ;; unknown mode: try to guess
2613 (mc--msg (substitute-command-keys
2614 "Don't know how to compile in %s mode, guessing... \\[mode-compile-kill] to kill.")
2615 mode-name)
2616 (mc--run-hooks 'mode-compile-before-compile-hook)
2617 ;; mc--funcall can launch the compilation
2618 ;; in another frame.
2619 (mc--funcall 'guess-compile)
2620 (mc--run-hooks 'mode-compile-after-compile-hook)))))
2622 (provide 'mode-compile)
2625 ;;;###autoload
2626 (defun mode-compile-kill()
2627 "*Kill the running compilation launched by `mode-compile' (\\[mode-compile]) \
2628 command.
2630 The compilation command is killed according to the current major mode
2631 the function was invoked from.
2633 Currently know how to kill compilations from:
2634 `c-mode' , -- function kill-compilation.
2635 `java-mode' , -- function kill-compilation.
2636 `c++-mode' , -- function kill-compilation.
2637 `ada-mode' , -- function kill-compilation.
2638 `fortran-mode' , -- function kill-compilation.
2639 `emacs-lisp-mode' -- function keyboard-quit.
2640 `lisp-interaction-mode' -- function keyboard-quit.
2641 `makefile-mode' -- function kill-compilation.
2642 `dired-mode' -- function kill-compilation.
2643 `sh-mode' -- function kill-compilation.
2644 `csh-mode' -- function kill-compilation.
2645 `zsh-mode' -- function kill-compilation.
2646 `perl-mode' -- function kill-compilation.
2647 `cperl-mode' -- function kill-compilation.
2648 `tcl-mode' -- function kill-compilation.
2649 `python-mode' -- function kill-compilation.
2650 `ruby-mode' -- function kill-compilation.
2651 `fundamental-mode' -- Bound dynamically.
2652 `text-mode' -- Bound dynamically.
2653 `indented-text-mode' -- Bound dynamically.
2654 `compilation-mode' -- function kill-compilation.
2656 The variable `mode-compile-modes-alist' contain description of ALL
2657 known modes. The hooks variables `mode-compile-before-kill-hook' and
2658 `mode-compile-after-kill-hook' are run just before and after invoking
2659 the kill compile command of the mode.
2661 Bound on \\[mode-compile-kill]."
2662 (interactive)
2663 (let ((mode-elem (assq major-mode mode-compile-modes-alist)))
2664 (if mode-elem
2665 ;; known mode
2666 (progn
2667 (mc--run-hooks 'mode-compile-before-kill-hook)
2668 (mc--msg "Killing compilation in %s mode..." mode-name)
2669 (let ((killfun (or (car-safe (cdr (cdr mode-elem)))
2670 mc--kill-compile
2671 nil)))
2672 (if killfun
2673 ;; I don't call mc--funcall here caus' we don't need
2674 ;; to switch to another frame to kill a compilation.
2675 (funcall killfun)
2676 (mc--msg "Unable to kill compilation in %s mode..." mode-name))
2677 (mc--run-hooks 'mode-compile-after-kill-hook)))
2678 ;; unknown mode
2679 (mc--msg "Don't know how to kill compilation in %s mode"
2680 mode-name))))
2682 (provide 'mode-compile-kill)
2686 ;;; Local variables:
2687 ;;; outline-regexp: ";; @+"
2688 ;;; eval: (outline-minor-mode 1)
2689 ;;; End:
2691 ;;; mode-compile.el ends here