PageRenderTime 58ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/compile.el

https://bitbucket.org/xemacs/xemacs-base
Emacs Lisp | 2377 lines | 1626 code | 234 blank | 517 comment | 53 complexity | 737629b1f34be93570df3d4247844702 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. ;;; compile.el --- run compiler as inferior of Emacs, parse error messages
  2. ;; Copyright (C) 1985, 86, 87, 93, 94, 1995, 1996 Free Software Foundation, Inc.
  3. ;; Copyright (C) 1995 Tinker Systems and INS Engineering Corp.
  4. ;; Copyright (C) 2001 Ben Wing.
  5. ;; Author: Roland McGrath <roland@prep.ai.mit.edu>
  6. ;; Maintainer: XEmacs Development Team
  7. ;; Keywords: tools, processes
  8. ;; This file is part of XEmacs.
  9. ;; XEmacs is free software; you can redistribute it and/or modify it
  10. ;; under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation; either version 2, or (at your option)
  12. ;; any later version.
  13. ;; XEmacs is distributed in the hope that it will be useful, but
  14. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. ;; General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with XEmacs; see the file COPYING. If not, write to the Free
  19. ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  20. ;; 02111-1307, USA.
  21. ;;; Synched up with: FSF 19.34, with a lot of divergence.
  22. ;;; Commentary:
  23. ;; This package provides the compile and grep facilities documented in
  24. ;; the Emacs user's manual.
  25. ;;; Code:
  26. (defgroup compilation nil
  27. "Run compiler as inferior of Emacs, parse error messages."
  28. :group 'programming
  29. :group 'tools
  30. :group 'processes)
  31. ;;;###autoload
  32. (defcustom compilation-mode-hook nil
  33. "*List of hook functions run by `compilation-mode' (see `run-hooks')."
  34. :type 'hook
  35. :group 'compilation)
  36. ;;;###autoload
  37. (defcustom compilation-window-height nil
  38. "*Number of lines in a compilation window. If nil, use Emacs default."
  39. :type '(choice (const nil)
  40. integer)
  41. :group 'compilation)
  42. ;; XEmacs change
  43. (defvar compilation-error-list 'invalid ; only valid buffer-local
  44. "List of error message descriptors for visiting erring functions.
  45. Each error descriptor is a cons (or nil). Its car is a marker pointing to
  46. an error message. If its cdr is a marker, it points to the text of the
  47. line the message is about. If its cdr is a cons, it is a list
  48. \(\(DIRECTORY . FILE\) LINE [COLUMN]\). Or its cdr may be nil if that
  49. error is not interesting.
  50. The value may be t instead of a list; this means that the buffer of
  51. error messages should be reparsed the next time the list of errors is wanted.
  52. Some other commands (like `diff') use this list to control the error
  53. message tracking facilities; if you change its structure, you should make
  54. sure you also change those packages. Perhaps it is better not to change
  55. it at all.")
  56. (defvar compilation-old-error-list nil
  57. "Value of `compilation-error-list' after errors were parsed.")
  58. (defvar compilation-parse-errors-function 'compilation-parse-errors
  59. "Function to call to parse error messages from a compilation.
  60. It takes args LIMIT-SEARCH and FIND-AT-LEAST.
  61. If LIMIT-SEARCH is non-nil, don't bother parsing past that location.
  62. If FIND-AT-LEAST is non-nil, don't bother parsing after finding that
  63. many new errors.
  64. It should read in the source files which have errors and set
  65. `compilation-error-list' to a list with an element for each error message
  66. found. See that variable for more info.")
  67. ;;;###autoload
  68. (defcustom compilation-buffer-name-function nil
  69. "Function to compute the name of a compilation buffer.
  70. The function receives one argument, the name of the major mode of the
  71. compilation buffer. It should return a string.
  72. nil means compute the name with `(concat \"*\" (downcase major-mode) \"*\")'."
  73. :type 'function
  74. :group 'compilation)
  75. ;; XEmacs change
  76. (defcustom compilation-shell-minor-mode-menubar-menu-name "Errors"
  77. "*Name of the menubar menu which displays error-navigation items."
  78. :type 'string
  79. :group 'compilation)
  80. ;;;###autoload
  81. (defcustom compilation-finish-function nil
  82. "*Function to call when a compilation process finishes.
  83. It is called with two arguments: the compilation buffer, and a string
  84. describing how the process finished."
  85. :type 'function
  86. :group 'compilation)
  87. (defvar compilation-last-buffer nil
  88. "The most recent compilation buffer.
  89. A buffer becomes most recent when its compilation is started
  90. or when it is used with \\[next-error] or \\[compile-goto-error].")
  91. (defvar compilation-in-progress nil
  92. "List of compilation processes now running.")
  93. (or (assq 'compilation-in-progress minor-mode-alist)
  94. (setq minor-mode-alist (cons '(compilation-in-progress " Compiling")
  95. minor-mode-alist)))
  96. ;; XEmacs change
  97. (defcustom compilation-always-signal-completion nil
  98. "*Always give an audible signal upon compilation completion.
  99. By default that signal is only given if the bottom of the compilation
  100. buffer is not visible in its window."
  101. :type 'boolean
  102. :group 'compilation)
  103. (defvar compilation-parsing-end nil
  104. "Position of end of buffer when last error messages were parsed.")
  105. (defvar compilation-error-message "No more errors"
  106. "Message to print when no more matches are found.")
  107. (defvar compilation-num-errors-found)
  108. (defun compilation-build-compilation-error-regexp-alist ()
  109. "Set the regular expressions used for parsing compiler
  110. errors based on the compilers listed in the variable
  111. `compilation-error-regexp-systems-list'. Updates the
  112. variable `compilation-error-regexp-alist'."
  113. (interactive)
  114. (setq compilation-error-regexp-alist
  115. (apply 'append
  116. (mapcar
  117. '(lambda (elt)
  118. (if (or (not (consp compilation-error-regexp-systems-list))
  119. (and (consp (car elt))
  120. (intersection (car elt)
  121. compilation-error-regexp-systems-list))
  122. (memq (car elt) compilation-error-regexp-systems-list))
  123. (cdr elt)
  124. nil))
  125. compilation-error-regexp-alist-alist))))
  126. ;;;###autoload
  127. (defvar compilation-error-regexp-alist-alist
  128. '(
  129. ;; NOTE! See also grep-regexp-alist, below.
  130. ;; 4.3BSD grep, cc, lint pass 1:
  131. ;; /usr/src/foo/foo.c(8): warning: w may be used before set
  132. ;; or GNU utilities:
  133. ;; foo.c:8: error message
  134. ;; or HP-UX 7.0 fc:
  135. ;; foo.f :16 some horrible error message
  136. ;; or GNU utilities with column (GNAT 1.82):
  137. ;; foo.adb:2:1: Unit name does not match file name
  138. ;;
  139. ;; We'll insist that the number be followed by a colon or closing
  140. ;; paren, because otherwise this matches just about anything
  141. ;; containing a number with spaces around it.
  142. ((4bsd gnu)
  143. ("\
  144. \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
  145. :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 2 5)
  146. )
  147. ;; Microsoft C/C++:
  148. ;; keyboard.c(537) : warning C4005: 'min' : macro redefinition
  149. ;; d:\tmp\test.c(23) : error C2143: syntax error : missing ';' before 'if'
  150. (msft
  151. ("\\(\\([a-zA-Z]:\\)?[^:( \t\n-]+\\)[:(][ \t]*\\([0-9]+\\)[:) \t]" 1 3)
  152. )
  153. ;; Borland C++, C++Builder:
  154. ;; Error ping.c 15: Unable to open include file 'sys/types.h'
  155. ;; Warning ping.c 68: Call to function 'func' with no prototype
  156. ;; Or with Borland C++ Builder 6.0:
  157. ;; Error E2209 ping.c 15: Unable to open include file 'sys/types.h'
  158. ;; Warning W8065 ping.c 68: Call to function 'func' with no prototype
  159. (borland
  160. ("\\(Error\\|Warning\\) \\([EW][0-9]+ \\)?\\([a-zA-Z]?:?[^:( \t\n]+\\)\
  161. \\([0-9]+\\)\\([) \t]\\|:[^0-9\n]\\)" 3 4)
  162. )
  163. ;; 4.3BSD lint pass 2
  164. ;; strcmp: variable # of args. llib-lc(359) :: /usr/src/foo/foo.c(8)
  165. (4bsd
  166. (".*[ \t:]\\([a-zA-Z]?:?[^:( \t\n]+\\)[:(](+[ \t]*\\([0-9]+\\))[:) \t]*$"
  167. 1 2)
  168. )
  169. ;; 4.3BSD lint pass 3
  170. ;; bloofle defined( /users/wolfgang/foo.c(4) ), but never used
  171. ;; This used to be
  172. ;; ("[ \t(]+\\([a-zA-Z]?:?[^:( \t\n]+\\)[:( \t]+\\([0-9]+\\)[:) \t]+" 1 2)
  173. ;; which is regexp Impressionism - it matches almost anything!
  174. (4bsd
  175. (".*([ \t]*\\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\))" 1 2)
  176. )
  177. ;; MIPS lint pass<n>; looks good for SunPro lint also
  178. ;; TrimMask (255) in solomon.c may be indistinguishable from TrimMasks (93) in solomon.c due to truncation
  179. (mips
  180. ("[^\n ]+ (\\([0-9]+\\)) in \\([^ \n]+\\)" 2 1)
  181. ;; name defined but never used: LinInt in cmap_calc.c(199)
  182. (".*in \\([^(\n]+\\)(\\([0-9]+\\))$" 1 2)
  183. )
  184. ;; Ultrix 3.0 f77:
  185. ;; fort: Severe: addstf.f, line 82: Missing operator or delimiter symbol
  186. ;; Some SGI cc version:
  187. ;; cfe: Warning 835: foo.c, line 2: something
  188. ((sgi ultrix)
  189. ("\\(cfe\\|fort\\): [^:\n]*: \\([^ \n]*\\), line \\([0-9]+\\):" 2 3)
  190. )
  191. ;; SGI Mipspro 7.3 compilers
  192. ;; cc-1020 CC: ERROR File = CUI_App.h, Line = 735
  193. (sgimipspro
  194. ("^cc-[0-9]* \\(cc\\|CC\\|f77\\): \\(REMARK\\|WARNING\\|ERROR\\) File = \\(.*\\), Line = \\([0-9]*\\)" 3 4 ))
  195. ;; Error on line 3 of t.f: Execution error unclassifiable statement
  196. ;; Unknown who does this:
  197. ;; Line 45 of "foo.c": bloofle undefined
  198. ;; Absoft FORTRAN 77 Compiler 3.1.3
  199. ;; error on line 19 of fplot.f: spelling error?
  200. ;; warning on line 17 of fplot.f: data type is undefined for variable d
  201. (of
  202. ("\\(.* on \\)?[Ll]ine[ \t]+\\([0-9]+\\)[ \t]+\
  203. of[ \t]+\"?\\([a-zA-Z]?:?[^\":\n]+\\)\"?:" 3 2)
  204. )
  205. ;; Apollo cc, 4.3BSD fc:
  206. ;; "foo.f", line 3: Error: syntax error near end of statement
  207. ;; IBM RS6000:
  208. ;; "vvouch.c", line 19.5: 1506-046 (S) Syntax error.
  209. ;; Unknown compiler:
  210. ;; File "foobar.ml", lines 5-8, characters 20-155: blah blah
  211. ;; Microtec mcc68k:
  212. ;; "foo.c", line 32 pos 1; (E) syntax error; unexpected symbol: "lossage"
  213. ;; GNAT (as of July 94):
  214. ;; "foo.adb", line 2(11): warning: file name does not match ...
  215. ;; IBM AIX xlc compiler:
  216. ;; "src/swapping.c", line 30.34: 1506-342 (W) "/*" detected in comment.
  217. (comma
  218. (".*\"\\([^,\" \n\t]+\\)\", lines? \
  219. \\([0-9]+\\)\\([\(.]\\([0-9]+\\)\)?\\)?[:., (-]" 1 2 4)
  220. )
  221. ;; Python:
  222. ;; File "foobar.py", line 5, blah blah
  223. (python
  224. ("^File \"\\([^,\" \n\t]+\\)\", line \\([0-9]+\\)," 1 2)
  225. )
  226. ;; Caml compiler:
  227. ;; File "foobar.ml", lines 5-8, characters 20-155: blah blah
  228. (caml
  229. ("^File \"\\([^,\" \n\t]+\\)\", lines? \\([0-9]+\\)[-0-9]*, characters? \\([0-9]+\\)" 1 2 3)
  230. )
  231. ;; MIPS RISC CC - the one distributed with Ultrix:
  232. ;; ccom: Error: foo.c, line 2: syntax error
  233. ;; DEC AXP OSF/1 cc
  234. ;; /usr/lib/cmplrs/cc/cfe: Error: foo.c: 1: blah blah
  235. ((mips ultrix)
  236. ("[a-z0-9/]+: \\([eE]rror\\|[wW]arning\\): \\([^,\" \n\t]+\\)[,:] \\(line \\)?\\([0-9]+\\):" 2 4)
  237. )
  238. ;; IBM AIX PS/2 C version 1.1:
  239. ;; ****** Error number 140 in line 8 of file errors.c ******
  240. (aix
  241. (".*in line \\([0-9]+\\) of file \\([^ \n]+[^. \n]\\)\\.? " 2 1)
  242. )
  243. ;; IBM AIX lint is too painful to do right this way. File name
  244. ;; prefixes entire sections rather than being on each line.
  245. ;; Lucid Compiler, lcc 3.x
  246. ;; E, file.cc(35,52) Illegal operation on pointers
  247. (lcc
  248. ("[EW], \\([^(\n]*\\)(\\([0-9]+\\),[ \t]*\\([0-9]+\\)" 1 2 3)
  249. )
  250. ;; GNU messages with program name and optional column number.
  251. (gnu
  252. ("[a-zA-Z]?:?[^0-9 \n\t:]+:[ \t]*\\([^ \n\t:]+\\):\
  253. \\([0-9]+\\):\\(\\([0-9]+\\)[: \t]\\)?" 1 2 4)
  254. )
  255. ;; GNU messages with program name and optional column number
  256. ;; and a severity letter after that. nsgmls makes them.
  257. (gnu
  258. ("[^0-9 \n\t:]+:[ \t]*\\([^ \n\t:]+\\):\
  259. \\([0-9]+\\):\\(\\([0-9]+\\):\\)?[A-Za-z]:" 1 2 4)
  260. )
  261. ;; jwz:
  262. ;; IRIX 5.2
  263. ;; cfe: Warning 712: foo.c, line 2: illegal combination of pointer and ...
  264. (sgi
  265. ("[^\n]* \\([^ \n,\"]+\\), line \\([0-9]+\\):" 1 2)
  266. )
  267. ;; IRIX 5.2
  268. ;; cfe: Warning 600: xfe.c: 170: Not in a conditional directive while ...
  269. (sgi
  270. ("[^\n]*: \\([^ \n,\"]+\\): \\([0-9]+\\):" 1 2)
  271. )
  272. ;; Cray C compiler error messages
  273. (cray
  274. ("\\(cc\\| cft\\)-[0-9]+ c\\(c\\|f77\\): ERROR \\([^,\n]+, \\)* File = \\([^,\n]+\\), Line = \\([0-9]+\\)" 4 5)
  275. )
  276. ;; IBM C/C++ Tools 2.01:
  277. ;; foo.c(2:0) : informational EDC0804: Function foo is not referenced.
  278. ;; foo.c(3:8) : warning EDC0833: Implicit return statement encountered.
  279. ;; foo.c(5:5) : error EDC0350: Syntax error.
  280. (ibm
  281. ("\\([^( \n\t]+\\)(\\([0-9]+\\):\\([0-9]+\\)) : " 1 2 3)
  282. )
  283. ;; IAR Systems C Compiler:
  284. ;; "foo.c",3 Error[32]: Error message
  285. ;; "foo.c",3 Warning[32]: Error message
  286. (iar
  287. ("\"\\(.*\\)\",\\([0-9]+\\)\\s-+\\(Error\\|Warning\\)\\[[0-9]+\\]:" 1 2)
  288. )
  289. ;; Sun ada (VADS, Solaris):
  290. ;; /home3/xdhar/rcds_rc/main.a, line 361, char 6:syntax error: "," inserted
  291. (ada
  292. ("\\([^, \n\t]+\\), line \\([0-9]+\\), char \\([0-9]+\\)[:., \(-]" 1 2 3)
  293. )
  294. ;; Perl -w:
  295. ;; syntax error at automake line 922, near "':'"
  296. ;; Perl debugging traces
  297. ;; store::odrecall('File_A', 'x2') called at store.pm line 90
  298. (perl
  299. (".* at \\([^ \n]+\\) line \\([0-9]+\\)[,.\n]" 1 2)
  300. )
  301. ;; Oracle pro*c:
  302. ;; Semantic error at line 528, column 5, file erosacqdb.pc:
  303. (oracle
  304. ("Semantic error at line \\([0-9]+\\), column \\([0-9]+\\), file \\(.*\\):"
  305. 3 1 2)
  306. )
  307. ;; EPC F90 compiler:
  308. ;; Error 24 at (2:progran.f90) : syntax error
  309. (epc
  310. ("Error [0-9]+ at (\\([0-9]*\\):\\([^)\n]+\\))" 2 1)
  311. )
  312. ;; SGI IRIX MipsPro 7.3 compilers:
  313. ;; cc-1070 cc: ERROR File = linkl.c, Line = 38
  314. (sgimipspro
  315. (".*: ERROR File = \\(.+\\), Line = \\([0-9]+\\)" 1 2)
  316. (".*: WARNING File = \\(.+\\), Line = \\([0-9]+\\)" 1 2)
  317. )
  318. ;; Sun F90 error messages:
  319. ;; cf90-113 f90comp: ERROR NSE, File = Hoved.f90, Line = 16, Column = 3
  320. (sun
  321. (".* ERROR [a-zA-Z0-9 ]+, File = \\(.+\\), Line = \\([0-9]+\\), Column = \\([0-9]+\\)"
  322. 1 2 3)
  323. )
  324. ;; Xerces-J jaxp.SourceValidator output
  325. (xerces-j
  326. ;; Each elt has the form (REGEXP FILE-IDX LINE-IDX [COLUMN-IDX FILE-FORMAT...])
  327. ;; [Error] Sample.xml:3:39: s4s-elt-character: ...
  328. ("\\[Error\\] \\([^:]+\\):\\([0-9]+\\):\\([0-9]+\\)" 1 2 3))
  329. ;; RXP - GPL XML validator at http://www.cogsci.ed.ac.uk/~richard/rxp.html:
  330. ;; Error: Mismatched end tag: expected </geroup>, got </group>
  331. ;; in unnamed entity at line 71 char 8 of file:///home/reto/test/group.xml
  332. (rxp
  333. ("Error:.*\n.* line \\([0-9]+\\) char \\([0-9]+\\) of file://\\(.+\\)"
  334. 3 1 2)
  335. )
  336. ;; Warning: Start tag for undeclared element geroup
  337. ;; in unnamed entity at line 4 char 8 of file:///home/reto/test/group.xml
  338. (rxp
  339. ("Warning:.*\n.* line \\([0-9]+\\) char \\([0-9]+\\) of file://\\(.+\\)"
  340. 3 1 2)
  341. )
  342. ;; See http://ant.apache.org/faq.html
  343. ;; Ant Java: works for jikes
  344. (ant
  345. ("^\\s-*\\[[^]]*\\]\\s-*\\(.+\\):\\([0-9]+\\):\\([0-9]+\\):[0-9]+:[0-9]+:" 1 2 3)
  346. )
  347. ;; Ant Java: works for javac
  348. (ant
  349. ("^\\s-*\\[[^]]*\\]\\s-*\\(.+\\):\\([0-9]+\\):" 1 2)
  350. )
  351. ;; Ant / cygwin:
  352. ;; file:G:/foobar/dev/build-myproj.xml:54: Compiler Adapter 'javac' can't be found.
  353. (ant
  354. ("file:\\(\\([a-zA-Z]:\\)?[^:(\t\n]+\\):[ \t]*\\([0-9]+\\)[: \t]" 1 3)
  355. )
  356. )
  357. "Alist of (system regexp-alist) for building
  358. `compilation-error-regexp-alist'. SYSTEM is either a system identifier,
  359. or a list of system identifiers. See the variable
  360. `compilation-error-regexp-systems-list'")
  361. (defvar compilation-error-regexp-alist nil
  362. "Alist that specifies how to match errors in compiler output.
  363. Each elt has the form (REGEXP FILE-IDX LINE-IDX [COLUMN-IDX FILE-FORMAT...])
  364. If REGEXP matches constrained to the beginning of the line, the
  365. FILE-IDX'th subexpression gives the file name, and the LINE-IDX'th
  366. subexpression gives the line number. If COLUMN-IDX is given, the
  367. COLUMN-IDX'th subexpression gives the column number on that line. If
  368. any FILE-FORMAT is given, each is a format string to produce a file name
  369. to try; %s in the string is replaced by the text matching the
  370. FILE-IDX'th subexpression. Note previously REGEXP was not constrained
  371. to the beginning of the line, so old patterns without leading `^' or `\\n'
  372. may now require a leading `.*'.
  373. Note that this now gets set by the function
  374. `compilation-build-compilation-error-regexp-alist' using the
  375. value of the variable `compilation-error-regexp-alist-alist'")
  376. (defcustom compilation-error-regexp-systems-list 'all
  377. "*This is either the symbol `all', or a list of systems for which
  378. compilation error regexps should be included in
  379. `compilation-error-regexp-alist'. You must run the function
  380. `compilation-build-compilation-error-regexp-alist' after changing
  381. the value of this variable for the change to take effect.
  382. The list of known systems is:
  383. 4bsd: Using 4bsd
  384. ada: Ada compilers
  385. aix: the operating system
  386. ant: Ant Java
  387. borland: Using Borland
  388. caml: Using caml compiler
  389. comma: Using tool that says \"foo.c\", line 12
  390. cray: Using Cray
  391. epc: Using EPC F90 compiler
  392. gnu: but of course
  393. iar: Using IAR systems compiler
  394. ibm: IBM C compilers
  395. lcc: Lucid compilers
  396. mips: Using Mips
  397. msft: Using microsoft
  398. of: Using tool that says line xx of foo.c
  399. oracle: Using Oracle pro*c
  400. perl: perl -w
  401. python: Using python
  402. xerces-j: Xerces-J jaxp.SourceValidator
  403. rxp: Using RXP GPL XML validator
  404. sgi: Using SGI
  405. sgimipspro: Using SGI Mipspro 7.3
  406. sun: Using Sun F90 compiler
  407. ultrix: Using DEC unixoid operating system
  408. See also the variable `compilation-error-regexp-alist-alist'."
  409. :type '(choice (const all)
  410. (set :menu-tag "Pick"
  411. (const 4bsd)
  412. (const ada)
  413. (const aix)
  414. (const ant)
  415. (const borland)
  416. (const caml)
  417. (const comma)
  418. (const cray)
  419. (const epc)
  420. (const gnu)
  421. (const iar)
  422. (const ibm)
  423. (const lcc)
  424. (const mips)
  425. (const msft)
  426. (const of)
  427. (const oracle)
  428. (const perl)
  429. (const python)
  430. (const xerces-j)
  431. (const rxp)
  432. (const sgi)
  433. (const sgimipspro)
  434. (const sun)
  435. (const ultrix)
  436. ))
  437. :set (lambda (symbol value)
  438. (set-default symbol value)
  439. (compilation-build-compilation-error-regexp-alist))
  440. :group 'compilation)
  441. (compilation-build-compilation-error-regexp-alist)
  442. (defcustom compilation-error-screen-columns t
  443. "*If non-nil, column numbers in error messages are screen columns.
  444. Otherwise they are interpreted as character positions, with
  445. each character occupying one column.
  446. The default is to use screen columns, which requires that the compilation
  447. program and Emacs agree about the display width of the characters,
  448. especially the TAB character."
  449. :type 'boolean
  450. :group 'compilation
  451. :version "20.4")
  452. (defcustom compilation-read-command t
  453. "*Non-nil means \\[compile] reads the compilation command to use.
  454. Otherwise, \\[compile] just uses the value of `compile-command'."
  455. :type 'boolean
  456. :group 'compilation)
  457. (defcustom compilation-ask-about-save t
  458. "*Non-nil means \\[compile] asks which buffers to save before compiling.
  459. Otherwise, it saves all modified buffers without asking."
  460. :type 'boolean
  461. :group 'compilation)
  462. (defcustom compilation-ask-about-kill t
  463. "*If not nil, M-x compile asks to kill a running compilation.
  464. Otherwise, it kills it without asking."
  465. :type 'boolean
  466. :group 'compilation)
  467. ;; Note: the character class after the optional drive letter does not
  468. ;; include a space to support file names with blanks.
  469. (defvar grep-regexp-alist
  470. '(("^\\([a-zA-Z]?:?[^:(\t\n]+\\)[:( \t]+\\([0-9]+\\)[:) \t]" 1 2))
  471. "Regexp used to match grep hits. See `compilation-error-regexp-alist'.")
  472. (defcustom grep-command "grep -n "
  473. "*Last grep command used in \\[grep]; default for next grep."
  474. :type 'string
  475. :group 'compilation)
  476. ;; The system null device.
  477. ;; #### Backward compatibility hack; recent (21.4.x and 21.5.x) XEmacsen
  478. ;; have `null-device', but 21.1 may not.
  479. (defvar grep-null-device
  480. (if (boundp 'null-device) null-device "/dev/null")
  481. "The system null device.")
  482. (defvar grep-find-use-xargs
  483. ;; XEmacs change: test xargs compatibility too, revert to non-print0 xargs
  484. ;; if any xargs is available.
  485. (if (condition-case nil
  486. (and
  487. (equal
  488. (call-process "find" nil nil nil grep-null-device "-print0") 0)
  489. (equal (call-process "xargs" nil nil nil "-0" "-e") 0))
  490. (error nil))
  491. 'gnu
  492. (condition-case nil (equal (call-process "xargs") 0) (error nil)))
  493. "Whether \\[grep-find] uses the `xargs' utility by default.
  494. If nil, it uses `find -exec'; if `gnu', it uses `find -print0' and `xargs -0';
  495. if not nil and not `gnu', it uses `find -print' and `xargs'.
  496. This variable's value takes effect when `compile.el' is loaded
  497. by influencing the default value for the variable `grep-find-command'.")
  498. (defvar grep-find-command
  499. (cond ((eq grep-find-use-xargs 'gnu)
  500. (format "find . -type f -print0 | xargs -0 -e %s" grep-command))
  501. (grep-find-use-xargs
  502. (format "find . -type f -print | xargs %s" grep-command))
  503. (t (cons (format "find . -type f -exec %s {} /dev/null \\;"
  504. grep-command)
  505. (+ 22 (length grep-command)))))
  506. "The default find command for \\[grep-find].")
  507. ;; XEmacs addition: all grep-all-files stuff
  508. (defvar grep-all-files-history nil)
  509. (defcustom grep-all-files-omitted-expressions
  510. '("*~" "#*" ".#*" ",*" "*.elc" "*.obj" "*.o" "*.exe" "*.dll" "*.lib" "*.a"
  511. "*.dvi" "*.class" "*.bin" "*.orig" "*.rej")
  512. "List of expressions matching files to be omitted in `grep-all-files-...'.
  513. Each entry should be a simple name or a shell wildcard expression."
  514. :type '(repeat string)
  515. :group 'compilation)
  516. (defcustom grep-all-files-omitted-directories '("CVS" "RCS" "SCCS")
  517. "List of directories not to recurse into in `grep-all-files-...'.
  518. Each entry should be a simple name or a shell wildcard expression."
  519. :type '(repeat string)
  520. :group 'compilation)
  521. ;;;###autoload
  522. (defcustom compilation-search-path '(nil)
  523. "*List of directories to search for source files named in error messages.
  524. Elements should be directory names, not file names of directories.
  525. nil as an element means to try the default directory."
  526. :type '(repeat (choice (const :tag "Default" nil)
  527. directory))
  528. :group 'compilation)
  529. (defcustom compile-command "make -k "
  530. "*Last shell command used to do a compilation; default for next compilation.
  531. Sometimes it is useful for files to supply local values for this variable.
  532. You might also use mode hooks to specify it in certain modes, like this:
  533. (add-hook 'c-mode-common-hook
  534. (lambda ()
  535. (or (file-exists-p \"makefile\") (file-exists-p \"Makefile\")
  536. (set (make-local-variable 'compile-command)
  537. (concat \"make -k \" buffer-file-name)))))"
  538. :type 'string
  539. :group 'compilation)
  540. (defvar compilation-enter-directory-regexp
  541. "[^\n]*: Entering directory `\\([^\n]*\\)'$"
  542. "Regular expression matching lines that indicate a new current directory.
  543. This must contain one \\(, \\) pair around the directory name.
  544. The default value matches lines printed by the `-w' option of GNU Make.")
  545. (defvar compilation-leave-directory-regexp
  546. "[^\n]*: Leaving directory `\\([^\n]*\\)'$"
  547. "Regular expression matching lines that indicate restoring current directory.
  548. This may contain one \\(, \\) pair around the name of the directory
  549. being moved from. If it does not, the last directory entered \(by a
  550. line matching `compilation-enter-directory-regexp'\) is assumed.
  551. The default value matches lines printed by the `-w' option of GNU Make.")
  552. (defvar compilation-directory-stack nil
  553. "Stack of previous directories for `compilation-leave-directory-regexp'.
  554. The head element is the directory the compilation was started in.")
  555. (defvar compilation-exit-message-function nil "\
  556. If non-nil, called when a compilation process dies to return a status message.
  557. This should be a function of three arguments: process status, exit status,
  558. and exit message; it returns a cons (MESSAGE . MODELINE) of the strings to
  559. write into the compilation buffer, and to put in its mode line.")
  560. ;; History of compile commands.
  561. (defvar compile-history nil)
  562. ;; History of grep commands.
  563. (defvar grep-history nil)
  564. (defvar grep-find-history nil)
  565. ;; XEmacs
  566. (defvar compilation-font-lock-keywords (purecopy
  567. (list
  568. '("^[-_.\"A-Za-z0-9/+]+\\(:\\|, line \\)[0-9]+: \\([wW]arning:\\).*$" .
  569. font-lock-keyword-face)
  570. '("^[-_.\"A-Za-z0-9/+]+\\(: *\\|, line \\)[0-9]+:.*$" . font-lock-function-name-face)
  571. '("^[^:\n]+-[a-zA-Z][^:\n]+$" . font-lock-doc-string-face)
  572. '("\\(^[-_.\"A-Za-z0-9/+]+\\)\\(: *\\|, line \\)[0-9]+" 1 font-lock-string-face t)
  573. '("^[-_.\"A-Za-z0-9/+]+\\(: *[0-9]+\\|, line [0-9]+\\)" 1 bold t)
  574. ))
  575. "Additional expressions to highlight in Compilation mode.")
  576. ;FSF's version. Ours looks better.
  577. ;(defvar compilation-mode-font-lock-keywords
  578. ; ;; This regexp needs a bit of rewriting. What is the third grouping for?
  579. ; '(("^\\([a-zA-Z]?:?[^ \n:]*:\\([0-9]+:\\)+\\)\\(.*\\)$"
  580. ; 1 font-lock-function-name-face))
  581. ;;; ("^\\([^\n:]*:\\([0-9]+:\\)+\\)\\(.*\\)$" 0 font-lock-keyword-face keep)
  582. ;; XEmacs change
  583. (put 'compilation-mode 'font-lock-defaults
  584. '(compilation-font-lock-keywords t))
  585. (defcustom compilation-mouse-motion-initiate-parsing nil
  586. "*Should mouse motion over the compilation buffer initiate parsing?
  587. When set to a non-nil value, mouse motion over the compilation/grep
  588. buffer may initiate parsing of the error messages or grep hits.
  589. When this is nil, errors and grep matches will no longer be
  590. highlighted until they have been parsed, but may still be selected
  591. with the center mouse button. This will then initiate parsing
  592. and jump to the corresponding source line."
  593. :type 'boolean
  594. :group 'compilation)
  595. ;;;###autoload
  596. (defun compile (command)
  597. "Compile the program including the current buffer. Default: run `make'.
  598. Runs COMMAND, a shell command, in a separate process asynchronously
  599. with output going to the buffer `*compilation*'.
  600. You can then use the command \\[next-error] to find the next error message
  601. and move to the source code that caused it.
  602. Interactively, prompts for the command if `compilation-read-command' is
  603. non-nil; otherwise uses `compile-command'. With prefix arg, always prompts.
  604. To run more than one compilation at once, start one and rename the
  605. \`*compilation*' buffer to some other name with \\[rename-buffer].
  606. Then start the next one.
  607. The name used for the buffer is actually whatever is returned by
  608. the function in `compilation-buffer-name-function', so you can set that
  609. to a function that generates a unique name."
  610. (interactive
  611. (if (or compilation-read-command current-prefix-arg)
  612. ;; XEmacs change
  613. (list (read-shell-command "Compile command: "
  614. compile-command
  615. ;; #### minibuffer code should do this
  616. (if (equal (car compile-history)
  617. compile-command)
  618. '(compile-history . 1)
  619. 'compile-history)))
  620. (list compile-command)))
  621. (setq compile-command command)
  622. (save-some-buffers (not compilation-ask-about-save) nil)
  623. (compile-internal compile-command "No more errors"))
  624. ;; run compile with the default command line
  625. (defun recompile ()
  626. "Re-compile the program including the current buffer."
  627. (interactive)
  628. (save-some-buffers (not compilation-ask-about-save) nil)
  629. (compile-internal compile-command "No more errors"))
  630. ;;;###autoload
  631. (defun grep (command-args)
  632. "Run grep, with user-specified args, and collect output in a buffer.
  633. While grep runs asynchronously, you can use the \\[next-error] command
  634. to find the text that grep hits refer to.
  635. This command uses a special history list for its arguments, so you can
  636. easily repeat a grep command."
  637. (interactive
  638. ;; XEmacs change
  639. (list (read-shell-command "Run grep (like this): "
  640. grep-command 'grep-history)))
  641. (let ((buf (compile-internal (concat command-args " " grep-null-device)
  642. "No more grep hits" "grep"
  643. ;; Give it a simpler regexp to match.
  644. nil grep-regexp-alist)))
  645. (save-excursion
  646. (set-buffer buf)
  647. (set (make-local-variable 'compilation-exit-message-function)
  648. ;; XEmacs change
  649. (lambda (proc msg)
  650. (let ((code (process-exit-status proc)))
  651. (if (eq (process-status proc) 'exit)
  652. (cond ((zerop code)
  653. (cons (format "finished (%d matches found)\n"
  654. ;; stolen from count-matches,
  655. ;; should be refactored by
  656. ;; count-matches returning
  657. ;; count.
  658. (let ((count 0) opoint)
  659. (save-excursion
  660. (goto-char (point-min))
  661. (while (and (not (eobp))
  662. (progn (setq opoint (point))
  663. (re-search-forward (caar grep-regexp-alist) nil t)))
  664. (if (= opoint (point))
  665. (forward-char 1)
  666. (setq count (1+ count))))
  667. count)))
  668. "matched"))
  669. ((= code 1)
  670. '("finished with no matches found\n" . "no match"))
  671. (t
  672. (cons msg code)))
  673. (cons msg code))))))))
  674. ;;;###autoload
  675. (defun grep-find (command-args)
  676. "Run grep via find, with user-specified args COMMAND-ARGS.
  677. Collect output in a buffer.
  678. While find runs asynchronously, you can use the \\[next-error] command
  679. to find the text that grep hits refer to.
  680. This command uses a special history list for its arguments, so you can
  681. easily repeat a find command."
  682. (interactive
  683. ;; XEmacs change..
  684. (list (read-shell-command "Run find (like this): "
  685. grep-find-command 'grep-find-history)))
  686. (let ((grep-null-device nil)) ; see grep
  687. (grep command-args)))
  688. ;; XEmacs addition
  689. (defalias 'find-grep 'grep-find)
  690. ;; XEmacs addition: all grep-all-files stuff
  691. (defun construct-grep-all-files-command (find-segment grep-segment)
  692. (let ((omit-annoying
  693. (mapconcat #'(lambda (wildcard)
  694. (concat "-name '" wildcard "' -or "))
  695. grep-all-files-omitted-expressions
  696. "")))
  697. (cond ((eq grep-find-use-xargs 'gnu)
  698. (format "find . %s %s -type f -print0 | xargs -0 -e %s"
  699. find-segment omit-annoying grep-segment))
  700. (grep-find-use-xargs
  701. (format "find . %s %s -type f -print | xargs %s"
  702. find-segment omit-annoying grep-segment))
  703. (t
  704. (format "find . %s %s -type f -exec %s {} /dev/null \\;"
  705. find-segment omit-annoying grep-segment)))))
  706. ;;;###autoload
  707. (defun grep-all-files-in-current-directory (command)
  708. "Run `grep' in all non-annoying files in the current directory.
  709. `Non-annoying' excludes backup files, autosave files, CVS merge files, etc.
  710. More specifically, this is controlled by `grep-all-files-omitted-expressions'.
  711. This function does not recurse into subdirectories. If you want this,
  712. use \\[grep-all-files-in-current-directory-and-below]."
  713. (interactive
  714. (progn
  715. (list (read-shell-command "Run grep (like this): "
  716. grep-command 'grep-all-files-history))))
  717. (grep (construct-grep-all-files-command
  718. "-name . -or -type d -prune -or" command)))
  719. ;;;###autoload
  720. (defun grep-all-files-in-current-directory-and-below (command)
  721. "Run `grep' in all non-annoying files in the current directory and below.
  722. `Non-annoying' excludes backup files, autosave files, CVS merge files, etc.
  723. More specifically, this is controlled by `grep-all-files-omitted-expressions'.
  724. This function recurses into subdirectories. If you do not want this,
  725. use \\[grep-all-files-in-current-directory]."
  726. (interactive
  727. (progn
  728. (list (read-shell-command "Run grep (like this): "
  729. grep-command 'grep-all-files-history))))
  730. (grep (construct-grep-all-files-command
  731. ;; prune all specified directories.
  732. (mapconcat #'(lambda (wildcard)
  733. (concat "-name '" wildcard "' -prune -or "))
  734. grep-all-files-omitted-directories
  735. "")
  736. command)))
  737. (defun compile-internal (command error-message
  738. &optional name-of-mode parser regexp-alist
  739. name-function)
  740. "Run compilation command COMMAND (low level interface).
  741. ERROR-MESSAGE is a string to print if the user asks to see another error
  742. and there are no more errors. Third argument NAME-OF-MODE is the name
  743. to display as the major mode in the compilation buffer.
  744. Fourth arg PARSER is the error parser function (nil means the default). Fifth
  745. arg REGEXP-ALIST is the error message regexp alist to use (nil means the
  746. default). Sixth arg NAME-FUNCTION is a function called to name the buffer (nil
  747. means the default). The defaults for these variables are the global values of
  748. \`compilation-parse-errors-function', `compilation-error-regexp-alist', and
  749. \`compilation-buffer-name-function', respectively.
  750. Returns the compilation buffer created."
  751. (let (outbuf)
  752. (save-excursion
  753. (or name-of-mode
  754. (setq name-of-mode "Compilation"))
  755. (setq outbuf
  756. (get-buffer-create
  757. (funcall (or name-function compilation-buffer-name-function
  758. (function (lambda (mode)
  759. (concat "*" (downcase mode) "*"))))
  760. name-of-mode)))
  761. (set-buffer outbuf)
  762. (let ((comp-proc (get-buffer-process (current-buffer))))
  763. (if comp-proc
  764. (if (or (not (eq (process-status comp-proc) 'run))
  765. (or
  766. (not compilation-ask-about-kill)
  767. (yes-or-no-p
  768. (format "A %s process is running; kill it? "
  769. name-of-mode))))
  770. (condition-case ()
  771. (progn
  772. (interrupt-process comp-proc)
  773. (sit-for 1)
  774. (delete-process comp-proc))
  775. (error nil))
  776. (error "Cannot have two processes in `%s' at once"
  777. (buffer-name))
  778. )))
  779. ;; In case the compilation buffer is current, make sure we get the global
  780. ;; values of compilation-error-regexp-alist, etc.
  781. (kill-all-local-variables))
  782. (let ((regexp-alist (or regexp-alist compilation-error-regexp-alist))
  783. (parser (or parser compilation-parse-errors-function))
  784. (thisdir default-directory)
  785. ;; XEmacs change
  786. (buffer-save (current-buffer))
  787. outwin)
  788. ;; XEmacs change
  789. ;; Pop up the compilation buffer.
  790. (setq outwin (display-buffer outbuf))
  791. (unwind-protect
  792. (progn
  793. ;; Clear out the compilation buffer and make it writable.
  794. ;; Change its default-directory to the directory where the compilation
  795. ;; will happen, and insert a `cd' command to indicate this.
  796. (set-buffer outbuf)
  797. (setq buffer-read-only nil)
  798. (buffer-disable-undo (current-buffer))
  799. (erase-buffer)
  800. (buffer-enable-undo (current-buffer))
  801. (setq default-directory thisdir)
  802. (insert "cd " thisdir "\n" command "\n")
  803. (set-buffer-modified-p nil)
  804. ;; XEmacs change
  805. ;; set it so the window will scroll to show compile output
  806. (save-window-excursion
  807. (select-window outwin)
  808. (goto-char (point-max)))
  809. (setq outwin (display-buffer outbuf))
  810. ;; XEmacs change
  811. (compilation-mode name-of-mode)
  812. ;; (setq buffer-read-only t) ;;; Non-ergonomic.
  813. ;; XEmacs change
  814. (set (make-local-variable 'compile-command) command)
  815. (set (make-local-variable 'compilation-parse-errors-function) parser)
  816. (set (make-local-variable 'compilation-error-message) error-message)
  817. (set (make-local-variable 'compilation-error-regexp-alist) regexp-alist)
  818. (setq default-directory thisdir
  819. compilation-directory-stack (list default-directory))
  820. (set-window-start outwin (point-min))
  821. (setq mode-name name-of-mode)
  822. ;; XEmacs change
  823. ; (or (eq outwin (selected-window))
  824. ; (set-window-point outwin (point-min)))
  825. (compilation-set-window-height outwin)
  826. ;; Start the compilation.
  827. (if (fboundp 'start-process)
  828. (let* ((process-environment (cons "EMACS=t" process-environment))
  829. (proc (start-process-shell-command (downcase mode-name)
  830. outbuf
  831. command)))
  832. (set-process-sentinel proc 'compilation-sentinel)
  833. (set-process-filter proc 'compilation-filter)
  834. ;; Causes problems; please investigate before using:
  835. ;(process-send-eof proc)
  836. (set-marker (process-mark proc) (point) outbuf)
  837. (setq compilation-in-progress
  838. (cons proc compilation-in-progress)))
  839. ;; No asynchronous processes available.
  840. (display-message
  841. 'progress
  842. (format "Executing `%s'..." command))
  843. ; FSF
  844. ; (setq mode-line-process ":run")
  845. ; (force-mode-line-update)
  846. (sit-for 0) ;; Force redisplay
  847. (let ((status (call-process shell-file-name nil outbuf nil
  848. shell-command-switch command))))
  849. (display-message
  850. 'progress
  851. (format "Executing `%s'...done" command))))
  852. (set-buffer buffer-save)))
  853. ;; Make it so the next C-x ` will use this buffer.
  854. (setq compilation-last-buffer outbuf)))
  855. ;; Set the height of WINDOW according to compilation-window-height.
  856. (defun compilation-set-window-height (window)
  857. (and compilation-window-height
  858. ;; Check if the window is split horizontally.
  859. ;; Emacs checks window width versus frame-width:
  860. ;; (= (window-width window) (frame-width (window-frame window)))
  861. ;; But XEmacs must take into account a possible left or right
  862. ;; toolbar:
  863. (and (window-leftmost-p (selected-window))
  864. (window-rightmost-p (selected-window)))
  865. ;; If window is alone in its frame, aside from a minibuffer,
  866. ;; don't change its height.
  867. (not (eq window (frame-root-window (window-frame window))))
  868. ;; This save-excursion prevents us from changing the current buffer,
  869. ;; which might not be the same as the selected window's buffer.
  870. (save-excursion
  871. (let ((w (selected-window)))
  872. (unwind-protect
  873. (progn
  874. (select-window window)
  875. (enlarge-window (- compilation-window-height
  876. (window-height))))
  877. (select-window w))))))
  878. ;;;###autoload
  879. (defvar compilation-minor-mode-map
  880. (let ((map (make-sparse-keymap)))
  881. (set-keymap-name map 'compilation-minor-mode-map)
  882. (define-key map "\C-c\C-c" 'compile-goto-error)
  883. (define-key map "\C-m" 'compile-goto-error)
  884. (define-key map "\C-c\C-k" 'kill-compilation)
  885. (define-key map "\M-n" 'compilation-next-error)
  886. (define-key map "\M-p" 'compilation-previous-error)
  887. (define-key map "\M-{" 'compilation-previous-file)
  888. (define-key map "\M-}" 'compilation-next-file)
  889. map)
  890. "Keymap for `compilation-minor-mode'.")
  891. ;;;###autoload
  892. (defvar compilation-shell-minor-mode-map
  893. (let ((map (make-sparse-keymap)))
  894. (define-key map "\M-\C-m" 'compile-goto-error)
  895. (define-key map "\M-\C-n" 'compilation-next-error)
  896. (define-key map "\M-\C-p" 'compilation-previous-error)
  897. (define-key map "\M-{" 'compilation-previous-file)
  898. (define-key map "\M-}" 'compilation-next-file)
  899. map)
  900. "Keymap for `compilation-shell-minor-mode'.")
  901. (defvar compilation-mode-map
  902. (let ((map (make-sparse-keymap)))
  903. (set-keymap-parents map (list compilation-minor-mode-map))
  904. (set-keymap-name map 'compilation-mode-map)
  905. (define-key map " " 'scroll-up)
  906. (define-key map "\^?" 'scroll-down)
  907. (define-key map 'button2 'compile-mouse-goto-error)
  908. map)
  909. "Keymap for compilation log buffers.
  910. `compilation-minor-mode-map' is a parent of this.")
  911. ;;; XEmacs menus
  912. (defun compilation-errors-exist-p (&optional buffer)
  913. "Whether we are in a state where the `next-error' command will work,
  914. that is, whether there exist (or may exist) error targets in the *compile*
  915. or *grep* buffers."
  916. (or buffer
  917. (setq buffer (condition-case nil
  918. (compilation-find-buffer)
  919. (error nil))))
  920. (and buffer
  921. (compilation-buffer-p buffer)
  922. (save-excursion
  923. (set-buffer buffer)
  924. ;; Has errors on the list, or needs to be parsed.
  925. ;; But don't parse it now!
  926. (or (not (null compilation-error-list))
  927. (< compilation-parsing-end (point-max))))))
  928. ;; XEmacs change
  929. (defvar compilation-shell-minor-mode-menubar-menu
  930. '("Errors"
  931. :filter compile-menu-filter
  932. ["Stop" comint-interrupt-subjob t]
  933. "---"
  934. ["First Error" first-error (compilation-errors-exist-p)]
  935. ["Previous Error" previous-error (compilation-errors-exist-p)]
  936. ["Next Error" next-error (compilation-errors-exist-p)]
  937. ))
  938. (defvar Compilation-mode-popup-menu
  939. '("Compilation Mode Commands"
  940. :filter compile-menu-filter
  941. ["Compile..." compile t]
  942. ["Recompile" recompile t]
  943. ["Kill Compilation" kill-compilation (get-buffer-process (current-buffer))]
  944. "---"
  945. ["Goto Error" compile-goto-error (compilation-errors-exist-p)]
  946. ["Next Error" next-error (compilation-errors-exist-p)]
  947. ["Previous Error" previous-error (compilation-errors-exist-p)]
  948. ["First Error" first-error (compilation-errors-exist-p)]
  949. ))
  950. (defvar Compilation-mode-menubar-menu
  951. (cons "Compile" (cdr Compilation-mode-popup-menu)))
  952. (defvar grep-mode-popup-menu
  953. '("Grep Mode Commands"
  954. :filter grep-menu-filter
  955. ["Grep..." grep t]
  956. ["Repeat Grep" recompile t]
  957. ["Kill Grep" kill-compilation (get-buffer-process (current-buffer))]
  958. "---"
  959. ["Goto Match" compile-goto-error (default-value 'compilation-error-list)]
  960. ["Next Match" next-error (default-value 'compilation-error-list)]
  961. ["Previous Match" previous-error (default-value 'compilation-error-list)]
  962. ["First Match" first-error (default-value 'compilation-error-list)]
  963. ))
  964. (defvar grep-mode-menubar-menu
  965. (cons "Grep" (cdr grep-mode-popup-menu)))
  966. (defun compile-menu-filter-1 (menu history-list item-name command-name)
  967. (let ((submenu (mapcar #'(lambda (string)
  968. (vector string
  969. (list command-name string)
  970. t))
  971. history-list))
  972. (existing (assoc item-name menu)))
  973. (if existing
  974. (progn
  975. (setcdr existing submenu)
  976. menu)
  977. (nconc menu (list (cons item-name submenu))))))
  978. (defun compile-menu-filter (menu)
  979. (compile-menu-filter-1 menu compile-history "Compile History" 'compile))
  980. (defun grep-menu-filter (menu)
  981. (compile-menu-filter-1 menu grep-history "Grep History" 'grep))
  982. ;;;###autoload
  983. (defun compilation-mode (&optional name-of-mode)
  984. "Major mode for compilation log buffers.
  985. \\<compilation-mode-map>To visit the source for a line-numbered error,
  986. move point to the error message line and type \\[compile-goto-error],
  987. or click on the line with \\[compile-mouse-goto-error].
  988. There is a menu of commands on \\[compile-popup-menu].
  989. To kill the compilation, type \\[kill-compilation].
  990. Runs `compilation-mode-hook' with `run-hooks' (which see)."
  991. (interactive)
  992. (kill-all-local-variables)
  993. (use-local-map compilation-mode-map)
  994. (setq major-mode 'compilation-mode
  995. mode-name "Compilation")
  996. (compilation-setup)
  997. (font-lock-set-defaults)
  998. (if (not name-of-mode) nil
  999. (let ((sym (intern (concat name-of-mode "-mode-popup-menu"))))
  1000. (if (boundp sym)
  1001. (setq mode-popup-menu (symbol-value sym))))
  1002. (if (featurep 'menubar)
  1003. (progn
  1004. ;; make a local copy of the menubar, so our modes don't
  1005. ;; change the global menubar
  1006. (set-buffer-menubar current-menubar)
  1007. (let ((sym (intern (concat name-of-mode "-mode-menubar-menu"))))
  1008. (if (boundp sym)
  1009. (add-submenu nil (symbol-value sym)))))))
  1010. (run-hooks 'compilation-mode-hook))
  1011. ;; XEmacs addition, hacked by Mly
  1012. (defun compilation-mode-motion-hook (event)
  1013. (mode-motion-highlight-internal
  1014. event
  1015. #'beginning-of-line
  1016. #'(lambda ()
  1017. (let* ((p (point))
  1018. (e (progn (end-of-line) (point)))
  1019. (l (progn
  1020. (if (and compilation-mouse-motion-initiate-parsing
  1021. (or (eq compilation-error-list 't)
  1022. (>= p compilation-parsing-end)))
  1023. ;; #### Does it suck too badly to have mouse-movement
  1024. ;; #### over a buffer parse errors in that buffer??
  1025. (save-window-excursion
  1026. (compile-reinitialize-errors nil p)))
  1027. (if (and compilation-error-list
  1028. (<= (car (car compilation-error-list)) p))
  1029. ;; Perhaps save time by only searching tail
  1030. compilation-error-list
  1031. compilation-old-error-list))))
  1032. (if (catch 'found
  1033. (while l
  1034. (let ((x (marker-position (car (car l)))))
  1035. (cond ((< x p)
  1036. (setq l (cdr l)))
  1037. ((<= x e)
  1038. (throw 'found t))
  1039. (t
  1040. (throw 'found nil)))))
  1041. nil)
  1042. (goto-char e)
  1043. (goto-char p))))))
  1044. (defun compilation-setup ()
  1045. "Prepare the buffer for the compilation parsing commands to work."
  1046. ;; Make the buffer's mode line show process state.
  1047. (setq mode-line-process '(":%s"))
  1048. (set (make-local-variable 'compilation-error-list) nil)
  1049. (set (make-local-variable 'compilation-old-error-list) nil)
  1050. (set (make-local-variable 'compilation-parsing-end) 1)
  1051. (set (make-local-variable 'compilation-directory-stack) nil)
  1052. (make-local-variable 'compilation-error-screen-columns)
  1053. (setq compilation-last-buffer (current-buffer))
  1054. ;; XEmacs change: highlight lines, install menubar.
  1055. (require 'mode-motion)
  1056. (setq mode-motion-hook 'compilation-mode-motion-hook)
  1057. (make-local-hook 'mouse-track-click-hook)
  1058. (add-hook 'mouse-track-click-hook 'compile-mouse-maybe-goto-error t t))
  1059. ;;;###autoload
  1060. (defvar compilation-shell-minor-mode nil
  1061. "Non-nil when in compilation-shell-minor-mode.
  1062. In this minor mode, all the error-parsing commands of the
  1063. Compilation major mode are available but bound to keys that don't
  1064. collide with Shell mode.")
  1065. (make-variable-buffer-local 'compilation-shell-minor-mode)
  1066. ;;;###autoload
  1067. (defvar compilation-minor-mode nil
  1068. "Non-nil when in compilation-minor-mode.
  1069. In this minor mode, all the error-parsing commands of the
  1070. Compilation major mode are available.")
  1071. (make-variable-buffer-local 'compilation-minor-mode)
  1072. ;;;###autoload
  1073. (defun compilation-shell-minor-mode (&optional arg)
  1074. "Toggle compilation shell minor mode.
  1075. With arg, turn compilation mode on if and only if arg is positive.
  1076. See `compilation-mode'.
  1077. Turning the mode on runs the normal hook `compilation-shell-minor-mode-hook'."
  1078. (interactive "P")
  1079. (if (setq compilation-shell-minor-mode (if (null arg)
  1080. (null compilation-shell-minor-mode)
  1081. (> (prefix-numeric-value arg) 0)))
  1082. (let ((mode-line-process))
  1083. (compilation-setup)
  1084. (run-hooks 'compilation-shell-minor-mode-hook)
  1085. (make-local-variable 'current-menubar)
  1086. (add-submenu nil
  1087. (cons compilation-shell-minor-mode-menubar-menu-name
  1088. (cdr compilation-shell-minor-mode-menubar-menu))))
  1089. (delete-menu-item (list compilation-shell-minor-mode-menubar-menu-name))))
  1090. ;;;###autoload
  1091. (add-minor-mode 'compilation-shell-minor-mode
  1092. " Shell-Compile"
  1093. compilation-shell-minor-mode-map
  1094. 'view-minor-mode
  1095. compilation-shell-minor-mode)
  1096. ;;;###autoload
  1097. (defun compilation-minor-mode (&optional arg)
  1098. "Toggle compilation minor mode.
  1099. With arg, turn compilation mode on if and only if arg is positive.
  1100. See `compilation-mode'.
  1101. ! \\{compilation-mode-map}"
  1102. (interactive "P")
  1103. (if (setq compilation-minor-mode (if (null arg)
  1104. (null compilation-minor-mode)
  1105. (> (prefix-numeric-value arg) 0)))
  1106. (progn
  1107. (compilation-setup)
  1108. (run-hooks 'compilation-minor-mode-hook))))
  1109. ;;;###autoload
  1110. (add-minor-mode 'compilation-minor-mode
  1111. " CMPL"
  1112. compilation-minor-mode-map
  1113. 'view-minor-mode
  1114. compilation-minor-mode)
  1115. (defun compilation-handle-exit (process-status exit-status msg)
  1116. "Write msg in the current buffer and hack its mode-line-process."
  1117. (let ((buffer-read-only nil)
  1118. (status (if compilation-exit-message-function
  1119. (funcall compilation-exit-message-function
  1120. process-status exit-status msg)
  1121. (cons msg exit-status)))
  1122. (omax (point-max))
  1123. (opoint (point)))
  1124. ;; Record where we put the message, so we can ignore it
  1125. ;; later on.
  1126. (goto-char omax)
  1127. (insert ?\n mode-name " " (car status))
  1128. (forward-char -1)
  1129. (insert " at " (substring (current-time-string) 0 19))
  1130. (forward-char 1)
  1131. (setq mode-line-process (format ":%s [%s]" process-status (cdr status)))
  1132. ;; Force mode line redisplay soon.
  1133. (force-mode-line-update)
  1134. (if (and opoint (< opoint omax))
  1135. (goto-char opoint))
  1136. (if compilation-finish-function
  1137. (funcall compilation-finish-function (current-buffer) msg))))
  1138. ;; Called when compilation process changes state.
  1139. (defun compilation-sentinel (proc msg)
  1140. "Sentinel for compilation buffers."
  1141. ;; XEmacs change
  1142. (let* ((buffer (process-buffer proc))
  1143. (window (get-buffer-window buffer)))
  1144. (if (memq (process-status proc) '(signal exit))
  1145. (progn
  1146. (if (null (buffer-name buffer))
  1147. ;; buffer killed
  1148. (set-process-buffer proc nil)
  1149. (let ((obuf (current-buffer))
  1150. omax opoint estatus)
  1151. ;; save-excursion isn't the right thing if
  1152. ;; process-buffer is current-buffer
  1153. (unwind-protect
  1154. (progn
  1155. ;; Write something in the compilation buffer
  1156. ;; and hack its mode line.
  1157. (set-buffer buffer)
  1158. (let ((buffer-read-only nil)
  1159. (status (if compilation-exit-message-function
  1160. (funcall compilation-exit-message-function
  1161. proc msg)
  1162. (cons msg (process-exit-status proc)))))
  1163. (setq omax (point-max)
  1164. opoint (point))
  1165. (goto-char omax)
  1166. ;; Record where we put the message, so we can ignore it
  1167. ;; later on.
  1168. (insert ?\n mode-name " " (car status))
  1169. (forward-char -1)
  1170. (insert " at " (substring (current-time-string) 0 19))
  1171. (forward-char 1)
  1172. (setq mode-line-process
  1173. (concat ":"
  1174. (symbol-name (process-status proc))
  1175. (if (zerop (process-exit-status proc))
  1176. " OK"
  1177. (setq estatus
  1178. (format " [exit-status %d]"
  1179. (process-exit-status proc))))
  1180. ))
  1181. ;; XEmacs - tedium should let you know when it's ended...
  1182. (if (and (not compilation-always-signal-completion)
  1183. window
  1184. (pos-visible-in-window-p (point-max) window))
  1185. nil ; assume that the user will see it...
  1186. (ding t 'ready)
  1187. (display-m…

Large files files are truncated, but you can click here to view the full file