PageRenderTime 75ms CodeModel.GetById 35ms RepoModel.GetById 0ms app.codeStats 1ms

/lisp/progmodes/compile.el

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

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