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

/lisp/progmodes/compile.el

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

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