PageRenderTime 53ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/lisp/progmodes/compile.el

http://github.com/jave/emacs
Emacs Lisp | 1631 lines | 1189 code | 189 blank | 253 comment | 49 complexity | 9f8286d71ab4b0b6e6e9819a40d98c39 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. ;; AFAWK, The message may be a "warning", "error", or "fatal error".
  238. "^\\([0-9]+>\\)?\\(\\(?:[a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\)) \
  239. : \\(?:warnin\\(g\\)\\|[a-z ]+\\) C[0-9]+:" 2 3 nil (4))
  240. (omake
  241. ;; "omake -P" reports "file foo changed"
  242. ;; (useful if you do "cvs up" and want to see what has changed)
  243. "omake: file \\(.*\\) changed" 1)
  244. (oracle
  245. "^\\(?:Semantic error\\|Error\\|PCC-[0-9]+:\\).* line \\([0-9]+\\)\
  246. \\(?:\\(?:,\\| at\\)? column \\([0-9]+\\)\\)?\
  247. \\(?:,\\| in\\| of\\)? file \\(.*?\\):?$"
  248. 3 1 2)
  249. ;; "during global destruction": This comes out under "use
  250. ;; warnings" in recent perl when breaking circular references
  251. ;; during program or thread exit.
  252. (perl
  253. " at \\([^ \n]+\\) line \\([0-9]+\\)\\(?:[,.]\\|$\\| \
  254. during global destruction\\.$\\)" 1 2)
  255. (php
  256. "\\(?:Parse\\|Fatal\\) error: \\(.*\\) in \\(.*\\) on line \\([0-9]+\\)"
  257. 2 3 nil nil)
  258. (rxp
  259. "^\\(?:Error\\|Warnin\\(g\\)\\):.*\n.* line \\([0-9]+\\) char\
  260. \\([0-9]+\\) of file://\\(.+\\)"
  261. 4 2 3 (1))
  262. (sparc-pascal-file
  263. "^\\w\\w\\w \\w\\w\\w +[0-3]?[0-9] +[0-2][0-9]:[0-5][0-9]:[0-5][0-9]\
  264. [12][09][0-9][0-9] +\\(.*\\):$"
  265. 1 nil nil 0)
  266. (sparc-pascal-line
  267. "^\\(\\(?:E\\|\\(w\\)\\) +[0-9]+\\) line \\([0-9]+\\) - "
  268. nil 3 nil (2) nil (1 (compilation-face '(2))))
  269. (sparc-pascal-example
  270. "^ +\\([0-9]+\\) +.*\n\\(\\(?:e\\|\\(w\\)\\) [0-9]+\\)-+"
  271. nil 1 nil (3) nil (2 (compilation-face '(3))))
  272. (sun
  273. ": \\(?:ERROR\\|WARNIN\\(G\\)\\|REMAR\\(K\\)\\) \\(?:[[:alnum:] ]+, \\)?\
  274. File = \\(.+\\), Line = \\([0-9]+\\)\\(?:, Column = \\([0-9]+\\)\\)?"
  275. 3 4 5 (1 . 2))
  276. (sun-ada
  277. "^\\([^, \n\t]+\\), line \\([0-9]+\\), char \\([0-9]+\\)[:., \(-]" 1 2 3)
  278. (watcom
  279. "\\(\\(?:[a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\)): ?\
  280. \\(?:\\(Error! E[0-9]+\\)\\|\\(Warning! W[0-9]+\\)\\):"
  281. 1 2 nil (4))
  282. (4bsd
  283. "\\(?:^\\|:: \\|\\S ( \\)\\(/[^ \n\t()]+\\)(\\([0-9]+\\))\
  284. \\(?:: \\(warning:\\)?\\|$\\| ),\\)" 1 2 nil (3))
  285. (gcov-file
  286. "^ *-: *\\(0\\):Source:\\(.+\\)$"
  287. 2 1 nil 0 nil
  288. (1 compilation-line-face prepend) (2 compilation-info-face prepend))
  289. (gcov-header
  290. "^ *-: *\\(0\\):\\(?:Object\\|Graph\\|Data\\|Runs\\|Programs\\):.+$"
  291. nil 1 nil 0 nil
  292. (1 compilation-line-face prepend))
  293. ;; Underlines over all lines of gcov output are too uncomfortable to read.
  294. ;; However, hyperlinks embedded in the lines are useful.
  295. ;; So I put default face on the lines; and then put
  296. ;; compilation-*-face by manually to eliminate the underlines.
  297. ;; The hyperlinks are still effective.
  298. (gcov-nomark
  299. "^ *-: *\\([1-9]\\|[0-9]\\{2,\\}\\):.*$"
  300. nil 1 nil 0 nil
  301. (0 'default t)
  302. (1 compilation-line-face prepend))
  303. (gcov-called-line
  304. "^ *\\([0-9]+\\): *\\([0-9]+\\):.*$"
  305. nil 2 nil 0 nil
  306. (0 'default t)
  307. (1 compilation-info-face prepend) (2 compilation-line-face prepend))
  308. (gcov-never-called
  309. "^ *\\(#####\\): *\\([0-9]+\\):.*$"
  310. nil 2 nil 2 nil
  311. (0 'default t)
  312. (1 compilation-error-face prepend) (2 compilation-line-face prepend))
  313. (perl--Pod::Checker
  314. ;; podchecker error messages, per Pod::Checker.
  315. ;; The style is from the Pod::Checker::poderror() function, eg.
  316. ;; *** ERROR: Spurious text after =cut at line 193 in file foo.pm
  317. ;;
  318. ;; Plus end_pod() can give "at line EOF" instead of a
  319. ;; number, so for that match "on line N" which is the
  320. ;; originating spot, eg.
  321. ;; *** ERROR: =over on line 37 without closing =back at line EOF in file bar.pm
  322. ;;
  323. ;; Plus command() can give both "on line N" and "at line N";
  324. ;; the latter is desired and is matched because the .* is
  325. ;; greedy.
  326. ;; *** ERROR: =over on line 1 without closing =back (at head1) at line 3 in file x.pod
  327. ;;
  328. "^\\*\\*\\* \\(?:ERROR\\|\\(WARNING\\)\\).* \\(?:at\\|on\\) line \
  329. \\([0-9]+\\) \\(?:.* \\)?in file \\([^ \t\n]+\\)"
  330. 3 2 nil (1))
  331. (perl--Test
  332. ;; perl Test module error messages.
  333. ;; Style per the ok() function "$context", eg.
  334. ;; # Failed test 1 in foo.t at line 6
  335. ;;
  336. "^# Failed test [0-9]+ in \\([^ \t\r\n]+\\) at line \\([0-9]+\\)"
  337. 1 2)
  338. (perl--Test2
  339. ;; Or when comparing got/want values,
  340. ;; # Test 2 got: "xx" (t-compilation-perl-2.t at line 10)
  341. ;;
  342. ;; And under Test::Harness they're preceded by progress stuff with
  343. ;; \r and "NOK",
  344. ;; ... NOK 1# Test 1 got: "1234" (t/foo.t at line 46)
  345. ;;
  346. "^\\(.*NOK.*\\)?# Test [0-9]+ got:.* (\\([^ \t\r\n]+\\) at line \
  347. \\([0-9]+\\))"
  348. 2 3)
  349. (perl--Test::Harness
  350. ;; perl Test::Harness output, eg.
  351. ;; NOK 1# Test 1 got: "1234" (t/foo.t at line 46)
  352. ;;
  353. ;; Test::Harness is slightly designed for tty output, since
  354. ;; it prints CRs to overwrite progress messages, but if you
  355. ;; run it in with M-x compile this pattern can at least step
  356. ;; through the failures.
  357. ;;
  358. "^.*NOK.* \\([^ \t\r\n]+\\) at line \\([0-9]+\\)"
  359. 1 2)
  360. (weblint
  361. ;; The style comes from HTML::Lint::Error::as_string(), eg.
  362. ;; index.html (13:1) Unknown element <fdjsk>
  363. ;;
  364. ;; The pattern only matches filenames without spaces, since that
  365. ;; should be usual and should help reduce the chance of a false
  366. ;; match of a message from some unrelated program.
  367. ;;
  368. ;; This message style is quite close to the "ibm" entry which is
  369. ;; for IBM C, though that ibm bit doesn't put a space after the
  370. ;; filename.
  371. ;;
  372. "^\\([^ \t\r\n(]+\\) (\\([0-9]+\\):\\([0-9]+\\)) "
  373. 1 2 3)
  374. )
  375. "Alist of values for `compilation-error-regexp-alist'.")
  376. (defcustom compilation-error-regexp-alist
  377. (mapcar 'car compilation-error-regexp-alist-alist)
  378. "Alist that specifies how to match errors in compiler output.
  379. On GNU and Unix, any string is a valid filename, so these
  380. matchers must make some common sense assumptions, which catch
  381. normal cases. A shorter list will be lighter on resource usage.
  382. Instead of an alist element, you can use a symbol, which is
  383. looked up in `compilation-error-regexp-alist-alist'. You can see
  384. the predefined symbols and their effects in the file
  385. `etc/compilation.txt' (linked below if you are customizing this).
  386. Each elt has the form (REGEXP FILE [LINE COLUMN TYPE HYPERLINK
  387. HIGHLIGHT...]). If REGEXP matches, the FILE'th subexpression
  388. gives the file name, and the LINE'th subexpression gives the line
  389. number. The COLUMN'th subexpression gives the column number on
  390. that line.
  391. If FILE, LINE or COLUMN are nil or that index didn't match, that
  392. information is not present on the matched line. In that case the
  393. file name is assumed to be the same as the previous one in the
  394. buffer, line number defaults to 1 and column defaults to
  395. beginning of line's indentation.
  396. FILE can also have the form (FILE FORMAT...), where the FORMATs
  397. \(e.g. \"%s.c\") will be applied in turn to the recognized file
  398. name, until a file of that name is found. Or FILE can also be a
  399. function that returns (FILENAME) or (RELATIVE-FILENAME . DIRNAME).
  400. In the former case, FILENAME may be relative or absolute.
  401. LINE can also be of the form (LINE . END-LINE) meaning a range
  402. of lines. COLUMN can also be of the form (COLUMN . END-COLUMN)
  403. meaning a range of columns starting on LINE and ending on
  404. END-LINE, if that matched.
  405. TYPE is 2 or nil for a real error or 1 for warning or 0 for info.
  406. TYPE can also be of the form (WARNING . INFO). In that case this
  407. will be equivalent to 1 if the WARNING'th subexpression matched
  408. or else equivalent to 0 if the INFO'th subexpression matched.
  409. See `compilation-error-face', `compilation-warning-face',
  410. `compilation-info-face' and `compilation-skip-threshold'.
  411. What matched the HYPERLINK'th subexpression has `mouse-face' and
  412. `compilation-message-face' applied. If this is nil, the text
  413. matched by the whole REGEXP becomes the hyperlink.
  414. Additional HIGHLIGHTs as described under `font-lock-keywords' can
  415. be added."
  416. :type `(set :menu-tag "Pick"
  417. ,@(mapcar (lambda (elt)
  418. (list 'const (car elt)))
  419. compilation-error-regexp-alist-alist))
  420. :link `(file-link :tag "example file"
  421. ,(expand-file-name "compilation.txt" data-directory))
  422. :group 'compilation)
  423. ;;;###autoload(put 'compilation-directory 'safe-local-variable 'stringp)
  424. (defvar compilation-directory nil
  425. "Directory to restore to when doing `recompile'.")
  426. (defvar compilation-directory-matcher
  427. '("\\(?:Entering\\|Leavin\\(g\\)\\) directory `\\(.+\\)'$" (2 . 1))
  428. "A list for tracking when directories are entered or left.
  429. If nil, do not track directories, e.g. if all file names are absolute. The
  430. first element is the REGEXP matching these messages. It can match any number
  431. of variants, e.g. different languages. The remaining elements are all of the
  432. form (DIR . LEAVE). If for any one of these the DIR'th subexpression
  433. matches, that is a directory name. If LEAVE is nil or the corresponding
  434. LEAVE'th subexpression doesn't match, this message is about going into another
  435. directory. If it does match anything, this message is about going back to the
  436. directory we were in before the last entering message. If you change this,
  437. you may also want to change `compilation-page-delimiter'.")
  438. (defvar compilation-page-delimiter
  439. "^\\(?:\f\\|.*\\(?:Entering\\|Leaving\\) directory `.+'\n\\)+"
  440. "Value of `page-delimiter' in Compilation mode.")
  441. (defvar compilation-mode-font-lock-keywords
  442. '(;; configure output lines.
  443. ("^[Cc]hecking \\(?:[Ff]or \\|[Ii]f \\|[Ww]hether \\(?:to \\)?\\)?\\(.+\\)\\.\\.\\. *\\(?:(cached) *\\)?\\(\\(yes\\(?: .+\\)?\\)\\|no\\|\\(.*\\)\\)$"
  444. (1 font-lock-variable-name-face)
  445. (2 (compilation-face '(4 . 3))))
  446. ;; Command output lines. Recognize `make[n]:' lines too.
  447. ("^\\([[:alnum:]_/.+-]+\\)\\(\\[\\([0-9]+\\)\\]\\)?[ \t]*:"
  448. (1 font-lock-function-name-face) (3 compilation-line-face nil t))
  449. (" --?o\\(?:utfile\\|utput\\)?[= ]?\\(\\S +\\)" . 1)
  450. ("^Compilation \\(finished\\).*"
  451. (0 '(face nil message nil help-echo nil mouse-face nil) t)
  452. (1 compilation-info-face))
  453. ("^Compilation \\(exited abnormally\\|interrupt\\|killed\\|terminated\\|segmentation fault\\)\\(?:.*with code \\([0-9]+\\)\\)?.*"
  454. (0 '(face nil message nil help-echo nil mouse-face nil) t)
  455. (1 compilation-error-face)
  456. (2 compilation-error-face nil t)))
  457. "Additional things to highlight in Compilation mode.
  458. This gets tacked on the end of the generated expressions.")
  459. (defvar compilation-highlight-regexp t
  460. "Regexp matching part of visited source lines to highlight temporarily.
  461. Highlight entire line if t; don't highlight source lines if nil.")
  462. (defvar compilation-highlight-overlay nil
  463. "Overlay used to temporarily highlight compilation matches.")
  464. (defcustom compilation-error-screen-columns t
  465. "If non-nil, column numbers in error messages are screen columns.
  466. Otherwise they are interpreted as character positions, with
  467. each character occupying one column.
  468. The default is to use screen columns, which requires that the compilation
  469. program and Emacs agree about the display width of the characters,
  470. especially the TAB character."
  471. :type 'boolean
  472. :group 'compilation
  473. :version "20.4")
  474. (defcustom compilation-read-command t
  475. "Non-nil means \\[compile] reads the compilation command to use.
  476. Otherwise, \\[compile] just uses the value of `compile-command'."
  477. :type 'boolean
  478. :group 'compilation)
  479. ;;;###autoload
  480. (defcustom compilation-ask-about-save t
  481. "Non-nil means \\[compile] asks which buffers to save before compiling.
  482. Otherwise, it saves all modified buffers without asking."
  483. :type 'boolean
  484. :group 'compilation)
  485. ;;;###autoload
  486. (defcustom compilation-search-path '(nil)
  487. "List of directories to search for source files named in error messages.
  488. Elements should be directory names, not file names of directories.
  489. The value nil as an element means to try the default directory."
  490. :type '(repeat (choice (const :tag "Default" nil)
  491. (string :tag "Directory")))
  492. :group 'compilation)
  493. ;;;###autoload
  494. (defcustom compile-command "make -k "
  495. "Last shell command used to do a compilation; default for next compilation.
  496. Sometimes it is useful for files to supply local values for this variable.
  497. You might also use mode hooks to specify it in certain modes, like this:
  498. (add-hook 'c-mode-hook
  499. (lambda ()
  500. (unless (or (file-exists-p \"makefile\")
  501. (file-exists-p \"Makefile\"))
  502. (set (make-local-variable 'compile-command)
  503. (concat \"make -k \"
  504. (file-name-sans-extension buffer-file-name))))))"
  505. :type 'string
  506. :group 'compilation)
  507. ;;;###autoload(put 'compile-command 'safe-local-variable 'stringp)
  508. ;;;###autoload
  509. (defcustom compilation-disable-input nil
  510. "If non-nil, send end-of-file as compilation process input.
  511. This only affects platforms that support asynchronous processes (see
  512. `start-process'); synchronous compilation processes never accept input."
  513. :type 'boolean
  514. :group 'compilation
  515. :version "22.1")
  516. ;; A weak per-compilation-buffer hash indexed by (FILENAME . DIRECTORY). Each
  517. ;; value is a FILE-STRUCTURE as described above, with the car eq to the hash
  518. ;; key. This holds the tree seen from root, for storing new nodes.
  519. (defvar compilation-locs ())
  520. (defvar compilation-debug nil
  521. "*Set this to t before creating a *compilation* buffer.
  522. Then every error line will have a debug text property with the matcher that
  523. fit this line and the match data. Use `describe-text-properties'.")
  524. (defvar compilation-exit-message-function nil "\
  525. If non-nil, called when a compilation process dies to return a status message.
  526. This should be a function of three arguments: process status, exit status,
  527. and exit message; it returns a cons (MESSAGE . MODELINE) of the strings to
  528. write into the compilation buffer, and to put in its mode line.")
  529. (defvar compilation-environment nil
  530. "*List of environment variables for compilation to inherit.
  531. Each element should be a string of the form ENVVARNAME=VALUE.
  532. This list is temporarily prepended to `process-environment' prior to
  533. starting the compilation process.")
  534. ;; History of compile commands.
  535. (defvar compile-history nil)
  536. (defface compilation-error
  537. '((t :inherit font-lock-warning-face))
  538. "Face used to highlight compiler errors."
  539. :group 'compilation
  540. :version "22.1")
  541. (defface compilation-warning
  542. '((((class color) (min-colors 16)) (:foreground "Orange" :weight bold))
  543. (((class color)) (:foreground "cyan" :weight bold))
  544. (t (:weight bold)))
  545. "Face used to highlight compiler warnings."
  546. :group 'compilation
  547. :version "22.1")
  548. (defface compilation-info
  549. '((((class color) (min-colors 16) (background light))
  550. (:foreground "Green3" :weight bold))
  551. (((class color) (min-colors 88) (background dark))
  552. (:foreground "Green1" :weight bold))
  553. (((class color) (min-colors 16) (background dark))
  554. (:foreground "Green" :weight bold))
  555. (((class color)) (:foreground "green" :weight bold))
  556. (t (:weight bold)))
  557. "Face used to highlight compiler information."
  558. :group 'compilation
  559. :version "22.1")
  560. (defface compilation-line-number
  561. '((t :inherit font-lock-variable-name-face))
  562. "Face for displaying line numbers in compiler messages."
  563. :group 'compilation
  564. :version "22.1")
  565. (defface compilation-column-number
  566. '((t :inherit font-lock-type-face))
  567. "Face for displaying column numbers in compiler messages."
  568. :group 'compilation
  569. :version "22.1")
  570. (defcustom compilation-message-face 'underline
  571. "Face name to use for whole messages.
  572. Faces `compilation-error-face', `compilation-warning-face',
  573. `compilation-info-face', `compilation-line-face' and
  574. `compilation-column-face' get prepended to this, when applicable."
  575. :type 'face
  576. :group 'compilation
  577. :version "22.1")
  578. (defvar compilation-error-face 'compilation-error
  579. "Face name to use for file name in error messages.")
  580. (defvar compilation-warning-face 'compilation-warning
  581. "Face name to use for file name in warning messages.")
  582. (defvar compilation-info-face 'compilation-info
  583. "Face name to use for file name in informational messages.")
  584. (defvar compilation-line-face 'compilation-line-number
  585. "Face name to use for line numbers in compiler messages.")
  586. (defvar compilation-column-face 'compilation-column-number
  587. "Face name to use for column numbers in compiler messages.")
  588. ;; same faces as dired uses
  589. (defvar compilation-enter-directory-face 'font-lock-function-name-face
  590. "Face name to use for entering directory messages.")
  591. (defvar compilation-leave-directory-face 'font-lock-type-face
  592. "Face name to use for leaving directory messages.")
  593. ;; Used for compatibility with the old compile.el.
  594. (defvaralias 'compilation-last-buffer 'next-error-last-buffer)
  595. (defvar compilation-parsing-end (make-marker))
  596. (defvar compilation-parse-errors-function nil)
  597. (defvar compilation-error-list nil)
  598. (defvar compilation-old-error-list nil)
  599. (defcustom compilation-auto-jump-to-first-error nil
  600. "If non-nil, automatically jump to the first error during compilation."
  601. :type 'boolean
  602. :group 'compilation
  603. :version "23.1")
  604. (defvar compilation-auto-jump-to-next nil
  605. "If non-nil, automatically jump to the next error encountered.")
  606. (make-variable-buffer-local 'compilation-auto-jump-to-next)
  607. (defvar compilation-skip-to-next-location t
  608. "*If non-nil, skip multiple error messages for the same source location.")
  609. (defcustom compilation-skip-threshold 1
  610. "Compilation motion commands skip less important messages.
  611. The value can be either 2 -- skip anything less than error, 1 --
  612. skip anything less than warning or 0 -- don't skip any messages.
  613. Note that all messages not positively identified as warning or
  614. info, are considered errors."
  615. :type '(choice (const :tag "Warnings and info" 2)
  616. (const :tag "Info" 1)
  617. (const :tag "None" 0))
  618. :group 'compilation
  619. :version "22.1")
  620. (defcustom compilation-skip-visited nil
  621. "Compilation motion commands skip visited messages if this is t.
  622. Visited messages are ones for which the file, line and column have been jumped
  623. to from the current content in the current compilation buffer, even if it was
  624. from a different message."
  625. :type 'boolean
  626. :group 'compilation
  627. :version "22.1")
  628. (defun compilation-face (type)
  629. (or (and (car type) (match-end (car type)) compilation-warning-face)
  630. (and (cdr type) (match-end (cdr type)) compilation-info-face)
  631. compilation-error-face))
  632. ;; Internal function for calculating the text properties of a directory
  633. ;; change message. The directory property is important, because it is
  634. ;; the stack of nested enter-messages. Relative filenames on the following
  635. ;; lines are relative to the top of the stack.
  636. (defun compilation-directory-properties (idx leave)
  637. (if leave (setq leave (match-end leave)))
  638. ;; find previous stack, and push onto it, or if `leave' pop it
  639. (let ((dir (previous-single-property-change (point) 'directory)))
  640. (setq dir (if dir (or (get-text-property (1- dir) 'directory)
  641. (get-text-property dir 'directory))))
  642. `(face ,(if leave
  643. compilation-leave-directory-face
  644. compilation-enter-directory-face)
  645. directory ,(if leave
  646. (or (cdr dir)
  647. '(nil)) ; nil only isn't a property-change
  648. (cons (match-string-no-properties idx) dir))
  649. mouse-face highlight
  650. keymap compilation-button-map
  651. help-echo "mouse-2: visit destination directory")))
  652. ;; Data type `reverse-ordered-alist' retriever. This function retrieves the
  653. ;; KEY element from the ALIST, creating it in the right position if not already
  654. ;; present. ALIST structure is
  655. ;; '(ANCHOR (KEY1 ...) (KEY2 ...)... (KEYn ALIST ...))
  656. ;; ANCHOR is ignored, but necessary so that elements can be inserted. KEY1
  657. ;; may be nil. The other KEYs are ordered backwards so that growing line
  658. ;; numbers can be inserted in front and searching can abort after half the
  659. ;; list on average.
  660. (eval-when-compile ;Don't keep it at runtime if not needed.
  661. (defmacro compilation-assq (key alist)
  662. `(let* ((l1 ,alist)
  663. (l2 (cdr l1)))
  664. (car (if (if (null ,key)
  665. (if l2 (null (caar l2)))
  666. (while (if l2 (if (caar l2) (< ,key (caar l2)) t))
  667. (setq l1 l2
  668. l2 (cdr l1)))
  669. (if l2 (eq ,key (caar l2))))
  670. l2
  671. (setcdr l1 (cons (list ,key) l2)))))))
  672. (defun compilation-auto-jump (buffer pos)
  673. (with-current-buffer buffer
  674. (goto-char pos)
  675. (let ((win (get-buffer-window buffer 0)))
  676. (if win (set-window-point win pos)))
  677. (if compilation-auto-jump-to-first-error
  678. (compile-goto-error))))
  679. ;; This function is the central driver, called when font-locking to gather
  680. ;; all information needed to later jump to corresponding source code.
  681. ;; Return a property list with all meta information on this error location.
  682. (defun compilation-error-properties (file line end-line col end-col type fmt)
  683. (unless (< (next-single-property-change (match-beginning 0)
  684. 'directory nil (point))
  685. (point))
  686. (if file
  687. (if (functionp file)
  688. (setq file (funcall file))
  689. (let (dir)
  690. (setq file (match-string-no-properties file))
  691. (unless (file-name-absolute-p file)
  692. (setq dir (previous-single-property-change (point) 'directory)
  693. dir (if dir (or (get-text-property (1- dir) 'directory)
  694. (get-text-property dir 'directory)))))
  695. (setq file (cons file (car dir)))))
  696. ;; This message didn't mention one, get it from previous
  697. (let ((prev-pos
  698. ;; Find the previous message.
  699. (previous-single-property-change (point) 'message)))
  700. (if prev-pos
  701. ;; Get the file structure that belongs to it.
  702. (let* ((prev
  703. (or (get-text-property (1- prev-pos) 'message)
  704. (get-text-property prev-pos 'message)))
  705. (prev-struct
  706. (car (nth 2 (car prev)))))
  707. ;; Construct FILE . DIR from that.
  708. (if prev-struct
  709. (setq file (cons (car prev-struct)
  710. (cadr prev-struct))))))
  711. (unless file
  712. (setq file '("*unknown*")))))
  713. ;; All of these fields are optional, get them only if we have an index, and
  714. ;; it matched some part of the message.
  715. (and line
  716. (setq line (match-string-no-properties line))
  717. (setq line (string-to-number line)))
  718. (and end-line
  719. (setq end-line (match-string-no-properties end-line))
  720. (setq end-line (string-to-number end-line)))
  721. (if col
  722. (if (functionp col)
  723. (setq col (funcall col))
  724. (and
  725. (setq col (match-string-no-properties col))
  726. (setq col (- (string-to-number col) compilation-first-column)))))
  727. (if (and end-col (functionp end-col))
  728. (setq end-col (funcall end-col))
  729. (if (and end-col (setq end-col (match-string-no-properties end-col)))
  730. (setq end-col (- (string-to-number end-col) compilation-first-column -1))
  731. (if end-line (setq end-col -1))))
  732. (if (consp type) ; not a static type, check what it is.
  733. (setq type (or (and (car type) (match-end (car type)) 1)
  734. (and (cdr type) (match-end (cdr type)) 0)
  735. 2)))
  736. (when (and compilation-auto-jump-to-next
  737. (>= type compilation-skip-threshold))
  738. (kill-local-variable 'compilation-auto-jump-to-next)
  739. (run-with-timer 0 nil 'compilation-auto-jump
  740. (current-buffer) (match-beginning 0)))
  741. (compilation-internal-error-properties file line end-line col end-col type fmt)))
  742. (defun compilation-move-to-column (col screen)
  743. "Go to column COL on the current line.
  744. If SCREEN is non-nil, columns are screen columns, otherwise, they are
  745. just char-counts."
  746. (if screen
  747. (move-to-column (max col 0))
  748. (goto-char (min (+ (line-beginning-position) col) (line-end-position)))))
  749. (defun compilation-internal-error-properties (file line end-line col end-col type fmts)
  750. "Get the meta-info that will be added as text-properties.
  751. LINE, END-LINE, COL, END-COL are integers or nil.
  752. TYPE can be 0, 1, or 2, meaning error, warning, or just info.
  753. FILE should be (FILENAME) or (RELATIVE-FILENAME . DIRNAME) or nil.
  754. FMTS is a list of format specs for transforming the file name.
  755. (See `compilation-error-regexp-alist'.)"
  756. (unless file (setq file '("*unknown*")))
  757. (let* ((file-struct (compilation-get-file-structure file fmts))
  758. ;; Get first already existing marker (if any has one, all have one).
  759. ;; Do this first, as the compilation-assq`s may create new nodes.
  760. (marker-line (car (cddr file-struct))) ; a line structure
  761. (marker (nth 3 (cadr marker-line))) ; its marker
  762. (compilation-error-screen-columns compilation-error-screen-columns)
  763. end-marker loc end-loc)
  764. (if (not (and marker (marker-buffer marker)))
  765. (setq marker nil) ; no valid marker for this file
  766. (setq loc (or line 1)) ; normalize no linenumber to line 1
  767. (catch 'marker ; find nearest loc, at least one exists
  768. (dolist (x (nthcdr 3 file-struct)) ; loop over remaining lines
  769. (if (> (car x) loc) ; still bigger
  770. (setq marker-line x)
  771. (if (> (- (or (car marker-line) 1) loc)
  772. (- loc (car x))) ; current line is nearer
  773. (setq marker-line x))
  774. (throw 'marker t))))
  775. (setq marker (nth 3 (cadr marker-line))
  776. marker-line (or (car marker-line) 1))
  777. (with-current-buffer (marker-buffer marker)
  778. (save-excursion
  779. (save-restriction
  780. (widen)
  781. (goto-char (marker-position marker))
  782. (when (or end-col end-line)
  783. (beginning-of-line (- (or end-line line) marker-line -1))
  784. (if (or (null end-col) (< end-col 0))
  785. (end-of-line)
  786. (compilation-move-to-column
  787. end-col compilation-error-screen-columns))
  788. (setq end-marker (list (point-marker))))
  789. (beginning-of-line (if end-line
  790. (- line end-line -1)
  791. (- loc marker-line -1)))
  792. (if col
  793. (compilation-move-to-column
  794. col compilation-error-screen-columns)
  795. (forward-to-indentation 0))
  796. (setq marker (list (point-marker)))))))
  797. (setq loc (compilation-assq line (cdr file-struct)))
  798. (if end-line
  799. (setq end-loc (compilation-assq end-line (cdr file-struct))
  800. end-loc (compilation-assq end-col end-loc))
  801. (if end-col ; use same line element
  802. (setq end-loc (compilation-assq end-col loc))))
  803. (setq loc (compilation-assq col loc))
  804. ;; If they are new, make the loc(s) reference the file they point to.
  805. (or (cdr loc) (setcdr loc `(,line ,file-struct ,@marker)))
  806. (if end-loc
  807. (or (cdr end-loc)
  808. (setcdr end-loc `(,(or end-line line) ,file-struct ,@end-marker))))
  809. ;; Must start with face
  810. `(face ,compilation-message-face
  811. message (,loc ,type ,end-loc)
  812. ,@(if compilation-debug
  813. `(debug (,(assoc (with-no-warnings matcher) font-lock-keywords)
  814. ,@(match-data))))
  815. help-echo ,(if col
  816. "mouse-2: visit this file, line and column"
  817. (if line
  818. "mouse-2: visit this file and line"
  819. "mouse-2: visit this file"))
  820. keymap compilation-button-map
  821. mouse-face highlight)))
  822. (defun compilation-mode-font-lock-keywords ()
  823. "Return expressions to highlight in Compilation mode."
  824. (if compilation-parse-errors-function
  825. ;; An old package! Try the compatibility code.
  826. '((compilation-compat-parse-errors))
  827. (append
  828. ;; make directory tracking
  829. (if compilation-directory-matcher
  830. `((,(car compilation-directory-matcher)
  831. ,@(mapcar (lambda (elt)
  832. `(,(car elt)
  833. (compilation-directory-properties
  834. ,(car elt) ,(cdr elt))
  835. t t))
  836. (cdr compilation-directory-matcher)))))
  837. ;; Compiler warning/error lines.
  838. (mapcar
  839. (lambda (item)
  840. (if (symbolp item)
  841. (setq item (cdr (assq item
  842. compilation-error-regexp-alist-alist))))
  843. (let ((file (nth 1 item))
  844. (line (nth 2 item))
  845. (col (nth 3 item))
  846. (type (nth 4 item))
  847. (pat (car item))
  848. end-line end-col fmt)
  849. ;; omake reports some error indented, so skip the indentation.
  850. ;; another solution is to modify (some?) regexps in
  851. ;; `compilation-error-regexp-alist'.
  852. ;; note that omake usage is not limited to ocaml and C (for stubs).
  853. (unless (string-match (concat "^" (regexp-quote "^ *")) pat)
  854. (setq pat (concat "^ *"
  855. (if (= ?^ (aref pat 0))
  856. (substring pat 1)
  857. pat))))
  858. (if (consp file) (setq fmt (cdr file) file (car file)))
  859. (if (consp line) (setq end-line (cdr line) line (car line)))
  860. (if (consp col) (setq end-col (cdr col) col (car col)))
  861. (if (functionp line)
  862. ;; The old compile.el had here an undocumented hook that
  863. ;; allowed `line' to be a function that computed the actual
  864. ;; error location. Let's do our best.
  865. `(,pat
  866. (0 (save-match-data
  867. (compilation-compat-error-properties
  868. (funcall ',line (cons (match-string ,file)
  869. (cons default-directory
  870. ',(nthcdr 4 item)))
  871. ,(if col `(match-string ,col))))))
  872. (,file compilation-error-face t))
  873. (unless (or (null (nth 5 item)) (integerp (nth 5 item)))
  874. (error "HYPERLINK should be an integer: %s" (nth 5 item)))
  875. `(,pat
  876. ,@(when (integerp file)
  877. `((,file ,(if (consp type)
  878. `(compilation-face ',type)
  879. (aref [compilation-info-face
  880. compilation-warning-face
  881. compilation-error-face]
  882. (or type 2))))))
  883. ,@(when line
  884. `((,line compilation-line-face nil t)))
  885. ,@(when end-line
  886. `((,end-line compilation-line-face nil t)))
  887. ,@(when (integerp col)
  888. `((,col compilation-column-face nil t)))
  889. ,@(when (integerp end-col)
  890. `((,end-col compilation-column-face nil t)))
  891. ,@(nthcdr 6 item)
  892. (,(or (nth 5 item) 0)
  893. (compilation-error-properties ',file ,line ,end-line
  894. ,col ,end-col ',(or type 2)
  895. ',fmt)
  896. append))))) ; for compilation-message-face
  897. compilation-error-regexp-alist)
  898. compilation-mode-font-lock-keywords)))
  899. (defun compilation-read-command (command)
  900. (read-shell-command "Compile command: " command
  901. (if (equal (car compile-history) command)
  902. '(compile-history . 1)
  903. 'compile-history)))
  904. ;;;###autoload
  905. (defun compile (command &optional comint)
  906. "Compile the program including the current buffer. Default: run `make'.
  907. Runs COMMAND, a shell command, in a separate process asynchronously
  908. with output going to the buffer `*compilation*'.
  909. You can then use the command \\[next-error] to find the next error message
  910. and move to the source code that caused it.
  911. If optional second arg COMINT is t the buffer will be in Comint mode with
  912. `compilation-shell-minor-mode'.
  913. Interactively, prompts for the command if `compilation-read-command' is
  914. non-nil; otherwise uses `compile-command'. With prefix arg, always prompts.
  915. Additionally, with universal prefix arg, compilation buffer will be in
  916. comint mode, i.e. interactive.
  917. To run more than one compilation at once, start one then rename
  918. the \`*compilation*' buffer to some other name with
  919. \\[rename-buffer]. Then _switch buffers_ and start the new compilation.
  920. It will create a new \`*compilation*' buffer.
  921. On most systems, termination of the main compilation process
  922. kills its subprocesses.
  923. The name used for the buffer is actually whatever is returned by
  924. the function in `compilation-buffer-name-function', so you can set that
  925. to a function that generates a unique name."
  926. (interactive
  927. (list
  928. (let ((command (eval compile-command)))
  929. (if (or compilation-read-command current-prefix-arg)
  930. (compilation-read-command command)
  931. command))
  932. (consp current-prefix-arg)))
  933. (unless (equal command (eval compile-command))
  934. (setq compile-command command))
  935. (save-some-buffers (not compilation-ask-about-save) nil)
  936. (setq-default compilation-directory default-directory)
  937. (compilation-start command comint))
  938. ;; run compile with the default command line
  939. (defun recompile (&optional edit-command)
  940. "Re-compile the program including the current buffer.
  941. If this is run in a Compilation mode buffer, re-use the arguments from the
  942. original use. Otherwise, recompile using `compile-command'.
  943. If the optional argument `edit-command' is non-nil, the command can be edited."
  944. (interactive "P")
  945. (save-some-buffers (not compilation-ask-about-save) nil)
  946. (let ((default-directory (or compilation-directory default-directory)))
  947. (when edit-command
  948. (setcar compilation-arguments
  949. (compilation-read-command (car compilation-arguments))))
  950. (apply 'compilation-start (or compilation-arguments
  951. `(,(eval compile-command))))))
  952. (defcustom compilation-scroll-output nil
  953. "Non-nil to scroll the *compilation* buffer window as output appears.
  954. Setting it causes the Compilation mode commands to put point at the
  955. end of their output window so that the end of the output is always
  956. visible rather than the beginning.
  957. The value `first-error' stops scrolling at the first error, and leaves
  958. point on its location in the *compilation* buffer."
  959. :type '(choice (const :tag "No scrolling" nil)
  960. (const :tag "Scroll compilation output" t)
  961. (const :tag "Stop scrolling at the first error" first-error))
  962. :version "20.3"
  963. :group 'compilation)
  964. (defun compilation-buffer-name (mode-name mode-command name-function)
  965. "Return the name of a compilation buffer to use.
  966. If NAME-FUNCTION is non-nil, call it with one argument MODE-NAME
  967. to determine the buffer name.
  968. Likewise if `compilation-buffer-name-function' is non-nil.
  969. If current buffer has the major mode MODE-COMMAND,
  970. return the name of the current buffer, so that it gets reused.
  971. Otherwise, construct a buffer name from MODE-NAME."
  972. (cond (name-function
  973. (funcall name-function mode-name))
  974. (compilation-buffer-name-function
  975. (funcall compilation-buffer-name-function mode-name))
  976. ((eq mode-command major-mode)
  977. (buffer-name))
  978. (t
  979. (concat "*" (downcase mode-name) "*"))))
  980. ;; This is a rough emulation of the old hack, until the transition to new
  981. ;; compile is complete.
  982. (defun compile-internal (command error-message
  983. &optional name-of-mode parser
  984. error-regexp-alist name-function
  985. enter-regexp-alist leave-regexp-alist
  986. file-regexp-alist nomessage-regexp-alist
  987. no-async highlight-regexp local-map)
  988. (if parser
  989. (error "Compile now works very differently, see `compilation-error-regexp-alist'"))
  990. (let ((compilation-error-regexp-alist
  991. (append file-regexp-alist (or error-regexp-alist
  992. compilation-error-regexp-alist)))
  993. (compilation-error (replace-regexp-in-string "^No more \\(.+\\)s\\.?"
  994. "\\1" error-message)))
  995. (compilation-start command nil name-function highlight-regexp)))
  996. (make-obsolete 'compile-internal 'compilation-start "22.1")
  997. ;;;###autoload
  998. (defun compilation-start (command &optional mode name-function highlight-regexp)
  999. "Run compilation command COMMAND (low level interface).
  1000. If COMMAND starts with a cd command, that becomes the `default-directory'.
  1001. The rest of the arguments are optional; for them, nil means use the default.
  1002. MODE is the major mode to set in the compilation buffer. Mode
  1003. may also be t meaning use `compilation-shell-minor-mode' under `comint-mode'.
  1004. If NAME-FUNCTION is non-nil, call it with one argument (the mode name)
  1005. to determine the buffer name. Otherwise, the default is to
  1006. reuses the current buffer if it has the proper major mode,
  1007. else use or create a buffer with name based on the major mode.
  1008. If HIGHLIGHT-REGEXP is non-nil, `next-error' will temporarily highlight
  1009. the matching section of the visited source line; the default is to use the
  1010. global value of `compilation-highlight-regexp'.
  1011. Returns the compilation buffer created."
  1012. (or mode (setq mode 'compilation-mode))
  1013. (let* ((name-of-mode
  1014. (if (eq mode t)
  1015. "compilation"
  1016. (replace-regexp-in-string "-mode$" "" (symbol-name mode))))
  1017. (thisdir default-directory)
  1018. outwin outbuf)
  1019. (with-current-buffer
  1020. (setq outbuf
  1021. (get-buffer-create
  1022. (compilation-buffer-name name-of-mode mode name-function)))
  1023. (let ((comp-proc (get-buffer-process (current-buffer))))
  1024. (if comp-proc
  1025. (if (or (not (eq (process-status comp-proc) 'run))
  1026. (yes-or-no-p
  1027. (format "A %s process is running; kill it? "
  1028. name-of-mode)))
  1029. (condition-case ()
  1030. (progn
  1031. (interrupt-process comp-proc)
  1032. (sit-for 1)
  1033. (delete-process comp-proc))
  1034. (error nil))
  1035. (error "Cannot have two processes in `%s' at once"
  1036. (buffer-name)))))
  1037. ;; first transfer directory from where M-x compile was called
  1038. (setq default-directory thisdir)
  1039. ;; Make compilation buffer read-only. The filter can still write it.
  1040. ;; Clear out the compilation buffer.
  1041. (let ((inhibit-read-only t)
  1042. (default-directory thisdir))
  1043. ;; Then evaluate a cd command if any, but don't perform it yet, else
  1044. ;; start-command would do it again through the shell: (cd "..") AND
  1045. ;; sh -c "cd ..; make"
  1046. (cd (if (string-match "^\\s *cd\\(?:\\s +\\(\\S +?\\)\\)?\\s *[;&\n]" command)
  1047. (if (match-end 1)
  1048. (substitute-env-vars (match-string 1 command))
  1049. "~")
  1050. default-directory))
  1051. (erase-buffer)
  1052. ;; Select the desired mode.
  1053. (if (not (eq mode t))
  1054. (progn
  1055. (buffer-disable-undo)
  1056. (funcall mode))
  1057. (setq buffer-read-only nil)
  1058. (with-no-warnings (comint-mode))
  1059. (compilation-shell-minor-mode))
  1060. ;; Remember the original dir, so we can use it when we recompile.
  1061. ;; default-directory' can't be used reliably for that because it may be
  1062. ;; affected by the special handling of "cd ...;".
  1063. ;; NB: must be fone after (funcall mode) as that resets local variables
  1064. (set (make-local-variable 'compilation-directory) thisdir)
  1065. (if highlight-regexp
  1066. (set (make-local-variable 'compilation-highlight-regexp)
  1067. highlight-regexp))
  1068. (if (or compilation-auto-jump-to-first-error
  1069. (eq compilation-scroll-output 'first-error))
  1070. (set (make-local-variable 'compilation-auto-jump-to-next) t))
  1071. ;; Output a mode setter, for saving and later reloading this buffer.
  1072. (insert "-*- mode: " name-of-mode
  1073. "; default-directory: " (prin1-to-string default-directory)
  1074. " -*-\n"
  1075. (format "%s started at %s\n\n"
  1076. mode-name
  1077. (substring (current-time-string) 0 19))
  1078. command "\n")
  1079. (setq thisdir default-directory))
  1080. (set-buffer-modified-p nil))
  1081. ;; Pop up the compilation buffer.
  1082. ;; http://lists.gnu.org/archive/html/emacs-devel/2007-11/msg01638.html
  1083. (setq outwin (display-buffer outbuf))
  1084. (with-current-buffer outb

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