PageRenderTime 59ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/.emacs.d/compile-mode/compile-mode.el

https://github.com/capotej/dotemacs
Emacs Lisp | 2691 lines | 1811 code | 323 blank | 557 comment | 90 complexity | 7be65c7dede24c8bfbc4c1048a2ff365 MD5 | raw file
Possible License(s): GPL-2.0
  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/>
  20. ;;
  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|
  25. ;;
  26. ;;; This file is NOT part of GNU Emacs but the same permissions apply.
  27. ;;
  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.
  32. ;;
  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.
  37. ;;
  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.
  41. ;;
  42. ;; @ Purpose:
  43. ;; ==========
  44. ;;
  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'.
  62. ;;
  63. ;; @ Installation:
  64. ;; ===============
  65. ;;
  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)
  74. ;;
  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.
  81. ;;
  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.
  86. ;;
  87. ;; @ Bug Reports:
  88. ;; ==============
  89. ;;
  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.
  94. ;;
  95. ;; @ Documentation:
  96. ;; ================
  97. ;;
  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.
  106. ;;
  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'.
  113. ;;
  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).
  125. ;;
  126. ;; @@ compilation-mode:
  127. ;; Call `compile' with the last compile command.
  128. ;;
  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).
  134. ;;
  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').
  139. ;;
  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'.
  147. ;;
  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.
  151. ;;
  152. ;; @@ c?perl-mode:
  153. ;; Run file with "perl -w" (can step throught errors with compile's
  154. ;; `next-error' command).
  155. ;;
  156. ;; @@ tcl-mode:
  157. ;; Run file with "wish" (can step throught errors with compile's
  158. ;; `next-error' command).
  159. ;;
  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).
  171. ;;
  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.
  184. ;;
  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.
  207. ;;
  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.
  211. ;;
  212. ;; @@ fortran-mode:
  213. ;; Same as c-mode but run Fortran compiler on .[Ff](or)? files.
  214. ;;
  215. ;; @@ java-mode:
  216. ;; Same as c-mode but call "javac" without the -o option on .java files
  217. ;;
  218. ;; @@ python-mode:
  219. ;; Run file with "python" (can step throught errors with compile's
  220. ;; `next-error' command).
  221. ;;
  222. ;; @@ ruby-mode:
  223. ;; Run file with "ruby" (can step throught errors with compile's
  224. ;; `next-error' command).
  225. ;;
  226. ;; @@ message-mode:
  227. ;; Run `message-send'.
  228. ;;
  229. ;; @ WhatsNew:
  230. ;; ===========
  231. ;;
  232. ;; Support for ruby-mode
  233. ;;
  234. ;; @ Contributors/Helpers:
  235. ;; =======================
  236. ;;
  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
  257. ;;
  258. ;; @ ToDo:
  259. ;; =======
  260. ;;
  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.
  267. ;;
  268. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  269. ;; @ Requirements ;;;
  270. ;; mode-compile is not a replacement for compile
  271. ;; it is just a layer above it.
  272. (require 'compile)
  273. ;;; For Emacs-Lisp files compilations
  274. (require 'byte-compile "bytecomp")
  275. ;;; For easy macros
  276. (require 'backquote)
  277. (require 'cl)
  278. (load-library "cl-macs")
  279. ;; Pretty print elisp
  280. (require 'pp)
  281. ;;; Setting obsolete vars
  282. (eval-and-compile
  283. (condition-case ()
  284. (require 'obsolete)
  285. (error nil))
  286. (if (and (featurep 'obsolete) (fboundp 'define-obsolete-variable-alias))
  287. nil ;; We've got what we needed
  288. (defmacro define-obsolete-variable-alias (old new)
  289. (` (progn (defalias (, old) (, new))
  290. (put (, old) 'byte-obsolete-variable (, new)))
  291. ))))
  292. ;;; For using custom - stolen from w3-cus.el -
  293. (eval-and-compile
  294. (condition-case ()
  295. (require 'custom)
  296. (error nil))
  297. (if (and (featurep 'custom) (fboundp 'custom-declare-variable))
  298. nil ;; We've got what we needed
  299. ;; We have the old custom-library, hack around it!
  300. (defmacro defgroup (&rest args)
  301. nil)
  302. (defmacro defcustom (var value doc &rest args)
  303. (` (defvar (, var) (, value) (, doc))))))
  304. ;; Custom groups
  305. (defgroup compilation nil
  306. "Compilations from within Emacs variables."
  307. :link '(url-link :tag "Author's Emacs Page"
  308. "http://www.tls.cena.fr/~boubaker/Emacs/")
  309. :group 'tools
  310. :group 'development)
  311. (defgroup compilation-lang nil
  312. "Language specific compilation options."
  313. :group 'languages
  314. :group 'compilation)
  315. (defgroup compilation-script nil
  316. "Scripts compilation options."
  317. :group 'compilation)
  318. (defgroup compilation-elisp nil
  319. "Emacs developpement compilation options."
  320. :group 'lisp
  321. :group 'compilation)
  322. ;; @ User variables ;;;
  323. ;; @@ Common variables to mode-compile for all modes ;;;
  324. (defcustom mode-compile-modes-alist
  325. '((c-mode . (cc-compile kill-compilation))
  326. (java-mode . (java-compile kill-compilation))
  327. (c++-mode . (c++-compile kill-compilation))
  328. (ada-mode . (ada-compile kill-compilation))
  329. (fortran-mode . (f77-compile kill-compilation))
  330. (dired-mode . (dired-compile kill-compilation))
  331. (emacs-lisp-mode . (elisp-compile keyboard-quit)) ; I'm SURE IT'S NOT the best way
  332. (lisp-interaction-mode . (elisp-compile keyboard-quit)) ; to kill a byte-compilation.
  333. (makefile-mode . (makefile-compile kill-compilation))
  334. (sh-mode . (sh-compile kill-compilation))
  335. (csh-mode . (csh-compile kill-compilation))
  336. (zsh-mode . (zsh-compile kill-compilation))
  337. (perl-mode . (perl-compile kill-compilation))
  338. (cperl-mode . (perl-compile kill-compilation))
  339. (tcl-mode . (tcl-compile kill-compilation)) ; JWH
  340. (python-mode . (python-compile kill-compilation)) ; BM
  341. (ruby-mode . (ruby-compile kill-compilation)) ; CLGC
  342. ;(message-mode . (message-compile kill-compilation))
  343. (fundamental-mode . (guess-compile nil)) ; bound dynamically
  344. (text-mode . (guess-compile nil)) ; itou
  345. (indented-text-mode . (guess-compile nil)) ; itou
  346. (compilation-mode . (default-compile kill-compilation)))
  347. "Assoc list of compile/kill functions for some known modes.
  348. Each element look like (MODE . (COMPILE-FUNCTION KILL-FUNCTION))
  349. `mode-compile' will call COMPILE-FUNCTION and `mode-compile-kill'
  350. KILL-FUNCTION if current major-mode is MODE.
  351. If you want to add or modify a COMPILE-FUNCTION and it's associated
  352. KILL-FUNCTION for MODE and don't want to hack `mode-compile' you could
  353. do the following (it exists however a more subtle method for
  354. modifying, this is left as an exercice for the reader :-):
  355. (defun my-mode-compile() ...)
  356. (defun my-mode-compile-kill() ...)
  357. (setq mode-compile-modes-alist
  358. (append '((my-mode . (my-mode-compile my-mode-compile-kill)))
  359. mode-compile-modes-alist))"
  360. :type '(repeat
  361. (cons :tag "Association: mode/compilation functions"
  362. (function :tag "Mode")
  363. (list :tag "Compilation functions"
  364. (choice :tag "Function to run the compilation"
  365. (function-item :tag "Default" :value default-compile)
  366. (function-item :tag "Guess" :value guess-compile)
  367. (function-item :tag "Emacs lisp byte compilation" :value elisp-compile)
  368. (function :tag "Your choice, take care..."))
  369. (choice :tag "Function to kill a running compilation"
  370. (function-item :tag "Just kill" :value kill-compilation)
  371. (const :tag "Nothing -- use with guess-compile --" :value nil)
  372. (function-item :tag "To use with elisp-compile" :value keyboard-quit)
  373. ;; This item could not be selected due to a custom (hum) feature ...
  374. (function :tag "Your choice, take care..." :value nil)))))
  375. :group 'compilation)
  376. (defcustom mode-compile-filename-regexp-alist
  377. ;; These could be in auto-mode-alist. But if you are like me
  378. ;; and don't like these modes (prefear to edit these kind of
  379. ;; files in text-mode) this is a nice way to compile them
  380. ;; without to be bored with their associated modes.
  381. '((mode-compile-makefile-regexp . makefile-mode)
  382. ("\\.sh$" . sh-mode)
  383. ("\\.csh$" . csh-mode)
  384. ("\\.zsh$" . zsh-mode))
  385. "Assoc list of major-modes for some filenames regexp.
  386. Each element look like (REGEXP . MODE) This variable is really similar
  387. to `auto-mode-alist' in the fact that it associate a MODE to a REGEXP
  388. matching a filename. The only differences is that you are not obliged
  389. to have the specified MODE available to use it (`guess-compile' use
  390. it), the MODE is only a pointer to an assoq in
  391. `mode-compile-modes-alist' to get the COMPILE-FUNCTION and the
  392. KILL-FUNCTION. The REGEXP could be a form wich evaluate to a string.
  393. To add a new filename regexp do the following:
  394. (setq mode-compile-filename-regexp-alist
  395. (append '((my-filename-regexp . some-mode-mode-compile-know)
  396. mode-compile-modes-alist))"
  397. :type '(repeat
  398. (cons :tag "Association: filename/mode"
  399. (choice :tag "Filename regexp match"
  400. (regexp :tag "Regexp as a string")
  401. (symbol :tag "Variable containing the regexp")
  402. (sexp :tag "Form wich evaluate to a string"))
  403. ;; I need to bind dynamicaly this with const, ideas??
  404. ;;`(choice
  405. ;; ,@(mapcar (lambda (x) `(const ,(car x))) mode-compile-modes-alist))))
  406. (function :tag "Mode to use -- should be a valid assoq in mode-compile-modes-alist --")))
  407. :group 'compilation)
  408. (defcustom mode-compile-shell-alist
  409. '(("sh" . sh-mode)
  410. ("csh" . csh-mode)
  411. ("zsh" . zsh-mode)
  412. ("perl" . perl-mode)
  413. ("tcl" . tcl-mode) ; JWH
  414. ("python" . python-mode) ; BM
  415. ("ruby" . ruby-mode)) ; CLGC
  416. "Assoc list of compile function for some known shells.
  417. Each element look like (SHELL . MODE) This variable look like
  418. `auto-mode-alist' in the fact that it associate a MODE to a name; A
  419. SHELL name here. The main difference is that you are not obliged to
  420. have the specified MODE available to use it (`guess-compile' use it),
  421. the MODE is only a pointer to an assoq in `mode-compile-modes-alist'
  422. to get the COMPILE-FUNCTION and the KILL-FUNCTION.
  423. To add a new shell do the following:
  424. (setq mode-compile-filename-shell-alist
  425. (append '((my-shell-name . some-mode-mode-compile-know)
  426. mode-compile-modes-alist))"
  427. :type '(repeat
  428. (cons :tag "Association: shell name/mode"
  429. (string :tag "Shell name")
  430. ;; I need to bind dynamicaly this with const, ideas??
  431. ;;`(choice
  432. ;; ,@(mapcar (lambda (x) `(const ,(car x))) mode-compile-modes-alist))))
  433. (function :tag "Mode to use -- should be a valid assoq in mode-compile-modes-alist --")))
  434. :group 'compilation)
  435. ;;;###autoload
  436. (defcustom mode-compile-make-program "make"
  437. "*The `make' program used to process makefiles.
  438. If you have GNU make installed with name \"gmake\" use it."
  439. :type 'string
  440. :group 'compilation)
  441. (defcustom mode-compile-makefile-regexp
  442. "\\(^[Mm]akefile\\|.*\\.[mM][aA]?[kK][eE]?\\.?.*$\\)"
  443. "Regexp matching 'could be' makefiles filenames."
  444. :type 'regexp
  445. :group 'compilation)
  446. (defcustom mode-compile-makefile-backups-regexp
  447. "\\(\\(~\\|\\.[bB][aA][cC]?[kK]\\)$\\)\\|\\(\\(^\\|/\\)[.,][^/]+$\\)"
  448. "Regexp to find if a Makefile is a backup or not"
  449. :type 'regexp
  450. :group 'compilation)
  451. ;;;###autoload
  452. (defcustom mode-compile-ignore-makefile-backups t
  453. "*Tell mode compile to ignore makefiles backup files when selecting the Makefile to use."
  454. :type 'boolean
  455. :group 'compilation)
  456. ;;;###autoload
  457. (defvar mode-compile-default-make-options "-k"
  458. "Default options to give to `make'.")
  459. ;;;###autoload
  460. (defcustom mode-compile-make-options (eval mode-compile-default-make-options)
  461. "*Options to give to `make'.
  462. This could be any form evaluating to a string.
  463. Some people asked me a way to modify the make options everytime a
  464. compilation command is launched, do that:
  465. (defun my-mode-compile-ask-make-options()
  466. \"*Hook called by mode-compile, asking for make options.\"
  467. (interactive)
  468. (read-string \"Make options: \"
  469. mode-compile-default-make-options))
  470. (setq mode-compile-make-options
  471. 'my-mode-compile-ask-make-options)"
  472. :type '(choice
  473. string
  474. (sexp :tag "Form evaluating to a string"))
  475. :group 'compilation)
  476. ;;;###autoload
  477. (defcustom mode-compile-prefered-default-makerule 'none
  478. "*Default makerule you would like to see in minibuffer as a default choice
  479. when selecting the make rule to build.
  480. Possible values are:
  481. 'none -- let mode-compile deciding for you.
  482. 'all -- try hard to show you the \"all\" rule.
  483. 'default -- try hard to show you the \"default\" rule.
  484. 'file -- try to show you the name of the file which will be
  485. result of compilation.
  486. The 'none action is taken as default is something fail."
  487. :type '(radio :tag "Symbol"
  488. (const :tag "None - Let mode compile made the choice" :value none)
  489. (const :tag "All - Show the \"all\" rule" :value all)
  490. (const :tag "Default - Show the \"default\" rule" :value default)
  491. (const :tag "File - Show the \"result file name\" rule" :value file))
  492. :group 'compilation)
  493. ;;;###autoload
  494. (defcustom mode-compile-ignore-makerule-regexp nil
  495. "*Makefile rules which must be ignored when building completion list.
  496. For example if you want to remove all `files rules' set
  497. it to: \"\\\\.\\\\([aoc]\\\\|s[ao][.0-9]*\\\\)\". "
  498. :type '(choice (const :tag "none" :value nil)
  499. (const :tag "The `all files' rule" :value "\\.\\([aoc]\\|s[ao][.0-9]*\\)")
  500. regexp)
  501. :group 'compilation)
  502. ;;;###autoload
  503. (defcustom mode-compile-save-all-p nil
  504. "*Non-nil means save ALL the modified buffers without asking
  505. before launching compilation command."
  506. :type 'boolean
  507. :group 'compilation)
  508. ;;;###autoload
  509. (defcustom mode-compile-always-save-buffer-p nil
  510. "*Non-nil means save the current buffer without asking
  511. before launching compilation command."
  512. :type 'boolean
  513. :group 'compilation)
  514. ;;;###autoload
  515. (defcustom mode-compile-never-edit-command-p nil
  516. "*Non-nil means never ask to user to edit the compile command."
  517. :type 'boolean
  518. :group 'compilation)
  519. ;; @@ Compilation in other frame vars ;;;
  520. (defgroup compilation-frame nil
  521. "Compile in another frame variables."
  522. :group 'frames
  523. :group 'compilation)
  524. ;;;###autoload
  525. (defcustom mode-compile-other-frame-p nil
  526. "*Non-nil means compile in another frame.
  527. A new Emacs FRAME is created and the compilation command is executed
  528. in this other frame. To specify the frame parameters see also
  529. variable `mode-compile-frame-parameters-alist'."
  530. :type 'boolean
  531. :group 'compilation-frame)
  532. (defcustom mode-compile-other-frame-name "COMPILATION"
  533. "Name of mode-compile's other frame.
  534. This name could be used in your .Xdefault or .Xresources file as:
  535. Emacs.MODE-COMPILE-OTHER-FRAME-NAME.resource_to_be_set: ..."
  536. :type 'string
  537. :group 'compilation-frame)
  538. (defconst mode-compile-default-frame-parameters
  539. (list
  540. (cons 'name mode-compile-other-frame-name)
  541. (cons 'width 85) ; columns
  542. (cons 'height 30)) ; lines
  543. "Default parameters for mode-compile's other frame.")
  544. (defvar mode-compile-frame-parameters-alist
  545. (purecopy mode-compile-default-frame-parameters)
  546. "Parameters for the new Compilation Screen created
  547. if variable `mode-compile-other-frame-p' is non nil..
  548. See also variable `mode-compile-default-frame-parameters' and
  549. `mode-compile-other-frame-name'.
  550. For informations about Screen/Frame parameters see:
  551. - Info, Nodes: Lispref::Screen::Screen Parameters
  552. - GNU Emacs Lisp Reference Manual, chapter 26 p375: Frames.")
  553. ;; @@ Hooks ;;;
  554. ;;;###autoload
  555. (defcustom mode-compile-before-compile-hook nil
  556. "Hook to be run before compile command is executed
  557. when `mode-compile' is invoked."
  558. :type 'hook
  559. :group 'compilation)
  560. ;;;###autoload
  561. (defcustom mode-compile-after-compile-hook nil
  562. "Hook to be run after compile command is executed
  563. when `mode-compile' is invoked."
  564. :type 'hook
  565. :group 'compilation)
  566. ;;;###autoload
  567. (defcustom mode-compile-before-kill-hook nil
  568. "Hook to be run before killing compile command is executed
  569. when `mode-compile-kill' is invoked."
  570. :type 'hook
  571. :group 'compilation)
  572. ;;;###autoload
  573. (defcustom mode-compile-after-kill-hook nil
  574. "Hook to be run after killing compile command is executed
  575. when `mode-compile-kill' is invoked."
  576. :type 'hook
  577. :group 'compilation)
  578. ;; @@ System dependencies ;;;
  579. (defvar mode-compile-exe-file-ext
  580. (cond
  581. ((memq system-type '(ms-dos emx windows-95 windows-98 windows-nt)) ".exe")
  582. (t ""))
  583. "*Extension of executable files (with dot included)")
  584. (defvar mode-compile-dir-separator-char
  585. (cond
  586. ;; MSDOSish file systems
  587. ((memq system-type '(ms-dos emx windows-95 windows-98 windows-nt)) "\\")
  588. ;; Unixish file systems
  589. (t "/"))
  590. "*Separator char between directories")
  591. ;; @@ Facilities variables ;;;
  592. ;;;###autoload
  593. (defvar mode-compile-choosen-compiler nil
  594. "*Global variable containing the name of the compiler
  595. which will be used for compiling without makefile.
  596. Could be used in combination with
  597. (cc|c++|ada|f77)-default-compiler-options
  598. to automaticaly choose the compiler specific options.
  599. example:
  600. (defun my-compiler-get-options()
  601. (cond
  602. ((string= mode-compile-choosen-compiler \"gcc\")
  603. \"-Wall -pedantic-errors\")
  604. ((string= mode-compile-choosen-compiler \"cc\")
  605. \"cc options whatever they are...\")
  606. (t
  607. (message \"Don't know this compiler: %s\" mode-compile-choosen-compiler)
  608. (read-string
  609. (format \"Options for %s compiler: \" mode-compile-choosen-compiler)))))
  610. (setq cc-default-compiler-options 'my-compiler-get-options)")
  611. ;; @@ User level ;;;
  612. ;;;###autoload
  613. (defcustom mode-compile-expert-p nil
  614. "*Non nil means `mode-compile' will not speaks too much.
  615. See also variable variable mode-compile-reading-time."
  616. :type 'boolean
  617. :group 'compilation)
  618. ;;;###autoload
  619. (defcustom mode-compile-reading-time 1
  620. "*Seconds to wait in verbose mode after printing a message.
  621. In verbose mode mode-compile print too much messages that it is
  622. allmost impossible to read them. Just setting this delay leave you the
  623. time to read all the messages. If you don't want any delay set it to
  624. `0'.
  625. See also function sit-for."
  626. :type 'integer
  627. :group 'compilation)
  628. ;; @@ Remote compilation vars ;;;
  629. (defgroup compilation-remote nil
  630. "Remote compilations options."
  631. :group 'compilation)
  632. (defcustom mode-compile-remote-hosts-alist '()
  633. "Alist of favourites hosts names and the username
  634. to use to log on (HOSTNAME . USERNAME).
  635. If USERNAME is a function it will be called with HOSTNAME as argument
  636. and should return an USERNAME string (for example you could use
  637. something like efs-get-user - not tested -), if it is nil the function
  638. user-login-name will be used."
  639. :type '(repeat
  640. (cons
  641. (string :tag "Hostname")
  642. (choice
  643. (const :tag "We'll use \'user-login-name" :value nil)
  644. (string :tag "Username")
  645. (function :tag "Function which return USERNAME given a HOSTNAME" :value efs-get-user))))
  646. :group 'compilation-remote)
  647. (defcustom mode-compile-remote-execute-command "rsh"
  648. "The shell command used to run a command remotely.
  649. \"rsh\" is the only choice I know but I'm far to know everything...
  650. This variable is set automaticaly with the value of
  651. remote-shell-program or efs-remote-shell-file-name at load time."
  652. :type 'string
  653. :group 'compilation)
  654. (eval-when 'load
  655. (cond
  656. ((not (string= mode-compile-remote-execute-command "rsh"))
  657. ;; user changed default
  658. nil)
  659. ;; Try to not multiply definitions of the same stuff
  660. ;; in too many emacs lisp packages ...
  661. ((and (boundp 'remote-shell-program) remote-shell-program)
  662. (setq mode-compile-remote-execute-command remote-shell-program))
  663. ((and (boundp 'efs-remote-shell-file-name) efs-remote-shell-file-name)
  664. (setq mode-compile-remote-execute-command efs-remote-shell-file-name))
  665. ))
  666. (defcustom mode-compile-remote-execute-set-host-arg ""
  667. "Argument To set the remote host name to the
  668. mode-compile-remote-execute-command,
  669. None is required for \"rsh\"."
  670. :type 'string
  671. :group 'compilation-remote)
  672. (defcustom mode-compile-remote-execute-set-command-arg ""
  673. "Argument to set the command to be run remotely to the
  674. mode-compile-remote-execute-command.
  675. None is required for \"rsh\"."
  676. :type 'string
  677. :group 'compilation-remote)
  678. (defcustom mode-compile-remote-execute-set-username-arg "-l"
  679. "Argument to set the username under which we will log on
  680. on the remote host, to give to mode-compile-remote-execute-command."
  681. :type 'string
  682. :group 'compilation-remote)
  683. (defcustom mode-compile-remote-execute-misc-args ""
  684. "Misc additionnals arguments to give to the
  685. mode-compile-remote-execute-command."
  686. :type 'string
  687. :group 'compilation-remote)
  688. ;; @@ c-mode compile variables ;;;
  689. (defgroup compile-c nil
  690. "C Compilation options."
  691. :group 'c
  692. :group 'compilation-lang)
  693. (defcustom cc-compilers-list '( "gcc" "c89" "acc" "cc" )
  694. "List of user's favourites C compilers in order of preferencies."
  695. :type '(repeat (string :tag "C Compiler name"))
  696. :group 'compile-c)
  697. (defcustom cc-companion-file-regexp "\\(_[Pp]\\)?\\.[pP]?h"
  698. "Regexp to find associated .c file from a .h."
  699. :type 'regexp
  700. :group 'compile-c)
  701. (defcustom cc-default-compiler "cc"
  702. "*Default C compiler to use when everything else fails.
  703. This could be any form evaluating to a string, so you could map it to
  704. a function asking you interactively to choose the compiler.
  705. example:
  706. (defun my-choose-compiler()
  707. (read-string \"C compiler: \"))
  708. (setq cc-compilers-list '()
  709. cc-default-compiler 'my-choose-compiler)"
  710. :type '(choice string function)
  711. :group 'compile-c)
  712. (defcustom cc-compiler-varenv "CC"
  713. "Varenv indicating the C compiler to use."
  714. :type 'string
  715. :group 'compile-c)
  716. (defcustom cc-cflags-varenv "CFLAGS"
  717. "Varenv indicating the C compiler flags to use."
  718. :type 'string
  719. :group 'compile-c)
  720. (defcustom cc-source-ext-list '( "c" )
  721. "Extensions for C compileable source files."
  722. :type '(repeat string)
  723. :group 'compile-c)
  724. (defcustom cc-headers-ext-list '( "h" )
  725. "Extensions for C headers source files."
  726. :type '(repeat string)
  727. :group 'compile-c)
  728. (defcustom cc-default-compiler-options "-g"
  729. "*Default options to give to the C compiler.
  730. This could be any form evaluating to a string.
  731. See `mode-compile-choosen-compiler' variable."
  732. :type '(choice
  733. string
  734. (sexp :tag "Form evaluating to a string"))
  735. :group 'compile-c)
  736. (defcustom cc-source-file-ext-regexp "\\.c"
  737. "Regexp to find, from it's name, if a C file is compileable."
  738. :type 'string
  739. :group 'compile-c)
  740. (defcustom cc-build-output-args t
  741. "Build output-args for c-mode."
  742. :type 'boolean
  743. :group 'compile-c)
  744. (defcustom cc-object-file-ext "o"
  745. "Extension of objects file (result of compilation)
  746. in c mode."
  747. :type 'string
  748. :group 'compile-c)
  749. ;; @@ java-mode compile variables ;;;
  750. (defgroup compile-java nil
  751. "Java compilation options."
  752. :group 'compilation-lang)
  753. (defcustom java-compilers-list '( "javac" )
  754. "List of user's favourites java compilers in order of preferencies."
  755. :type '(repeat (string :tag "Java Compiler name"))
  756. :group 'compile-java)
  757. (defcustom java-companion-file-regexp ""
  758. "Regexp to find associated compileable Java companion file.
  759. This is useless in Java because there do not exists uncompileable files."
  760. :type 'regexp
  761. :group 'compile-java)
  762. (defcustom java-default-compiler "javac"
  763. "*Default C compiler to use when everything else fails.
  764. This could be any form evaluating to a string, so you could map it to
  765. a function asking you interactively to choose the compiler.
  766. example:
  767. (defun my-choose-compiler()
  768. (read-string \"Java compiler: \"))
  769. (setq java-default-compiler 'my-choose-compiler)."
  770. :type '(choice string function)
  771. :group 'compile-java)
  772. (defcustom java-compiler-varenv "JAVAC"
  773. "Varenv indicating the C compiler to use."
  774. :type 'string
  775. :group 'compile-java)
  776. (defcustom java-cflags-varenv "JAVAC_FLAGS"
  777. "Varenv indicating the C compiler flags to use."
  778. :type 'string
  779. :group 'compile-java)
  780. (defcustom java-source-ext-list '( "java" )
  781. "Extensions for Java compileable source files."
  782. :type '(repeat string)
  783. :group 'compile-java)
  784. (defcustom java-headers-ext-list '( "java" )
  785. "Extensions for Java source files."
  786. :type '(repeat string)
  787. :group 'compile-java)
  788. (defcustom java-default-compiler-options "-O"
  789. "*Default options to give to the Java compiler.
  790. This could be any form evaluating to a string. See
  791. `mode-compile-choosen-compiler' variable."
  792. :type '(choice
  793. string
  794. (sexp :tag "Form evaluating to a string"))
  795. :group 'compile-java)
  796. (defcustom java-source-file-ext-regexp "\\.java"
  797. "Regexp to find, from it's name, if a Java file is compileable."
  798. :type 'regexp
  799. :group 'compile-java)
  800. (defcustom java-build-output-args nil
  801. "Dont build output-args for Java-mode."
  802. :type 'boolean
  803. :group 'compile-java)
  804. (defcustom java-object-file-ext "class"
  805. "Extension of objects file (result of compilation)
  806. in java mode."
  807. :type 'string
  808. :group 'compile-java)
  809. ;; @@ c++-mode compile variables ;;;
  810. (defgroup compile-c++ nil
  811. "C++ compilation options"
  812. :group 'compilation-lang)
  813. (defcustom c++-compilers-list '( "g++" "gcc" "CC" )
  814. "List of user's favourites C++ compilers in order of preferencies."
  815. :type '(repeat (string :tag "C++ Compiler name"))
  816. :group 'compile-c++)
  817. (defcustom c++-companion-file-regexp "\\(_[Pp]\\)?\\.\\([pP]?[Hh][Hh]?\\|[Hh]\\+\\+?\\)"
  818. "Regexp to find associated compileable C++ companion file
  819. from a header file."
  820. :type 'regexp
  821. :group 'compile-c++)
  822. (defcustom c++-default-compiler "CC"
  823. "*Default C++ compiler to use when everything else fails..
  824. This could be any form evaluating to a string, so you could map it to
  825. a function asking you interactively to choose the compiler.
  826. example:
  827. (defun my-choose-compiler()
  828. (read-string \"C++ compiler: \"))
  829. (setq c++-default-compiler 'my-choose-compiler)"
  830. :type '(choice string function)
  831. :group 'compile-c++)
  832. (defcustom c++-compiler-varenv "CXX"
  833. "Varenv indicating the C++ compiler to use."
  834. :type 'string
  835. :group 'compile-c++)
  836. (defcustom c++-cflags-varenv "CXXFLAGS"
  837. "Varenv indicating the C++ compiler flags to use."
  838. :type 'string
  839. :group 'compile-c++)
  840. (defcustom c++-source-ext-list '( "cc" "C" "CC" "cpp" "cxx" "c++" "c+" )
  841. "Extensions for C++ compileable source files."
  842. :type '(repeat string)
  843. :group 'compile-c++)
  844. (defcustom c++-headers-ext-list '( "H" "hh" "HH" "h++" "h+" "h" "hpp" "hxx" )
  845. "Extensions for C++ headers source files."
  846. :type '(repeat string)
  847. :group 'compile-c++)
  848. (defcustom c++-default-compiler-options "-g"
  849. "*Default options to give to the C++ compiler.
  850. This could be any form evaluating to a string. See
  851. `mode-compile-choosen-compiler' variable."
  852. :type '(choice
  853. string
  854. (sexp :tag "Form evaluating to a string"))
  855. :group 'compile-c++)
  856. (defcustom c++-source-file-ext-regexp "\\.\\(cc\\|CC?\\|c\\+\\+?\\|cpp\\|cxx\\)"
  857. "Regexp to find, from it's name, if a C++ file is compileable."
  858. :type 'regexp
  859. :group 'compile-c++)
  860. (defcustom c++-build-output-args t
  861. "Build output-args for c++-mode."
  862. :type 'boolean
  863. :group 'compile-c++)
  864. (defcustom c++-object-file-ext "o"
  865. "Extension of objects file (result of compilation)
  866. in c++ mode."
  867. :type 'string
  868. :group 'compile-c++)
  869. ;; @@ ada-mode compile variables ;;;
  870. (defgroup compile-ada nil
  871. "Ada compilation options"
  872. :group 'compilation-lang)
  873. (defcustom ada-compilers-list
  874. '( "gcc" "gnat" "ada" )
  875. "List of user's favourites Ada compilers in order of preferencies."
  876. :type '(repeat (string :tag "Ada Compiler name"))
  877. :group 'compile-ada)
  878. (defcustom ada-companion-file-regexp ""
  879. "Regexp to find associated compileable Ada companion file from a spec file.
  880. This is useless in Ada because there do not exists uncompileable files."
  881. :type 'regexp
  882. :group 'compile-ada)
  883. (defcustom ada-default-compiler "ada"
  884. "*Default Ada compiler to use when everything else fails.
  885. This could be any form evaluating to a string, so you could map it to
  886. a function asking you interactively to choose the compiler.
  887. example:
  888. (defun my-choose-compiler()
  889. (read-string \"Ada compiler: \"))
  890. (setq ada-default-compiler 'my-choose-compiler)"
  891. :type '(choice string function)
  892. :group 'compile-ada)
  893. (defcustom ada-compiler-varenv "ADA"
  894. "Varenv indicating the Ada compiler to use."
  895. :type 'string
  896. :group 'compile-ada)
  897. (defcustom ada-aflags-varenv "AFLAGS"
  898. "Varenv indicating the Ada compiler flags to use."
  899. :type 'string
  900. :group 'compile-ada)
  901. (defcustom ada-source-ext-list '( "ads" "adb" "ada" "a" )
  902. "Extensions for Ada compileable source files."
  903. :type '(repeat string)
  904. :group 'compile-ada)
  905. (defcustom ada-headers-ext-list '( "ads" "ada" "a" )
  906. "Extensions for Ada spec source files."
  907. :type '(repeat string)
  908. :group 'compile-ada)
  909. (defcustom ada-default-compiler-options "-g"
  910. "*Default options to give to the Ada compiler.
  911. This could be any form evaluating to a string. See
  912. `mode-compile-choosen-compiler' variable."
  913. :type '(choice
  914. string
  915. (sexp :tag "Form evaluating to a string"))
  916. :group 'compile-ada)
  917. (defcustom ada-source-file-ext-regexp "\\.\\(ad[abs]\\|a\\)"
  918. "Regexp to find, from it's name, if an Ada file is compileable.
  919. This is useless in Ada because there do not exists uncompileable files."
  920. :type 'regexp
  921. :group 'compile-ada)
  922. (defcustom ada-build-output-args t
  923. "Build output-args for ada-mode."
  924. :type 'boolean
  925. :group 'compile-ada)
  926. (defcustom ada-object-file-ext "o"
  927. "Extension of objects file (result of compilation)
  928. in ada mode."
  929. :type 'string
  930. :group 'compile-ada)
  931. ;; @@ fortran-mode compile variables ;;;
  932. (defgroup compile-fortran nil
  933. "Fortran compilation options"
  934. :group 'compilation-lang)
  935. (defcustom f77-compilers-list '( "f77" "fc" )
  936. "List of user's favourite Fortran compilers in order of preferencies."
  937. :type '(repeat (string :tag "C Compiler name"))
  938. :group 'compile-fortran)
  939. (defcustom f77-companion-file-regexp "\\(_[Pp]\\)?\\.[pP]?inc"
  940. "Regexp to find associated .f file from a .inc."
  941. :type 'regexp
  942. :group 'compile-fortran)
  943. (defcustom f77-default-compiler "f77"
  944. "*Default fortran compiler to use when everything else fails..
  945. This could be any form evaluating to a string, so you could map it to
  946. a function asking you interactively to choose the compiler.
  947. example:
  948. (defun my-choose-compiler()
  949. (read-string \"Fortran compiler: \"))
  950. (setq f77-default-compiler 'my-choose-compiler)"
  951. :type '(choice string function)
  952. :group 'compile-fortran)
  953. (defcustom f77-compiler-varenv "F77"
  954. "Varenv indicating the fortran compiler to use."
  955. :type 'string
  956. :group 'compile-fortran)
  957. (defcustom f77-cflags-varenv "FCOPTS"
  958. "Varenv indicating the fortran compiler flags to use."
  959. :type 'string
  960. :group 'compile-fortran)
  961. (defcustom f77-source-ext-list '( "f" "F" "for" "For" )
  962. "Extensions for fortran compileable source files."
  963. :type '(repeat string)
  964. :group 'compile-fortran)
  965. (defcustom f77-headers-ext-list '( "inc" "h")
  966. "Extensions for fortran include files."
  967. :type '(repeat string)
  968. :group 'compile-fortran)
  969. (defcustom f77-default-compiler-options "-w66 -a"
  970. "*Default options to give to the fortran compiler.
  971. This could be any form evaluating to a string. See
  972. `mode-compile-choosen-compiler' variable."
  973. :type '(choice
  974. string
  975. (sexp :tag "Form evaluating to a string"))
  976. :group 'compile-fortran)
  977. (defcustom f77-source-file-ext-regexp "\\.\\([Ff]\\|for\\)"
  978. "Regexp to find, from it's name, if a fortran file is compileable."
  979. :type 'regexp
  980. :group 'compile-fortran)
  981. (defcustom f77-build-output-args t
  982. "Build output-args for f77-mode."
  983. :type 'boolean
  984. :group 'compile-fortran)
  985. (defcustom f77-object-file-ext "o"
  986. "Extension of objects file (result of compilation)
  987. in Fortran mode."
  988. :type 'string
  989. :group 'compile-fortran)
  990. ;; @@ sh-mode compile variables ;;;
  991. (defgroup compile-sh nil
  992. "Sh (Bourne Shell scripts) compilation options"
  993. :group 'compilation-script)
  994. (defcustom sh-command "sh"
  995. "Command to run sh scripts"
  996. :type 'string
  997. :group 'compile-sh)
  998. (defcustom sh-dbg-flags "-fvx"
  999. "*Flags to give to sh for debugging a Bourne Shell script.
  1000. The -f flag must always be present."
  1001. :type 'string
  1002. :group 'compile-sh)
  1003. (defvar sh-compilation-error-regexp-alist nil
  1004. ;; I'd never seen a Bourne shell returning file+line where a syntax
  1005. ;; error occured.
  1006. "Alist that specifies how to match errors in sh output.
  1007. See variable compilation-error-regexp-alist for more details.")
  1008. ;; @@ csh-mode compile variables ;;;
  1009. (defgroup compile-csh nil
  1010. "Csh (C Shell) compilation options"
  1011. :group 'compilation-script)
  1012. (defcustom csh-command "csh"
  1013. "Command to run csh scripts"
  1014. :type 'string
  1015. :group 'compile-csh)
  1016. (defcustom csh-dbg-flags "-fVX"
  1017. "*Flags to give to csh for debugging a C Shell script.
  1018. The -f flag must always be present."
  1019. :type 'string
  1020. :group 'compile-csh)
  1021. (defvar csh-compilation-error-regexp-alist nil
  1022. ;; I'd never seen a C shell returning file+line where a syntax
  1023. ;; error occured.
  1024. "Alist that specifies how to match errors in csh output.
  1025. See variable compilation-error-regexp-alist for more details.")
  1026. ;; @@ zsh-mode compile variables ;;;
  1027. (defgroup compile-zsh nil
  1028. "Zsh (Z Shell scripts) compilation options"
  1029. :group 'compilation-script)
  1030. (defcustom zsh-command "zsh"
  1031. "Command to run zsh scripts"
  1032. :type 'string
  1033. :group 'compile-zsh)
  1034. (defcustom zsh-dbg-flags "-nCvx"
  1035. "*Flags to give to zsh for debugging a Z Shell script."
  1036. :type 'string
  1037. :group 'compile-zsh)
  1038. (defvar zsh-compilation-error-regexp-alist nil
  1039. ;; I'd never seen a Z shell returning file+line where a syntax
  1040. ;; error occured.
  1041. "Alist that specifies how to match errors in csh output.
  1042. See variable compilation-error-regexp-alist for more details.")
  1043. ;; @@ tcl-mode compile variables - JWH ;;;
  1044. (defgroup compile-tcl nil
  1045. "Tcl compilation options"
  1046. :group 'compilation-script)
  1047. (defcustom tcl-command "wish"
  1048. "Command to run tcl scripts"
  1049. :type 'string
  1050. :group 'compile-tcl)
  1051. (defcustom tcl-dbg-flags ""
  1052. "*Flags to give to tcl -- none."
  1053. :type 'string
  1054. :group 'compile-tcl)
  1055. (defvar tcl-compilation-error-regexp-alist
  1056. ;; TK (file "/directory-path/filename.tcl" line XY)
  1057. '(
  1058. ("file \"\\([^ ]+\\)\" line \\([0-9]+\\)[)]" 1 2)
  1059. )
  1060. "Alist that specifies how to match errors in tcl output.
  1061. See variable compilation-error-regexp-alist for more details.")
  1062. ;; @@ python-mode compile variables - BM ;;;
  1063. (defgroup compile-python nil
  1064. "Python compilation options"
  1065. :group 'compilation-script)
  1066. (defcustom python-command "python"
  1067. "Command to run python scripts"
  1068. :type 'string
  1069. :group 'compile-python)
  1070. (defcustom python-dbg-flags ""
  1071. "*Flags to give to python -- none."
  1072. :type 'string
  1073. :group 'compile-python)
  1074. (defvar python-compilation-error-regexp-alist
  1075. ;; TK (file "/directory-path/filename.tcl" line XY in ZZZ)
  1076. '(
  1077. ("File \"\\([^ ]+\\)\", line \\([0-9]+\\).*" 1 2)
  1078. )
  1079. "Alist that specifies how to match errors in python output.
  1080. See variable compilation-error-regexp-alist for more details.")
  1081. ;; @@ perl-mode compile variables ;;;
  1082. (defgroup compile-perl nil
  1083. "Perl compilation options"
  1084. :group 'compilation-script)
  1085. (defcustom perl-command "perl"
  1086. "Command to run perl."
  1087. :type 'string
  1088. :group 'compile-perl)
  1089. (defcustom perl-dbg-flags "-w"
  1090. "*Flags to give to perl for debugging a Perl script."
  1091. :type 'string
  1092. :group 'compile-perl)
  1093. (defvar perl-compilation-error-regexp-alist
  1094. ;; Contributed by Martin Jost
  1095. '(
  1096. ;; PERL 4
  1097. ("in file \\([^ ]+\\) at line \\([0-9]+\\).*" 1 2)
  1098. ;; PERL 5 Blubber at FILE line XY, <XY> line ab.
  1099. ("at \\([^ ]+\\) line \\([0-9]+\\)," 1 2)
  1100. ;; PERL 5 Blubber at FILE line XY.
  1101. ("at \\([^ ]+\\) line \\([0-9]+\\)." 1 2)
  1102. )
  1103. ;; This look like a paranoiac regexp: could anybody find a better one? (which WORK).
  1104. ;;'(("^[^\n]* \\(file\\|at\\) \\([^ \t\n]+\\) [^\n]*line \\([0-9]+\\)[\\.,]" 2 3))
  1105. "Alist that specifies how to match errors in perl output.
  1106. See variable compilation-error-regexp-alist for more details.")
  1107. ;; @@ ruby-mode compile variables ;;;
  1108. (defgroup compile-ruby nil
  1109. "Ruby compilation options"
  1110. :group 'compilation-script)
  1111. (defcustom ruby-command "ruby"
  1112. "Command to run ruby"
  1113. :type 'string
  1114. :group 'compile-ruby)
  1115. (defcustom ruby-dbg-flags "-w"
  1116. "Flags to give ruby for catching warnings"
  1117. :type 'string
  1118. :group 'compile-ruby)
  1119. (defvar ruby-compilation-error-regexp-alist
  1120. '(
  1121. ;; Unit Tests
  1122. ("test[a-zA-Z0-9_]*([A-Z][a-zA-Z0-9_]*) \\[\\(.*\\):\\([0-9]+\\)\\]:" 1 2)
  1123. ;; Errors and Warnings
  1124. ("\\(.*?\\)\\([0-9A-Za-z_./\:-]+\\.rb\\):\\([0-9]+\\)" 2 3))
  1125. "Alist that specifies how to match errors in ruby output.
  1126. See variable compilation-error-regexp-alist for more details.")
  1127. ;; @@ emacs lisp compile variables ;;;
  1128. ;;;###autoload
  1129. (defcustom emacs-lisp-byte-compile-dir-interactive-p t
  1130. "*Non-nil means when byte-compiling a directory ask for each file
  1131. needing to be recompiled or not."
  1132. :type 'boolean
  1133. :group 'compilation-elisp)
  1134. (define-obsolete-variable-alias
  1135. 'mode-compile-byte-compile-dir-interactive-p
  1136. 'emacs-lisp-byte-compile-dir-interactive-p)
  1137. (defcustom emacs-lisp-sources-regexp
  1138. (cond
  1139. ((boundp 'emacs-lisp-file-regexp)
  1140. emacs-lisp-file-regexp)
  1141. (t
  1142. "\\.el$"))
  1143. "Regexp to find emacs lisp sources files."
  1144. :type 'regexp
  1145. :group 'compilation-elisp)
  1146. (defcustom emacs-lisp-bytecomp-ext "c"
  1147. "Extension added to byte-compiled emacs sources files."
  1148. :type 'string
  1149. :group 'compilation-elisp)
  1150. ;; @@ Misc declarations ;;;
  1151. ;;;###autoload
  1152. (defconst mode-compile-version "2.28"
  1153. "Current version of mode-compile package.
  1154. mode-compile.el,v 2.28 2003/04/01 13:52:47 boubaker Exp
  1155. Please send bugs-fixes/contributions/comments to boubaker@cena.fr")
  1156. (defconst mode-compile-help-address "heddy.Boubaker@cena.fr"
  1157. "E-Mail address of mode-compile maintainer.")
  1158. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1159. ;; @ No user modifiable stuff below this line ;;;
  1160. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1161. ;; Save old compile function. In case someone will bound
  1162. ;; mode-compile on 'compile.
  1163. (or (fboundp 'mc--compile-sav)
  1164. (if (fboundp 'compile)
  1165. (progn
  1166. (fset 'mc--compile-sav (symbol-function 'compile))
  1167. (put 'compile 'compile-saved-on-mc--compile-sav t))
  1168. (error "`compile' function not known to be defined...")))
  1169. ;; @@ Internals variables and constants ;;;
  1170. ;; Mode specific
  1171. (defvar mc--comp-lst nil) ; c-mode,c++-mode,ada-mode,fortran-mode
  1172. (defvar mc--def-comp nil) ; itou
  1173. (defvar mc--compfile-regexp nil) ; itou
  1174. (defvar mc--comp-varenv nil) ; itou
  1175. (defvar mc--comp-options nil) ; itou
  1176. (defvar mc--cflags-varenv nil) ; itou
  1177. (defvar mc--source-ext-lst nil) ; itou
  1178. (defvar mc--head-ext-lst nil) ; itou
  1179. (defvar mc--source-ext-regexp nil) ; itou
  1180. (defvar mc--build-op-args nil) ; itou
  1181. (defvar mc--outfile-ext nil) ; itou
  1182. ;; remote stuff
  1183. (defvar mc--efs-path-list nil)
  1184. (defvar mc--remote-host nil)
  1185. (defvar mc--remote-host-history nil)
  1186. (defvar mc--remote-username nil)
  1187. (defvar mc--remote-command nil)
  1188. (defvar mc--remote-pathname nil)
  1189. ;; Frames/Windows stuff
  1190. (defvar mc--other-frame nil)
  1191. (defvar mc--ws (or
  1192. (and (fboundp 'console-type) (console-type))
  1193. (and (fboundp 'device-type) (device-type))
  1194. window-system))
  1195. (defvar mc--compile-command nil)
  1196. ;; Compile command used when no makefile has been found.
  1197. ;; This variable is buffer local to keep history for read-string.
  1198. ;; Unfortunately not a real history, keep only memory of
  1199. ;; the last compile command used.
  1200. (make-variable-buffer-local 'mc--compile-command)
  1201. (defvar mc--kill-compile nil)
  1202. ;; kill-compile command bound dynamically by `guess-compile'.
  1203. (make-variable-buffer-local 'mc--kill-compile)
  1204. (defvar mc--selected-makefile nil)
  1205. (defvar mc--selected-makefile-history nil)
  1206. ;; User selected makefile among the list, to run make with.
  1207. ;; This variable is buffer local to keep history for completing-read
  1208. ;; Unfortunately not a real history, keep only memory of
  1209. ;; the last makefile used.
  1210. (make-variable-buffer-local 'mc--selected-makefile)
  1211. (defvar mc--selected-makerule nil)
  1212. (defvar mc--selected-makerule-history nil)
  1213. ;; User selected make rule to rebuild.
  1214. ;; This variable is buffer local to keep history for completing-read
  1215. ;; Unfortunately not a real history, keep only memory of
  1216. ;; the last makerule used.
  1217. (make-variable-buffer-local 'mc--selected-makerule)
  1218. (defconst mc--find-C-main-regexp
  1219. "^[ \t]*\\(int\\|void\\)?[ \t\n]*main[ \t\n]*\(+" )
  1220. ;; Regexp to find the main() function in a C/C++ file
  1221. (defconst mc--makefile-rules-regexp
  1222. "^\n*\\([^.$ \t#\n][^$ \t#\n:]*\\)[ \t]*:")
  1223. ;; Regexp to extract makefiles rules.
  1224. ;; But only those not containing references to $(VARIABLES)
  1225. ;; and not starting with `.'
  1226. (defvar mc--makefile-rules nil)
  1227. ;; List of all rules extracted from makefile
  1228. (make-variable-buffer-local 'mc--makefile-rules)
  1229. (defvar mc--mkfl-buffer-tick nil)
  1230. ;; Tick counter for the buffer at the time of the rules extraction.
  1231. (make-variable-buffer-local 'mc--mkfl-buffer-tick)
  1232. (defvar mc--shell-args nil)
  1233. ;; Shell arguments for the script to debug.
  1234. ;; This variable is buffer local to keep history for read-string.
  1235. ;; Unfortunately not a real history, keep only memory of
  1236. ;; the last shell arguments used.
  1237. (make-variable-buffer-local 'mc--shell-args)
  1238. ;; nil in GNU FSF Emacs, >= 0 in GNU Lucid Emacs/XEmacs
  1239. (defconst mc--lucid-emacs-p (or (string-match "Lucid" emacs-version)
  1240. (string-match "XEmacs" emacs-version)))
  1241. ;; @@ Internals functions and macros ;;;
  1242. (if (not (fboundp 'defsubst))
  1243. ;; Emacs 18
  1244. (fset 'defsubst (symbol-function 'defun)))
  1245. (defun mc--compile (compile-command)
  1246. ;; Call compile with the compile command
  1247. ;; but append the remote-command before
  1248. (if (null mc--remote-command)
  1249. ;; local compile
  1250. (mc--compile-sav compile-command)
  1251. ;; remote compile
  1252. (let ((thisdir (expand-file-name (or default-directory "~"))))
  1253. (mc--compile-sav
  1254. (concat
  1255. ;; The command to lauch remote commands
  1256. mc--remote-command
  1257. ;; Change to this buffer directory ...
  1258. "'( cd " thisdir " ; "
  1259. ;; then run the compile command
  1260. compile-command " )'")))))
  1261. (defsubst mc--msg (msg &rest args)
  1262. ;; Print MSG with ARGS and wait to let time to user
  1263. ;; to read the message in minibuffer.
  1264. (cond ((not mode-compile-expert-p)
  1265. (apply 'message (concat "mode-compile: " msg) args)
  1266. (sit-for mode-compile-reading-time))))
  1267. (cond
  1268. ;; Check availaibles frames functions
  1269. ((fboundp 'make-frame)
  1270. ;; GNU Emacs
  1271. (fset 'mc--make-frame (symbol-function 'make-frame))
  1272. (fset 'mc--select-frame (symbol-function 'select-frame))
  1273. (fset 'mc--frame-live-p (symbol-function 'frame-live-p))
  1274. (fset 'mc--make-frame-visible (symbol-function 'make-frame-visible))
  1275. (fset 'mc--raise-frame (symbol-function 'raise-frame)))
  1276. ((fboundp 'make-screen)
  1277. ;; XEmacs
  1278. (fset 'mc--make-frame (symbol-function 'make-screen))
  1279. (fset 'mc--select-frame (symbol-function 'select-screen))
  1280. (fset 'mc--frame-live-p (symbol-function 'screen-live-p))
  1281. (fset 'mc--make-frame-visible (symbol-function 'make-screen-visible))
  1282. (fset 'mc--raise-frame (symbol-function 'raise-screen)))
  1283. ((fboundp 'new-screen)
  1284. ;; Lucid Emacs/obsolete
  1285. (fset 'mc--make-frame (symbol-function 'new-screen))
  1286. (fset 'mc--select-frame (symbol-function 'select-screen))
  1287. (fset 'mc--frame-live-p (symbol-function 'screen-live-p))
  1288. (fset 'mc--make-frame-visible (symbol-function 'make-screen-visible))
  1289. (fset 'mc--raise-frame (symbol-function 'raise-screen))))
  1290. (defsubst mc--funcall (command &rest params)
  1291. ;; Run command with params in another frame or not:
  1292. ;; only if user ask for it and if window system is X
  1293. ;; (maybe test window-system is set will be enought?).
  1294. (cond ((and (eq mc--ws 'x)
  1295. mode-compile-other-frame-p)
  1296. ;; switch to another frame
  1297. (mc--msg "Switching to another frame to compile...")
  1298. (let ((buffer (current-buffer))
  1299. (win-attr (or mode-compile-frame-parameters-alist
  1300. mode-compile-default-frame-parameters))
  1301. (frame (cond ((fboundp 'mc--frame-live-p)
  1302. (if (mc--frame-live-p mc--other-frame)
  1303. mc--other-frame
  1304. nil))
  1305. (t
  1306. (mc--msg "Don't know how to check frame existence.")
  1307. nil))))
  1308. (cond ((fboundp 'mc--make-frame)
  1309. (mc--select-frame (or frame
  1310. (setq mc--other-frame
  1311. (mc--make-frame win-attr))))
  1312. ;; I really don't understand why the 3 following
  1313. ;; are necessary (raise-frame must be enought?).
  1314. (mc--make-frame-visible mc--other-frame)
  1315. (mc--raise-frame mc--other-frame)
  1316. (switch-to-buffer buffer))
  1317. (t
  1318. (mc--msg "Don't know how to create a new frame."))))))
  1319. ;; Just run the command with it's parameters
  1320. (apply command params))
  1321. (defun mc--byte-compile-buffer()
  1322. (if (fboundp 'byte-compile-buffer) (byte-compile-buffer)
  1323. ;; No byte-compile-buffer
  1324. ;; Save current-buffer in a temporary file and byte-compile it.
  1325. (let ((tmp-file (concat (or (getenv "TMPDIR")
  1326. (concat mode-compile-dir-separator-char "tmp"))
  1327. mode-compile-dir-separator-char (make-temp-name "mc--"))))
  1328. (save-restriction
  1329. (widen)
  1330. (write-region (point-min) (point-max) tmp-file)
  1331. (condition-case err
  1332. (byte-compile-file tmp-file)
  1333. ;; handler
  1334. (error (mc--msg "Failing to byte-compile %s, #error %s"
  1335. (buffer-name) err)))
  1336. (delete-file tmp-file)
  1337. (let ((elc-file (concat tmp-file emacs-lisp-bytecomp-ext)))
  1338. (if (file-writable-p elc-file)
  1339. (condition-case err
  1340. (delete-file elc-file)
  1341. ;; handler
  1342. (error (mc--msg "Failing to delete %s, #error %s"
  1343. elc-file err)))))
  1344. (message nil))))) ; to clean minibuffer
  1345. (fset 'mc--member
  1346. (if (fboundp 'member)
  1347. (symbol-function 'member)
  1348. ;; No member function
  1349. (function
  1350. (lambda (elt list)
  1351. (catch 'elt-is-member
  1352. (while list
  1353. (if (equal elt (car list))
  1354. (throw 'elt-is-member list))
  1355. (setq list (cdr list))))))))
  1356. (fset 'mc--run-hooks
  1357. (if (fboundp 'run-hooks)
  1358. (symbol-function 'run-hooks)
  1359. ;; No run-hooks
  1360. (function
  1361. (lambda (hooklist)
  1362. (mapcar '(lambda (x)
  1363. ;; report an error if x not a function
  1364. (funcall x))
  1365. hooklist)))))
  1366. (defsubst mc--read-string (prompt &optional initial-contents)
  1367. ;; On Lucid Emacs I use compile-history as 3rd argument but
  1368. ;; no history is possible with GNU emacs.
  1369. (if mc--lucid-emacs-p
  1370. (read-string prompt initial-contents 'compile-history)
  1371. (read-string prompt initial-contents)))
  1372. (defmacro mc--eval (sym &optional arg)
  1373. ;; Evaluate symbol
  1374. (` (cond
  1375. ((and (symbolp (, sym))
  1376. (fboundp (, sym)))
  1377. (funcall (, sym) (, arg)))
  1378. (t
  1379. (eval (, sym))))))
  1380. (defmacro mc--common-completion (alist)
  1381. ;; Return the greatest common string for all
  1382. ;; possible completions in alist.
  1383. (` (try-completion "" (, alist))))
  1384. (defun mc--byte-recompile-files (files)
  1385. ;; Byte recompile all FILES which are older than their
  1386. ;; .elc files in the current directory
  1387. (let ((tmp-fl files))
  1388. (while (car-safe tmp-fl)
  1389. (let* ((el-file (car tmp-fl))
  1390. (elc-file (concat el-file emacs-lisp-bytecomp-ext)))
  1391. (mc--msg "Checking file %s ..." el-file)
  1392. ;; is el-file newer than elc-file (if exists)
  1393. (if (and (file-newer-than-file-p el-file elc-file)
  1394. (or (not emacs-lisp-byte-compile-dir-interactive-p)
  1395. (y-or-n-p (format "byte-recompile file %s? " el-file))))
  1396. (condition-case err
  1397. (byte-compile-file el-file)
  1398. ;; handler
  1399. (error (mc--msg "Failing to byte-compile %s, #error %s"
  1400. el-file err))))
  1401. (setq tmp-fl (cdr-safe tmp-fl))))
  1402. (mc--msg "All files processed")))
  1403. (defun mc--which (file)
  1404. ;; Find an executable FILE in exec-path
  1405. (if (not (stringp file))
  1406. (error "mc--which: nil FILE arg"))
  1407. (if mc--lucid-emacs-p
  1408. ;; Some emacses don't have locate-file some have...
  1409. ;; Lucid have it in standard, some others (GNU) have it
  1410. ;; (add-on pkg) but the syntax is not always consistent...
  1411. ; (locate-file file exec-path nil 1)
  1412. (locate-file file exec-path mode-compile-exe-file-ext 1)
  1413. (let ((tmp-p-lst exec-path)
  1414. (found nil)
  1415. (file-found nil))
  1416. (while (and (car-safe tmp-p-lst)
  1417. (not (setq found
  1418. (file-executable-p
  1419. (setq file-found
  1420. (concat (car tmp-p-lst)
  1421. mode-compile-dir-separator-char
  1422. file
  1423. mode-compile-exe-file-ext))))))
  1424. (setq tmp-p-lst (cdr-safe tmp-p-lst)))
  1425. (if found file-found nil))))
  1426. (defun mc--find-compiler ()
  1427. ;; Find user's favourite mode compiler
  1428. (mc--msg "Searching for your favourite %s compiler ..." mode-name)
  1429. (let ((tmp-comp-lst mc--comp-lst)
  1430. (compiler nil))
  1431. (or (getenv mc--comp-varenv)
  1432. (progn
  1433. (while (and tmp-comp-lst
  1434. (not (setq compiler
  1435. (mc--which (car tmp-comp-lst)))))
  1436. (setq tmp-comp-lst (cdr tmp-comp-lst)))
  1437. (file-name-nondirectory (or compiler (mc--eval mc--def-comp)))))))
  1438. (defun mc--find-to-compile-file (&optional fname)
  1439. ;; Find the name of the file to compile.
  1440. (let ((file-name (or fname
  1441. (buffer-file-name)
  1442. (error "Compilation abort: Buffer %s has no filename."
  1443. (buffer-name))))
  1444. (assoc-file nil)
  1445. (found nil)
  1446. (pos 0))
  1447. (cond
  1448. ((string-match mc--source-ext-regexp file-name)
  1449. ;; buffer is a compileable file
  1450. (file-name-nondirectory file-name))
  1451. ((setq pos (string-match mc--compfile-regexp file-name))
  1452. ;; Buffer is not a compileable file, try to find associated
  1453. ;; compileable file.
  1454. (let ((tmp-ext-lst mc--source-ext-lst))
  1455. (mc--msg "Looking for a compileable companion file for %s..."
  1456. (file-name-nondirectory file-name))
  1457. (while (and tmp-ext-lst
  1458. (not (setq found
  1459. (file-readable-p
  1460. (setq assoc-file
  1461. (concat
  1462. (substring file-name 0 pos)
  1463. "." (car tmp-ext-lst)))))))
  1464. (setq tmp-ext-lst (cdr tmp-ext-lst))))
  1465. (if found
  1466. ;; A compileable companion source file found
  1467. (file-name-nondirectory assoc-file)
  1468. ;; No compileable companion source file found
  1469. (mc--msg "Couldn't find any compileable companion file for %s ..."
  1470. (file-name-nondirectory file-name))
  1471. nil))
  1472. (t
  1473. ;; Buffer has an unknown file extension
  1474. ;; Could I be more cool?
  1475. (error "Compilation abort: Don't know how to compile %s."
  1476. (file-name-nondirectory file-name))))))
  1477. (defun mc--guess-compile-result-fname (infile)
  1478. ;; Try to guess if outfile will be an object file or
  1479. ;; an executable file by grepping for `main()' in INFILE.
  1480. (let ((base-fname
  1481. (substring infile 0
  1482. (string-match mc--source-ext-regexp infile))))
  1483. (save-excursion
  1484. ;; Create a temporary buffer containing infile contents
  1485. (set-buffer (find-file-noselect infile))
  1486. (save-excursion
  1487. (save-restriction
  1488. (widen)
  1489. (goto-char (point-min))
  1490. ;; Grep into tmp buffer for main function
  1491. ;; THIS WILL NOT WORK FOR PROGRAMMING LANGAGES
  1492. ;; WHICH ARE NOT C DIALECTS:
  1493. ;; In non C-ish modes I hope this regexp will never be found :-(
  1494. (if (re-search-forward mc--find-C-main-regexp (point-max) t)
  1495. (concat base-fname mode-compile-exe-file-ext)
  1496. (concat base-fname "." mc--outfile-ext)))))))
  1497. (defun mc--build-output-args (infile)
  1498. ;; Build output arguments for compile command by scanning INFILE.
  1499. (mc--msg "Looking into %s to build compile command ..." infile)
  1500. (let ((out-file (mc--guess-compile-result-fname infile)))
  1501. (concat (if (string-match
  1502. (concat "\\." mc--outfile-ext "$")
  1503. out-file)
  1504. ;; outfile will be an object file
  1505. " -c "
  1506. ;; outfile will be an executable file
  1507. " ")
  1508. infile " -o " out-file )))
  1509. (defun mc--set-remote-cmd (remote-host &optional username pathname)
  1510. ;; Check validity of remote-host or ask one to user
  1511. ;; Then build the first part of the remote command
  1512. (if (stringp remote-host)
  1513. ;; Arg is the remote host name
  1514. (let ((host-infos (assoc remote-host
  1515. mode-compile-remote-hosts-alist)))
  1516. (setq mc--remote-host
  1517. remote-host)
  1518. (setq mc--remote-username
  1519. (or username
  1520. (let ((usrnam (cdr host-infos)))
  1521. (if usrnam
  1522. (cond
  1523. ((stringp usrnam)
  1524. usrnam)
  1525. ((functionp usrnam)
  1526. ;; usrnam is a function call it with hostname arg
  1527. (funcall usrnam mc--remote-host))
  1528. (t
  1529. ;; What's that??
  1530. (mc--msg "%s is not a valid option using user-login-name" (pp-to-string usrnam))
  1531. (user-login-name)))
  1532. (user-login-name)))))
  1533. (setq mc--remote-pathname pathname)
  1534. ;; Add host to the user's list
  1535. (or host-infos
  1536. (setq mode-compile-remote-hosts-alist
  1537. (append (list (list remote-host))
  1538. mode-compile-remote-hosts-alist)))
  1539. ;; Prepare the command
  1540. (setq mc--remote-command
  1541. (concat
  1542. ;; "rsh host -l username"
  1543. mode-compile-remote-execute-command " "
  1544. mode-compile-remote-execute-set-host-arg " "
  1545. mc--remote-host " "
  1546. mode-compile-remote-execute-set-username-arg " "
  1547. mc--remote-username " "
  1548. mode-compile-remote-execute-misc-args " "
  1549. mode-compile-remote-execute-set-command-arg " "
  1550. )))
  1551. ;; Arg is: Ask to user then check
  1552. (let ((rhost (completing-read
  1553. "Remote host to compile to: "
  1554. mode-compile-remote-hosts-alist
  1555. nil nil
  1556. ;; Initial contents
  1557. (or mc--remote-host
  1558. (car-safe (car-safe mode-compile-remote-hosts-alist)))
  1559. mc--remote-host-history)))
  1560. (or (string= rhost "")
  1561. (mc--set-remote-cmd rhost)))))
  1562. ;(defmacro mc--makefile-test-p (makefile)
  1563. ; (` (and (, makefile)
  1564. ; (not (string-equal (, makefile) ""))
  1565. ; (not (file-directory-p (, makefile)))
  1566. ; (file-readable-p (, makefile)))))
  1567. (defun mc--makefile-test-p (makefile)
  1568. (cond
  1569. ((or (not makefile)
  1570. (string-equal makefile ""))
  1571. (mc--msg "Empty makefile selection")
  1572. nil)
  1573. ((file-directory-p makefile)
  1574. (mc--msg "Makefile selection %s is a directory !!" makefile)
  1575. nil)
  1576. ((not (file-readable-p makefile))
  1577. (mc--msg "Makefile %s unreadable" makefile)
  1578. nil)
  1579. (t)))
  1580. (if (not (fboundp 'buffer-modified-tick))
  1581. (fset 'buffer-modified-tick
  1582. ;; allways indicate modified
  1583. (function
  1584. (lambda()
  1585. (if mc--mkfl-buffer-tick
  1586. (+ mc--mkfl-buffer-tick 1)
  1587. 1)))))
  1588. (defun mc--get-makefile-rules (makefile)
  1589. ;; Try to find if makefile's buffer has been modified
  1590. ;; since last rule extraction
  1591. (if (or (not mc--mkfl-buffer-tick)
  1592. (not (equal mc--mkfl-buffer-tick
  1593. (buffer-modified-tick))))
  1594. (save-excursion
  1595. (save-restriction
  1596. (widen)
  1597. (goto-char (point-min))
  1598. (setq mc--mkfl-buffer-tick (buffer-modified-tick))
  1599. (setq mc--makefile-rules nil)
  1600. (mc--msg "Extracting rules from %s ..." makefile)
  1601. ;; Grep into tmp buffer for makefile rules
  1602. (while (re-search-forward mc--makefile-rules-regexp nil t)
  1603. (let ((rule (buffer-substring
  1604. (match-beginning 1)
  1605. (match-end 1))))
  1606. ;; add rule to list if it don't match the ignore regexp
  1607. ;; and if not allready in rules list.
  1608. (if (and
  1609. (or (not mode-compile-ignore-makerule-regexp)
  1610. (not (string-match
  1611. mode-compile-ignore-makerule-regexp
  1612. rule)))
  1613. (not (mc--member rule mc--makefile-rules)))
  1614. (setq mc--makefile-rules
  1615. (append mc--makefile-rules
  1616. (list rule))))))))
  1617. (mc--msg "Rules had already been extracted from %s ..." makefile))
  1618. ;; Always add an empty rule to allow `default' choice.
  1619. (append mc--makefile-rules '([])))
  1620. (defun mc--makerule-completion (alist outfile &optional pref)
  1621. ;; Return the makerule completion according to the prefered
  1622. ;; default makerule
  1623. (let ((preference (or pref
  1624. mode-compile-prefered-default-makerule)))
  1625. (mc--msg "Prefered makerule choice is '%s" preference)
  1626. (cond
  1627. ((eq preference 'none)
  1628. ;; Just show max common completion string to user
  1629. (or (mc--common-completion alist) ""))
  1630. ((eq preference 'all)
  1631. ;; Find the all rule or 'none
  1632. (if (assoc "all" alist) "all"
  1633. (mc--makerule-completion alist outfile 'none)))
  1634. ((eq preference 'file)
  1635. ;; The out file is prefered or 'none
  1636. (or outfile (mc--makerule-completion alist outfile 'none)))
  1637. ((eq preference 'default)
  1638. ;; Find the default rule or ""
  1639. (if (assoc "default" alist) "default" ""))
  1640. (t
  1641. ;; Invalid preference return 'none
  1642. (mc--msg "Invalid `mode-compile-prefered-default-makerule': '%s"
  1643. mode-compile-prefered-default-makerule)
  1644. (mc--makerule-completion alist outfile 'none)))))
  1645. (defun mc--choose-makefile-rule (makefile &optional outfile)
  1646. ;; Choose the makefile rule and set it makefile local
  1647. (save-excursion
  1648. ;; Switch to makefile buffer
  1649. (set-buffer (find-file-noselect makefile))
  1650. (setq mc--selected-makerule
  1651. ;; Add the name of the out file to the makefile
  1652. ;; rules list if not allready in.
  1653. (let* ((mk-rules-alist (mc--get-makefile-rules makefile))
  1654. (choices (mapcar '(lambda (x) (list x))
  1655. (if (or (not outfile)
  1656. (mc--member outfile
  1657. mk-rules-alist))
  1658. mk-rules-alist
  1659. (append mk-rules-alist
  1660. (list outfile))))))
  1661. (completing-read
  1662. (if mode-compile-expert-p
  1663. "Make rule: "
  1664. "Using `make', enter rule to rebuild ([TAB] to complete): ")
  1665. choices
  1666. nil nil
  1667. ;; initial contents
  1668. (or mc--selected-makerule
  1669. (mc--makerule-completion choices outfile
  1670. (if outfile 'file)))
  1671. mc--selected-makerule-history
  1672. )))))
  1673. (defmacro mc--cleanup-makefile-list (makefile-list)
  1674. ;; Remove unusable and/or backups makefiles from list
  1675. (` (let ((newlist))
  1676. (mapcar
  1677. '(lambda (x)
  1678. (if (and (mc--makefile-test-p x)
  1679. (or (not mode-compile-ignore-makefile-backups)
  1680. (not (string-match
  1681. mode-compile-makefile-backups-regexp
  1682. x))))
  1683. (setq newlist (cons x newlist))
  1684. (mc--msg "Removing makefile \"%s\" from completion list"
  1685. x)))
  1686. (, makefile-list))
  1687. newlist)))
  1688. (defun mc--makefile-to-use (&optional directory)
  1689. ;; Find the makefile to use in the current directory
  1690. (let ((makefile-list (mc--cleanup-makefile-list
  1691. (directory-files
  1692. ;; I do not use the 5th parameter in Lucid Emacs
  1693. ;; to be compatible with GNU Emacs which accept
  1694. ;; only 4 parameters - no NOSORT -.
  1695. (or directory default-directory)
  1696. nil mode-compile-makefile-regexp t))))
  1697. (cond
  1698. ((not makefile-list)
  1699. ;; No makefile found
  1700. nil)
  1701. ((and (not (cdr-safe makefile-list))
  1702. (mc--makefile-test-p (car makefile-list)))
  1703. ;; Only one valid makefile
  1704. (car makefile-list))
  1705. (t
  1706. ;; Many makefiles in directory ask user to select one
  1707. (let ((choices (mapcar
  1708. '(lambda (x) (list x))
  1709. makefile-list))
  1710. (makefile nil))
  1711. (while
  1712. ;; While the makefile do not pass the test.
  1713. (not (mc--makefile-test-p
  1714. (setq makefile
  1715. (completing-read
  1716. (if mode-compile-expert-p
  1717. "Makefile: "
  1718. "Using `make', select makefile to use ([TAB] to complete): ")
  1719. choices
  1720. nil t
  1721. ;; initial contents
  1722. (or mc--selected-makefile
  1723. (mc--common-completion choices))
  1724. mc--selected-makefile-history
  1725. )))))
  1726. makefile)))))
  1727. (defun mc--set-command (&optional file)
  1728. ;; Return a compilation command, built according to the existence
  1729. ;; of a makefile or not, to compile FILE .
  1730. (setq completion-ignore-case nil) ; let completion be case sensitive
  1731. (let ((to-compile-fname (or file (mc--find-to-compile-file))))
  1732. (if (setq mc--selected-makefile (mc--makefile-to-use))
  1733. (progn
  1734. ;; A makefile found in the directory:
  1735. ;; using make to compile
  1736. (let ((out-fname (if to-compile-fname
  1737. (mc--guess-compile-result-fname
  1738. to-compile-fname)
  1739. nil)))
  1740. ;; build make command by asking rule to user
  1741. (concat mode-compile-make-program " "
  1742. (or (mc--eval mode-compile-make-options) "")
  1743. " -f " mc--selected-makefile " "
  1744. (mc--choose-makefile-rule
  1745. mc--selected-makefile out-fname))))
  1746. ;; else
  1747. ;; No makefile: build compile command asking for confirmation to user.
  1748. ;; Should this be replaced by the creation of a makefile (and then
  1749. ;; running it) as rms proposed me?
  1750. (or mc--compile-command
  1751. (setq mc--compile-command
  1752. (concat (setq mode-compile-choosen-compiler
  1753. (mc--find-compiler)) " "
  1754. (or (getenv mc--cflags-varenv)
  1755. (mc--eval mc--comp-options))
  1756. (if to-compile-fname
  1757. (if mc--build-op-args
  1758. (mc--build-output-args to-compile-fname)
  1759. (concat " " to-compile-fname)
  1760. )
  1761. " "))))
  1762. (if (not mode-compile-never-edit-command-p)
  1763. (setq mc--compile-command
  1764. (mc--read-string
  1765. (if mode-compile-expert-p
  1766. "Compile command: "
  1767. (if to-compile-fname
  1768. (format "Edit command to compile %s: "
  1769. to-compile-fname)
  1770. "Edit compile command: " ))
  1771. mc--compile-command))
  1772. mc--compile-command))))
  1773. (defun mc--shell-compile (shell dbgflags &optional errors-regexp-alist)
  1774. ;; Run SHELL with debug flags DBGFLAGS on current-buffer
  1775. (let* ((shcmd (or (mc--which shell)
  1776. (error "Compilation abort: command %s not found" shell)))
  1777. (shfile (or mc--remote-pathname (buffer-file-name)
  1778. (error "Compilation abort: Buffer %s has no filename"
  1779. (buffer-name))))
  1780. (run-cmd (concat shcmd " " dbgflags " " shfile " "
  1781. (setq mc--shell-args
  1782. (read-string (if mode-compile-expert-p
  1783. "Argv: "
  1784. (format "Arguments to %s %s script: "
  1785. shfile shell))
  1786. mc--shell-args)))))
  1787. ;; Modify compilation-error-regexp-alist if needed
  1788. (if errors-regexp-alist
  1789. (progn
  1790. ;; Set compilation-error-regexp-alist from compile
  1791. (or (listp errors-regexp-alist)
  1792. (error "Compilation abort: In mc--shell-compile errors-regexp-alist not a list."))
  1793. ;; Add new regexp alist to compilation-error-regexp-alist
  1794. (mapcar '(lambda(x)
  1795. (if (mc--member x compilation-error-regexp-alist) nil
  1796. (setq compilation-error-regexp-alist
  1797. (append (list x)
  1798. compilation-error-regexp-alist))))
  1799. errors-regexp-alist)))
  1800. ;; Run compile with run-cmd
  1801. (mc--compile run-cmd)))
  1802. (defmacro mc--assq-get-fcomp (asq)
  1803. ;; Return compile-function associated to ASQ
  1804. (` (let* ((mode (cdr (, asq)))
  1805. (massq (assq mode mode-compile-modes-alist)))
  1806. (if massq (car-safe (cdr massq))))))
  1807. (defmacro mc--assq-get-fkill (asq)
  1808. ;; Return kill-compile-function associated to ASQ
  1809. (` (let* ((mode (cdr (, asq)))
  1810. (massq (assq mode mode-compile-modes-alist)))
  1811. (if massq (car-safe (cdr-safe (cdr massq)))))))
  1812. (defun mc--lookin-for-shell ()
  1813. ;; Look into current-buffer to see if it is a shell script
  1814. ;; and return function to compile it or nil.
  1815. (mc--msg "Looking if buffer %s is a shell script..." (buffer-name))
  1816. (save-excursion
  1817. (save-restriction
  1818. (widen)
  1819. (goto-char (point-min))
  1820. (if (looking-at "#![ \t]*/\\([^ \t\n]+/\\)\\([^ \t\n]+\\)")
  1821. (let* ((shell-name (buffer-substring (match-beginning 2)
  1822. (match-end 2)))
  1823. (shell-assq (assoc shell-name mode-compile-shell-alist)))
  1824. (if shell-assq
  1825. (progn
  1826. (mc--msg "Buffer is a %s script" shell-name)
  1827. (setq mc--kill-compile (mc--assq-get-fkill shell-assq))
  1828. (mc--assq-get-fcomp shell-assq))
  1829. nil))))))
  1830. (defun mc--lookat-name ()
  1831. ;; Lookat buffer file name to see if it can return a function
  1832. ;; to compile it or nil.
  1833. (mc--msg "Trying to guess compile command from buffer %s file name..."
  1834. (buffer-name))
  1835. (let ((fname (buffer-file-name)))
  1836. (if (not fname) nil
  1837. ;; try regexp from mode-compile-filename-regexp-alist
  1838. (let ((tmp-al mode-compile-filename-regexp-alist)
  1839. (found nil))
  1840. (while (and tmp-al (car tmp-al) (not found))
  1841. ;; evaluate to string
  1842. (let ((regxp (mc--eval (car (car tmp-al)))))
  1843. (if (string-match regxp fname)
  1844. (setq found (car tmp-al)))
  1845. (setq tmp-al (cdr tmp-al))))
  1846. (if (not found)
  1847. nil
  1848. (mc--msg "File %s matches regexp %s" fname (car found))
  1849. (setq mc--kill-compile (mc--assq-get-fkill found))
  1850. (mc--assq-get-fcomp found))))))
  1851. ;; @ mode specific functions ;;;
  1852. (defun cc-compile ()
  1853. "Run `compile' with a dynamically built command for `c-mode'.
  1854. The command is built depending of the existence of a makefile (which could
  1855. be specified by changing value of variable mode-compile-makefile-regexp) in
  1856. the current directory or not.
  1857. If no makefile is found try to run a C compiler on the file or it's companion.
  1858. See also variables:
  1859. -- cc-compilers-list
  1860. -- cc-default-compiler
  1861. -- cc-companion-file-regexp
  1862. -- cc-compiler-varenv
  1863. -- cc-cflags-varenv
  1864. -- cc-source-ext-list
  1865. -- cc-headers-ext-list
  1866. -- cc-source-file-ext-regexp"
  1867. (setq
  1868. mc--comp-lst cc-compilers-list
  1869. mc--def-comp cc-default-compiler
  1870. mc--compfile-regexp cc-companion-file-regexp
  1871. mc--comp-varenv cc-compiler-varenv
  1872. mc--comp-options cc-default-compiler-options
  1873. mc--cflags-varenv cc-cflags-varenv
  1874. mc--source-ext-lst cc-source-ext-list
  1875. mc--head-ext-lst cc-headers-ext-list
  1876. mc--source-ext-regexp cc-source-file-ext-regexp
  1877. mc--build-op-args cc-build-output-args
  1878. mc--outfile-ext cc-object-file-ext
  1879. )
  1880. (mc--compile (mc--set-command)))
  1881. (defun java-compile ()
  1882. "Run `compile' with a dynamically built command for `java-mode'.
  1883. The command is built depending of the existence of a makefile (which could
  1884. be specified by changing value of variable mode-compile-makefile-regexp) in
  1885. the current directory or not.
  1886. If no makefile is found try to run a Java compiler on the file or it's
  1887. companion.
  1888. See also variables:
  1889. -- java-compilers-list
  1890. -- java-default-compiler
  1891. -- java-companion-file-regexp
  1892. -- java-compiler-varenv
  1893. -- java-cflags-varenv
  1894. -- java-source-ext-list
  1895. -- java-headers-ext-list
  1896. -- java-source-file-ext-regexp"
  1897. (setq
  1898. mc--comp-lst java-compilers-list
  1899. mc--def-comp java-default-compiler
  1900. mc--compfile-regexp java-companion-file-regexp
  1901. mc--comp-varenv java-compiler-varenv
  1902. mc--comp-options java-default-compiler-options
  1903. mc--cflags-varenv java-cflags-varenv
  1904. mc--source-ext-lst java-source-ext-list
  1905. mc--head-ext-lst java-headers-ext-list
  1906. mc--source-ext-regexp java-source-file-ext-regexp
  1907. mc--build-op-args java-build-output-args
  1908. mc--outfile-ext java-object-file-ext
  1909. )
  1910. (mc--compile (mc--set-command)))
  1911. (defun c++-compile ()
  1912. "Run `compile' with a dynamically built command for `c++-mode'.
  1913. The command is built depending of the existence of a makefile (which could
  1914. be specified by changing value of variable mode-compile-makefile-regexp) in
  1915. the current directory or not.
  1916. If no makefile is found try to run a C++ compiler on the file or it's companion.
  1917. See also variables:
  1918. -- c++-compilers-list
  1919. -- c++-default-compiler
  1920. -- c++-companion-file-regexp
  1921. -- c++-compiler-varenv
  1922. -- c++-cflags-varenv
  1923. -- c++-source-ext-list
  1924. -- c++-headers-ext-list
  1925. -- c++-source-file-ext-regexp"
  1926. (setq
  1927. mc--comp-lst c++-compilers-list
  1928. mc--def-comp c++-default-compiler
  1929. mc--compfile-regexp c++-companion-file-regexp
  1930. mc--comp-varenv c++-compiler-varenv
  1931. mc--comp-options c++-default-compiler-options
  1932. mc--cflags-varenv c++-cflags-varenv
  1933. mc--source-ext-lst c++-source-ext-list
  1934. mc--head-ext-lst c++-headers-ext-list
  1935. mc--source-ext-regexp c++-source-file-ext-regexp
  1936. mc--build-op-args c++-build-output-args
  1937. mc--outfile-ext c++-object-file-ext
  1938. )
  1939. (mc--compile (mc--set-command)))
  1940. (defun ada-compile ()
  1941. "Run `compile' with a dynamically built command for `ada-mode'.
  1942. The command is built depending of the existence of a makefile (which could
  1943. be specified by changing value of variable mode-compile-makefile-regexp) in
  1944. the current directory or not.
  1945. If no makefile is found try to run an Ada compiler on the file.
  1946. See also variables:
  1947. -- ada-compilers-list
  1948. -- ada-default-compiler
  1949. -- ada-companion-file-regexp
  1950. -- ada-compiler-varenv
  1951. -- ada-aflags-varenv
  1952. -- ada-source-ext-list
  1953. -- ada-headers-ext-list
  1954. -- ada-source-file-ext-regexp)"
  1955. (setq
  1956. mc--comp-lst ada-compilers-list
  1957. mc--def-comp ada-default-compiler
  1958. mc--compfile-regexp ada-companion-file-regexp
  1959. mc--comp-varenv ada-compiler-varenv
  1960. mc--comp-options ada-default-compiler-options
  1961. mc--cflags-varenv ada-aflags-varenv
  1962. mc--source-ext-lst ada-source-ext-list
  1963. mc--head-ext-lst ada-headers-ext-list
  1964. mc--source-ext-regexp ada-source-file-ext-regexp
  1965. mc--build-op-args ada-build-output-args
  1966. mc--outfile-ext ada-object-file-ext
  1967. )
  1968. (mc--compile (mc--set-command)))
  1969. (defun f77-compile ()
  1970. "Run `compile' with a dynamically built command for `fortran-mode'.
  1971. The command is built depending of the existence of a makefile (which could
  1972. be specified by changing value of variable mode-compile-makefile-regexp) in
  1973. the current directory or not.
  1974. If no makefile is found try to run a Fortran compiler on the file or it's companion..
  1975. See also variables:
  1976. -- f77-compilers-list
  1977. -- f77-default-compiler
  1978. -- f77-companion-file-regexp
  1979. -- f77-compiler-varenv
  1980. -- f77-cflags-varenv
  1981. -- f77-source-ext-list
  1982. -- f77-headers-ext-list
  1983. -- f77-source-file-ext-regexp)"
  1984. (setq
  1985. mc--comp-lst f77-compilers-list
  1986. mc--def-comp f77-default-compiler
  1987. mc--compfile-regexp f77-companion-file-regexp
  1988. mc--comp-varenv f77-compiler-varenv
  1989. mc--cflags-varenv f77-cflags-varenv
  1990. mc--comp-options f77-default-compiler-options
  1991. mc--source-ext-lst f77-source-ext-list
  1992. mc--head-ext-lst f77-headers-ext-list
  1993. mc--source-ext-regexp f77-source-file-ext-regexp
  1994. mc--build-op-args f77-build-output-args
  1995. mc--outfile-ext f77-object-file-ext
  1996. )
  1997. (mc--compile (mc--set-command)))
  1998. (defun elisp-compile ()
  1999. "Run `byte-compile' on the current Emacs lisp buffer.
  2000. For `emacs-lisp-mode' and `lisp-interaction-mode'.
  2001. Produce a `.elc' file if possible or `byte-compile' only the buffer."
  2002. (let ((comp-file (or (buffer-file-name) "")))
  2003. (if (string-match emacs-lisp-sources-regexp comp-file)
  2004. (progn
  2005. (mc--msg "Byte compiling file %s ..." comp-file)
  2006. (byte-compile-file comp-file))
  2007. (mc--msg "Byte compiling buffer %s #No .elc produced ..." (buffer-name))
  2008. (mc--byte-compile-buffer))))
  2009. (defun makefile-compile (&optional makefile)
  2010. "Run `make' on the current-buffer (`makefile-mode').
  2011. The user is prompted for a selection of make rules to build."
  2012. (let ((mkfile (or makefile (buffer-file-name)
  2013. (error
  2014. "Compilation abort: buffer %s has no file name"
  2015. (buffer-name)))))
  2016. (setq mc--selected-makefile mkfile)
  2017. (setq mc--compile-command
  2018. (concat mode-compile-make-program " "
  2019. (or (mc--eval mode-compile-make-options) "")
  2020. " -f " mkfile " "
  2021. (mc--choose-makefile-rule mkfile))))
  2022. (mc--compile mc--compile-command))
  2023. (defun dired-compile ()
  2024. "Run `make' if a Makefile is present in current directory (`dired-mode').
  2025. The user is prompted for a selection of a makefile to choose if many
  2026. matching `mode-compile-makefile-regexp' are present in the directory and
  2027. for the make rules to build. If directory contain no makefile the function
  2028. try to find if there are some un-byte-compiled .el files and recompile them
  2029. if needed.
  2030. Ask for the complete `compile-command' if no makefile and no .el files found."
  2031. (let ((makefile (mc--makefile-to-use)))
  2032. (if makefile
  2033. ;; Makefile exists compile with it
  2034. (makefile-compile makefile)
  2035. ;; No makefile found look for some .el files
  2036. (mc--msg "No makefile found, looking for .el files ...")
  2037. (let ((el-files (directory-files
  2038. default-directory nil emacs-lisp-sources-regexp)))
  2039. (if el-files
  2040. ;; Some .el files found byte-recompile them
  2041. (mc--byte-recompile-files el-files)
  2042. ;; No .el files ask compile command to user
  2043. (mc--msg "No .el files found in directory %s" default-directory)
  2044. (default-compile))))))
  2045. (defun sh-compile ()
  2046. "Run `sh-command' (Bourne Shell) with `sh-dbg-flags' on current-buffer (`sh-mode').
  2047. User is prompted for arguments to run his sh program with.
  2048. If you want to step throught errors set the variable `sh-compilation-error-regexp-alist'
  2049. to a value understandable by compile's `next-error'.
  2050. See variables compilation-error-regexp-alist or sh-compilation-error-regexp-alist."
  2051. (mc--shell-compile sh-command sh-dbg-flags sh-compilation-error-regexp-alist))
  2052. (defun csh-compile ()
  2053. "Run `csh-command' (C Shell) with `csh-dbg-flags' on current-buffer (`csh-mode').
  2054. User is prompted for arguments to run his csh program with.
  2055. If you want to step throught errors set the variable `csh-compilation-error-regexp-alist'
  2056. to a value understandable by compile's `next-error'.
  2057. See variables compilation-error-regexp-alist or csh-compilation-error-regexp-alist."
  2058. (mc--shell-compile csh-command csh-dbg-flags csh-compilation-error-regexp-alist))
  2059. (defun zsh-compile ()
  2060. "Run `zsh-command' (Z Shell) with `zsh-dbg-flags' on current-buffer (`zsh-mode').
  2061. User is prompted for arguments to run his zsh program with.
  2062. If you want to step throught errors set the variable `zsh-compilation-error-regexp-alist'
  2063. to a value understandable by compile's `next-error'.
  2064. See variables compilation-error-regexp-alist or zsh-compilation-error-regexp-alist."
  2065. (mc--shell-compile zsh-command zsh-dbg-flags zsh-compilation-error-regexp-alist))
  2066. (defun perl-compile ()
  2067. "Run Perl with `perl-dbg-flags' on current-buffer (`perl-mode').
  2068. User is prompted for arguments to run his perl program with.
  2069. If you want to step throught errors set the variable `perl-compilation-error-regexp-alist'
  2070. to a value understandable by compile's `next-error'.
  2071. See variables compilation-error-regexp-alist or perl-compilation-error-regexp-alist."
  2072. (mc--shell-compile perl-command perl-dbg-flags perl-compilation-error-regexp-alist))
  2073. (defun tcl-compile ()
  2074. ;; JWH
  2075. "Run `tcl-command' with `tcl-dbg-flags' on current-buffer (`tcl-mode').
  2076. User is prompted for arguments to run his Tcl/Tk program with.
  2077. If you want to step throught errors set the variable `tcl-compilation-error-regexp-alist'
  2078. to a value understandable by compile's `next-error'.
  2079. See variables compilation-error-regexp-alist or tcl-compilation-error-regexp-alist."
  2080. (mc--shell-compile tcl-command tcl-dbg-flags tcl-compilation-error-regexp-alist))
  2081. (defun python-compile ()
  2082. ;; BM
  2083. "Run `python-command' with `python-dbg-flags' on current-buffer (`python-mode').
  2084. User is prompted for arguments to run his Python program with.
  2085. If you want to step throught errors set the variable `python-compilation-error-regexp-alist'
  2086. to a value understandable by compile's `next-error'.
  2087. See variables compilation-error-regexp-alist or python-compilation-error-regexp-alist."
  2088. (mc--shell-compile python-command python-dbg-flags python-compilation-error-regexp-alist))
  2089. (defun ruby-compile ()
  2090. ;; CLGC
  2091. "Run `ruby-command' with `ruby-dbg-flags' on current-buffer (`ruby-mode').
  2092. User is prompted for arguments to run their ruby program with.
  2093. If you want to step throught errors set the variable `ruby-compilation-error-regexp-alist'
  2094. to a value understandable by compile's `next-error'.
  2095. See variables compilation-error-regexp-alist or ruby-compilation-error-regexp-alist."
  2096. (mc--shell-compile ruby-command ruby-dbg-flags ruby-compilation-error-regexp-alist))
  2097. (defun default-compile ()
  2098. "Default function invoked by `mode-compile' (\\[mode-compile])
  2099. when everything else failed.
  2100. Ask to user to edit `compile-command' and run `compile' (\\[compile]) with it."
  2101. (setq mc--compile-command
  2102. (mc--read-string
  2103. (if mode-compile-expert-p
  2104. "Compile command: "
  2105. (format "Edit command to compile %s : " (buffer-name)))
  2106. (or mc--compile-command compile-command)))
  2107. (mc--compile mc--compile-command))
  2108. (defvar mc--makefile) ;; Just to avoid compiler warning
  2109. (defun guess-compile ()
  2110. "Try to guess how to compile current-buffer.
  2111. When the compile command could not be extrapolated from major-mode this function
  2112. is called which try to guess from number of parameters which command to build.
  2113. The steps to guess which command to use to compile are:
  2114. 1st : Look into the file to check if it is a shell script
  2115. See variable mode-compile-shell-alist
  2116. 2nd : Try to guess from the file name
  2117. See variable mode-compile-filename-regexp-alist
  2118. 3rd : Look for a makefile in the current directory
  2119. See variable mode-compile-makefile-regexp
  2120. Last: Give up and ask user for the command to use
  2121. See function default-compile"
  2122. (mc--msg "Trying to guess how to compile buffer %s ..." (buffer-name))
  2123. (let ((mc--makefile))
  2124. (funcall
  2125. (or
  2126. ;; step 1
  2127. (mc--lookin-for-shell)
  2128. ;; step 2
  2129. (mc--lookat-name)
  2130. ;; step 3
  2131. (progn
  2132. (mc--msg "Looking for a makefile in current directory...")
  2133. (if (setq mc--makefile (mc--makefile-to-use
  2134. (and (buffer-file-name)
  2135. (file-name-directory (buffer-file-name)))))
  2136. (progn
  2137. (setq mc--kill-compile 'kill-compilation)
  2138. ;; Byte-compiling says `makefile' is not referenced.
  2139. '(lambda () (makefile-compile mc--makefile)))))
  2140. ;; step 4
  2141. (progn
  2142. (mc--msg "Don't know how to compile %s, giving up..."
  2143. (buffer-name))
  2144. (setq mc--kill-compile 'kill-compilation)
  2145. 'default-compile)))))
  2146. ;; @ user accessible/exported function ;;;
  2147. ;; get reporter-submit-bug-report when byte-compiling
  2148. (and (fboundp 'eval-when-compile)
  2149. (eval-when-compile (require 'reporter)))
  2150. ;;;###autoload
  2151. (defun mode-compile-submit-bug-report ()
  2152. "*Submit via mail a bug report on mode-compile v2.27."
  2153. (interactive)
  2154. (and
  2155. (y-or-n-p "Do you REALLY want to submit a report on mode-compile? ")
  2156. (require 'reporter)
  2157. (reporter-submit-bug-report
  2158. mode-compile-help-address
  2159. (concat "mode-compile " mode-compile-version)
  2160. (list
  2161. ;; Interesting mode-compile variables
  2162. 'mode-compile-modes-alist
  2163. 'mode-compile-filename-regexp-alist
  2164. 'mode-compile-shell-alist
  2165. 'mode-compile-makefile-regexp
  2166. 'mode-compile-make-program
  2167. 'mode-compile-default-make-options
  2168. 'mode-compile-make-options
  2169. 'mode-compile-reading-time
  2170. 'mode-compile-expert-p
  2171. 'mode-compile-never-edit-command-p
  2172. 'mode-compile-save-all-p
  2173. 'mode-compile-always-save-buffer-p
  2174. 'mode-compile-before-compile-hook
  2175. 'mode-compile-after-compile-hook
  2176. 'mode-compile-before-kill-hook
  2177. 'mode-compile-after-kill-hook
  2178. 'mode-compile-other-frame-p
  2179. 'mode-compile-other-frame-name
  2180. 'mode-compile-frame-parameters-alist
  2181. 'mode-compile-prefered-default-makerule
  2182. 'emacs-lisp-byte-compile-dir-interactive-p
  2183. ;; others variables
  2184. 'features
  2185. 'compilation-error-regexp-alist
  2186. 'compile-command
  2187. )
  2188. nil
  2189. nil
  2190. "Dear Heddy,")))
  2191. ;;;###autoload
  2192. (defun mode-compile (&optional remote-host)
  2193. "*Compile the file in the current buffer with a dynamically built command.
  2194. The command is built according to the current major mode the function
  2195. was invoked from.
  2196. Running this command preceded by universal-argument (\\[universal-argument])
  2197. allows remote compilation, the user is prompted for a host name to run the
  2198. compilation command on.
  2199. Currently know how to compile in:
  2200. `c-mode' , -- function cc-compile.
  2201. `java-mode' , -- function java-compile.
  2202. `c++-mode', -- function c++-compile.
  2203. `ada-mode', -- function ada-compile.
  2204. `fortran-mode', -- function f77-compile.
  2205. `emacs-lisp-mode' -- function elisp-compile.
  2206. `lisp-interaction-mode' -- function elisp-compile.
  2207. `makefile-mode' -- function makefile-compile.
  2208. `dired-mode' -- function dired-compile.
  2209. `sh-mode' -- function sh-compile.
  2210. `csh-mode' -- function csh-compile.
  2211. `zsh-mode' -- function zsh-compile.
  2212. `perl-mode' -- function perl-compile.
  2213. `cperl-mode' -- function perl-compile.
  2214. `tcl-mode' -- function tcl-compile.
  2215. `python-mode' -- function python-compile.
  2216. `ruby-mode' -- function ruby-compile.
  2217. `fundamental-mode' -- function guess-compile.
  2218. `text-mode' -- function guess-compile.
  2219. `indented-text-mode' -- function guess-compile.
  2220. `compilation-mode' -- function default-compile.
  2221. The function `guess-compile' is called when mode is unknown.
  2222. The variable `mode-compile-modes-alist' contain description of known
  2223. modes. The hooks variables `mode-compile-before-compile-hook' and
  2224. `mode-compile-after-compile-hook' are run just before and after
  2225. invoking the compile command of the mode.
  2226. Use the command `mode-compile-kill' (\\[mode-compile-kill]) to abort a
  2227. running compilation.
  2228. Bound on \\[mode-compile]."
  2229. (interactive "P")
  2230. ;; reinit
  2231. (setq
  2232. mc--efs-path-list nil
  2233. mc--remote-command nil)
  2234. (if remote-host
  2235. ;; Remote compilation asked
  2236. ;; prepare remote command
  2237. (mc--set-remote-cmd remote-host)
  2238. ;; Not asked but check buffer-file-name to see
  2239. ;; if it is not an efs file
  2240. (setq mc--efs-path-list (and (fboundp 'efs-ftp-path)
  2241. (buffer-file-name)
  2242. (efs-ftp-path (buffer-file-name))))
  2243. (and mc--efs-path-list (mc--set-remote-cmd
  2244. (car mc--efs-path-list)
  2245. (nth 1 mc--efs-path-list)
  2246. (nth 2 mc--efs-path-list))))
  2247. (if (and mode-compile-always-save-buffer-p
  2248. (buffer-file-name))
  2249. ;; save-buffer allready check if buffer had been modified
  2250. (save-buffer))
  2251. (if mode-compile-save-all-p (save-some-buffers t))
  2252. ;; Check if compile-command set as local variable
  2253. (if (and
  2254. (boundp 'compile-command)
  2255. (local-variable-p 'compile-command (current-buffer))
  2256. compile-command ; not null
  2257. (if mc--compile-command
  2258. (equal compile-command mc--compile-command)
  2259. t)
  2260. )
  2261. ;; Just ask user and go
  2262. (progn
  2263. (mc--run-hooks 'mode-compile-before-compile-hook)
  2264. (default-compile)
  2265. (mc--run-hooks 'mode-compile-after-compile-hook)
  2266. )
  2267. ;; Here is the real work
  2268. (let ((mode-elem (assq major-mode mode-compile-modes-alist)))
  2269. (if mode-elem
  2270. ;; known mode
  2271. (progn
  2272. (mc--msg (substitute-command-keys
  2273. "Compiling in %s mode ... \\[mode-compile-kill] to kill.")
  2274. mode-name)
  2275. (mc--run-hooks 'mode-compile-before-compile-hook)
  2276. ;; mc--funcall can launch the compilation
  2277. ;; in another frame.
  2278. (mc--funcall (car (cdr mode-elem)))
  2279. (mc--run-hooks 'mode-compile-after-compile-hook))
  2280. ;; unknown mode: try to guess
  2281. (mc--msg (substitute-command-keys
  2282. "Don't know how to compile in %s mode, guessing... \\[mode-compile-kill] to kill.")
  2283. mode-name)
  2284. (mc--run-hooks 'mode-compile-before-compile-hook)
  2285. ;; mc--funcall can launch the compilation
  2286. ;; in another frame.
  2287. (mc--funcall 'guess-compile)
  2288. (mc--run-hooks 'mode-compile-after-compile-hook)))))
  2289. (provide 'mode-compile)
  2290. ;;;###autoload
  2291. (defun mode-compile-kill()
  2292. "*Kill the running compilation launched by `mode-compile' (\\[mode-compile]) \
  2293. command.
  2294. The compilation command is killed according to the current major mode
  2295. the function was invoked from.
  2296. Currently know how to kill compilations from:
  2297. `c-mode' , -- function kill-compilation.
  2298. `java-mode' , -- function kill-compilation.
  2299. `c++-mode' , -- function kill-compilation.
  2300. `ada-mode' , -- function kill-compilation.
  2301. `fortran-mode' , -- function kill-compilation.
  2302. `emacs-lisp-mode' -- function keyboard-quit.
  2303. `lisp-interaction-mode' -- function keyboard-quit.
  2304. `makefile-mode' -- function kill-compilation.
  2305. `dired-mode' -- function kill-compilation.
  2306. `sh-mode' -- function kill-compilation.
  2307. `csh-mode' -- function kill-compilation.
  2308. `zsh-mode' -- function kill-compilation.
  2309. `perl-mode' -- function kill-compilation.
  2310. `cperl-mode' -- function kill-compilation.
  2311. `tcl-mode' -- function kill-compilation.
  2312. `python-mode' -- function kill-compilation.
  2313. `ruby-mode' -- function kill-compilation.
  2314. `fundamental-mode' -- Bound dynamically.
  2315. `text-mode' -- Bound dynamically.
  2316. `indented-text-mode' -- Bound dynamically.
  2317. `compilation-mode' -- function kill-compilation.
  2318. The variable `mode-compile-modes-alist' contain description of ALL
  2319. known modes. The hooks variables `mode-compile-before-kill-hook' and
  2320. `mode-compile-after-kill-hook' are run just before and after invoking
  2321. the kill compile command of the mode.
  2322. Bound on \\[mode-compile-kill]."
  2323. (interactive)
  2324. (let ((mode-elem (assq major-mode mode-compile-modes-alist)))
  2325. (if mode-elem
  2326. ;; known mode
  2327. (progn
  2328. (mc--run-hooks 'mode-compile-before-kill-hook)
  2329. (mc--msg "Killing compilation in %s mode..." mode-name)
  2330. (let ((killfun (or (car-safe (cdr (cdr mode-elem)))
  2331. mc--kill-compile
  2332. nil)))
  2333. (if killfun
  2334. ;; I don't call mc--funcall here caus' we don't need
  2335. ;; to switch to another frame to kill a compilation.
  2336. (funcall killfun)
  2337. (mc--msg "Unable to kill compilation in %s mode..." mode-name))
  2338. (mc--run-hooks 'mode-compile-after-kill-hook)))
  2339. ;; unknown mode
  2340. (mc--msg "Don't know how to kill compilation in %s mode"
  2341. mode-name))))
  2342. (provide 'mode-compile-kill)
  2343. ;;; Local variables:
  2344. ;;; outline-regexp: ";; @+"
  2345. ;;; eval: (outline-minor-mode 1)
  2346. ;;; End:
  2347. ;;; mode-compile.el ends here