PageRenderTime 66ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/lisp/progmodes/compile.el

https://bitbucket.org/danchr/emacs
Emacs Lisp | 2411 lines | 1765 code | 234 blank | 412 comment | 77 complexity | 7a30a5aa71ba715eddb7acebe5beda71 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.0, AGPL-3.0

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

  1. ;;; compile.el --- run compiler as inferior of Emacs, parse error messages
  2. ;; Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
  3. ;; 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
  4. ;; Free Software Foundation, Inc.
  5. ;; Authors: Roland McGrath <roland@gnu.org>,
  6. ;; Daniel Pfeiffer <occitan@esperanto.org>
  7. ;; Maintainer: FSF
  8. ;; Keywords: tools, processes
  9. ;; This file is part of GNU Emacs.
  10. ;; GNU Emacs is free software: you can redistribute it and/or modify
  11. ;; it under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation, either version 3 of the License, or
  13. ;; (at your option) any later version.
  14. ;; GNU Emacs is distributed in the hope that it will be useful,
  15. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;; GNU General Public License for more details.
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  20. ;;; Commentary:
  21. ;; This package provides the compile facilities documented in the Emacs user's
  22. ;; manual.
  23. ;; This mode uses some complex data-structures:
  24. ;; LOC (or location) is a list of (COLUMN LINE FILE-STRUCTURE)
  25. ;; COLUMN and LINE are numbers parsed from an error message. COLUMN and maybe
  26. ;; LINE will be nil for a message that doesn't contain them. Then the
  27. ;; location refers to a indented beginning of line or beginning of file.
  28. ;; Once any location in some file has been jumped to, the list is extended to
  29. ;; (COLUMN LINE FILE-STRUCTURE MARKER TIMESTAMP . VISITED)
  30. ;; for all LOCs pertaining to that file.
  31. ;; MARKER initially points to LINE and COLUMN in a buffer visiting that file.
  32. ;; Being a marker it sticks to some text, when the buffer grows or shrinks
  33. ;; before that point. VISITED is t if we have jumped there, else nil.
  34. ;; TIMESTAMP is necessary because of "incremental compilation": `omake -P'
  35. ;; polls filesystem for changes and recompiles when a file is modified
  36. ;; using the same *compilation* buffer. this necessitates re-parsing markers.
  37. ;; FILE-STRUCTURE is a list of
  38. ;; ((FILENAME . DIRECTORY) FORMATS (LINE LOC ...) ...)
  39. ;; FILENAME is a string parsed from an error message. DIRECTORY is a string
  40. ;; obtained by following directory change messages. DIRECTORY will be nil for
  41. ;; an absolute filename. FORMATS is a list of formats to apply to FILENAME if
  42. ;; a file of that name can't be found.
  43. ;; The rest of the list is an alist of elements with LINE as key. The keys
  44. ;; are either nil or line numbers. If present, nil comes first, followed by
  45. ;; the numbers in decreasing order. The LOCs for each line are again an alist
  46. ;; ordered the same way. Note that the whole file structure is referenced in
  47. ;; every LOC.
  48. ;; MESSAGE is a list of (LOC TYPE END-LOC)
  49. ;; TYPE is 0 for info or 1 for warning if the message matcher identified it as
  50. ;; such, 2 otherwise (for a real error). END-LOC is a LOC pointing to the
  51. ;; other end, if the parsed message contained a range. If the end of the
  52. ;; range didn't specify a COLUMN, it defaults to -1, meaning end of line.
  53. ;; These are the value of the `message' text-properties in the compilation
  54. ;; buffer.
  55. ;;; Code:
  56. (eval-when-compile (require 'cl))
  57. (require 'tool-bar)
  58. (require 'comint)
  59. (defvar font-lock-extra-managed-props)
  60. (defvar font-lock-keywords)
  61. (defvar font-lock-maximum-size)
  62. (defvar font-lock-support-mode)
  63. (defgroup compilation nil
  64. "Run compiler as inferior of Emacs, parse error messages."
  65. :group 'tools
  66. :group 'processes)
  67. ;;;###autoload
  68. (defcustom compilation-mode-hook nil
  69. "List of hook functions run by `compilation-mode' (see `run-mode-hooks')."
  70. :type 'hook
  71. :group 'compilation)
  72. ;;;###autoload
  73. (defcustom compilation-start-hook nil
  74. "List of hook functions run by `compilation-start' on the compilation process.
  75. \(See `run-hook-with-args').
  76. If you use \"omake -P\" and do not want \\[save-buffers-kill-terminal] to ask whether you want
  77. the compilation to be killed, you can use this hook:
  78. (add-hook 'compilation-start-hook
  79. (lambda (process) (set-process-query-on-exit-flag process nil)) nil t)"
  80. :type 'hook
  81. :group 'compilation)
  82. ;;;###autoload
  83. (defcustom compilation-window-height nil
  84. "Number of lines in a compilation window. If nil, use Emacs default."
  85. :type '(choice (const :tag "Default" nil)
  86. integer)
  87. :group 'compilation)
  88. (defvar compilation-first-column 1
  89. "*This is how compilers number the first column, usually 1 or 0.")
  90. (defvar compilation-parse-errors-filename-function nil
  91. "Function to call to post-process filenames while parsing error messages.
  92. It takes one arg FILENAME which is the name of a file as found
  93. in the compilation output, and should return a transformed file name.")
  94. ;;;###autoload
  95. (defvar compilation-process-setup-function nil
  96. "*Function to call to customize the compilation process.
  97. This function is called immediately before the compilation process is
  98. started. It can be used to set any variables or functions that are used
  99. while processing the output of the compilation process. The function
  100. is called with variables `compilation-buffer' and `compilation-window'
  101. bound to the compilation buffer and window, respectively.")
  102. ;;;###autoload
  103. (defvar compilation-buffer-name-function nil
  104. "Function to compute the name of a compilation buffer.
  105. The function receives one argument, the name of the major mode of the
  106. compilation buffer. It should return a string.
  107. If nil, compute the name with `(concat \"*\" (downcase major-mode) \"*\")'.")
  108. ;;;###autoload
  109. (defvar compilation-finish-function nil
  110. "Function to call when a compilation process finishes.
  111. It is called with two arguments: the compilation buffer, and a string
  112. describing how the process finished.")
  113. (make-obsolete-variable 'compilation-finish-function
  114. "use `compilation-finish-functions', but it works a little differently."
  115. "22.1")
  116. ;;;###autoload
  117. (defvar compilation-finish-functions nil
  118. "Functions to call when a compilation process finishes.
  119. Each function is called with two arguments: the compilation buffer,
  120. and a string describing how the process finished.")
  121. (defvar compilation-in-progress nil
  122. "List of compilation processes now running.")
  123. (or (assq 'compilation-in-progress minor-mode-alist)
  124. (setq minor-mode-alist (cons '(compilation-in-progress " Compiling")
  125. minor-mode-alist)))
  126. (defvar compilation-error "error"
  127. "Stem of message to print when no matches are found.")
  128. (defvar compilation-arguments nil
  129. "Arguments that were given to `compilation-start'.")
  130. (defvar compilation-num-errors-found)
  131. (defconst compilation-error-regexp-alist-alist
  132. '((absoft
  133. "^\\(?:[Ee]rror on \\|[Ww]arning on\\( \\)\\)?[Ll]ine[ \t]+\\([0-9]+\\)[ \t]+\
  134. of[ \t]+\"?\\([a-zA-Z]?:?[^\":\n]+\\)\"?:" 3 2 nil (1))
  135. (ada
  136. "\\(warning: .*\\)? at \\([^ \n]+\\):\\([0-9]+\\)$" 2 3 nil (1))
  137. (aix
  138. " in line \\([0-9]+\\) of file \\([^ \n]+[^. \n]\\)\\.? " 2 1)
  139. (ant
  140. "^[ \t]*\\[[^] \n]+\\][ \t]*\\([^: \n]+\\):\\([0-9]+\\):\\(?:\\([0-9]+\\):[0-9]+:[0-9]+:\\)?\
  141. \\( warning\\)?" 1 2 3 (4))
  142. (bash
  143. "^\\([^: \n\t]+\\): line \\([0-9]+\\):" 1 2)
  144. (borland
  145. "^\\(?:Error\\|Warnin\\(g\\)\\) \\(?:[FEW][0-9]+ \\)?\
  146. \\([a-zA-Z]?:?[^:( \t\n]+\\)\
  147. \\([0-9]+\\)\\(?:[) \t]\\|:[^0-9\n]\\)" 2 3 nil (1))
  148. (caml
  149. "^ *File \\(\"?\\)\\([^,\" \n\t<>]+\\)\\1, lines? \\([0-9]+\\)-?\\([0-9]+\\)?\\(?:$\\|,\
  150. \\(?: characters? \\([0-9]+\\)-?\\([0-9]+\\)?:\\)?\\([ \n]Warning:\\)?\\)"
  151. 2 (3 . 4) (5 . 6) (7))
  152. (comma
  153. "^\"\\([^,\" \n\t]+\\)\", line \\([0-9]+\\)\
  154. \\(?:[(. pos]+\\([0-9]+\\))?\\)?[:.,; (-]\\( warning:\\|[-0-9 ]*(W)\\)?" 1 2 3 (4))
  155. (edg-1
  156. "^\\([^ \n]+\\)(\\([0-9]+\\)): \\(?:error\\|warnin\\(g\\)\\|remar\\(k\\)\\)"
  157. 1 2 nil (3 . 4))
  158. (edg-2
  159. "at line \\([0-9]+\\) of \"\\([^ \n]+\\)\"$"
  160. 2 1 nil 0)
  161. (epc
  162. "^Error [0-9]+ at (\\([0-9]+\\):\\([^)\n]+\\))" 2 1)
  163. (ftnchek
  164. "\\(^Warning .*\\)? line[ \n]\\([0-9]+\\)[ \n]\\(?:col \\([0-9]+\\)[ \n]\\)?file \\([^ :;\n]+\\)"
  165. 4 2 3 (1))
  166. (iar
  167. "^\"\\(.*\\)\",\\([0-9]+\\)\\s-+\\(?:Error\\|Warnin\\(g\\)\\)\\[[0-9]+\\]:"
  168. 1 2 nil (3))
  169. (ibm
  170. "^\\([^( \n\t]+\\)(\\([0-9]+\\):\\([0-9]+\\)) :\
  171. \\(?:warnin\\(g\\)\\|informationa\\(l\\)\\)?" 1 2 3 (4 . 5))
  172. ;; fixme: should be `mips'
  173. (irix
  174. "^[-[:alnum:]_/ ]+: \\(?:\\(?:[sS]evere\\|[eE]rror\\|[wW]arnin\\(g\\)\\|[iI]nf\\(o\\)\\)[0-9 ]*: \\)?\
  175. \\([^,\" \n\t]+\\)\\(?:, line\\|:\\) \\([0-9]+\\):" 3 4 nil (1 . 2))
  176. (java
  177. "^\\(?:[ \t]+at \\|==[0-9]+== +\\(?:at\\|b\\(y\\)\\)\\).+(\\([^()\n]+\\):\\([0-9]+\\))$" 2 3 nil (1))
  178. (jikes-file
  179. "^\\(?:Found\\|Issued\\) .* compiling \"\\(.+\\)\":$" 1 nil nil 0)
  180. (jikes-line
  181. "^ *\\([0-9]+\\)\\.[ \t]+.*\n +\\(<-*>\n\\*\\*\\* \\(?:Error\\|Warnin\\(g\\)\\)\\)"
  182. nil 1 nil 2 0
  183. (2 (compilation-face '(3))))
  184. (gnu
  185. ;; The first line matches the program name for
  186. ;; PROGRAM:SOURCE-FILE-NAME:LINENO: MESSAGE
  187. ;; format, which is used for non-interactive programs other than
  188. ;; compilers (e.g. the "jade:" entry in compilation.txt).
  189. ;; This first line makes things ambiguous with output such as
  190. ;; "foo:344:50:blabla" since the "foo" part can match this first
  191. ;; line (in which case the file name as "344"). To avoid this,
  192. ;; the second line disallows filenames exclusively composed of
  193. ;; digits.
  194. ;; Similarly, we get lots of false positives with messages including
  195. ;; times of the form "HH:MM:SS" where MM is taken as a line number, so
  196. ;; the last line tries to rule out message where the info after the
  197. ;; line number starts with "SS". --Stef
  198. ;; The core of the regexp is the one with *?. It says that a file name
  199. ;; can be composed of any non-newline char, but it also rules out some
  200. ;; valid but unlikely cases, such as a trailing space or a space
  201. ;; followed by a -.
  202. "^\\(?:[[:alpha:]][-[:alnum:].]+: ?\\)?\
  203. \\([0-9]*[^0-9\n]\\(?:[^\n ]\\| [^-/\n]\\)*?\\): ?\
  204. \\([0-9]+\\)\\(?:\\([.:]\\)\\([0-9]+\\)\\)?\
  205. \\(?:-\\([0-9]+\\)?\\(?:\\.\\([0-9]+\\)\\)?\\)?:\
  206. \\(?: *\\(\\(?:Future\\|Runtime\\)?[Ww]arning\\|W:\\)\\|\
  207. *\\([Ii]nfo\\(?:\\>\\|rmationa?l?\\)\\|I:\\|instantiated from\\|[Nn]ote\\)\\|\
  208. \[0-9]?\\(?:[^0-9\n]\\|$\\)\\|[0-9][0-9][0-9]\\)"
  209. 1 (2 . 5) (4 . 6) (7 . 8))
  210. ;; The `gnu' style above can incorrectly match gcc's "In file
  211. ;; included from" message, so we process that first. -- cyd
  212. (gcc-include
  213. "^\\(?:In file included\\| \\) from \
  214. \\(.+\\):\\([0-9]+\\)\\(?:\\(:\\)\\|\\(,\\)\\)?" 1 2 nil (3 . 4))
  215. (lcc
  216. "^\\(?:E\\|\\(W\\)\\), \\([^(\n]+\\)(\\([0-9]+\\),[ \t]*\\([0-9]+\\)"
  217. 2 3 4 (1))
  218. (makepp
  219. "^makepp\\(?:\\(?:: warning\\(:\\).*?\\|\\(: Scanning\\|: [LR]e?l?oading makefile\\|: Imported\\|log:.*?\\) \\|: .*?\\)\
  220. `\\(\\(\\S +?\\)\\(?::\\([0-9]+\\)\\)?\\)['(]\\)"
  221. 4 5 nil (1 . 2) 3
  222. ("`\\(\\(\\S +?\\)\\(?::\\([0-9]+\\)\\)?\\)['(]" nil nil
  223. (2 compilation-info-face)
  224. (3 compilation-line-face nil t)
  225. (1 (compilation-error-properties 2 3 nil nil nil 0 nil)
  226. append)))
  227. ;; This regexp is pathologically slow on long lines (Bug#3441).
  228. ;; (maven
  229. ;; ;; Maven is a popular build tool for Java. Maven is Free Software.
  230. ;; "\\(.*?\\):\\[\\([0-9]+\\),\\([0-9]+\\)\\]" 1 2 3)
  231. ;; Should be lint-1, lint-2 (SysV lint)
  232. (mips-1
  233. " (\\([0-9]+\\)) in \\([^ \n]+\\)" 2 1)
  234. (mips-2
  235. " in \\([^()\n ]+\\)(\\([0-9]+\\))$" 1 2)
  236. (msft
  237. ;; The message may be a "warning", "error", or "fatal error" with
  238. ;; an error code, or "see declaration of" without an error code.
  239. "^ *\\([0-9]+>\\)?\\(\\(?:[a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\)) \
  240. : \\(?:see declaration\\|\\(?:warnin\\(g\\)\\|[a-z ]+\\) C[0-9]+:\\)"
  241. 2 3 nil (4))
  242. (omake
  243. ;; "omake -P" reports "file foo changed"
  244. ;; (useful if you do "cvs up" and want to see what has changed)
  245. "omake: file \\(.*\\) changed" 1)
  246. (oracle
  247. "^\\(?:Semantic error\\|Error\\|PCC-[0-9]+:\\).* line \\([0-9]+\\)\
  248. \\(?:\\(?:,\\| at\\)? column \\([0-9]+\\)\\)?\
  249. \\(?:,\\| in\\| of\\)? file \\(.*?\\):?$"
  250. 3 1 2)
  251. ;; "during global destruction": This comes out under "use
  252. ;; warnings" in recent perl when breaking circular references
  253. ;; during program or thread exit.
  254. (perl
  255. " at \\([^ \n]+\\) line \\([0-9]+\\)\\(?:[,.]\\|$\\| \
  256. during global destruction\\.$\\)" 1 2)
  257. (php
  258. "\\(?:Parse\\|Fatal\\) error: \\(.*\\) in \\(.*\\) on line \\([0-9]+\\)"
  259. 2 3 nil nil)
  260. (rxp
  261. "^\\(?:Error\\|Warnin\\(g\\)\\):.*\n.* line \\([0-9]+\\) char\
  262. \\([0-9]+\\) of file://\\(.+\\)"
  263. 4 2 3 (1))
  264. (sparc-pascal-file
  265. "^\\w\\w\\w \\w\\w\\w +[0-3]?[0-9] +[0-2][0-9]:[0-5][0-9]:[0-5][0-9]\
  266. [12][09][0-9][0-9] +\\(.*\\):$"
  267. 1 nil nil 0)
  268. (sparc-pascal-line
  269. "^\\(\\(?:E\\|\\(w\\)\\) +[0-9]+\\) line \\([0-9]+\\) - "
  270. nil 3 nil (2) nil (1 (compilation-face '(2))))
  271. (sparc-pascal-example
  272. "^ +\\([0-9]+\\) +.*\n\\(\\(?:e\\|\\(w\\)\\) [0-9]+\\)-+"
  273. nil 1 nil (3) nil (2 (compilation-face '(3))))
  274. (sun
  275. ": \\(?:ERROR\\|WARNIN\\(G\\)\\|REMAR\\(K\\)\\) \\(?:[[:alnum:] ]+, \\)?\
  276. File = \\(.+\\), Line = \\([0-9]+\\)\\(?:, Column = \\([0-9]+\\)\\)?"
  277. 3 4 5 (1 . 2))
  278. (sun-ada
  279. "^\\([^, \n\t]+\\), line \\([0-9]+\\), char \\([0-9]+\\)[:., \(-]" 1 2 3)
  280. (watcom
  281. "^[ \t]*\\(\\(?:[a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\)): ?\
  282. \\(?:\\(Error! E[0-9]+\\)\\|\\(Warning! W[0-9]+\\)\\):"
  283. 1 2 nil (4))
  284. (4bsd
  285. "\\(?:^\\|:: \\|\\S ( \\)\\(/[^ \n\t()]+\\)(\\([0-9]+\\))\
  286. \\(?:: \\(warning:\\)?\\|$\\| ),\\)" 1 2 nil (3))
  287. (gcov-file
  288. "^ *-: *\\(0\\):Source:\\(.+\\)$"
  289. 2 1 nil 0 nil
  290. (1 compilation-line-face prepend) (2 compilation-info-face prepend))
  291. (gcov-header
  292. "^ *-: *\\(0\\):\\(?:Object\\|Graph\\|Data\\|Runs\\|Programs\\):.+$"
  293. nil 1 nil 0 nil
  294. (1 compilation-line-face prepend))
  295. ;; Underlines over all lines of gcov output are too uncomfortable to read.
  296. ;; However, hyperlinks embedded in the lines are useful.
  297. ;; So I put default face on the lines; and then put
  298. ;; compilation-*-face by manually to eliminate the underlines.
  299. ;; The hyperlinks are still effective.
  300. (gcov-nomark
  301. "^ *-: *\\([1-9]\\|[0-9]\\{2,\\}\\):.*$"
  302. nil 1 nil 0 nil
  303. (0 'default t)
  304. (1 compilation-line-face prepend))
  305. (gcov-called-line
  306. "^ *\\([0-9]+\\): *\\([0-9]+\\):.*$"
  307. nil 2 nil 0 nil
  308. (0 'default t)
  309. (1 compilation-info-face prepend) (2 compilation-line-face prepend))
  310. (gcov-never-called
  311. "^ *\\(#####\\): *\\([0-9]+\\):.*$"
  312. nil 2 nil 2 nil
  313. (0 'default t)
  314. (1 compilation-error-face prepend) (2 compilation-line-face prepend))
  315. (perl--Pod::Checker
  316. ;; podchecker error messages, per Pod::Checker.
  317. ;; The style is from the Pod::Checker::poderror() function, eg.
  318. ;; *** ERROR: Spurious text after =cut at line 193 in file foo.pm
  319. ;;
  320. ;; Plus end_pod() can give "at line EOF" instead of a
  321. ;; number, so for that match "on line N" which is the
  322. ;; originating spot, eg.
  323. ;; *** ERROR: =over on line 37 without closing =back at line EOF in file bar.pm
  324. ;;
  325. ;; Plus command() can give both "on line N" and "at line N";
  326. ;; the latter is desired and is matched because the .* is
  327. ;; greedy.
  328. ;; *** ERROR: =over on line 1 without closing =back (at head1) at line 3 in file x.pod
  329. ;;
  330. "^\\*\\*\\* \\(?:ERROR\\|\\(WARNING\\)\\).* \\(?:at\\|on\\) line \
  331. \\([0-9]+\\) \\(?:.* \\)?in file \\([^ \t\n]+\\)"
  332. 3 2 nil (1))
  333. (perl--Test
  334. ;; perl Test module error messages.
  335. ;; Style per the ok() function "$context", eg.
  336. ;; # Failed test 1 in foo.t at line 6
  337. ;;
  338. "^# Failed test [0-9]+ in \\([^ \t\r\n]+\\) at line \\([0-9]+\\)"
  339. 1 2)
  340. (perl--Test2
  341. ;; Or when comparing got/want values,
  342. ;; # Test 2 got: "xx" (t-compilation-perl-2.t at line 10)
  343. ;;
  344. ;; And under Test::Harness they're preceded by progress stuff with
  345. ;; \r and "NOK",
  346. ;; ... NOK 1# Test 1 got: "1234" (t/foo.t at line 46)
  347. ;;
  348. "^\\(.*NOK.*\\)?# Test [0-9]+ got:.* (\\([^ \t\r\n]+\\) at line \
  349. \\([0-9]+\\))"
  350. 2 3)
  351. (perl--Test::Harness
  352. ;; perl Test::Harness output, eg.
  353. ;; NOK 1# Test 1 got: "1234" (t/foo.t at line 46)
  354. ;;
  355. ;; Test::Harness is slightly designed for tty output, since
  356. ;; it prints CRs to overwrite progress messages, but if you
  357. ;; run it in with M-x compile this pattern can at least step
  358. ;; through the failures.
  359. ;;
  360. "^.*NOK.* \\([^ \t\r\n]+\\) at line \\([0-9]+\\)"
  361. 1 2)
  362. (weblint
  363. ;; The style comes from HTML::Lint::Error::as_string(), eg.
  364. ;; index.html (13:1) Unknown element <fdjsk>
  365. ;;
  366. ;; The pattern only matches filenames without spaces, since that
  367. ;; should be usual and should help reduce the chance of a false
  368. ;; match of a message from some unrelated program.
  369. ;;
  370. ;; This message style is quite close to the "ibm" entry which is
  371. ;; for IBM C, though that ibm bit doesn't put a space after the
  372. ;; filename.
  373. ;;
  374. "^\\([^ \t\r\n(]+\\) (\\([0-9]+\\):\\([0-9]+\\)) "
  375. 1 2 3)
  376. )
  377. "Alist of values for `compilation-error-regexp-alist'.")
  378. (defcustom compilation-error-regexp-alist
  379. (mapcar 'car compilation-error-regexp-alist-alist)
  380. "Alist that specifies how to match errors in compiler output.
  381. On GNU and Unix, any string is a valid filename, so these
  382. matchers must make some common sense assumptions, which catch
  383. normal cases. A shorter list will be lighter on resource usage.
  384. Instead of an alist element, you can use a symbol, which is
  385. looked up in `compilation-error-regexp-alist-alist'. You can see
  386. the predefined symbols and their effects in the file
  387. `etc/compilation.txt' (linked below if you are customizing this).
  388. Each elt has the form (REGEXP FILE [LINE COLUMN TYPE HYPERLINK
  389. HIGHLIGHT...]). If REGEXP matches, the FILE'th subexpression
  390. gives the file name, and the LINE'th subexpression gives the line
  391. number. The COLUMN'th subexpression gives the column number on
  392. that line.
  393. If FILE, LINE or COLUMN are nil or that index didn't match, that
  394. information is not present on the matched line. In that case the
  395. file name is assumed to be the same as the previous one in the
  396. buffer, line number defaults to 1 and column defaults to
  397. beginning of line's indentation.
  398. FILE can also have the form (FILE FORMAT...), where the FORMATs
  399. \(e.g. \"%s.c\") will be applied in turn to the recognized file
  400. name, until a file of that name is found. Or FILE can also be a
  401. function that returns (FILENAME) or (RELATIVE-FILENAME . DIRNAME).
  402. In the former case, FILENAME may be relative or absolute.
  403. LINE can also be of the form (LINE . END-LINE) meaning a range
  404. of lines. COLUMN can also be of the form (COLUMN . END-COLUMN)
  405. meaning a range of columns starting on LINE and ending on
  406. END-LINE, if that matched.
  407. TYPE is 2 or nil for a real error or 1 for warning or 0 for info.
  408. TYPE can also be of the form (WARNING . INFO). In that case this
  409. will be equivalent to 1 if the WARNING'th subexpression matched
  410. or else equivalent to 0 if the INFO'th subexpression matched.
  411. See `compilation-error-face', `compilation-warning-face',
  412. `compilation-info-face' and `compilation-skip-threshold'.
  413. What matched the HYPERLINK'th subexpression has `mouse-face' and
  414. `compilation-message-face' applied. If this is nil, the text
  415. matched by the whole REGEXP becomes the hyperlink.
  416. Additional HIGHLIGHTs as described under `font-lock-keywords' can
  417. be added."
  418. :type `(set :menu-tag "Pick"
  419. ,@(mapcar (lambda (elt)
  420. (list 'const (car elt)))
  421. compilation-error-regexp-alist-alist))
  422. :link `(file-link :tag "example file"
  423. ,(expand-file-name "compilation.txt" data-directory))
  424. :group 'compilation)
  425. ;;;###autoload(put 'compilation-directory 'safe-local-variable 'stringp)
  426. (defvar compilation-directory nil
  427. "Directory to restore to when doing `recompile'.")
  428. (defvar compilation-directory-matcher
  429. '("\\(?:Entering\\|Leavin\\(g\\)\\) directory `\\(.+\\)'$" (2 . 1))
  430. "A list for tracking when directories are entered or left.
  431. If nil, do not track directories, e.g. if all file names are absolute. The
  432. first element is the REGEXP matching these messages. It can match any number
  433. of variants, e.g. different languages. The remaining elements are all of the
  434. form (DIR . LEAVE). If for any one of these the DIR'th subexpression
  435. matches, that is a directory name. If LEAVE is nil or the corresponding
  436. LEAVE'th subexpression doesn't match, this message is about going into another
  437. directory. If it does match anything, this message is about going back to the
  438. directory we were in before the last entering message. If you change this,
  439. you may also want to change `compilation-page-delimiter'.")
  440. (defvar compilation-page-delimiter
  441. "^\\(?:\f\\|.*\\(?:Entering\\|Leaving\\) directory `.+'\n\\)+"
  442. "Value of `page-delimiter' in Compilation mode.")
  443. (defvar compilation-mode-font-lock-keywords
  444. '(;; configure output lines.
  445. ("^[Cc]hecking \\(?:[Ff]or \\|[Ii]f \\|[Ww]hether \\(?:to \\)?\\)?\\(.+\\)\\.\\.\\. *\\(?:(cached) *\\)?\\(\\(yes\\(?: .+\\)?\\)\\|no\\|\\(.*\\)\\)$"
  446. (1 font-lock-variable-name-face)
  447. (2 (compilation-face '(4 . 3))))
  448. ;; Command output lines. Recognize `make[n]:' lines too.
  449. ("^\\([[:alnum:]_/.+-]+\\)\\(\\[\\([0-9]+\\)\\]\\)?[ \t]*:"
  450. (1 font-lock-function-name-face) (3 compilation-line-face nil t))
  451. (" --?o\\(?:utfile\\|utput\\)?[= ]?\\(\\S +\\)" . 1)
  452. ("^Compilation \\(finished\\).*"
  453. (0 '(face nil message nil help-echo nil mouse-face nil) t)
  454. (1 compilation-info-face))
  455. ("^Compilation \\(exited abnormally\\|interrupt\\|killed\\|terminated\\|segmentation fault\\)\\(?:.*with code \\([0-9]+\\)\\)?.*"
  456. (0 '(face nil message nil help-echo nil mouse-face nil) t)
  457. (1 compilation-error-face)
  458. (2 compilation-error-face nil t)))
  459. "Additional things to highlight in Compilation mode.
  460. This gets tacked on the end of the generated expressions.")
  461. (defvar compilation-highlight-regexp t
  462. "Regexp matching part of visited source lines to highlight temporarily.
  463. Highlight entire line if t; don't highlight source lines if nil.")
  464. (defvar compilation-highlight-overlay nil
  465. "Overlay used to temporarily highlight compilation matches.")
  466. (defcustom compilation-error-screen-columns t
  467. "If non-nil, column numbers in error messages are screen columns.
  468. Otherwise they are interpreted as character positions, with
  469. each character occupying one column.
  470. The default is to use screen columns, which requires that the compilation
  471. program and Emacs agree about the display width of the characters,
  472. especially the TAB character."
  473. :type 'boolean
  474. :group 'compilation
  475. :version "20.4")
  476. (defcustom compilation-read-command t
  477. "Non-nil means \\[compile] reads the compilation command to use.
  478. Otherwise, \\[compile] just uses the value of `compile-command'.
  479. Note that changing this to nil may be a security risk, because a
  480. file might define a malicious `compile-command' as a file local
  481. variable, and you might not notice. Therefore, `compile-command'
  482. is considered unsafe if this variable is nil."
  483. :type 'boolean
  484. :group 'compilation)
  485. ;;;###autoload
  486. (defcustom compilation-ask-about-save t
  487. "Non-nil means \\[compile] asks which buffers to save before compiling.
  488. Otherwise, it saves all modified buffers without asking."
  489. :type 'boolean
  490. :group 'compilation)
  491. (defcustom compilation-save-buffers-predicate nil
  492. "The second argument (PRED) passed to `save-some-buffers' before compiling.
  493. E.g., one can set this to
  494. (lambda ()
  495. (string-prefix-p my-compilation-root (file-truename (buffer-file-name))))
  496. to limit saving to files located under `my-compilation-root'.
  497. Note, that, in general, `compilation-directory' cannot be used instead
  498. of `my-compilation-root' here."
  499. :type '(choice
  500. (const :tag "Default (save all file-visiting buffers)" nil)
  501. (const :tag "Save all buffers" t)
  502. function)
  503. :group 'compilation
  504. :version "24.1")
  505. ;;;###autoload
  506. (defcustom compilation-search-path '(nil)
  507. "List of directories to search for source files named in error messages.
  508. Elements should be directory names, not file names of directories.
  509. The value nil as an element means to try the default directory."
  510. :type '(repeat (choice (const :tag "Default" nil)
  511. (string :tag "Directory")))
  512. :group 'compilation)
  513. ;;;###autoload
  514. (defcustom compile-command (purecopy "make -k ")
  515. "Last shell command used to do a compilation; default for next compilation.
  516. Sometimes it is useful for files to supply local values for this variable.
  517. You might also use mode hooks to specify it in certain modes, like this:
  518. (add-hook 'c-mode-hook
  519. (lambda ()
  520. (unless (or (file-exists-p \"makefile\")
  521. (file-exists-p \"Makefile\"))
  522. (set (make-local-variable 'compile-command)
  523. (concat \"make -k \"
  524. (file-name-sans-extension buffer-file-name))))))"
  525. :type 'string
  526. :group 'compilation)
  527. ;;;###autoload(put 'compile-command 'safe-local-variable (lambda (a) (and (stringp a) (or (not (boundp 'compilation-read-command)) compilation-read-command))))
  528. ;;;###autoload
  529. (defcustom compilation-disable-input nil
  530. "If non-nil, send end-of-file as compilation process input.
  531. This only affects platforms that support asynchronous processes (see
  532. `start-process'); synchronous compilation processes never accept input."
  533. :type 'boolean
  534. :group 'compilation
  535. :version "22.1")
  536. ;; A weak per-compilation-buffer hash indexed by (FILENAME . DIRECTORY). Each
  537. ;; value is a FILE-STRUCTURE as described above, with the car eq to the hash
  538. ;; key. This holds the tree seen from root, for storing new nodes.
  539. (defvar compilation-locs ())
  540. (defvar compilation-debug nil
  541. "*Set this to t before creating a *compilation* buffer.
  542. Then every error line will have a debug text property with the matcher that
  543. fit this line and the match data. Use `describe-text-properties'.")
  544. (defvar compilation-exit-message-function nil "\
  545. If non-nil, called when a compilation process dies to return a status message.
  546. This should be a function of three arguments: process status, exit status,
  547. and exit message; it returns a cons (MESSAGE . MODELINE) of the strings to
  548. write into the compilation buffer, and to put in its mode line.")
  549. (defvar compilation-environment nil
  550. "*List of environment variables for compilation to inherit.
  551. Each element should be a string of the form ENVVARNAME=VALUE.
  552. This list is temporarily prepended to `process-environment' prior to
  553. starting the compilation process.")
  554. ;; History of compile commands.
  555. (defvar compile-history nil)
  556. (defface compilation-error
  557. '((t :inherit font-lock-warning-face))
  558. "Face used to highlight compiler errors."
  559. :group 'compilation
  560. :version "22.1")
  561. (defface compilation-warning
  562. '((((class color) (min-colors 16)) (:foreground "Orange" :weight bold))
  563. (((class color)) (:foreground "cyan" :weight bold))
  564. (t (:weight bold)))
  565. "Face used to highlight compiler warnings."
  566. :group 'compilation
  567. :version "22.1")
  568. (defface compilation-info
  569. '((((class color) (min-colors 16) (background light))
  570. (:foreground "Green3" :weight bold))
  571. (((class color) (min-colors 88) (background dark))
  572. (:foreground "Green1" :weight bold))
  573. (((class color) (min-colors 16) (background dark))
  574. (:foreground "Green" :weight bold))
  575. (((class color)) (:foreground "green" :weight bold))
  576. (t (:weight bold)))
  577. "Face used to highlight compiler information."
  578. :group 'compilation
  579. :version "22.1")
  580. (defface compilation-line-number
  581. '((t :inherit font-lock-variable-name-face))
  582. "Face for displaying line numbers in compiler messages."
  583. :group 'compilation
  584. :version "22.1")
  585. (defface compilation-column-number
  586. '((t :inherit font-lock-type-face))
  587. "Face for displaying column numbers in compiler messages."
  588. :group 'compilation
  589. :version "22.1")
  590. (defcustom compilation-message-face 'underline
  591. "Face name to use for whole messages.
  592. Faces `compilation-error-face', `compilation-warning-face',
  593. `compilation-info-face', `compilation-line-face' and
  594. `compilation-column-face' get prepended to this, when applicable."
  595. :type 'face
  596. :group 'compilation
  597. :version "22.1")
  598. (defvar compilation-error-face 'compilation-error
  599. "Face name to use for file name in error messages.")
  600. (defvar compilation-warning-face 'compilation-warning
  601. "Face name to use for file name in warning messages.")
  602. (defvar compilation-info-face 'compilation-info
  603. "Face name to use for file name in informational messages.")
  604. (defvar compilation-line-face 'compilation-line-number
  605. "Face name to use for line numbers in compiler messages.")
  606. (defvar compilation-column-face 'compilation-column-number
  607. "Face name to use for column numbers in compiler messages.")
  608. ;; same faces as dired uses
  609. (defvar compilation-enter-directory-face 'font-lock-function-name-face
  610. "Face name to use for entering directory messages.")
  611. (defvar compilation-leave-directory-face 'font-lock-type-face
  612. "Face name to use for leaving directory messages.")
  613. ;; Used for compatibility with the old compile.el.
  614. (defvaralias 'compilation-last-buffer 'next-error-last-buffer)
  615. (defvar compilation-parsing-end (make-marker))
  616. (defvar compilation-parse-errors-function nil)
  617. (defvar compilation-error-list nil)
  618. (defvar compilation-old-error-list nil)
  619. (defcustom compilation-auto-jump-to-first-error nil
  620. "If non-nil, automatically jump to the first error during compilation."
  621. :type 'boolean
  622. :group 'compilation
  623. :version "23.1")
  624. (defvar compilation-auto-jump-to-next nil
  625. "If non-nil, automatically jump to the next error encountered.")
  626. (make-variable-buffer-local 'compilation-auto-jump-to-next)
  627. (defvar buffer-modtime nil
  628. "The buffer modification time, for buffers not associated with files.")
  629. (make-variable-buffer-local 'buffer-modtime)
  630. (defvar compilation-skip-to-next-location t
  631. "*If non-nil, skip multiple error messages for the same source location.")
  632. (defcustom compilation-skip-threshold 1
  633. "Compilation motion commands skip less important messages.
  634. The value can be either 2 -- skip anything less than error, 1 --
  635. skip anything less than warning or 0 -- don't skip any messages.
  636. Note that all messages not positively identified as warning or
  637. info, are considered errors."
  638. :type '(choice (const :tag "Warnings and info" 2)
  639. (const :tag "Info" 1)
  640. (const :tag "None" 0))
  641. :group 'compilation
  642. :version "22.1")
  643. (defcustom compilation-skip-visited nil
  644. "Compilation motion commands skip visited messages if this is t.
  645. Visited messages are ones for which the file, line and column have been jumped
  646. to from the current content in the current compilation buffer, even if it was
  647. from a different message."
  648. :type 'boolean
  649. :group 'compilation
  650. :version "22.1")
  651. (defun compilation-face (type)
  652. (or (and (car type) (match-end (car type)) compilation-warning-face)
  653. (and (cdr type) (match-end (cdr type)) compilation-info-face)
  654. compilation-error-face))
  655. ;; Internal function for calculating the text properties of a directory
  656. ;; change message. The directory property is important, because it is
  657. ;; the stack of nested enter-messages. Relative filenames on the following
  658. ;; lines are relative to the top of the stack.
  659. (defun compilation-directory-properties (idx leave)
  660. (if leave (setq leave (match-end leave)))
  661. ;; find previous stack, and push onto it, or if `leave' pop it
  662. (let ((dir (previous-single-property-change (point) 'directory)))
  663. (setq dir (if dir (or (get-text-property (1- dir) 'directory)
  664. (get-text-property dir 'directory))))
  665. `(face ,(if leave
  666. compilation-leave-directory-face
  667. compilation-enter-directory-face)
  668. directory ,(if leave
  669. (or (cdr dir)
  670. '(nil)) ; nil only isn't a property-change
  671. (cons (match-string-no-properties idx) dir))
  672. mouse-face highlight
  673. keymap compilation-button-map
  674. help-echo "mouse-2: visit destination directory")))
  675. ;; Data type `reverse-ordered-alist' retriever. This function retrieves the
  676. ;; KEY element from the ALIST, creating it in the right position if not already
  677. ;; present. ALIST structure is
  678. ;; '(ANCHOR (KEY1 ...) (KEY2 ...)... (KEYn ALIST ...))
  679. ;; ANCHOR is ignored, but necessary so that elements can be inserted. KEY1
  680. ;; may be nil. The other KEYs are ordered backwards so that growing line
  681. ;; numbers can be inserted in front and searching can abort after half the
  682. ;; list on average.
  683. (eval-when-compile ;Don't keep it at runtime if not needed.
  684. (defmacro compilation-assq (key alist)
  685. `(let* ((l1 ,alist)
  686. (l2 (cdr l1)))
  687. (car (if (if (null ,key)
  688. (if l2 (null (caar l2)))
  689. (while (if l2 (if (caar l2) (< ,key (caar l2)) t))
  690. (setq l1 l2
  691. l2 (cdr l1)))
  692. (if l2 (eq ,key (caar l2))))
  693. l2
  694. (setcdr l1 (cons (list ,key) l2)))))))
  695. (defun compilation-auto-jump (buffer pos)
  696. (with-current-buffer buffer
  697. (goto-char pos)
  698. (let ((win (get-buffer-window buffer 0)))
  699. (if win (set-window-point win pos)))
  700. (if compilation-auto-jump-to-first-error
  701. (compile-goto-error))))
  702. ;; This function is the central driver, called when font-locking to gather
  703. ;; all information needed to later jump to corresponding source code.
  704. ;; Return a property list with all meta information on this error location.
  705. (defun compilation-error-properties (file line end-line col end-col type fmt)
  706. (unless (< (next-single-property-change (match-beginning 0)
  707. 'directory nil (point))
  708. (point))
  709. (if file
  710. (if (functionp file)
  711. (setq file (funcall file))
  712. (let (dir)
  713. (setq file (match-string-no-properties file))
  714. (unless (file-name-absolute-p file)
  715. (setq dir (previous-single-property-change (point) 'directory)
  716. dir (if dir (or (get-text-property (1- dir) 'directory)
  717. (get-text-property dir 'directory)))))
  718. (setq file (cons file (car dir)))))
  719. ;; This message didn't mention one, get it from previous
  720. (let ((prev-pos
  721. ;; Find the previous message.
  722. (previous-single-property-change (point) 'message)))
  723. (if prev-pos
  724. ;; Get the file structure that belongs to it.
  725. (let* ((prev
  726. (or (get-text-property (1- prev-pos) 'message)
  727. (get-text-property prev-pos 'message)))
  728. (prev-struct
  729. (car (nth 2 (car prev)))))
  730. ;; Construct FILE . DIR from that.
  731. (if prev-struct
  732. (setq file (cons (car prev-struct)
  733. (cadr prev-struct))))))
  734. (unless file
  735. (setq file '("*unknown*")))))
  736. ;; All of these fields are optional, get them only if we have an index, and
  737. ;; it matched some part of the message.
  738. (and line
  739. (setq line (match-string-no-properties line))
  740. (setq line (string-to-number line)))
  741. (and end-line
  742. (setq end-line (match-string-no-properties end-line))
  743. (setq end-line (string-to-number end-line)))
  744. (if col
  745. (if (functionp col)
  746. (setq col (funcall col))
  747. (and
  748. (setq col (match-string-no-properties col))
  749. (setq col (- (string-to-number col) compilation-first-column)))))
  750. (if (and end-col (functionp end-col))
  751. (setq end-col (funcall end-col))
  752. (if (and end-col (setq end-col (match-string-no-properties end-col)))
  753. (setq end-col (- (string-to-number end-col) compilation-first-column -1))
  754. (if end-line (setq end-col -1))))
  755. (if (consp type) ; not a static type, check what it is.
  756. (setq type (or (and (car type) (match-end (car type)) 1)
  757. (and (cdr type) (match-end (cdr type)) 0)
  758. 2)))
  759. (when (and compilation-auto-jump-to-next
  760. (>= type compilation-skip-threshold))
  761. (kill-local-variable 'compilation-auto-jump-to-next)
  762. (run-with-timer 0 nil 'compilation-auto-jump
  763. (current-buffer) (match-beginning 0)))
  764. (compilation-internal-error-properties file line end-line col end-col type fmt)))
  765. (defun compilation-move-to-column (col screen)
  766. "Go to column COL on the current line.
  767. If SCREEN is non-nil, columns are screen columns, otherwise, they are
  768. just char-counts."
  769. (if screen
  770. (move-to-column (max col 0))
  771. (goto-char (min (+ (line-beginning-position) col) (line-end-position)))))
  772. (defun compilation-internal-error-properties (file line end-line col end-col type fmts)
  773. "Get the meta-info that will be added as text-properties.
  774. LINE, END-LINE, COL, END-COL are integers or nil.
  775. TYPE can be 0, 1, or 2, meaning error, warning, or just info.
  776. FILE should be (FILENAME) or (RELATIVE-FILENAME . DIRNAME) or nil.
  777. FMTS is a list of format specs for transforming the file name.
  778. (See `compilation-error-regexp-alist'.)"
  779. (unless file (setq file '("*unknown*")))
  780. (let* ((file-struct (compilation-get-file-structure file fmts))
  781. ;; Get first already existing marker (if any has one, all have one).
  782. ;; Do this first, as the compilation-assq`s may create new nodes.
  783. (marker-line (car (cddr file-struct))) ; a line structure
  784. (marker (nth 3 (cadr marker-line))) ; its marker
  785. (compilation-error-screen-columns compilation-error-screen-columns)
  786. end-marker loc end-loc)
  787. (if (not (and marker (marker-buffer marker)))
  788. (setq marker nil) ; no valid marker for this file
  789. (setq loc (or line 1)) ; normalize no linenumber to line 1
  790. (catch 'marker ; find nearest loc, at least one exists
  791. (dolist (x (nthcdr 3 file-struct)) ; loop over remaining lines
  792. (if (> (car x) loc) ; still bigger
  793. (setq marker-line x)
  794. (if (> (- (or (car marker-line) 1) loc)
  795. (- loc (car x))) ; current line is nearer
  796. (setq marker-line x))
  797. (throw 'marker t))))
  798. (setq marker (nth 3 (cadr marker-line))
  799. marker-line (or (car marker-line) 1))
  800. (with-current-buffer (marker-buffer marker)
  801. (save-excursion
  802. (save-restriction
  803. (widen)
  804. (goto-char (marker-position marker))
  805. (when (or end-col end-line)
  806. (beginning-of-line (- (or end-line line) marker-line -1))
  807. (if (or (null end-col) (< end-col 0))
  808. (end-of-line)
  809. (compilation-move-to-column
  810. end-col compilation-error-screen-columns))
  811. (setq end-marker (list (point-marker))))
  812. (beginning-of-line (if end-line
  813. (- line end-line -1)
  814. (- loc marker-line -1)))
  815. (if col
  816. (compilation-move-to-column
  817. col compilation-error-screen-columns)
  818. (forward-to-indentation 0))
  819. (setq marker (list (point-marker)))))))
  820. (setq loc (compilation-assq line (cdr file-struct)))
  821. (if end-line
  822. (setq end-loc (compilation-assq end-line (cdr file-struct))
  823. end-loc (compilation-assq end-col end-loc))
  824. (if end-col ; use same line element
  825. (setq end-loc (compilation-assq end-col loc))))
  826. (setq loc (compilation-assq col loc))
  827. ;; If they are new, make the loc(s) reference the file they point to.
  828. (or (cdr loc) (setcdr loc `(,line ,file-struct ,@marker)))
  829. (if end-loc
  830. (or (cdr end-loc)
  831. (setcdr end-loc `(,(or end-line line) ,file-struct ,@end-marker))))
  832. ;; Must start with face
  833. `(face ,compilation-message-face
  834. message (,loc ,type ,end-loc)
  835. ,@(if compilation-debug
  836. `(debug (,(assoc (with-no-warnings matcher) font-lock-keywords)
  837. ,@(match-data))))
  838. help-echo ,(if col
  839. "mouse-2: visit this file, line and column"
  840. (if line
  841. "mouse-2: visit this file and line"
  842. "mouse-2: visit this file"))
  843. keymap compilation-button-map
  844. mouse-face highlight)))
  845. (defun compilation-mode-font-lock-keywords ()
  846. "Return expressions to highlight in Compilation mode."
  847. (if compilation-parse-errors-function
  848. ;; An old package! Try the compatibility code.
  849. '((compilation-compat-parse-errors))
  850. (append
  851. ;; make directory tracking
  852. (if compilation-directory-matcher
  853. `((,(car compilation-directory-matcher)
  854. ,@(mapcar (lambda (elt)
  855. `(,(car elt)
  856. (compilation-directory-properties
  857. ,(car elt) ,(cdr elt))
  858. t t))
  859. (cdr compilation-directory-matcher)))))
  860. ;; Compiler warning/error lines.
  861. (mapcar
  862. (lambda (item)
  863. (if (symbolp item)
  864. (setq item (cdr (assq item
  865. compilation-error-regexp-alist-alist))))
  866. (let ((file (nth 1 item))
  867. (line (nth 2 item))
  868. (col (nth 3 item))
  869. (type (nth 4 item))
  870. (pat (car item))
  871. end-line end-col fmt)
  872. ;; omake reports some error indented, so skip the indentation.
  873. ;; another solution is to modify (some?) regexps in
  874. ;; `compilation-error-regexp-alist'.
  875. ;; note that omake usage is not limited to ocaml and C (for stubs).
  876. (when (and (= ?^ (aref pat 0)) ; anchored: starts with "^"
  877. ;; but does not allow an arbitrary number of leading spaces
  878. (not (and (= ? (aref pat 1)) (= ?* (aref pat 2)))))
  879. (setq pat (concat "^ *" (substring pat 1))))
  880. (if (consp file) (setq fmt (cdr file) file (car file)))
  881. (if (consp line) (setq end-line (cdr line) line (car line)))
  882. (if (consp col) (setq end-col (cdr col) col (car col)))
  883. (if (functionp line)
  884. ;; The old compile.el had here an undocumented hook that
  885. ;; allowed `line' to be a function that computed the actual
  886. ;; error location. Let's do our best.
  887. `(,pat
  888. (0 (save-match-data
  889. (compilation-compat-error-properties
  890. (funcall ',line (cons (match-string ,file)
  891. (cons default-directory
  892. ',(nthcdr 4 item)))
  893. ,(if col `(match-string ,col))))))
  894. (,file compilation-error-face t))
  895. (unless (or (null (nth 5 item)) (integerp (nth 5 item)))
  896. (error "HYPERLINK should be an integer: %s" (nth 5 item)))
  897. `(,pat
  898. ,@(when (integerp file)
  899. `((,file ,(if (consp type)
  900. `(compilation-face ',type)
  901. (aref [compilation-info-face
  902. compilation-warning-face
  903. compilation-error-face]
  904. (or type 2))))))
  905. ,@(when line
  906. `((,line compilation-line-face nil t)))
  907. ,@(when end-line
  908. `((,end-line compilation-line-face nil t)))
  909. ,@(when (integerp col)
  910. `((,col compilation-column-face nil t)))
  911. ,@(when (integerp end-col)
  912. `((,end-col compilation-column-face nil t)))
  913. ,@(nthcdr 6 item)
  914. (,(or (nth 5 item) 0)
  915. (compilation-error-properties ',file ,line ,end-line
  916. ,col ,end-col ',(or type 2)
  917. ',fmt)
  918. append))))) ; for compilation-message-face
  919. compilation-error-regexp-alist)
  920. compilation-mode-font-lock-keywords)))
  921. (defun compilation-read-command (command)
  922. (read-shell-command "Compile command: " command
  923. (if (equal (car compile-history) command)
  924. '(compile-history . 1)
  925. 'compile-history)))
  926. ;;;###autoload
  927. (defun compile (command &optional comint)
  928. "Compile the program including the current buffer. Default: run `make'.
  929. Runs COMMAND, a shell command, in a separate process asynchronously
  930. with output going to the buffer `*compilation*'.
  931. You can then use the command \\[next-error] to find the next error message
  932. and move to the source code that caused it.
  933. If optional second arg COMINT is t the buffer will be in Comint mode with
  934. `compilation-shell-minor-mode'.
  935. Interactively, prompts for the command if `compilation-read-command' is
  936. non-nil; otherwise uses `compile-command'. With prefix arg, always prompts.
  937. Additionally, with universal prefix arg, compilation buffer will be in
  938. comint mode, i.e. interactive.
  939. To run more than one compilation at once, start one then rename
  940. the \`*compilation*' buffer to some other name with
  941. \\[rename-buffer]. Then _switch buffers_ and start the new compilation.
  942. It will create a new \`*compilation*' buffer.
  943. On most systems, termination of the main compilation process
  944. kills its subprocesses.
  945. The name used for the buffer is actually whatever is returned by
  946. the function in `compilation-buffer-name-function', so you can set that
  947. to a function that generates a unique name."
  948. (interactive
  949. (list
  950. (let ((command (eval compile-command)))
  951. (if (or compilation-read-command current-prefix-arg)
  952. (compilation-read-command command)
  953. command))
  954. (consp current-prefix-arg)))
  955. (unless (equal command (eval compile-command))
  956. (setq compile-command command))
  957. (save-some-buffers (not compilation-ask-about-save)
  958. compilation-save-buffers-predicate)
  959. (setq-default compilation-directory default-directory)
  960. (compilation-start command comint))
  961. ;; run compile with the default command line
  962. (defun recompile (&optional edit-command)
  963. "Re-compile the program including the current buffer.
  964. If this is run in a Compilation mode buffer, re-use the arguments from the
  965. original use. Otherwise, recompile using `compile-command'.
  966. If the optional argument `edit-command' is non-nil, the command can be edited."
  967. (interactive "P")
  968. (save-some-buffers (not compilation-ask-about-save)
  969. compilation-save-buffers-predicate)
  970. (let ((default-directory (or compilation-directory default-directory)))
  971. (when edit-command
  972. (setcar compilation-arguments
  973. (compilation-read-command (car compilation-arguments))))
  974. (apply 'compilation-start (or compilation-arguments
  975. `(,(eval compile-command))))))
  976. (defcustom compilation-scroll-output nil
  977. "Non-nil to scroll the *compilation* buffer window as output appears.
  978. Setting it causes the Compilation mode commands to put point at the
  979. end of their output window so that the end of the output is always
  980. visible rather than the beginning.
  981. The value `first-error' stops scrolling at the first error, and leaves
  982. point on its location in the *compilation* buffer."
  983. :type '(choice (const :tag "No scrolling" nil)
  984. (const :tag "Scroll compilation output" t)
  985. (const :tag "Stop scrolling at the first error" first-error))
  986. :version "20.3"
  987. :group 'compilation)
  988. (defun compilation-buffer-name (mode-name mode-command name-function)
  989. "Return the name of a compilation buffer to use.
  990. If NAME-FUNCTION is non-nil, call it with one argument MODE-NAME
  991. to determine the buffer name.
  992. Likewise if `compilation-buffer-name-function' is non-nil.
  993. If current buffer has the major mode MODE-COMMAND,
  994. return the name of the current buffer, so that it gets reused.
  995. Otherwise, construct a buffer name from MODE-NAME."
  996. (cond (name-function
  997. (funcall name-function mode-name))
  998. (compilation-buffer-name-function
  999. (funcall compilation-buffer-name-function mode-name))
  1000. ((eq mode-command major-mode)
  1001. (buffer-name))
  1002. (t
  1003. (concat "*" (downcase mode-name) "*"))))
  1004. ;; This is a rough emulation of the old hack, until the transition to new
  1005. ;; compile is complete.
  1006. (defun compile-internal (command error-message
  1007. &optional name-of-mode parser
  1008. error-regexp-alist name-function
  1009. enter-regexp-alist leave-regexp-alist
  1010. file-regexp-alist nomessage-regexp-alist
  1011. no-async highlight-regexp local-map)
  1012. (if parser
  1013. (error "Compile now works very differently, see `compilation-error-regexp-alist'"))
  1014. (let ((compilation-error-regexp-alist
  1015. (append file-regexp-alist (or error-regexp-alist
  1016. compilation-error-regexp-alist)))
  1017. (compilation-error (replace-regexp-in-string "^No more \\(.+\\)s\\.?"
  1018. "\\1" error-message)))
  1019. (compilation-start command nil name-function highlight-regexp)))
  1020. (make-obsolete 'compile-internal 'compilation-start "22.1")
  1021. ;;;###autoload
  1022. (defun compilation-start (command &optional mode name-function highlight-regexp)
  1023. "Run compilation command COMMAND (low level interface).
  1024. If COMMAND starts with a cd command, that becomes the `default-directory'.
  1025. The rest of the arguments are optional; for them, nil means use the default.
  1026. MODE is the major mode to set in the compilation buffer. Mode
  1027. may also be t meaning use `compilation-shell-minor-mode' under `comint-mode'.
  1028. If NAME-FUNCTION is non-nil, call it with one argument (the mode name)
  1029. to determine the buffer name. Otherwise, the default is to
  1030. reuses the current buffer if it has the proper major mode,
  1031. else use or create a buffer with name based on the major mode.
  1032. If HIGHLIGHT-REGEXP is non-nil, `next-error' will temporarily highlight
  1033. the matching section of the visited source line; the default is to use the
  1034. global value of `compilation-highlight-regexp'.
  1035. Returns the compilation buffer created."
  1036. (or mode (setq mode 'compilation-mode))
  1037. (let* ((name-of-mode
  1038. (if (eq mode t)
  1039. "compilation"
  1040. (replace-regexp-in-string "-mode$" "" (symbol-name mode))))
  1041. (thisdir default-directory)
  1042. outwin outbuf)
  1043. (with-current-buffer
  1044. (setq outbuf
  1045. (get-buffer-create
  1046. (compilation-buffer-name name-of-mode mode name-function)))
  1047. (let ((comp-proc (get-buffer-process (current-buffer))))
  1048. (if comp-proc
  1049. (if (or (not (eq (process-status comp-proc) 'run))
  1050. (yes-or-no-p
  1051. (format "A %s process is running; kill it? "
  1052. name-of-mode)))
  1053. (condition-case ()
  1054. (progn
  1055. (interrupt-process comp-proc)
  1056. (sit-for 1)
  1057. (delete-process comp-proc))
  1058. (error nil))
  1059. (error "Cannot have two processes in `%s' at once"
  1060. (buffer-name)))))
  1061. ;; first transfer directory from where M-x compile was called
  1062. (setq default-directory thisdir)
  1063. ;; Make compilation buffer read-only. The filter can still write it.
  1064. ;; Clear out the compilation buffer.
  1065. (let ((inhibit-read-only t)
  1066. (default-directory thisdir))
  1067. ;; Then evaluate a cd command if any, but don't perform it yet, else
  1068. ;; start-command would do it again through the shell: (cd "..") AND
  1069. ;; sh -c "cd ..; make"
  1070. (cd (if (string-match "\\`\\s *cd\\(?:\\s +\\(\\S +?\\)\\)?\\s *[;&\n]"
  1071. command)
  1072. (if (match-end 1)
  1073. (substitute-env-vars (match-string 1 command))
  1074. "~")
  1075. default-directory))
  1076. (erase-buffer)
  1077. ;; Select the desired mode.
  1078. (if (not (eq mode t))
  1079. (p

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