PageRenderTime 71ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 1ms

/lisp/progmodes/compile.el

http://github.com/typester/emacs
Emacs Lisp | 2385 lines | 1741 code | 232 blank | 412 comment | 75 complexity | 5c180a536f949658176f2959b77cf927 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
  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. "\\(\\(?:[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. :type 'boolean
  480. :group 'compilation)
  481. ;;;###autoload
  482. (defcustom compilation-ask-about-save t
  483. "Non-nil means \\[compile] asks which buffers to save before compiling.
  484. Otherwise, it saves all modified buffers without asking."
  485. :type 'boolean
  486. :group 'compilation)
  487. ;;;###autoload
  488. (defcustom compilation-search-path '(nil)
  489. "List of directories to search for source files named in error messages.
  490. Elements should be directory names, not file names of directories.
  491. The value nil as an element means to try the default directory."
  492. :type '(repeat (choice (const :tag "Default" nil)
  493. (string :tag "Directory")))
  494. :group 'compilation)
  495. ;;;###autoload
  496. (defcustom compile-command (purecopy "make -k ")
  497. "Last shell command used to do a compilation; default for next compilation.
  498. Sometimes it is useful for files to supply local values for this variable.
  499. You might also use mode hooks to specify it in certain modes, like this:
  500. (add-hook 'c-mode-hook
  501. (lambda ()
  502. (unless (or (file-exists-p \"makefile\")
  503. (file-exists-p \"Makefile\"))
  504. (set (make-local-variable 'compile-command)
  505. (concat \"make -k \"
  506. (file-name-sans-extension buffer-file-name))))))"
  507. :type 'string
  508. :group 'compilation)
  509. ;;;###autoload(put 'compile-command 'safe-local-variable 'stringp)
  510. ;;;###autoload
  511. (defcustom compilation-disable-input nil
  512. "If non-nil, send end-of-file as compilation process input.
  513. This only affects platforms that support asynchronous processes (see
  514. `start-process'); synchronous compilation processes never accept input."
  515. :type 'boolean
  516. :group 'compilation
  517. :version "22.1")
  518. ;; A weak per-compilation-buffer hash indexed by (FILENAME . DIRECTORY). Each
  519. ;; value is a FILE-STRUCTURE as described above, with the car eq to the hash
  520. ;; key. This holds the tree seen from root, for storing new nodes.
  521. (defvar compilation-locs ())
  522. (defvar compilation-debug nil
  523. "*Set this to t before creating a *compilation* buffer.
  524. Then every error line will have a debug text property with the matcher that
  525. fit this line and the match data. Use `describe-text-properties'.")
  526. (defvar compilation-exit-message-function nil "\
  527. If non-nil, called when a compilation process dies to return a status message.
  528. This should be a function of three arguments: process status, exit status,
  529. and exit message; it returns a cons (MESSAGE . MODELINE) of the strings to
  530. write into the compilation buffer, and to put in its mode line.")
  531. (defvar compilation-environment nil
  532. "*List of environment variables for compilation to inherit.
  533. Each element should be a string of the form ENVVARNAME=VALUE.
  534. This list is temporarily prepended to `process-environment' prior to
  535. starting the compilation process.")
  536. ;; History of compile commands.
  537. (defvar compile-history nil)
  538. (defface compilation-error
  539. '((t :inherit font-lock-warning-face))
  540. "Face used to highlight compiler errors."
  541. :group 'compilation
  542. :version "22.1")
  543. (defface compilation-warning
  544. '((((class color) (min-colors 16)) (:foreground "Orange" :weight bold))
  545. (((class color)) (:foreground "cyan" :weight bold))
  546. (t (:weight bold)))
  547. "Face used to highlight compiler warnings."
  548. :group 'compilation
  549. :version "22.1")
  550. (defface compilation-info
  551. '((((class color) (min-colors 16) (background light))
  552. (:foreground "Green3" :weight bold))
  553. (((class color) (min-colors 88) (background dark))
  554. (:foreground "Green1" :weight bold))
  555. (((class color) (min-colors 16) (background dark))
  556. (:foreground "Green" :weight bold))
  557. (((class color)) (:foreground "green" :weight bold))
  558. (t (:weight bold)))
  559. "Face used to highlight compiler information."
  560. :group 'compilation
  561. :version "22.1")
  562. (defface compilation-line-number
  563. '((t :inherit font-lock-variable-name-face))
  564. "Face for displaying line numbers in compiler messages."
  565. :group 'compilation
  566. :version "22.1")
  567. (defface compilation-column-number
  568. '((t :inherit font-lock-type-face))
  569. "Face for displaying column numbers in compiler messages."
  570. :group 'compilation
  571. :version "22.1")
  572. (defcustom compilation-message-face 'underline
  573. "Face name to use for whole messages.
  574. Faces `compilation-error-face', `compilation-warning-face',
  575. `compilation-info-face', `compilation-line-face' and
  576. `compilation-column-face' get prepended to this, when applicable."
  577. :type 'face
  578. :group 'compilation
  579. :version "22.1")
  580. (defvar compilation-error-face 'compilation-error
  581. "Face name to use for file name in error messages.")
  582. (defvar compilation-warning-face 'compilation-warning
  583. "Face name to use for file name in warning messages.")
  584. (defvar compilation-info-face 'compilation-info
  585. "Face name to use for file name in informational messages.")
  586. (defvar compilation-line-face 'compilation-line-number
  587. "Face name to use for line numbers in compiler messages.")
  588. (defvar compilation-column-face 'compilation-column-number
  589. "Face name to use for column numbers in compiler messages.")
  590. ;; same faces as dired uses
  591. (defvar compilation-enter-directory-face 'font-lock-function-name-face
  592. "Face name to use for entering directory messages.")
  593. (defvar compilation-leave-directory-face 'font-lock-type-face
  594. "Face name to use for leaving directory messages.")
  595. ;; Used for compatibility with the old compile.el.
  596. (defvaralias 'compilation-last-buffer 'next-error-last-buffer)
  597. (defvar compilation-parsing-end (make-marker))
  598. (defvar compilation-parse-errors-function nil)
  599. (defvar compilation-error-list nil)
  600. (defvar compilation-old-error-list nil)
  601. (defcustom compilation-auto-jump-to-first-error nil
  602. "If non-nil, automatically jump to the first error during compilation."
  603. :type 'boolean
  604. :group 'compilation
  605. :version "23.1")
  606. (defvar compilation-auto-jump-to-next nil
  607. "If non-nil, automatically jump to the next error encountered.")
  608. (make-variable-buffer-local 'compilation-auto-jump-to-next)
  609. (defvar compilation-skip-to-next-location t
  610. "*If non-nil, skip multiple error messages for the same source location.")
  611. (defcustom compilation-skip-threshold 1
  612. "Compilation motion commands skip less important messages.
  613. The value can be either 2 -- skip anything less than error, 1 --
  614. skip anything less than warning or 0 -- don't skip any messages.
  615. Note that all messages not positively identified as warning or
  616. info, are considered errors."
  617. :type '(choice (const :tag "Warnings and info" 2)
  618. (const :tag "Info" 1)
  619. (const :tag "None" 0))
  620. :group 'compilation
  621. :version "22.1")
  622. (defcustom compilation-skip-visited nil
  623. "Compilation motion commands skip visited messages if this is t.
  624. Visited messages are ones for which the file, line and column have been jumped
  625. to from the current content in the current compilation buffer, even if it was
  626. from a different message."
  627. :type 'boolean
  628. :group 'compilation
  629. :version "22.1")
  630. (defun compilation-face (type)
  631. (or (and (car type) (match-end (car type)) compilation-warning-face)
  632. (and (cdr type) (match-end (cdr type)) compilation-info-face)
  633. compilation-error-face))
  634. ;; Internal function for calculating the text properties of a directory
  635. ;; change message. The directory property is important, because it is
  636. ;; the stack of nested enter-messages. Relative filenames on the following
  637. ;; lines are relative to the top of the stack.
  638. (defun compilation-directory-properties (idx leave)
  639. (if leave (setq leave (match-end leave)))
  640. ;; find previous stack, and push onto it, or if `leave' pop it
  641. (let ((dir (previous-single-property-change (point) 'directory)))
  642. (setq dir (if dir (or (get-text-property (1- dir) 'directory)
  643. (get-text-property dir 'directory))))
  644. `(face ,(if leave
  645. compilation-leave-directory-face
  646. compilation-enter-directory-face)
  647. directory ,(if leave
  648. (or (cdr dir)
  649. '(nil)) ; nil only isn't a property-change
  650. (cons (match-string-no-properties idx) dir))
  651. mouse-face highlight
  652. keymap compilation-button-map
  653. help-echo "mouse-2: visit destination directory")))
  654. ;; Data type `reverse-ordered-alist' retriever. This function retrieves the
  655. ;; KEY element from the ALIST, creating it in the right position if not already
  656. ;; present. ALIST structure is
  657. ;; '(ANCHOR (KEY1 ...) (KEY2 ...)... (KEYn ALIST ...))
  658. ;; ANCHOR is ignored, but necessary so that elements can be inserted. KEY1
  659. ;; may be nil. The other KEYs are ordered backwards so that growing line
  660. ;; numbers can be inserted in front and searching can abort after half the
  661. ;; list on average.
  662. (eval-when-compile ;Don't keep it at runtime if not needed.
  663. (defmacro compilation-assq (key alist)
  664. `(let* ((l1 ,alist)
  665. (l2 (cdr l1)))
  666. (car (if (if (null ,key)
  667. (if l2 (null (caar l2)))
  668. (while (if l2 (if (caar l2) (< ,key (caar l2)) t))
  669. (setq l1 l2
  670. l2 (cdr l1)))
  671. (if l2 (eq ,key (caar l2))))
  672. l2
  673. (setcdr l1 (cons (list ,key) l2)))))))
  674. (defun compilation-auto-jump (buffer pos)
  675. (with-current-buffer buffer
  676. (goto-char pos)
  677. (let ((win (get-buffer-window buffer 0)))
  678. (if win (set-window-point win pos)))
  679. (if compilation-auto-jump-to-first-error
  680. (compile-goto-error))))
  681. ;; This function is the central driver, called when font-locking to gather
  682. ;; all information needed to later jump to corresponding source code.
  683. ;; Return a property list with all meta information on this error location.
  684. (defun compilation-error-properties (file line end-line col end-col type fmt)
  685. (unless (< (next-single-property-change (match-beginning 0)
  686. 'directory nil (point))
  687. (point))
  688. (if file
  689. (if (functionp file)
  690. (setq file (funcall file))
  691. (let (dir)
  692. (setq file (match-string-no-properties file))
  693. (unless (file-name-absolute-p file)
  694. (setq dir (previous-single-property-change (point) 'directory)
  695. dir (if dir (or (get-text-property (1- dir) 'directory)
  696. (get-text-property dir 'directory)))))
  697. (setq file (cons file (car dir)))))
  698. ;; This message didn't mention one, get it from previous
  699. (let ((prev-pos
  700. ;; Find the previous message.
  701. (previous-single-property-change (point) 'message)))
  702. (if prev-pos
  703. ;; Get the file structure that belongs to it.
  704. (let* ((prev
  705. (or (get-text-property (1- prev-pos) 'message)
  706. (get-text-property prev-pos 'message)))
  707. (prev-struct
  708. (car (nth 2 (car prev)))))
  709. ;; Construct FILE . DIR from that.
  710. (if prev-struct
  711. (setq file (cons (car prev-struct)
  712. (cadr prev-struct))))))
  713. (unless file
  714. (setq file '("*unknown*")))))
  715. ;; All of these fields are optional, get them only if we have an index, and
  716. ;; it matched some part of the message.
  717. (and line
  718. (setq line (match-string-no-properties line))
  719. (setq line (string-to-number line)))
  720. (and end-line
  721. (setq end-line (match-string-no-properties end-line))
  722. (setq end-line (string-to-number end-line)))
  723. (if col
  724. (if (functionp col)
  725. (setq col (funcall col))
  726. (and
  727. (setq col (match-string-no-properties col))
  728. (setq col (- (string-to-number col) compilation-first-column)))))
  729. (if (and end-col (functionp end-col))
  730. (setq end-col (funcall end-col))
  731. (if (and end-col (setq end-col (match-string-no-properties end-col)))
  732. (setq end-col (- (string-to-number end-col) compilation-first-column -1))
  733. (if end-line (setq end-col -1))))
  734. (if (consp type) ; not a static type, check what it is.
  735. (setq type (or (and (car type) (match-end (car type)) 1)
  736. (and (cdr type) (match-end (cdr type)) 0)
  737. 2)))
  738. (when (and compilation-auto-jump-to-next
  739. (>= type compilation-skip-threshold))
  740. (kill-local-variable 'compilation-auto-jump-to-next)
  741. (run-with-timer 0 nil 'compilation-auto-jump
  742. (current-buffer) (match-beginning 0)))
  743. (compilation-internal-error-properties file line end-line col end-col type fmt)))
  744. (defun compilation-move-to-column (col screen)
  745. "Go to column COL on the current line.
  746. If SCREEN is non-nil, columns are screen columns, otherwise, they are
  747. just char-counts."
  748. (if screen
  749. (move-to-column (max col 0))
  750. (goto-char (min (+ (line-beginning-position) col) (line-end-position)))))
  751. (defun compilation-internal-error-properties (file line end-line col end-col type fmts)
  752. "Get the meta-info that will be added as text-properties.
  753. LINE, END-LINE, COL, END-COL are integers or nil.
  754. TYPE can be 0, 1, or 2, meaning error, warning, or just info.
  755. FILE should be (FILENAME) or (RELATIVE-FILENAME . DIRNAME) or nil.
  756. FMTS is a list of format specs for transforming the file name.
  757. (See `compilation-error-regexp-alist'.)"
  758. (unless file (setq file '("*unknown*")))
  759. (let* ((file-struct (compilation-get-file-structure file fmts))
  760. ;; Get first already existing marker (if any has one, all have one).
  761. ;; Do this first, as the compilation-assq`s may create new nodes.
  762. (marker-line (car (cddr file-struct))) ; a line structure
  763. (marker (nth 3 (cadr marker-line))) ; its marker
  764. (compilation-error-screen-columns compilation-error-screen-columns)
  765. end-marker loc end-loc)
  766. (if (not (and marker (marker-buffer marker)))
  767. (setq marker nil) ; no valid marker for this file
  768. (setq loc (or line 1)) ; normalize no linenumber to line 1
  769. (catch 'marker ; find nearest loc, at least one exists
  770. (dolist (x (nthcdr 3 file-struct)) ; loop over remaining lines
  771. (if (> (car x) loc) ; still bigger
  772. (setq marker-line x)
  773. (if (> (- (or (car marker-line) 1) loc)
  774. (- loc (car x))) ; current line is nearer
  775. (setq marker-line x))
  776. (throw 'marker t))))
  777. (setq marker (nth 3 (cadr marker-line))
  778. marker-line (or (car marker-line) 1))
  779. (with-current-buffer (marker-buffer marker)
  780. (save-excursion
  781. (save-restriction
  782. (widen)
  783. (goto-char (marker-position marker))
  784. (when (or end-col end-line)
  785. (beginning-of-line (- (or end-line line) marker-line -1))
  786. (if (or (null end-col) (< end-col 0))
  787. (end-of-line)
  788. (compilation-move-to-column
  789. end-col compilation-error-screen-columns))
  790. (setq end-marker (list (point-marker))))
  791. (beginning-of-line (if end-line
  792. (- line end-line -1)
  793. (- loc marker-line -1)))
  794. (if col
  795. (compilation-move-to-column
  796. col compilation-error-screen-columns)
  797. (forward-to-indentation 0))
  798. (setq marker (list (point-marker)))))))
  799. (setq loc (compilation-assq line (cdr file-struct)))
  800. (if end-line
  801. (setq end-loc (compilation-assq end-line (cdr file-struct))
  802. end-loc (compilation-assq end-col end-loc))
  803. (if end-col ; use same line element
  804. (setq end-loc (compilation-assq end-col loc))))
  805. (setq loc (compilation-assq col loc))
  806. ;; If they are new, make the loc(s) reference the file they point to.
  807. (or (cdr loc) (setcdr loc `(,line ,file-struct ,@marker)))
  808. (if end-loc
  809. (or (cdr end-loc)
  810. (setcdr end-loc `(,(or end-line line) ,file-struct ,@end-marker))))
  811. ;; Must start with face
  812. `(face ,compilation-message-face
  813. message (,loc ,type ,end-loc)
  814. ,@(if compilation-debug
  815. `(debug (,(assoc (with-no-warnings matcher) font-lock-keywords)
  816. ,@(match-data))))
  817. help-echo ,(if col
  818. "mouse-2: visit this file, line and column"
  819. (if line
  820. "mouse-2: visit this file and line"
  821. "mouse-2: visit this file"))
  822. keymap compilation-button-map
  823. mouse-face highlight)))
  824. (defun compilation-mode-font-lock-keywords ()
  825. "Return expressions to highlight in Compilation mode."
  826. (if compilation-parse-errors-function
  827. ;; An old package! Try the compatibility code.
  828. '((compilation-compat-parse-errors))
  829. (append
  830. ;; make directory tracking
  831. (if compilation-directory-matcher
  832. `((,(car compilation-directory-matcher)
  833. ,@(mapcar (lambda (elt)
  834. `(,(car elt)
  835. (compilation-directory-properties
  836. ,(car elt) ,(cdr elt))
  837. t t))
  838. (cdr compilation-directory-matcher)))))
  839. ;; Compiler warning/error lines.
  840. (mapcar
  841. (lambda (item)
  842. (if (symbolp item)
  843. (setq item (cdr (assq item
  844. compilation-error-regexp-alist-alist))))
  845. (let ((file (nth 1 item))
  846. (line (nth 2 item))
  847. (col (nth 3 item))
  848. (type (nth 4 item))
  849. (pat (car item))
  850. end-line end-col fmt)
  851. ;; omake reports some error indented, so skip the indentation.
  852. ;; another solution is to modify (some?) regexps in
  853. ;; `compilation-error-regexp-alist'.
  854. ;; note that omake usage is not limited to ocaml and C (for stubs).
  855. (when (and (= ?^ (aref pat 0)) ; anchored: starts with "^"
  856. ;; but does not allow an arbitrary number of leading spaces
  857. (not (and (= ? (aref pat 1)) (= ?* (aref pat 2)))))
  858. (setq pat (concat "^ *" (substring pat 1))))
  859. (if (consp file) (setq fmt (cdr file) file (car file)))
  860. (if (consp line) (setq end-line (cdr line) line (car line)))
  861. (if (consp col) (setq end-col (cdr col) col (car col)))
  862. (if (functionp line)
  863. ;; The old compile.el had here an undocumented hook that
  864. ;; allowed `line' to be a function that computed the actual
  865. ;; error location. Let's do our best.
  866. `(,pat
  867. (0 (save-match-data
  868. (compilation-compat-error-properties
  869. (funcall ',line (cons (match-string ,file)
  870. (cons default-directory
  871. ',(nthcdr 4 item)))
  872. ,(if col `(match-string ,col))))))
  873. (,file compilation-error-face t))
  874. (unless (or (null (nth 5 item)) (integerp (nth 5 item)))
  875. (error "HYPERLINK should be an integer: %s" (nth 5 item)))
  876. `(,pat
  877. ,@(when (integerp file)
  878. `((,file ,(if (consp type)
  879. `(compilation-face ',type)
  880. (aref [compilation-info-face
  881. compilation-warning-face
  882. compilation-error-face]
  883. (or type 2))))))
  884. ,@(when line
  885. `((,line compilation-line-face nil t)))
  886. ,@(when end-line
  887. `((,end-line compilation-line-face nil t)))
  888. ,@(when (integerp col)
  889. `((,col compilation-column-face nil t)))
  890. ,@(when (integerp end-col)
  891. `((,end-col compilation-column-face nil t)))
  892. ,@(nthcdr 6 item)
  893. (,(or (nth 5 item) 0)
  894. (compilation-error-properties ',file ,line ,end-line
  895. ,col ,end-col ',(or type 2)
  896. ',fmt)
  897. append))))) ; for compilation-message-face
  898. compilation-error-regexp-alist)
  899. compilation-mode-font-lock-keywords)))
  900. (defun compilation-read-command (command)
  901. (read-shell-command "Compile command: " command
  902. (if (equal (car compile-history) command)
  903. '(compile-history . 1)
  904. 'compile-history)))
  905. ;;;###autoload
  906. (defun compile (command &optional comint)
  907. "Compile the program including the current buffer. Default: run `make'.
  908. Runs COMMAND, a shell command, in a separate process asynchronously
  909. with output going to the buffer `*compilation*'.
  910. You can then use the command \\[next-error] to find the next error message
  911. and move to the source code that caused it.
  912. If optional second arg COMINT is t the buffer will be in Comint mode with
  913. `compilation-shell-minor-mode'.
  914. Interactively, prompts for the command if `compilation-read-command' is
  915. non-nil; otherwise uses `compile-command'. With prefix arg, always prompts.
  916. Additionally, with universal prefix arg, compilation buffer will be in
  917. comint mode, i.e. interactive.
  918. To run more than one compilation at once, start one then rename
  919. the \`*compilation*' buffer to some other name with
  920. \\[rename-buffer]. Then _switch buffers_ and start the new compilation.
  921. It will create a new \`*compilation*' buffer.
  922. On most systems, termination of the main compilation process
  923. kills its subprocesses.
  924. The name used for the buffer is actually whatever is returned by
  925. the function in `compilation-buffer-name-function', so you can set that
  926. to a function that generates a unique name."
  927. (interactive
  928. (list
  929. (let ((command (eval compile-command)))
  930. (if (or compilation-read-command current-prefix-arg)
  931. (compilation-read-command command)
  932. command))
  933. (consp current-prefix-arg)))
  934. (unless (equal command (eval compile-command))
  935. (setq compile-command command))
  936. (save-some-buffers (not compilation-ask-about-save) nil)
  937. (setq-default compilation-directory default-directory)
  938. (compilation-start command comint))
  939. ;; run compile with the default command line
  940. (defun recompile (&optional edit-command)
  941. "Re-compile the program including the current buffer.
  942. If this is run in a Compilation mode buffer, re-use the arguments from the
  943. original use. Otherwise, recompile using `compile-command'.
  944. If the optional argument `edit-command' is non-nil, the command can be edited."
  945. (interactive "P")
  946. (save-some-buffers (not compilation-ask-about-save) nil)
  947. (let ((default-directory (or compilation-directory default-directory)))
  948. (when edit-command
  949. (setcar compilation-arguments
  950. (compilation-read-command (car compilation-arguments))))
  951. (apply 'compilation-start (or compilation-arguments
  952. `(,(eval compile-command))))))
  953. (defcustom compilation-scroll-output nil
  954. "Non-nil to scroll the *compilation* buffer window as output appears.
  955. Setting it causes the Compilation mode commands to put point at the
  956. end of their output window so that the end of the output is always
  957. visible rather than the beginning.
  958. The value `first-error' stops scrolling at the first error, and leaves
  959. point on its location in the *compilation* buffer."
  960. :type '(choice (const :tag "No scrolling" nil)
  961. (const :tag "Scroll compilation output" t)
  962. (const :tag "Stop scrolling at the first error" first-error))
  963. :version "20.3"
  964. :group 'compilation)
  965. (defun compilation-buffer-name (mode-name mode-command name-function)
  966. "Return the name of a compilation buffer to use.
  967. If NAME-FUNCTION is non-nil, call it with one argument MODE-NAME
  968. to determine the buffer name.
  969. Likewise if `compilation-buffer-name-function' is non-nil.
  970. If current buffer has the major mode MODE-COMMAND,
  971. return the name of the current buffer, so that it gets reused.
  972. Otherwise, construct a buffer name from MODE-NAME."
  973. (cond (name-function
  974. (funcall name-function mode-name))
  975. (compilation-buffer-name-function
  976. (funcall compilation-buffer-name-function mode-name))
  977. ((eq mode-command major-mode)
  978. (buffer-name))
  979. (t
  980. (concat "*" (downcase mode-name) "*"))))
  981. ;; This is a rough emulation of the old hack, until the transition to new
  982. ;; compile is complete.
  983. (defun compile-internal (command error-message
  984. &optional name-of-mode parser
  985. error-regexp-alist name-function
  986. enter-regexp-alist leave-regexp-alist
  987. file-regexp-alist nomessage-regexp-alist
  988. no-async highlight-regexp local-map)
  989. (if parser
  990. (error "Compile now works very differently, see `compilation-error-regexp-alist'"))
  991. (let ((compilation-error-regexp-alist
  992. (append file-regexp-alist (or error-regexp-alist
  993. compilation-error-regexp-alist)))
  994. (compilation-error (replace-regexp-in-string "^No more \\(.+\\)s\\.?"
  995. "\\1" error-message)))
  996. (compilation-start command nil name-function highlight-regexp)))
  997. (make-obsolete 'compile-internal 'compilation-start "22.1")
  998. ;;;###autoload
  999. (defun compilation-start (command &optional mode name-function highlight-regexp)
  1000. "Run compilation command COMMAND (low level interface).
  1001. If COMMAND starts with a cd command, that becomes the `default-directory'.
  1002. The rest of the arguments are optional; for them, nil means use the default.
  1003. MODE is the major mode to set in the compilation buffer. Mode
  1004. may also be t meaning use `compilation-shell-minor-mode' under `comint-mode'.
  1005. If NAME-FUNCTION is non-nil, call it with one argument (the mode name)
  1006. to determine the buffer name. Otherwise, the default is to
  1007. reuses the current buffer if it has the proper major mode,
  1008. else use or create a buffer with name based on the major mode.
  1009. If HIGHLIGHT-REGEXP is non-nil, `next-error' will temporarily highlight
  1010. the matching section of the visited source line; the default is to use the
  1011. global value of `compilation-highlight-regexp'.
  1012. Returns the compilation buffer created."
  1013. (or mode (setq mode 'compilation-mode))
  1014. (let* ((name-of-mode
  1015. (if (eq mode t)
  1016. "compilation"
  1017. (replace-regexp-in-string "-mode$" "" (symbol-name mode))))
  1018. (thisdir default-directory)
  1019. outwin outbuf)
  1020. (with-current-buffer
  1021. (setq outbuf
  1022. (get-buffer-create
  1023. (compilation-buffer-name name-of-mode mode name-function)))
  1024. (let ((comp-proc (get-buffer-process (current-buffer))))
  1025. (if comp-proc
  1026. (if (or (not (eq (process-status comp-proc) 'run))
  1027. (yes-or-no-p
  1028. (format "A %s process is running; kill it? "
  1029. name-of-mode)))
  1030. (condition-case ()
  1031. (progn
  1032. (interrupt-process comp-proc)
  1033. (sit-for 1)
  1034. (delete-process comp-proc))
  1035. (error nil))
  1036. (error "Cannot have two processes in `%s' at once"
  1037. (buffer-name)))))
  1038. ;; first transfer directory from where M-x compile was called
  1039. (setq default-directory thisdir)
  1040. ;; Make compilation buffer read-only. The filter can still write it.
  1041. ;; Clear out the compilation buffer.
  1042. (let ((inhibit-read-only t)
  1043. (default-directory thisdir))
  1044. ;; Then evaluate a cd command if any, but don't perform it yet, else
  1045. ;; start-command would do it again through the shell: (cd "..") AND
  1046. ;; sh -c "cd ..; make"
  1047. (cd (if (string-match "^\\s *cd\\(?:\\s +\\(\\S +?\\)\\)?\\s *[;&\n]" command)
  1048. (if (match-end 1)
  1049. (substitute-env-vars (match-string 1 command))
  1050. "~")
  1051. default-directory))
  1052. (erase-buffer)
  1053. ;; Select the desired mode.
  1054. (if (not (eq mode t))
  1055. (progn
  1056. (buffer-disable-undo)
  1057. (funcall mode))
  1058. (setq buffer-read-only nil)
  1059. (with-no-warnings (comint-mode))
  1060. (compilation-shell-minor-mode))
  1061. ;; Remember the original dir, so we can use it when we recompile.
  1062. ;; default-directory' can't be used reliably for that because it may be
  1063. ;; affected by the special handling of "cd ...;".
  1064. ;; NB: must be fone after (funcall mode) as that resets local variables
  1065. (set (make-local-variable 'compilation-directory) thisdir)
  1066. (if highlight-regexp
  1067. (set (make-local-variable 'compilation-highlight-regexp)
  1068. highlight-regexp))
  1069. (if (or compilation-auto-jump-to-first-error
  1070. (eq compilation-scroll-output 'first-error))
  1071. (set (make-local-variable 'compilation-auto-jump-to-next) t))
  1072. ;; Output a mode setter, for saving and later reloading this buffer.
  1073. (insert "-*- mode: " name-of-mode
  1074. "; default-directory: " (prin1-to-string default-directory)
  1075. " -*-\n"
  1076. (format "%s started at %s\n\n"
  1077. mode-name
  1078. (substring (current-time-string) 0 19))
  1079. command "\n")
  1080. (setq thisdir default-directory))
  1081. (set-buffer-modified-p nil))
  1082. ;; Pop up the compilation buffer.
  1083. ;; ht

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