PageRenderTime 193ms CodeModel.GetById 108ms RepoModel.GetById 1ms app.codeStats 1ms

/lisp/progmodes/compile.el

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

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