PageRenderTime 78ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 1ms

/emacs-24.2/lisp/progmodes/compile.el

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

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