PageRenderTime 76ms 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
  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-message
  1188. 'progress
  1189. (format "Compilation process completed%s."
  1190. (or estatus " successfully")
  1191. )))
  1192. ;; Since the buffer and mode line will show that the
  1193. ;; process is dead, we can delete it now. Otherwise it
  1194. ;; will stay around until M-x list-processes.
  1195. (delete-process proc)
  1196. ;; Force mode line redisplay soon.
  1197. (redraw-modeline))
  1198. (if (and opoint (< opoint omax))
  1199. (goto-char opoint))
  1200. (if compilation-finish-function
  1201. (funcall compilation-finish-function buffer msg)))
  1202. (set-buffer obuf))))
  1203. (setq compilation-in-progress (delq proc compilation-in-progress))
  1204. ))))
  1205. (defun compilation-filter (proc string)
  1206. "Process filter for compilation buffers.
  1207. Just inserts the text, but uses `insert-before-markers'."
  1208. (if (buffer-name (process-buffer proc))
  1209. (save-excursion
  1210. (set-buffer (process-buffer proc))
  1211. (let ((buffer-read-only nil))
  1212. (save-excursion
  1213. (goto-char (process-mark proc))
  1214. (insert-before-markers string)
  1215. (run-hooks 'compilation-filter-hook)
  1216. (set-marker (process-mark proc) (point)))))))
  1217. (defun compile-error-at-point ()
  1218. "Return the cdr of `compilation-old-error-list' for error containing point."
  1219. (compile-reinitialize-errors nil (point))
  1220. (let ((errors compilation-old-error-list))
  1221. (while (and errors
  1222. (> (point) (car (car errors))))
  1223. (setq errors (cdr errors)))
  1224. errors))
  1225. (defsubst compilation-buffer-p (buffer)
  1226. (save-excursion
  1227. (set-buffer buffer)
  1228. (or compilation-shell-minor-mode compilation-minor-mode
  1229. (eq major-mode 'compilation-mode))))
  1230. (defun compilation-next-error (n)
  1231. "Move point to the next error in the compilation buffer.
  1232. Prefix arg N says how many error messages to move forwards (or
  1233. backwards, if negative).
  1234. Does NOT find the source line like \\[next-error]."
  1235. (interactive "p")
  1236. (or (compilation-buffer-p (current-buffer))
  1237. (error "Not in a compilation buffer"))
  1238. (setq compilation-last-buffer (current-buffer))
  1239. (let ((errors (compile-error-at-point)))
  1240. ;; Move to the error after the one containing point.
  1241. (goto-char (car (if (< n 0)
  1242. (let ((i 0)
  1243. (e compilation-old-error-list))
  1244. ;; See how many cdrs away ERRORS is from the start.
  1245. (while (not (eq e errors))
  1246. (setq i (1+ i)
  1247. e (cdr e)))
  1248. (if (> (- n) i)
  1249. (error "Moved back past first error")
  1250. (nth (+ i n) compilation-old-error-list)))
  1251. (let ((compilation-error-list (cdr errors)))
  1252. (compile-reinitialize-errors nil nil n)
  1253. (if compilation-error-list
  1254. (nth (1- n) compilation-error-list)
  1255. (error "Moved past last error"))))))))
  1256. (defun compilation-previous-error (n)
  1257. "Move point to the previous error in the compilation buffer.
  1258. Prefix arg N says how many error messages to move backwards (or
  1259. forwards, if negative).
  1260. Does NOT find the source line like \\[next-error]."
  1261. (interactive "p")
  1262. (compilation-next-error (- n)))
  1263. ;; Given an elt of `compilation-error-list', return an object representing
  1264. ;; the referenced file which is equal to (but not necessarily eq to) what
  1265. ;; this function would return for another error in the same file.
  1266. (defsubst compilation-error-filedata (data)
  1267. (setq data (cdr data))
  1268. (if (markerp data)
  1269. (marker-buffer data)
  1270. (car data)))
  1271. ;; Return a string describing a value from compilation-error-filedata.
  1272. ;; This value is not necessarily useful as a file name, but should be
  1273. ;; indicative to the user of what file's errors are being referred to.
  1274. (defsubst compilation-error-filedata-file-name (filedata)
  1275. (if (bufferp filedata)
  1276. (buffer-file-name filedata)
  1277. (car filedata)))
  1278. (defun compilation-next-file (n)
  1279. "Move point to the next error for a different file than the current one."
  1280. (interactive "p")
  1281. (or (compilation-buffer-p (current-buffer))
  1282. (error "Not in a compilation buffer"))
  1283. (setq compilation-last-buffer (current-buffer))
  1284. (let ((reversed (< n 0))
  1285. errors filedata)
  1286. (if (not reversed)
  1287. (setq errors (or (compile-error-at-point)
  1288. (error "Moved past last error")))
  1289. ;; Get a reversed list of the errors up through the one containing point.
  1290. (compile-reinitialize-errors nil (point))
  1291. (setq errors (reverse compilation-old-error-list)
  1292. n (- n))
  1293. ;; Ignore errors after point. (car ERRORS) will be the error
  1294. ;; containing point, (cadr ERRORS) the one before it.
  1295. (while (and errors
  1296. (< (point) (car (car errors))))
  1297. (setq errors (cdr errors))))
  1298. (while (> n 0)
  1299. (setq filedata (compilation-error-filedata (car errors)))
  1300. ;; Skip past the following errors for this file.
  1301. (while (equal filedata
  1302. (compilation-error-filedata
  1303. (car (or errors
  1304. (if reversed
  1305. (error "%s the first erring file"
  1306. (compilation-error-filedata-file-name
  1307. filedata))
  1308. (let ((compilation-error-list nil))
  1309. ;; Parse some more.
  1310. (compile-reinitialize-errors nil nil 2)
  1311. (setq errors compilation-error-list)))
  1312. (error "%s is the last erring file"
  1313. (compilation-error-filedata-file-name
  1314. filedata))))))
  1315. (setq errors (cdr errors)))
  1316. (setq n (1- n)))
  1317. ;; Move to the following error.
  1318. (goto-char (car (car (or errors
  1319. (if reversed
  1320. (error "This is the first erring file")
  1321. (let ((compilation-error-list nil))
  1322. ;; Parse the last one.
  1323. (compile-reinitialize-errors nil nil 1)
  1324. compilation-error-list))))))))
  1325. (defun compilation-previous-file (n)
  1326. "Move point to the previous error for a different file than the current one."
  1327. (interactive "p")
  1328. (compilation-next-file (- n)))
  1329. (defun kill-compilation ()
  1330. "Kill the process made by the \\[compile] command."
  1331. (interactive)
  1332. (let ((buffer (compilation-find-buffer)))
  1333. (if (get-buffer-process buffer)
  1334. (interrupt-process (get-buffer-process buffer))
  1335. (error "The compilation process is not running"))))
  1336. ;; Parse any new errors in the compilation buffer,
  1337. ;; or reparse from the beginning if the user has asked for that.
  1338. (defun compile-reinitialize-errors (reparse
  1339. &optional limit-search find-at-least)
  1340. (save-excursion
  1341. ;; XEmacs change: Below we made a change to possibly change the
  1342. ;; selected window. If we don't save and restore the old window
  1343. ;; then if we get an error such as 'no more errors' we'll end up
  1344. ;; in the compilation buffer.
  1345. (save-window-excursion
  1346. (set-buffer compilation-last-buffer)
  1347. ;; If we are out of errors, or if user says "reparse",
  1348. ;; discard the info we have, to force reparsing.
  1349. (if (or (eq compilation-error-list t)
  1350. reparse)
  1351. (compilation-forget-errors))
  1352. (if (and compilation-error-list
  1353. (or (not limit-search)
  1354. (> compilation-parsing-end limit-search))
  1355. (or (not find-at-least)
  1356. (>= (length compilation-error-list) find-at-least)))
  1357. ;; Since compilation-error-list is non-nil, it points to a specific
  1358. ;; error the user wanted. So don't move it around.
  1359. nil
  1360. ;; XEmacs change: if the compilation buffer is already visible
  1361. ;; in a window, use that instead of thrashing the display.
  1362. (let ((w (get-buffer-window compilation-last-buffer)))
  1363. (if w
  1364. (select-window w)
  1365. (switch-to-buffer compilation-last-buffer)))
  1366. ;; This was here for a long time (before my rewrite); why? --roland
  1367. ;;(switch-to-buffer compilation-last-buffer)
  1368. (set-buffer-modified-p nil)
  1369. (if (< compilation-parsing-end (point-max))
  1370. ;; compilation-error-list might be non-nil if we have a non-nil
  1371. ;; LIMIT-SEARCH or FIND-AT-LEAST arg. In that case its value
  1372. ;; records the current position in the error list, and we must
  1373. ;; preserve that after reparsing.
  1374. (let ((error-list-pos compilation-error-list))
  1375. (funcall compilation-parse-errors-function
  1376. limit-search
  1377. (and find-at-least
  1378. ;; We only need enough new parsed errors to reach
  1379. ;; FIND-AT-LEAST errors past the current
  1380. ;; position.
  1381. (- find-at-least (length compilation-error-list))))
  1382. ;; Remember the entire list for compilation-forget-errors. If
  1383. ;; this is an incremental parse, append to previous list. If
  1384. ;; we are parsing anew, compilation-forget-errors cleared
  1385. ;; compilation-old-error-list above.
  1386. (setq compilation-old-error-list
  1387. (nconc compilation-old-error-list compilation-error-list))
  1388. (if error-list-pos
  1389. ;; We started in the middle of an existing list of parsed
  1390. ;; errors before parsing more; restore that position.
  1391. (setq compilation-error-list error-list-pos))
  1392. ))))))
  1393. ;; XEmacs addition
  1394. ;; FSF has added this by 19.34, but it is highly complex, why? -sb
  1395. (defun compile-mouse-goto-error (event)
  1396. "Visit the source for the error under the mouse.
  1397. Use this command in a compilation log buffer."
  1398. (interactive "e")
  1399. (mouse-set-point event)
  1400. (beginning-of-line)
  1401. (compile-goto-error))
  1402. (defun compile-goto-error (&optional argp)
  1403. "Visit the source for the error message point is on.
  1404. Use this command in a compilation log buffer. Sets the mark at point there.
  1405. \\[universal-argument] as a prefix arg means to reparse the buffer's error messages first;
  1406. other kinds of prefix arguments are ignored."
  1407. (interactive "P")
  1408. (or (compilation-buffer-p (current-buffer))
  1409. (error "Not in a compilation buffer"))
  1410. (setq compilation-last-buffer (current-buffer))
  1411. (compile-reinitialize-errors (consp argp) (point))
  1412. ;; Move to bol; the marker for the error on this line will point there.
  1413. (beginning-of-line)
  1414. ;; Move compilation-error-list to the elt of compilation-old-error-list
  1415. ;; we want.
  1416. (setq compilation-error-list compilation-old-error-list)
  1417. (while (and compilation-error-list
  1418. (> (point) (car (car compilation-error-list))))
  1419. (setq compilation-error-list (cdr compilation-error-list)))
  1420. ;; Move to another window, so that next-error's window changes
  1421. ;; result in the desired setup.
  1422. (or (one-window-p)
  1423. (progn
  1424. (other-window -1)
  1425. ;; other-window changed the selected buffer,
  1426. ;; but we didn't want to do that.
  1427. (set-buffer compilation-last-buffer)))
  1428. (push-mark)
  1429. (next-error 1))
  1430. ;; XEmacs addition
  1431. (defun compile-mouse-maybe-goto-error (event &optional click-count)
  1432. (interactive "e")
  1433. (if (equal (event-button event) 2)
  1434. (let ((buffer (current-buffer))
  1435. (point (point))
  1436. (config (current-window-configuration)))
  1437. (condition-case nil
  1438. (progn
  1439. (compile-mouse-goto-error event)
  1440. t)
  1441. (error
  1442. (set-window-configuration config)
  1443. (set-buffer buffer)
  1444. (goto-char point)
  1445. nil)))))
  1446. ;; Return a compilation buffer.
  1447. ;; If the current buffer is a compilation buffer, return it.
  1448. ;; If compilation-last-buffer is set to a live buffer, use that.
  1449. ;; Otherwise, look for a compilation buffer and signal an error
  1450. ;; if there are none.
  1451. (defun compilation-find-buffer (&optional other-buffer)
  1452. (if (and (not other-buffer)
  1453. (compilation-buffer-p (current-buffer)))
  1454. ;; The current buffer is a compilation buffer.
  1455. (current-buffer)
  1456. (if (and compilation-last-buffer (buffer-name compilation-last-buffer)
  1457. (compilation-buffer-p compilation-last-buffer)
  1458. (or (not other-buffer) (not (eq compilation-last-buffer
  1459. (current-buffer)))))
  1460. compilation-last-buffer
  1461. (let ((buffers (buffer-list)))
  1462. (while (and buffers (or (not (compilation-buffer-p (car buffers)))
  1463. (and other-buffer
  1464. (eq (car buffers) (current-buffer)))))
  1465. (setq buffers (cdr buffers)))
  1466. (if buffers
  1467. (car buffers)
  1468. (or (and other-buffer
  1469. (compilation-buffer-p (current-buffer))
  1470. ;; The current buffer is a compilation buffer.
  1471. (progn
  1472. (if other-buffer
  1473. (message "This is the only compilation buffer."))
  1474. (current-buffer)))
  1475. (error "No compilation started!")))))))
  1476. ;;;###autoload
  1477. (defun next-error (&optional argp)
  1478. "Visit next compilation error message and corresponding source code.
  1479. If all the error messages parsed so far have been processed already,
  1480. the message buffer is checked for new ones.
  1481. A prefix ARGP specifies how many error messages to move;
  1482. negative means move back to previous error messages.
  1483. Just \\[universal-argument] as a prefix means reparse the error message buffer
  1484. and start at the first error.
  1485. \\[next-error] normally uses the most recently started compilation or
  1486. grep buffer. However, it can operate on any buffer with output from
  1487. the \\[compile] and \\[grep] commands, or, more generally, on any
  1488. buffer in Compilation mode or with Compilation Minor mode enabled. To
  1489. specify use of a particular buffer for error messages, type
  1490. \\[next-error] in that buffer.
  1491. Once \\[next-error] has chosen the buffer for error messages,
  1492. it stays with that buffer until you use it in some other buffer which
  1493. uses Compilation mode or Compilation Minor mode.
  1494. See variables `compilation-parse-errors-function' and
  1495. \`compilation-error-regexp-alist' for customization ideas."
  1496. (interactive "P")
  1497. (setq compilation-last-buffer (compilation-find-buffer))
  1498. (compilation-goto-locus (compilation-next-error-locus
  1499. ;; We want to pass a number here only if
  1500. ;; we got a numeric prefix arg, not just C-u.
  1501. (and (not (consp argp))
  1502. (prefix-numeric-value argp))
  1503. (consp argp))))
  1504. ;;;###autoload (define-key ctl-x-map "`" 'next-error)
  1505. ;; XEmacs change
  1506. ;;;###autoload
  1507. (defun previous-error (&optional argp)
  1508. "Visit previous compilation error message and corresponding source code.
  1509. A prefix ARGP specifies how many error messages to move;
  1510. negative means move forward to next error messages.
  1511. This operates on the output from the \\[compile] and \\[grep] commands."
  1512. (interactive "P")
  1513. (next-error (cond ((null argp) -1)
  1514. ((numberp argp) (- argp))
  1515. (t argp))))
  1516. ;;;###autoload
  1517. (defun first-error ()
  1518. "Reparse the error message buffer and start at the first error.
  1519. Visit corresponding source code.
  1520. This operates on the output from the \\[compile] command."
  1521. (interactive)
  1522. (next-error '(4)))
  1523. (defun compilation-next-error-locus (&optional move reparse silent)
  1524. "Visit next compilation error and return locus in corresponding source code.
  1525. This operates on the output from the \\[compile] command.
  1526. If all preparsed error messages have been processed,
  1527. the error message buffer is checked for new ones.
  1528. Returns a cons (ERROR . SOURCE) of two markers: ERROR is a marker at the
  1529. location of the error message in the compilation buffer, and SOURCE is a
  1530. marker at the location in the source code indicated by the error message.
  1531. Optional first arg MOVE says how many error messages to move forwards (or
  1532. backwards, if negative); default is 1. Optional second arg REPARSE, if
  1533. non-nil, says to reparse the error message buffer and reset to the first
  1534. error (plus MOVE - 1). If optional third argument SILENT is non-nil, return
  1535. nil instead of raising an error if there are no more errors.
  1536. The current buffer should be the desired compilation output buffer."
  1537. (or move (setq move 1))
  1538. (compile-reinitialize-errors reparse nil (and (not reparse)
  1539. (if (< move 1) 0 (1- move))))
  1540. (let (next-errors next-error)
  1541. (catch 'no-next-error
  1542. (save-excursion
  1543. (set-buffer compilation-last-buffer)
  1544. ;; compilation-error-list points to the "current" error.
  1545. (setq next-errors
  1546. (if (> move 0)
  1547. (nthcdr (1- move)
  1548. compilation-error-list)
  1549. ;; Zero or negative arg; we need to move back in the list.
  1550. (let ((n (1- move))
  1551. (i 0)
  1552. (e compilation-old-error-list))
  1553. ;; See how many cdrs away the current error is from the start.
  1554. (while (not (eq e compilation-error-list))
  1555. (setq i (1+ i)
  1556. e (cdr e)))
  1557. (if (> (- n) i)
  1558. (error "Moved back past first error")
  1559. (nthcdr (+ i n) compilation-old-error-list))))
  1560. next-error (car next-errors))
  1561. (while
  1562. (if (null next-error)
  1563. (progn
  1564. (and move (/= move 1)
  1565. (error (if (> move 0)
  1566. "Moved past last error"
  1567. "Moved back past first error")))
  1568. ;; Forget existing error messages if compilation has finished.
  1569. ;;; XEmacs change by Barry Warsaw.
  1570. ;;; Without this, if you get a "no more errors" error, then you can't do
  1571. ;;; previous-error or goto-error until you kill the buffer.
  1572. ; (if (not (and (get-buffer-process (current-buffer))
  1573. ; (eq (process-status
  1574. ; (get-buffer-process
  1575. ; (current-buffer)))
  1576. ; 'run)))
  1577. ; (compilation-forget-errors))
  1578. (if silent
  1579. (throw 'no-next-error nil)
  1580. (error (concat compilation-error-message
  1581. (and (get-buffer-process (current-buffer))
  1582. (eq (process-status
  1583. (get-buffer-process
  1584. (current-buffer)))
  1585. 'run)
  1586. " yet")))))
  1587. (setq compilation-error-list (cdr next-errors))
  1588. (if (null (cdr next-error))
  1589. ;; This error is boring. Go to the next.
  1590. t
  1591. (or (markerp (cdr next-error))
  1592. ;; This error has a filename/lineno pair.
  1593. ;; Find the file and turn it into a marker.
  1594. (let* ((fileinfo (car (cdr next-error)))
  1595. (cbuf (current-buffer)) ;XEmacs addition
  1596. (buffer (apply 'compilation-find-file
  1597. (car next-error) fileinfo)))
  1598. (if (null buffer)
  1599. ;; We can't find this error's file.
  1600. ;; Remove all errors in the same file.
  1601. (progn
  1602. (setq next-errors compilation-old-error-list)
  1603. (while next-errors
  1604. (and (consp (cdr (car next-errors)))
  1605. (equal (car (cdr (car next-errors)))
  1606. fileinfo)
  1607. (progn
  1608. (set-marker (car (car next-errors)) nil)
  1609. (setcdr (car next-errors) nil)))
  1610. (setq next-errors (cdr next-errors)))
  1611. ;; Look for the next error.
  1612. t)
  1613. ;; We found the file. Get a marker for this error.
  1614. ;; compilation-old-error-list and
  1615. ;; compilation-error-screen-columns are buffer-local
  1616. ;; so we must be careful to extract their value
  1617. ;; before switching to the source file buffer.
  1618. (let ((errors compilation-old-error-list)
  1619. (columns compilation-error-screen-columns)
  1620. (last-line (nth 1 (cdr next-error)))
  1621. (column (nth 2 (cdr next-error))))
  1622. (set-buffer buffer)
  1623. (save-excursion
  1624. (save-restriction
  1625. (widen)
  1626. (goto-line last-line)
  1627. (if (and column (> column 0))
  1628. ;; Columns in error msgs are 1-origin.
  1629. (if columns
  1630. (move-to-column (1- column))
  1631. (forward-char (1- column)))
  1632. (beginning-of-line))
  1633. (setcdr next-error (point-marker))
  1634. ;; Make all the other error messages referring
  1635. ;; to the same file have markers into the buffer.
  1636. (while errors
  1637. (and (consp (cdr (car errors)))
  1638. (equal (car (cdr (car errors))) fileinfo)
  1639. (let* ((this (nth 1 (cdr (car errors))))
  1640. (column (nth 2 (cdr (car errors))))
  1641. (lines (- this last-line)))
  1642. (if (eq selective-display t)
  1643. ;; When selective-display is t,
  1644. ;; each C-m is a line boundary,
  1645. ;; as well as each newline.
  1646. (if (< lines 0)
  1647. (re-search-backward "[\n\C-m]"
  1648. nil 'end
  1649. (- lines))
  1650. (re-search-forward "[\n\C-m]"
  1651. nil 'end
  1652. lines))
  1653. (forward-line lines))
  1654. (if (and column (> column 1))
  1655. (if columns
  1656. (move-to-column (1- column))
  1657. (forward-char (1- column)))
  1658. (beginning-of-line))
  1659. (setq last-line this)
  1660. (setcdr (car errors) (point-marker))))
  1661. (setq errors (cdr errors)))))
  1662. ;; XEmacs addition
  1663. (set-buffer cbuf)))))
  1664. ;; If we didn't get a marker for this error, or this
  1665. ;; marker's buffer was killed, go on to the next one.
  1666. (or (not (markerp (cdr next-error)))
  1667. (not (marker-buffer (cdr next-error))))))
  1668. (setq next-errors compilation-error-list
  1669. next-error (car next-errors)))
  1670. ;; XEmacs -- move this inside save-excursion
  1671. ;; Skip over multiple error messages for the same source location,
  1672. ;; so the next C-x ` won't go to an error in the same place.
  1673. (while (and compilation-error-list
  1674. (equal (cdr (car compilation-error-list))
  1675. (cdr next-error)))
  1676. (setq compilation-error-list (cdr compilation-error-list)))
  1677. ))
  1678. ;; XEmacs change: If a new window has to be displayed, select the other
  1679. ;; window to avoid swapping the position of the compilation error buffer.
  1680. (and next-error (get-buffer-window (marker-buffer (car next-error)))
  1681. (progn
  1682. (select-window (get-buffer-window (marker-buffer (car next-error))))
  1683. (other-window -1)))
  1684. ;; We now have a marker for the position of the error source code.
  1685. ;; NEXT-ERROR is a cons (ERROR . SOURCE) of two markers.
  1686. next-error))
  1687. (defun compilation-goto-locus (next-error)
  1688. "Jump to an error locus returned by `compilation-next-error-locus'.
  1689. Takes one argument, a cons (ERROR . SOURCE) of two markers.
  1690. Selects a window with point at SOURCE, with another window displaying ERROR."
  1691. ;; XEmacs: this code is horrendous, and makes windows do all sorts of
  1692. ;; weird things when you're using separate frames for the compilation
  1693. ;; and source buffer.
  1694. ; (if (and (window-dedicated-p (selected-window))
  1695. ; (eq (selected-window) (frame-root-window)))
  1696. ; (switch-to-buffer-other-frame (marker-buffer (cdr next-error)))
  1697. ; (switch-to-buffer (marker-buffer (cdr next-error))))
  1698. ; (goto-char (cdr next-error))
  1699. ; ;; If narrowing got in the way of
  1700. ; ;; going to the right place, widen.
  1701. ; (or (= (point) (marker-position (cdr next-error)))
  1702. ; (progn
  1703. ; (widen)
  1704. ; (goto-char (cdr next-error))))
  1705. ;
  1706. ; ;; Show compilation buffer in other window, scrolled to this error.
  1707. ; (let* ((pop-up-windows t)
  1708. ; (w (or (get-buffer-window (marker-buffer (car next-error)) 'visible)
  1709. ; (display-buffer (marker-buffer (car next-error))))))
  1710. ; (set-window-point w (car next-error))
  1711. ; (set-window-start w (car next-error))
  1712. ; (compilation-set-window-height w)))
  1713. (let* ((pop-up-windows t)
  1714. (compilation-buffer (marker-buffer (car next-error)))
  1715. (source-buffer (marker-buffer (cdr next-error)))
  1716. ;; make sure compilation buffer is visible ...
  1717. (compilation-window
  1718. ;; Use an existing window if it is in a visible frame.
  1719. (or (get-buffer-window compilation-buffer 'visible)
  1720. ;; Pop up a window.
  1721. (display-buffer compilation-buffer))))
  1722. ;; now, make the compilation buffer **STAY WHERE IT IS** and
  1723. ;; make sure the source buffer is visible
  1724. (select-window compilation-window)
  1725. (pop-to-buffer source-buffer)
  1726. ;; now put things aright in the compilation window.
  1727. (set-window-point compilation-window (car next-error))
  1728. (set-window-start compilation-window (car next-error))
  1729. (compilation-set-window-height compilation-window)
  1730. ;; now put things aright in the source window.
  1731. (set-buffer source-buffer)
  1732. (goto-char (cdr next-error))
  1733. ;; If narrowing got in the way of
  1734. ;; going to the right place, widen.
  1735. (or (= (point) (marker-position (cdr next-error)))
  1736. (progn
  1737. (widen)
  1738. (goto-char (cdr next-error))))))
  1739. ;; helper routine to compilation-find-file
  1740. (defun compare-file-to-buffer (filename buffer)
  1741. "compare BUFFER to FILENAME and see if they are really the same. Returns nil
  1742. if not, BUFFER if they are"
  1743. (interactive "FCompare FILE :
  1744. bTo BUFFER : ")
  1745. ;; (print (format "%s %s " buffer filename))
  1746. (if (and (stringp filename) (bufferp buffer))
  1747. (save-excursion
  1748. (set-buffer buffer)
  1749. (if (equal (file-truename (buffer-file-name))
  1750. (file-truename filename))
  1751. buffer
  1752. nil))
  1753. nil)
  1754. )
  1755. ;; Find a buffer for file FILENAME.
  1756. ;; Search the directories in compilation-search-path.
  1757. ;; A nil in compilation-search-path means to try the
  1758. ;; current directory, which is passed in DIR.
  1759. ;; If FILENAME is not found at all, ask the user where to find it.
  1760. ;; Pop up the buffer containing MARKER and scroll to MARKER if we ask the user.
  1761. (defun compilation-find-file (marker filename dir &rest formats)
  1762. (or formats (setq formats '("%s")))
  1763. (let* ((dirs compilation-search-path)
  1764. (true-file-name (file-name-nondirectory filename))
  1765. (buffer (get-buffer true-file-name))
  1766. thisdir fmts name)
  1767. (flet ((push-file-name-history (name)
  1768. (setq file-name-history
  1769. (if minibuffer-history-uniquify
  1770. (cons name (remove name file-name-history))
  1771. (cons name file-name-history)))))
  1772. ;; first see if buffer is there already
  1773. (if (compare-file-to-buffer buffer filename)
  1774. (switch-to-buffer buffer)
  1775. (progn
  1776. (setq buffer nil) ; its the wrong buffer, so forget it
  1777. (if (file-name-absolute-p filename)
  1778. ;; The file name is absolute. Use its explicit directory as
  1779. ;; the first in the search path, and strip it from FILENAME.
  1780. (setq filename (abbreviate-file-name (expand-file-name filename))
  1781. dirs (cons (file-name-directory filename) dirs)
  1782. filename (file-name-nondirectory filename)))
  1783. ;; Now search the path.
  1784. (while (and dirs (null buffer))
  1785. (setq thisdir (or (car dirs) dir)
  1786. fmts formats)
  1787. ;; For each directory, try each format string.
  1788. (while (and fmts (null buffer))
  1789. (setq name (expand-file-name (format (car fmts) filename) thisdir)
  1790. buffer (and (file-exists-p name)
  1791. (progn
  1792. (push-file-name-history name)
  1793. (find-file-noselect name)))
  1794. fmts (cdr fmts)))
  1795. (setq dirs (cdr dirs)))
  1796. (or buffer
  1797. ;; The file doesn't exist.
  1798. ;; Ask the user where to find it.
  1799. ;; If he hits C-g, then the next time he does
  1800. ;; next-error, he'll skip past it.
  1801. (let* ((pop-up-windows t)
  1802. (w (display-buffer (marker-buffer marker))))
  1803. (set-window-point w marker)
  1804. (set-window-start w marker)
  1805. (let ((name (expand-file-name
  1806. (read-file-name
  1807. (format "Find this error in: (default %s) "
  1808. filename)
  1809. dir filename t))))
  1810. (if (file-directory-p name)
  1811. (setq name (expand-file-name filename name)))
  1812. (and (file-exists-p name)
  1813. (progn
  1814. (push-file-name-history name)
  1815. (find-file-noselect name)))))))))))
  1816. ;; Set compilation-error-list to nil, and unchain the markers that point to the
  1817. ;; error messages and their text, so that they no longer slow down gap motion.
  1818. ;; This would happen anyway at the next garbage collection, but it is better to
  1819. ;; do it right away.
  1820. (defun compilation-forget-errors ()
  1821. (while compilation-old-error-list
  1822. (let ((next-error (car compilation-old-error-list)))
  1823. (set-marker (car next-error) nil)
  1824. (if (markerp (cdr next-error))
  1825. (set-marker (cdr next-error) nil)))
  1826. (setq compilation-old-error-list (cdr compilation-old-error-list)))
  1827. (setq compilation-error-list nil
  1828. compilation-directory-stack nil
  1829. compilation-parsing-end 1))
  1830. (defun count-regexp-groupings (regexp)
  1831. "Return the number of \\( ... \\) groupings in REGEXP (a string)."
  1832. (let ((groupings 0)
  1833. (len (length regexp))
  1834. (i 0)
  1835. c)
  1836. (while (< i len)
  1837. (setq c (aref regexp i)
  1838. i (1+ i))
  1839. (cond ((= c ?\[)
  1840. ;; Find the end of this [...].
  1841. (while (and (< i len)
  1842. (not (= (aref regexp i) ?\])))
  1843. (setq i (1+ i))))
  1844. ((= c ?\\)
  1845. (if (< i len)
  1846. (progn
  1847. (setq c (aref regexp i)
  1848. i (1+ i))
  1849. (if (= c ?\))
  1850. ;; We found the end of a grouping,
  1851. ;; so bump our counter.
  1852. (setq groupings (1+ groupings))))))))
  1853. groupings))
  1854. (defun compilation-parse-errors (limit-search find-at-least)
  1855. "Parse the current buffer as grep, cc or lint error messages.
  1856. See variable `compilation-parse-errors-function' for the interface it uses."
  1857. (setq compilation-error-list nil)
  1858. (display-message 'progress "Parsing error messages...")
  1859. (let (;;text-buffer -- unused
  1860. orig orig-expanded parent-expanded
  1861. regexp enter-group leave-group error-group
  1862. alist subexpr error-regexp-groups
  1863. (found-desired nil)
  1864. (compilation-num-errors-found 0)
  1865. (message-freq (max 1 (/ (count-lines (point-min) (point-max)) 50))))
  1866. ;; Don't reparse messages already seen at last parse.
  1867. (goto-char compilation-parsing-end)
  1868. ;; Don't parse the first two lines as error messages.
  1869. ;; This matters for grep.
  1870. (if (bobp)
  1871. (progn
  1872. (forward-line 2)
  1873. ;; Move back so point is before the newline.
  1874. ;; This matters because some error regexps use \n instead of ^
  1875. ;; to be faster.
  1876. (forward-char -1)))
  1877. ;; Compile all the regexps we want to search for into one.
  1878. (setq regexp (concat "\\(" compilation-enter-directory-regexp "\\)\\|"
  1879. "\\(" compilation-leave-directory-regexp "\\)\\|"
  1880. "\\(" (mapconcat (function
  1881. (lambda (elt)
  1882. (concat "\\(" (car elt) "\\)")))
  1883. compilation-error-regexp-alist
  1884. "\\|") "\\)"))
  1885. ;; Find out how many \(...\) groupings are in each of the regexps, and set
  1886. ;; *-GROUP to the grouping containing each constituent regexp (whose
  1887. ;; subgroups will come immediately thereafter) of the big regexp we have
  1888. ;; just constructed.
  1889. (setq enter-group 1
  1890. leave-group (+ enter-group
  1891. (count-regexp-groupings
  1892. compilation-enter-directory-regexp)
  1893. 1)
  1894. error-group (+ leave-group
  1895. (count-regexp-groupings
  1896. compilation-leave-directory-regexp)
  1897. 1))
  1898. ;; Compile an alist (IDX FILE LINE [COL]), where IDX is the number of
  1899. ;; the subexpression for an entire error-regexp, and FILE and LINE (and
  1900. ;; possibly COL) are the numbers for the subexpressions giving the file
  1901. ;; name and line number (and possibly column number).
  1902. (setq alist (or compilation-error-regexp-alist
  1903. (error "compilation-error-regexp-alist is empty!"))
  1904. subexpr (1+ error-group))
  1905. (while alist
  1906. (setq error-regexp-groups
  1907. (cons (list subexpr
  1908. (+ subexpr (nth 1 (car alist)))
  1909. (+ subexpr (nth 2 (car alist)))
  1910. ;;#### This is buggy in FSFmacs
  1911. (let ((col (nth 3 (car alist))))
  1912. (and col
  1913. (+ subexpr col))))
  1914. error-regexp-groups))
  1915. (setq subexpr (+ subexpr 1 (count-regexp-groupings (car (car alist)))))
  1916. (setq alist (cdr alist)))
  1917. ;; Set up now the expanded, abbreviated directory variables
  1918. ;; that compile-abbreviate-directory will need, so we can
  1919. ;; compute them just once here.
  1920. (setq orig (abbreviate-file-name default-directory)
  1921. orig-expanded (abbreviate-file-name
  1922. (file-truename default-directory))
  1923. parent-expanded (abbreviate-file-name
  1924. (expand-file-name "../" orig-expanded)))
  1925. (while (and (not found-desired)
  1926. ;; We don't just pass LIMIT-SEARCH to re-search-forward
  1927. ;; because we want to find matches containing LIMIT-SEARCH
  1928. ;; but which extend past it.
  1929. ;; Instead of using re-search-forward,
  1930. ;; we use this loop which tries only at each line.
  1931. (progn
  1932. (while (and (not (eobp))
  1933. (not (looking-at regexp)))
  1934. (forward-line 1))
  1935. (not (eobp))))
  1936. ;; Move to the end of the match we just found.
  1937. (goto-char (match-end 0))
  1938. ;; Figure out which constituent regexp matched.
  1939. (cond ((match-beginning enter-group)
  1940. ;; The match was the enter-directory regexp.
  1941. (let ((dir
  1942. (file-name-as-directory
  1943. (expand-file-name
  1944. (buffer-substring (match-beginning (+ enter-group 1))
  1945. (match-end (+ enter-group 1)))))))
  1946. ;; The directory name in the "entering" message
  1947. ;; is a truename. Try to convert it to a form
  1948. ;; like what the user typed in.
  1949. (setq dir
  1950. (compile-abbreviate-directory dir orig orig-expanded
  1951. parent-expanded))
  1952. (setq compilation-directory-stack
  1953. (cons dir compilation-directory-stack))
  1954. (and (file-directory-p dir)
  1955. (setq default-directory dir)))
  1956. (and limit-search (>= (point) limit-search)
  1957. ;; The user wanted a specific error, and we're past it.
  1958. ;; We do this check here (and in the leave-group case)
  1959. ;; rather than at the end of the loop because if the last
  1960. ;; thing seen is an error message, we must carefully
  1961. ;; discard the last error when it is the first in a new
  1962. ;; file (see below in the error-group case).
  1963. (setq found-desired t)))
  1964. ((match-beginning leave-group)
  1965. ;; The match was the leave-directory regexp.
  1966. (let ((beg (match-beginning (+ leave-group 1)))
  1967. (stack compilation-directory-stack))
  1968. (if beg
  1969. (let ((dir
  1970. (file-name-as-directory
  1971. (expand-file-name
  1972. (buffer-substring beg
  1973. (match-end (+ leave-group
  1974. 1)))))))
  1975. ;; The directory name in the "leaving" message
  1976. ;; is a truename. Try to convert it to a form
  1977. ;; like what the user typed in.
  1978. (setq dir
  1979. (compile-abbreviate-directory dir orig orig-expanded
  1980. parent-expanded))
  1981. (while (and stack
  1982. (not (string-equal (car stack) dir)))
  1983. (setq stack (cdr stack)))))
  1984. (setq compilation-directory-stack (cdr stack))
  1985. (setq stack (car compilation-directory-stack))
  1986. (if stack
  1987. (setq default-directory stack))
  1988. )
  1989. (and limit-search (>= (point) limit-search)
  1990. ;; The user wanted a specific error, and we're past it.
  1991. ;; We do this check here (and in the enter-group case)
  1992. ;; rather than at the end of the loop because if the last
  1993. ;; thing seen is an error message, we must carefully
  1994. ;; discard the last error when it is the first in a new
  1995. ;; file (see below in the error-group case).
  1996. (setq found-desired t)))
  1997. ((match-beginning error-group)
  1998. ;; The match was the composite error regexp.
  1999. ;; Find out which individual regexp matched.
  2000. (setq alist error-regexp-groups)
  2001. (while (and alist
  2002. (null (match-beginning (car (car alist)))))
  2003. (setq alist (cdr alist)))
  2004. (if alist
  2005. (setq alist (car alist))
  2006. (error "compilation-parse-errors: impossible regexp match!"))
  2007. ;; Extract the file name and line number from the error message.
  2008. (let ((beginning-of-match (match-beginning 0)) ;looking-at nukes
  2009. (filename (buffer-substring (match-beginning (nth 1 alist))
  2010. (match-end (nth 1 alist))))
  2011. (linenum (string-to-int
  2012. (buffer-substring
  2013. (match-beginning (nth 2 alist))
  2014. (match-end (nth 2 alist)))))
  2015. (column (and (nth 3 alist)
  2016. (match-beginning (nth 3 alist))
  2017. (string-to-int
  2018. (buffer-substring
  2019. (match-beginning (nth 3 alist))
  2020. (match-end (nth 3 alist)))))))
  2021. ;; Check for a comint-file-name-prefix and prepend it if
  2022. ;; appropriate. (This is very useful for
  2023. ;; compilation-minor-mode in an rlogin-mode buffer.)
  2024. (and (boundp 'comint-file-name-prefix)
  2025. ;; If the file name is relative, default-directory will
  2026. ;; already contain the comint-file-name-prefix (done by
  2027. ;; compile-abbreviate-directory).
  2028. (file-name-absolute-p filename)
  2029. (setq filename (concat comint-file-name-prefix filename)))
  2030. ;; Some compilers (e.g. Sun's java compiler, reportedly)
  2031. ;; produce bogus file names like "./bar//foo.c" for the file
  2032. ;; "bar/foo.c"; expand-file-name will collapse these into
  2033. ;; "/foo.c" and fail to find the appropriate file. So we look
  2034. ;; for doubled slashes in the file name and fix them up in the
  2035. ;; buffer.
  2036. (when (fboundp 'command-line-normalize-file-name)
  2037. (setq filename (command-line-normalize-file-name filename)))
  2038. (setq filename (cons filename (cons default-directory
  2039. (nthcdr 4 alist))))
  2040. ;; Locate the erring file and line.
  2041. ;; Cons a new elt onto compilation-error-list,
  2042. ;; giving a marker for the current compilation buffer
  2043. ;; location, and the file and line number of the error.
  2044. (save-excursion
  2045. ;; Save as the start of the error the beginning of the
  2046. ;; line containing the match unless the match starts at a
  2047. ;; newline, in which case the beginning of the next line.
  2048. (goto-char beginning-of-match)
  2049. (forward-line (if (eolp) 1 0))
  2050. (let ((this (cons (point-marker)
  2051. (list filename linenum column))))
  2052. ;; Don't add the same source line more than once.
  2053. (if (equal (cdr this) (cdr (car compilation-error-list)))
  2054. nil
  2055. (setq compilation-error-list
  2056. (cons this
  2057. compilation-error-list))
  2058. (setq compilation-num-errors-found
  2059. (1+ compilation-num-errors-found)))))
  2060. (and (or (and find-at-least (> compilation-num-errors-found
  2061. find-at-least))
  2062. (and limit-search (>= (point) limit-search)))
  2063. ;; We have found as many new errors as the user wants,
  2064. ;; or past the buffer position he indicated. We
  2065. ;; continue to parse until we have seen all the
  2066. ;; consecutive errors in the same file, so the error
  2067. ;; positions will be recorded as markers in this buffer
  2068. ;; that might change.
  2069. (cdr compilation-error-list) ; Must check at least two.
  2070. (not (equal (car (cdr (nth 0 compilation-error-list)))
  2071. (car (cdr (nth 1 compilation-error-list)))))
  2072. (progn
  2073. ;; Discard the error just parsed, so that the next
  2074. ;; parsing run can get it and the following errors in
  2075. ;; the same file all at once. If we didn't do this, we
  2076. ;; would have the same problem we are trying to avoid
  2077. ;; with the test above, just delayed until the next run!
  2078. (setq compilation-error-list
  2079. (cdr compilation-error-list))
  2080. (goto-char beginning-of-match)
  2081. (setq found-desired t)))
  2082. )
  2083. )
  2084. (t
  2085. (error "compilation-parse-errors: known groups didn't match!")))
  2086. (when (= (% compilation-num-errors-found message-freq) 0)
  2087. (display-message
  2088. 'progress
  2089. (format "Parsing error messages...%d (%.0f%% of buffer)"
  2090. compilation-num-errors-found
  2091. ;; Use floating-point because (* 100 (point)) frequently
  2092. ;; exceeds the range of Emacs Lisp integers.
  2093. (/ (* 100.0 (point)) (point-max)))))
  2094. ;;; This is broken - it foils the logic above which is supposed to ensure
  2095. ;;; that all errors for the current file are found before we quit.
  2096. ; (and limit-search (>= (point) limit-search)
  2097. ; ;; The user wanted a specific error, and we're past it.
  2098. ; (setq found-desired t))
  2099. )
  2100. (setq compilation-parsing-end (if found-desired
  2101. (point)
  2102. ;; We have searched the whole buffer.
  2103. (point-max))))
  2104. (setq compilation-error-list (nreverse compilation-error-list))
  2105. (display-message 'progress "Parsing error messages...done"))
  2106. (defun compile-buffer-substring (index)
  2107. "Get substring matched by INDEXth subexpression."
  2108. (if index
  2109. (let ((beg (match-beginning index)))
  2110. (if beg (buffer-substring beg (match-end index))))))
  2111. ;; If directory DIR is a subdir of ORIG or of ORIG's parent,
  2112. ;; return a relative name for it starting from ORIG or its parent.
  2113. ;; ORIG-EXPANDED is an expanded version of ORIG.
  2114. ;; PARENT-EXPANDED is an expanded version of ORIG's parent.
  2115. ;; Those two args could be computed here, but we run faster by
  2116. ;; having the caller compute them just once.
  2117. (defun compile-abbreviate-directory (dir orig orig-expanded parent-expanded)
  2118. ;; Apply canonical abbreviations to DIR first thing.
  2119. ;; Those abbreviations are already done in the other arguments passed.
  2120. (setq dir (abbreviate-file-name dir))
  2121. ;; Check for a comint-file-name-prefix and prepend it if appropriate.
  2122. ;; (This is very useful for compilation-minor-mode in an rlogin-mode
  2123. ;; buffer.)
  2124. (if (boundp 'comint-file-name-prefix)
  2125. (setq dir (concat comint-file-name-prefix dir)))
  2126. (if (and (> (length dir) (length orig-expanded))
  2127. (string= orig-expanded
  2128. (substring dir 0 (length orig-expanded))))
  2129. (setq dir
  2130. (concat orig
  2131. (substring dir (length orig-expanded)))))
  2132. (if (and (> (length dir) (length parent-expanded))
  2133. (string= parent-expanded
  2134. (substring dir 0 (length parent-expanded))))
  2135. (setq dir
  2136. (concat (file-name-directory
  2137. (directory-file-name orig))
  2138. (substring dir (length parent-expanded)))))
  2139. dir)
  2140. (provide 'compile)
  2141. ;;; compile.el ends here