PageRenderTime 31ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/lisp/progmodes/compile.el

http://github.com/typester/emacs
Emacs Lisp | 2385 lines | 1741 code | 232 blank | 412 comment | 75 complexity | 5c180a536f949658176f2959b77cf927 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.0, AGPL-3.0
  1. ;;; compile.el --- run compiler as inferior of Emacs, parse error messages
  2. ;; Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
  3. ;; 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
  4. ;; Free Software Foundation, Inc.
  5. ;; Authors: Roland McGrath <roland@gnu.org>,
  6. ;; Daniel Pfeiffer <occitan@esperanto.org>
  7. ;; Maintainer: FSF
  8. ;; Keywords: tools, processes
  9. ;; This file is part of GNU Emacs.
  10. ;; GNU Emacs is free software: you can redistribute it and/or modify
  11. ;; it under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation, either version 3 of the License, or
  13. ;; (at your option) any later version.
  14. ;; GNU Emacs is distributed in the hope that it will be useful,
  15. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;; GNU General Public License for more details.
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  20. ;;; Commentary:
  21. ;; This package provides the compile facilities documented in the Emacs user's
  22. ;; manual.
  23. ;; This mode uses some complex data-structures:
  24. ;; LOC (or location) is a list of (COLUMN LINE FILE-STRUCTURE)
  25. ;; COLUMN and LINE are numbers parsed from an error message. COLUMN and maybe
  26. ;; LINE will be nil for a message that doesn't contain them. Then the
  27. ;; location refers to a indented beginning of line or beginning of file.
  28. ;; Once any location in some file has been jumped to, the list is extended to
  29. ;; (COLUMN LINE FILE-STRUCTURE MARKER TIMESTAMP . VISITED)
  30. ;; for all LOCs pertaining to that file.
  31. ;; MARKER initially points to LINE and COLUMN in a buffer visiting that file.
  32. ;; Being a marker it sticks to some text, when the buffer grows or shrinks
  33. ;; before that point. VISITED is t if we have jumped there, else nil.
  34. ;; TIMESTAMP is necessary because of "incremental compilation": `omake -P'
  35. ;; polls filesystem for changes and recompiles when a file is modified
  36. ;; using the same *compilation* buffer. this necessitates re-parsing markers.
  37. ;; FILE-STRUCTURE is a list of
  38. ;; ((FILENAME . DIRECTORY) FORMATS (LINE LOC ...) ...)
  39. ;; FILENAME is a string parsed from an error message. DIRECTORY is a string
  40. ;; obtained by following directory change messages. DIRECTORY will be nil for
  41. ;; an absolute filename. FORMATS is a list of formats to apply to FILENAME if
  42. ;; a file of that name can't be found.
  43. ;; The rest of the list is an alist of elements with LINE as key. The keys
  44. ;; are either nil or line numbers. If present, nil comes first, followed by
  45. ;; the numbers in decreasing order. The LOCs for each line are again an alist
  46. ;; ordered the same way. Note that the whole file structure is referenced in
  47. ;; every LOC.
  48. ;; MESSAGE is a list of (LOC TYPE END-LOC)
  49. ;; TYPE is 0 for info or 1 for warning if the message matcher identified it as
  50. ;; such, 2 otherwise (for a real error). END-LOC is a LOC pointing to the
  51. ;; other end, if the parsed message contained a range. If the end of the
  52. ;; range didn't specify a COLUMN, it defaults to -1, meaning end of line.
  53. ;; These are the value of the `message' text-properties in the compilation
  54. ;; buffer.
  55. ;;; Code:
  56. (eval-when-compile (require 'cl))
  57. (require 'tool-bar)
  58. (require 'comint)
  59. (defvar font-lock-extra-managed-props)
  60. (defvar font-lock-keywords)
  61. (defvar font-lock-maximum-size)
  62. (defvar font-lock-support-mode)
  63. (defgroup compilation nil
  64. "Run compiler as inferior of Emacs, parse error messages."
  65. :group 'tools
  66. :group 'processes)
  67. ;;;###autoload
  68. (defcustom compilation-mode-hook nil
  69. "List of hook functions run by `compilation-mode' (see `run-mode-hooks')."
  70. :type 'hook
  71. :group 'compilation)
  72. ;;;###autoload
  73. (defcustom compilation-start-hook nil
  74. "List of hook functions run by `compilation-start' on the compilation process.
  75. \(See `run-hook-with-args').
  76. If you use \"omake -P\" and do not want \\[save-buffers-kill-terminal] to ask whether you want
  77. the compilation to be killed, you can use this hook:
  78. (add-hook 'compilation-start-hook
  79. (lambda (process) (set-process-query-on-exit-flag process nil)) nil t)"
  80. :type 'hook
  81. :group 'compilation)
  82. ;;;###autoload
  83. (defcustom compilation-window-height nil
  84. "Number of lines in a compilation window. If nil, use Emacs default."
  85. :type '(choice (const :tag "Default" nil)
  86. integer)
  87. :group 'compilation)
  88. (defvar compilation-first-column 1
  89. "*This is how compilers number the first column, usually 1 or 0.")
  90. (defvar compilation-parse-errors-filename-function nil
  91. "Function to call to post-process filenames while parsing error messages.
  92. It takes one arg FILENAME which is the name of a file as found
  93. in the compilation output, and should return a transformed file name.")
  94. ;;;###autoload
  95. (defvar compilation-process-setup-function nil
  96. "*Function to call to customize the compilation process.
  97. This function is called immediately before the compilation process is
  98. started. It can be used to set any variables or functions that are used
  99. while processing the output of the compilation process. The function
  100. is called with variables `compilation-buffer' and `compilation-window'
  101. bound to the compilation buffer and window, respectively.")
  102. ;;;###autoload
  103. (defvar compilation-buffer-name-function nil
  104. "Function to compute the name of a compilation buffer.
  105. The function receives one argument, the name of the major mode of the
  106. compilation buffer. It should return a string.
  107. If nil, compute the name with `(concat \"*\" (downcase major-mode) \"*\")'.")
  108. ;;;###autoload
  109. (defvar compilation-finish-function nil
  110. "Function to call when a compilation process finishes.
  111. It is called with two arguments: the compilation buffer, and a string
  112. describing how the process finished.")
  113. (make-obsolete-variable 'compilation-finish-function
  114. "use `compilation-finish-functions', but it works a little differently."
  115. "22.1")
  116. ;;;###autoload
  117. (defvar compilation-finish-functions nil
  118. "Functions to call when a compilation process finishes.
  119. Each function is called with two arguments: the compilation buffer,
  120. and a string describing how the process finished.")
  121. (defvar compilation-in-progress nil
  122. "List of compilation processes now running.")
  123. (or (assq 'compilation-in-progress minor-mode-alist)
  124. (setq minor-mode-alist (cons '(compilation-in-progress " Compiling")
  125. minor-mode-alist)))
  126. (defvar compilation-error "error"
  127. "Stem of message to print when no matches are found.")
  128. (defvar compilation-arguments nil
  129. "Arguments that were given to `compilation-start'.")
  130. (defvar compilation-num-errors-found)
  131. (defconst compilation-error-regexp-alist-alist
  132. '((absoft
  133. "^\\(?:[Ee]rror on \\|[Ww]arning on\\( \\)\\)?[Ll]ine[ \t]+\\([0-9]+\\)[ \t]+\
  134. of[ \t]+\"?\\([a-zA-Z]?:?[^\":\n]+\\)\"?:" 3 2 nil (1))
  135. (ada
  136. "\\(warning: .*\\)? at \\([^ \n]+\\):\\([0-9]+\\)$" 2 3 nil (1))
  137. (aix
  138. " in line \\([0-9]+\\) of file \\([^ \n]+[^. \n]\\)\\.? " 2 1)
  139. (ant
  140. "^[ \t]*\\[[^] \n]+\\][ \t]*\\([^: \n]+\\):\\([0-9]+\\):\\(?:\\([0-9]+\\):[0-9]+:[0-9]+:\\)?\
  141. \\( warning\\)?" 1 2 3 (4))
  142. (bash
  143. "^\\([^: \n\t]+\\): line \\([0-9]+\\):" 1 2)
  144. (borland
  145. "^\\(?:Error\\|Warnin\\(g\\)\\) \\(?:[FEW][0-9]+ \\)?\
  146. \\([a-zA-Z]?:?[^:( \t\n]+\\)\
  147. \\([0-9]+\\)\\(?:[) \t]\\|:[^0-9\n]\\)" 2 3 nil (1))
  148. (caml
  149. "^ *File \\(\"?\\)\\([^,\" \n\t<>]+\\)\\1, lines? \\([0-9]+\\)-?\\([0-9]+\\)?\\(?:$\\|,\
  150. \\(?: characters? \\([0-9]+\\)-?\\([0-9]+\\)?:\\)?\\([ \n]Warning:\\)?\\)"
  151. 2 (3 . 4) (5 . 6) (7))
  152. (comma
  153. "^\"\\([^,\" \n\t]+\\)\", line \\([0-9]+\\)\
  154. \\(?:[(. pos]+\\([0-9]+\\))?\\)?[:.,; (-]\\( warning:\\|[-0-9 ]*(W)\\)?" 1 2 3 (4))
  155. (edg-1
  156. "^\\([^ \n]+\\)(\\([0-9]+\\)): \\(?:error\\|warnin\\(g\\)\\|remar\\(k\\)\\)"
  157. 1 2 nil (3 . 4))
  158. (edg-2
  159. "at line \\([0-9]+\\) of \"\\([^ \n]+\\)\"$"
  160. 2 1 nil 0)
  161. (epc
  162. "^Error [0-9]+ at (\\([0-9]+\\):\\([^)\n]+\\))" 2 1)
  163. (ftnchek
  164. "\\(^Warning .*\\)? line[ \n]\\([0-9]+\\)[ \n]\\(?:col \\([0-9]+\\)[ \n]\\)?file \\([^ :;\n]+\\)"
  165. 4 2 3 (1))
  166. (iar
  167. "^\"\\(.*\\)\",\\([0-9]+\\)\\s-+\\(?:Error\\|Warnin\\(g\\)\\)\\[[0-9]+\\]:"
  168. 1 2 nil (3))
  169. (ibm
  170. "^\\([^( \n\t]+\\)(\\([0-9]+\\):\\([0-9]+\\)) :\
  171. \\(?:warnin\\(g\\)\\|informationa\\(l\\)\\)?" 1 2 3 (4 . 5))
  172. ;; fixme: should be `mips'
  173. (irix
  174. "^[-[:alnum:]_/ ]+: \\(?:\\(?:[sS]evere\\|[eE]rror\\|[wW]arnin\\(g\\)\\|[iI]nf\\(o\\)\\)[0-9 ]*: \\)?\
  175. \\([^,\" \n\t]+\\)\\(?:, line\\|:\\) \\([0-9]+\\):" 3 4 nil (1 . 2))
  176. (java
  177. "^\\(?:[ \t]+at \\|==[0-9]+== +\\(?:at\\|b\\(y\\)\\)\\).+(\\([^()\n]+\\):\\([0-9]+\\))$" 2 3 nil (1))
  178. (jikes-file
  179. "^\\(?:Found\\|Issued\\) .* compiling \"\\(.+\\)\":$" 1 nil nil 0)
  180. (jikes-line
  181. "^ *\\([0-9]+\\)\\.[ \t]+.*\n +\\(<-*>\n\\*\\*\\* \\(?:Error\\|Warnin\\(g\\)\\)\\)"
  182. nil 1 nil 2 0
  183. (2 (compilation-face '(3))))
  184. (gnu
  185. ;; The first line matches the program name for
  186. ;; PROGRAM:SOURCE-FILE-NAME:LINENO: MESSAGE
  187. ;; format, which is used for non-interactive programs other than
  188. ;; compilers (e.g. the "jade:" entry in compilation.txt).
  189. ;; This first line makes things ambiguous with output such as
  190. ;; "foo:344:50:blabla" since the "foo" part can match this first
  191. ;; line (in which case the file name as "344"). To avoid this,
  192. ;; the second line disallows filenames exclusively composed of
  193. ;; digits.
  194. ;; Similarly, we get lots of false positives with messages including
  195. ;; times of the form "HH:MM:SS" where MM is taken as a line number, so
  196. ;; the last line tries to rule out message where the info after the
  197. ;; line number starts with "SS". --Stef
  198. ;; The core of the regexp is the one with *?. It says that a file name
  199. ;; can be composed of any non-newline char, but it also rules out some
  200. ;; valid but unlikely cases, such as a trailing space or a space
  201. ;; followed by a -.
  202. "^\\(?:[[:alpha:]][-[:alnum:].]+: ?\\)?\
  203. \\([0-9]*[^0-9\n]\\(?:[^\n ]\\| [^-/\n]\\)*?\\): ?\
  204. \\([0-9]+\\)\\(?:\\([.:]\\)\\([0-9]+\\)\\)?\
  205. \\(?:-\\([0-9]+\\)?\\(?:\\.\\([0-9]+\\)\\)?\\)?:\
  206. \\(?: *\\(\\(?:Future\\|Runtime\\)?[Ww]arning\\|W:\\)\\|\
  207. *\\([Ii]nfo\\(?:\\>\\|rmationa?l?\\)\\|I:\\|instantiated from\\|[Nn]ote\\)\\|\
  208. \[0-9]?\\(?:[^0-9\n]\\|$\\)\\|[0-9][0-9][0-9]\\)"
  209. 1 (2 . 5) (4 . 6) (7 . 8))
  210. ;; The `gnu' style above can incorrectly match gcc's "In file
  211. ;; included from" message, so we process that first. -- cyd
  212. (gcc-include
  213. "^\\(?:In file included\\| \\) from \
  214. \\(.+\\):\\([0-9]+\\)\\(?:\\(:\\)\\|\\(,\\)\\)?" 1 2 nil (3 . 4))
  215. (lcc
  216. "^\\(?:E\\|\\(W\\)\\), \\([^(\n]+\\)(\\([0-9]+\\),[ \t]*\\([0-9]+\\)"
  217. 2 3 4 (1))
  218. (makepp
  219. "^makepp\\(?:\\(?:: warning\\(:\\).*?\\|\\(: Scanning\\|: [LR]e?l?oading makefile\\|: Imported\\|log:.*?\\) \\|: .*?\\)\
  220. `\\(\\(\\S +?\\)\\(?::\\([0-9]+\\)\\)?\\)['(]\\)"
  221. 4 5 nil (1 . 2) 3
  222. ("`\\(\\(\\S +?\\)\\(?::\\([0-9]+\\)\\)?\\)['(]" nil nil
  223. (2 compilation-info-face)
  224. (3 compilation-line-face nil t)
  225. (1 (compilation-error-properties 2 3 nil nil nil 0 nil)
  226. append)))
  227. ;; This regexp is pathologically slow on long lines (Bug#3441).
  228. ;; (maven
  229. ;; ;; Maven is a popular build tool for Java. Maven is Free Software.
  230. ;; "\\(.*?\\):\\[\\([0-9]+\\),\\([0-9]+\\)\\]" 1 2 3)
  231. ;; Should be lint-1, lint-2 (SysV lint)
  232. (mips-1
  233. " (\\([0-9]+\\)) in \\([^ \n]+\\)" 2 1)
  234. (mips-2
  235. " in \\([^()\n ]+\\)(\\([0-9]+\\))$" 1 2)
  236. (msft
  237. ;; The message may be a "warning", "error", or "fatal error" with
  238. ;; an error code, or "see declaration of" without an error code.
  239. "^ *\\([0-9]+>\\)?\\(\\(?:[a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\)) \
  240. : \\(?:see declaration\\|\\(?:warnin\\(g\\)\\|[a-z ]+\\) C[0-9]+:\\)"
  241. 2 3 nil (4))
  242. (omake
  243. ;; "omake -P" reports "file foo changed"
  244. ;; (useful if you do "cvs up" and want to see what has changed)
  245. "omake: file \\(.*\\) changed" 1)
  246. (oracle
  247. "^\\(?:Semantic error\\|Error\\|PCC-[0-9]+:\\).* line \\([0-9]+\\)\
  248. \\(?:\\(?:,\\| at\\)? column \\([0-9]+\\)\\)?\
  249. \\(?:,\\| in\\| of\\)? file \\(.*?\\):?$"
  250. 3 1 2)
  251. ;; "during global destruction": This comes out under "use
  252. ;; warnings" in recent perl when breaking circular references
  253. ;; during program or thread exit.
  254. (perl
  255. " at \\([^ \n]+\\) line \\([0-9]+\\)\\(?:[,.]\\|$\\| \
  256. during global destruction\\.$\\)" 1 2)
  257. (php
  258. "\\(?:Parse\\|Fatal\\) error: \\(.*\\) in \\(.*\\) on line \\([0-9]+\\)"
  259. 2 3 nil nil)
  260. (rxp
  261. "^\\(?:Error\\|Warnin\\(g\\)\\):.*\n.* line \\([0-9]+\\) char\
  262. \\([0-9]+\\) of file://\\(.+\\)"
  263. 4 2 3 (1))
  264. (sparc-pascal-file
  265. "^\\w\\w\\w \\w\\w\\w +[0-3]?[0-9] +[0-2][0-9]:[0-5][0-9]:[0-5][0-9]\
  266. [12][09][0-9][0-9] +\\(.*\\):$"
  267. 1 nil nil 0)
  268. (sparc-pascal-line
  269. "^\\(\\(?:E\\|\\(w\\)\\) +[0-9]+\\) line \\([0-9]+\\) - "
  270. nil 3 nil (2) nil (1 (compilation-face '(2))))
  271. (sparc-pascal-example
  272. "^ +\\([0-9]+\\) +.*\n\\(\\(?:e\\|\\(w\\)\\) [0-9]+\\)-+"
  273. nil 1 nil (3) nil (2 (compilation-face '(3))))
  274. (sun
  275. ": \\(?:ERROR\\|WARNIN\\(G\\)\\|REMAR\\(K\\)\\) \\(?:[[:alnum:] ]+, \\)?\
  276. File = \\(.+\\), Line = \\([0-9]+\\)\\(?:, Column = \\([0-9]+\\)\\)?"
  277. 3 4 5 (1 . 2))
  278. (sun-ada
  279. "^\\([^, \n\t]+\\), line \\([0-9]+\\), char \\([0-9]+\\)[:., \(-]" 1 2 3)
  280. (watcom
  281. "\\(\\(?:[a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\)): ?\
  282. \\(?:\\(Error! E[0-9]+\\)\\|\\(Warning! W[0-9]+\\)\\):"
  283. 1 2 nil (4))
  284. (4bsd
  285. "\\(?:^\\|:: \\|\\S ( \\)\\(/[^ \n\t()]+\\)(\\([0-9]+\\))\
  286. \\(?:: \\(warning:\\)?\\|$\\| ),\\)" 1 2 nil (3))
  287. (gcov-file
  288. "^ *-: *\\(0\\):Source:\\(.+\\)$"
  289. 2 1 nil 0 nil
  290. (1 compilation-line-face prepend) (2 compilation-info-face prepend))
  291. (gcov-header
  292. "^ *-: *\\(0\\):\\(?:Object\\|Graph\\|Data\\|Runs\\|Programs\\):.+$"
  293. nil 1 nil 0 nil
  294. (1 compilation-line-face prepend))
  295. ;; Underlines over all lines of gcov output are too uncomfortable to read.
  296. ;; However, hyperlinks embedded in the lines are useful.
  297. ;; So I put default face on the lines; and then put
  298. ;; compilation-*-face by manually to eliminate the underlines.
  299. ;; The hyperlinks are still effective.
  300. (gcov-nomark
  301. "^ *-: *\\([1-9]\\|[0-9]\\{2,\\}\\):.*$"
  302. nil 1 nil 0 nil
  303. (0 'default t)
  304. (1 compilation-line-face prepend))
  305. (gcov-called-line
  306. "^ *\\([0-9]+\\): *\\([0-9]+\\):.*$"
  307. nil 2 nil 0 nil
  308. (0 'default t)
  309. (1 compilation-info-face prepend) (2 compilation-line-face prepend))
  310. (gcov-never-called
  311. "^ *\\(#####\\): *\\([0-9]+\\):.*$"
  312. nil 2 nil 2 nil
  313. (0 'default t)
  314. (1 compilation-error-face prepend) (2 compilation-line-face prepend))
  315. (perl--Pod::Checker
  316. ;; podchecker error messages, per Pod::Checker.
  317. ;; The style is from the Pod::Checker::poderror() function, eg.
  318. ;; *** ERROR: Spurious text after =cut at line 193 in file foo.pm
  319. ;;
  320. ;; Plus end_pod() can give "at line EOF" instead of a
  321. ;; number, so for that match "on line N" which is the
  322. ;; originating spot, eg.
  323. ;; *** ERROR: =over on line 37 without closing =back at line EOF in file bar.pm
  324. ;;
  325. ;; Plus command() can give both "on line N" and "at line N";
  326. ;; the latter is desired and is matched because the .* is
  327. ;; greedy.
  328. ;; *** ERROR: =over on line 1 without closing =back (at head1) at line 3 in file x.pod
  329. ;;
  330. "^\\*\\*\\* \\(?:ERROR\\|\\(WARNING\\)\\).* \\(?:at\\|on\\) line \
  331. \\([0-9]+\\) \\(?:.* \\)?in file \\([^ \t\n]+\\)"
  332. 3 2 nil (1))
  333. (perl--Test
  334. ;; perl Test module error messages.
  335. ;; Style per the ok() function "$context", eg.
  336. ;; # Failed test 1 in foo.t at line 6
  337. ;;
  338. "^# Failed test [0-9]+ in \\([^ \t\r\n]+\\) at line \\([0-9]+\\)"
  339. 1 2)
  340. (perl--Test2
  341. ;; Or when comparing got/want values,
  342. ;; # Test 2 got: "xx" (t-compilation-perl-2.t at line 10)
  343. ;;
  344. ;; And under Test::Harness they're preceded by progress stuff with
  345. ;; \r and "NOK",
  346. ;; ... NOK 1# Test 1 got: "1234" (t/foo.t at line 46)
  347. ;;
  348. "^\\(.*NOK.*\\)?# Test [0-9]+ got:.* (\\([^ \t\r\n]+\\) at line \
  349. \\([0-9]+\\))"
  350. 2 3)
  351. (perl--Test::Harness
  352. ;; perl Test::Harness output, eg.
  353. ;; NOK 1# Test 1 got: "1234" (t/foo.t at line 46)
  354. ;;
  355. ;; Test::Harness is slightly designed for tty output, since
  356. ;; it prints CRs to overwrite progress messages, but if you
  357. ;; run it in with M-x compile this pattern can at least step
  358. ;; through the failures.
  359. ;;
  360. "^.*NOK.* \\([^ \t\r\n]+\\) at line \\([0-9]+\\)"
  361. 1 2)
  362. (weblint
  363. ;; The style comes from HTML::Lint::Error::as_string(), eg.
  364. ;; index.html (13:1) Unknown element <fdjsk>
  365. ;;
  366. ;; The pattern only matches filenames without spaces, since that
  367. ;; should be usual and should help reduce the chance of a false
  368. ;; match of a message from some unrelated program.
  369. ;;
  370. ;; This message style is quite close to the "ibm" entry which is
  371. ;; for IBM C, though that ibm bit doesn't put a space after the
  372. ;; filename.
  373. ;;
  374. "^\\([^ \t\r\n(]+\\) (\\([0-9]+\\):\\([0-9]+\\)) "
  375. 1 2 3)
  376. )
  377. "Alist of values for `compilation-error-regexp-alist'.")
  378. (defcustom compilation-error-regexp-alist
  379. (mapcar 'car compilation-error-regexp-alist-alist)
  380. "Alist that specifies how to match errors in compiler output.
  381. On GNU and Unix, any string is a valid filename, so these
  382. matchers must make some common sense assumptions, which catch
  383. normal cases. A shorter list will be lighter on resource usage.
  384. Instead of an alist element, you can use a symbol, which is
  385. looked up in `compilation-error-regexp-alist-alist'. You can see
  386. the predefined symbols and their effects in the file
  387. `etc/compilation.txt' (linked below if you are customizing this).
  388. Each elt has the form (REGEXP FILE [LINE COLUMN TYPE HYPERLINK
  389. HIGHLIGHT...]). If REGEXP matches, the FILE'th subexpression
  390. gives the file name, and the LINE'th subexpression gives the line
  391. number. The COLUMN'th subexpression gives the column number on
  392. that line.
  393. If FILE, LINE or COLUMN are nil or that index didn't match, that
  394. information is not present on the matched line. In that case the
  395. file name is assumed to be the same as the previous one in the
  396. buffer, line number defaults to 1 and column defaults to
  397. beginning of line's indentation.
  398. FILE can also have the form (FILE FORMAT...), where the FORMATs
  399. \(e.g. \"%s.c\") will be applied in turn to the recognized file
  400. name, until a file of that name is found. Or FILE can also be a
  401. function that returns (FILENAME) or (RELATIVE-FILENAME . DIRNAME).
  402. In the former case, FILENAME may be relative or absolute.
  403. LINE can also be of the form (LINE . END-LINE) meaning a range
  404. of lines. COLUMN can also be of the form (COLUMN . END-COLUMN)
  405. meaning a range of columns starting on LINE and ending on
  406. END-LINE, if that matched.
  407. TYPE is 2 or nil for a real error or 1 for warning or 0 for info.
  408. TYPE can also be of the form (WARNING . INFO). In that case this
  409. will be equivalent to 1 if the WARNING'th subexpression matched
  410. or else equivalent to 0 if the INFO'th subexpression matched.
  411. See `compilation-error-face', `compilation-warning-face',
  412. `compilation-info-face' and `compilation-skip-threshold'.
  413. What matched the HYPERLINK'th subexpression has `mouse-face' and
  414. `compilation-message-face' applied. If this is nil, the text
  415. matched by the whole REGEXP becomes the hyperlink.
  416. Additional HIGHLIGHTs as described under `font-lock-keywords' can
  417. be added."
  418. :type `(set :menu-tag "Pick"
  419. ,@(mapcar (lambda (elt)
  420. (list 'const (car elt)))
  421. compilation-error-regexp-alist-alist))
  422. :link `(file-link :tag "example file"
  423. ,(expand-file-name "compilation.txt" data-directory))
  424. :group 'compilation)
  425. ;;;###autoload(put 'compilation-directory 'safe-local-variable 'stringp)
  426. (defvar compilation-directory nil
  427. "Directory to restore to when doing `recompile'.")
  428. (defvar compilation-directory-matcher
  429. '("\\(?:Entering\\|Leavin\\(g\\)\\) directory `\\(.+\\)'$" (2 . 1))
  430. "A list for tracking when directories are entered or left.
  431. If nil, do not track directories, e.g. if all file names are absolute. The
  432. first element is the REGEXP matching these messages. It can match any number
  433. of variants, e.g. different languages. The remaining elements are all of the
  434. form (DIR . LEAVE). If for any one of these the DIR'th subexpression
  435. matches, that is a directory name. If LEAVE is nil or the corresponding
  436. LEAVE'th subexpression doesn't match, this message is about going into another
  437. directory. If it does match anything, this message is about going back to the
  438. directory we were in before the last entering message. If you change this,
  439. you may also want to change `compilation-page-delimiter'.")
  440. (defvar compilation-page-delimiter
  441. "^\\(?:\f\\|.*\\(?:Entering\\|Leaving\\) directory `.+'\n\\)+"
  442. "Value of `page-delimiter' in Compilation mode.")
  443. (defvar compilation-mode-font-lock-keywords
  444. '(;; configure output lines.
  445. ("^[Cc]hecking \\(?:[Ff]or \\|[Ii]f \\|[Ww]hether \\(?:to \\)?\\)?\\(.+\\)\\.\\.\\. *\\(?:(cached) *\\)?\\(\\(yes\\(?: .+\\)?\\)\\|no\\|\\(.*\\)\\)$"
  446. (1 font-lock-variable-name-face)
  447. (2 (compilation-face '(4 . 3))))
  448. ;; Command output lines. Recognize `make[n]:' lines too.
  449. ("^\\([[:alnum:]_/.+-]+\\)\\(\\[\\([0-9]+\\)\\]\\)?[ \t]*:"
  450. (1 font-lock-function-name-face) (3 compilation-line-face nil t))
  451. (" --?o\\(?:utfile\\|utput\\)?[= ]?\\(\\S +\\)" . 1)
  452. ("^Compilation \\(finished\\).*"
  453. (0 '(face nil message nil help-echo nil mouse-face nil) t)
  454. (1 compilation-info-face))
  455. ("^Compilation \\(exited abnormally\\|interrupt\\|killed\\|terminated\\|segmentation fault\\)\\(?:.*with code \\([0-9]+\\)\\)?.*"
  456. (0 '(face nil message nil help-echo nil mouse-face nil) t)
  457. (1 compilation-error-face)
  458. (2 compilation-error-face nil t)))
  459. "Additional things to highlight in Compilation mode.
  460. This gets tacked on the end of the generated expressions.")
  461. (defvar compilation-highlight-regexp t
  462. "Regexp matching part of visited source lines to highlight temporarily.
  463. Highlight entire line if t; don't highlight source lines if nil.")
  464. (defvar compilation-highlight-overlay nil
  465. "Overlay used to temporarily highlight compilation matches.")
  466. (defcustom compilation-error-screen-columns t
  467. "If non-nil, column numbers in error messages are screen columns.
  468. Otherwise they are interpreted as character positions, with
  469. each character occupying one column.
  470. The default is to use screen columns, which requires that the compilation
  471. program and Emacs agree about the display width of the characters,
  472. especially the TAB character."
  473. :type 'boolean
  474. :group 'compilation
  475. :version "20.4")
  476. (defcustom compilation-read-command t
  477. "Non-nil means \\[compile] reads the compilation command to use.
  478. Otherwise, \\[compile] just uses the value of `compile-command'."
  479. :type 'boolean
  480. :group 'compilation)
  481. ;;;###autoload
  482. (defcustom compilation-ask-about-save t
  483. "Non-nil means \\[compile] asks which buffers to save before compiling.
  484. Otherwise, it saves all modified buffers without asking."
  485. :type 'boolean
  486. :group 'compilation)
  487. ;;;###autoload
  488. (defcustom compilation-search-path '(nil)
  489. "List of directories to search for source files named in error messages.
  490. Elements should be directory names, not file names of directories.
  491. The value nil as an element means to try the default directory."
  492. :type '(repeat (choice (const :tag "Default" nil)
  493. (string :tag "Directory")))
  494. :group 'compilation)
  495. ;;;###autoload
  496. (defcustom compile-command (purecopy "make -k ")
  497. "Last shell command used to do a compilation; default for next compilation.
  498. Sometimes it is useful for files to supply local values for this variable.
  499. You might also use mode hooks to specify it in certain modes, like this:
  500. (add-hook 'c-mode-hook
  501. (lambda ()
  502. (unless (or (file-exists-p \"makefile\")
  503. (file-exists-p \"Makefile\"))
  504. (set (make-local-variable 'compile-command)
  505. (concat \"make -k \"
  506. (file-name-sans-extension buffer-file-name))))))"
  507. :type 'string
  508. :group 'compilation)
  509. ;;;###autoload(put 'compile-command 'safe-local-variable 'stringp)
  510. ;;;###autoload
  511. (defcustom compilation-disable-input nil
  512. "If non-nil, send end-of-file as compilation process input.
  513. This only affects platforms that support asynchronous processes (see
  514. `start-process'); synchronous compilation processes never accept input."
  515. :type 'boolean
  516. :group 'compilation
  517. :version "22.1")
  518. ;; A weak per-compilation-buffer hash indexed by (FILENAME . DIRECTORY). Each
  519. ;; value is a FILE-STRUCTURE as described above, with the car eq to the hash
  520. ;; key. This holds the tree seen from root, for storing new nodes.
  521. (defvar compilation-locs ())
  522. (defvar compilation-debug nil
  523. "*Set this to t before creating a *compilation* buffer.
  524. Then every error line will have a debug text property with the matcher that
  525. fit this line and the match data. Use `describe-text-properties'.")
  526. (defvar compilation-exit-message-function nil "\
  527. If non-nil, called when a compilation process dies to return a status message.
  528. This should be a function of three arguments: process status, exit status,
  529. and exit message; it returns a cons (MESSAGE . MODELINE) of the strings to
  530. write into the compilation buffer, and to put in its mode line.")
  531. (defvar compilation-environment nil
  532. "*List of environment variables for compilation to inherit.
  533. Each element should be a string of the form ENVVARNAME=VALUE.
  534. This list is temporarily prepended to `process-environment' prior to
  535. starting the compilation process.")
  536. ;; History of compile commands.
  537. (defvar compile-history nil)
  538. (defface compilation-error
  539. '((t :inherit font-lock-warning-face))
  540. "Face used to highlight compiler errors."
  541. :group 'compilation
  542. :version "22.1")
  543. (defface compilation-warning
  544. '((((class color) (min-colors 16)) (:foreground "Orange" :weight bold))
  545. (((class color)) (:foreground "cyan" :weight bold))
  546. (t (:weight bold)))
  547. "Face used to highlight compiler warnings."
  548. :group 'compilation
  549. :version "22.1")
  550. (defface compilation-info
  551. '((((class color) (min-colors 16) (background light))
  552. (:foreground "Green3" :weight bold))
  553. (((class color) (min-colors 88) (background dark))
  554. (:foreground "Green1" :weight bold))
  555. (((class color) (min-colors 16) (background dark))
  556. (:foreground "Green" :weight bold))
  557. (((class color)) (:foreground "green" :weight bold))
  558. (t (:weight bold)))
  559. "Face used to highlight compiler information."
  560. :group 'compilation
  561. :version "22.1")
  562. (defface compilation-line-number
  563. '((t :inherit font-lock-variable-name-face))
  564. "Face for displaying line numbers in compiler messages."
  565. :group 'compilation
  566. :version "22.1")
  567. (defface compilation-column-number
  568. '((t :inherit font-lock-type-face))
  569. "Face for displaying column numbers in compiler messages."
  570. :group 'compilation
  571. :version "22.1")
  572. (defcustom compilation-message-face 'underline
  573. "Face name to use for whole messages.
  574. Faces `compilation-error-face', `compilation-warning-face',
  575. `compilation-info-face', `compilation-line-face' and
  576. `compilation-column-face' get prepended to this, when applicable."
  577. :type 'face
  578. :group 'compilation
  579. :version "22.1")
  580. (defvar compilation-error-face 'compilation-error
  581. "Face name to use for file name in error messages.")
  582. (defvar compilation-warning-face 'compilation-warning
  583. "Face name to use for file name in warning messages.")
  584. (defvar compilation-info-face 'compilation-info
  585. "Face name to use for file name in informational messages.")
  586. (defvar compilation-line-face 'compilation-line-number
  587. "Face name to use for line numbers in compiler messages.")
  588. (defvar compilation-column-face 'compilation-column-number
  589. "Face name to use for column numbers in compiler messages.")
  590. ;; same faces as dired uses
  591. (defvar compilation-enter-directory-face 'font-lock-function-name-face
  592. "Face name to use for entering directory messages.")
  593. (defvar compilation-leave-directory-face 'font-lock-type-face
  594. "Face name to use for leaving directory messages.")
  595. ;; Used for compatibility with the old compile.el.
  596. (defvaralias 'compilation-last-buffer 'next-error-last-buffer)
  597. (defvar compilation-parsing-end (make-marker))
  598. (defvar compilation-parse-errors-function nil)
  599. (defvar compilation-error-list nil)
  600. (defvar compilation-old-error-list nil)
  601. (defcustom compilation-auto-jump-to-first-error nil
  602. "If non-nil, automatically jump to the first error during compilation."
  603. :type 'boolean
  604. :group 'compilation
  605. :version "23.1")
  606. (defvar compilation-auto-jump-to-next nil
  607. "If non-nil, automatically jump to the next error encountered.")
  608. (make-variable-buffer-local 'compilation-auto-jump-to-next)
  609. (defvar compilation-skip-to-next-location t
  610. "*If non-nil, skip multiple error messages for the same source location.")
  611. (defcustom compilation-skip-threshold 1
  612. "Compilation motion commands skip less important messages.
  613. The value can be either 2 -- skip anything less than error, 1 --
  614. skip anything less than warning or 0 -- don't skip any messages.
  615. Note that all messages not positively identified as warning or
  616. info, are considered errors."
  617. :type '(choice (const :tag "Warnings and info" 2)
  618. (const :tag "Info" 1)
  619. (const :tag "None" 0))
  620. :group 'compilation
  621. :version "22.1")
  622. (defcustom compilation-skip-visited nil
  623. "Compilation motion commands skip visited messages if this is t.
  624. Visited messages are ones for which the file, line and column have been jumped
  625. to from the current content in the current compilation buffer, even if it was
  626. from a different message."
  627. :type 'boolean
  628. :group 'compilation
  629. :version "22.1")
  630. (defun compilation-face (type)
  631. (or (and (car type) (match-end (car type)) compilation-warning-face)
  632. (and (cdr type) (match-end (cdr type)) compilation-info-face)
  633. compilation-error-face))
  634. ;; Internal function for calculating the text properties of a directory
  635. ;; change message. The directory property is important, because it is
  636. ;; the stack of nested enter-messages. Relative filenames on the following
  637. ;; lines are relative to the top of the stack.
  638. (defun compilation-directory-properties (idx leave)
  639. (if leave (setq leave (match-end leave)))
  640. ;; find previous stack, and push onto it, or if `leave' pop it
  641. (let ((dir (previous-single-property-change (point) 'directory)))
  642. (setq dir (if dir (or (get-text-property (1- dir) 'directory)
  643. (get-text-property dir 'directory))))
  644. `(face ,(if leave
  645. compilation-leave-directory-face
  646. compilation-enter-directory-face)
  647. directory ,(if leave
  648. (or (cdr dir)
  649. '(nil)) ; nil only isn't a property-change
  650. (cons (match-string-no-properties idx) dir))
  651. mouse-face highlight
  652. keymap compilation-button-map
  653. help-echo "mouse-2: visit destination directory")))
  654. ;; Data type `reverse-ordered-alist' retriever. This function retrieves the
  655. ;; KEY element from the ALIST, creating it in the right position if not already
  656. ;; present. ALIST structure is
  657. ;; '(ANCHOR (KEY1 ...) (KEY2 ...)... (KEYn ALIST ...))
  658. ;; ANCHOR is ignored, but necessary so that elements can be inserted. KEY1
  659. ;; may be nil. The other KEYs are ordered backwards so that growing line
  660. ;; numbers can be inserted in front and searching can abort after half the
  661. ;; list on average.
  662. (eval-when-compile ;Don't keep it at runtime if not needed.
  663. (defmacro compilation-assq (key alist)
  664. `(let* ((l1 ,alist)
  665. (l2 (cdr l1)))
  666. (car (if (if (null ,key)
  667. (if l2 (null (caar l2)))
  668. (while (if l2 (if (caar l2) (< ,key (caar l2)) t))
  669. (setq l1 l2
  670. l2 (cdr l1)))
  671. (if l2 (eq ,key (caar l2))))
  672. l2
  673. (setcdr l1 (cons (list ,key) l2)))))))
  674. (defun compilation-auto-jump (buffer pos)
  675. (with-current-buffer buffer
  676. (goto-char pos)
  677. (let ((win (get-buffer-window buffer 0)))
  678. (if win (set-window-point win pos)))
  679. (if compilation-auto-jump-to-first-error
  680. (compile-goto-error))))
  681. ;; This function is the central driver, called when font-locking to gather
  682. ;; all information needed to later jump to corresponding source code.
  683. ;; Return a property list with all meta information on this error location.
  684. (defun compilation-error-properties (file line end-line col end-col type fmt)
  685. (unless (< (next-single-property-change (match-beginning 0)
  686. 'directory nil (point))
  687. (point))
  688. (if file
  689. (if (functionp file)
  690. (setq file (funcall file))
  691. (let (dir)
  692. (setq file (match-string-no-properties file))
  693. (unless (file-name-absolute-p file)
  694. (setq dir (previous-single-property-change (point) 'directory)
  695. dir (if dir (or (get-text-property (1- dir) 'directory)
  696. (get-text-property dir 'directory)))))
  697. (setq file (cons file (car dir)))))
  698. ;; This message didn't mention one, get it from previous
  699. (let ((prev-pos
  700. ;; Find the previous message.
  701. (previous-single-property-change (point) 'message)))
  702. (if prev-pos
  703. ;; Get the file structure that belongs to it.
  704. (let* ((prev
  705. (or (get-text-property (1- prev-pos) 'message)
  706. (get-text-property prev-pos 'message)))
  707. (prev-struct
  708. (car (nth 2 (car prev)))))
  709. ;; Construct FILE . DIR from that.
  710. (if prev-struct
  711. (setq file (cons (car prev-struct)
  712. (cadr prev-struct))))))
  713. (unless file
  714. (setq file '("*unknown*")))))
  715. ;; All of these fields are optional, get them only if we have an index, and
  716. ;; it matched some part of the message.
  717. (and line
  718. (setq line (match-string-no-properties line))
  719. (setq line (string-to-number line)))
  720. (and end-line
  721. (setq end-line (match-string-no-properties end-line))
  722. (setq end-line (string-to-number end-line)))
  723. (if col
  724. (if (functionp col)
  725. (setq col (funcall col))
  726. (and
  727. (setq col (match-string-no-properties col))
  728. (setq col (- (string-to-number col) compilation-first-column)))))
  729. (if (and end-col (functionp end-col))
  730. (setq end-col (funcall end-col))
  731. (if (and end-col (setq end-col (match-string-no-properties end-col)))
  732. (setq end-col (- (string-to-number end-col) compilation-first-column -1))
  733. (if end-line (setq end-col -1))))
  734. (if (consp type) ; not a static type, check what it is.
  735. (setq type (or (and (car type) (match-end (car type)) 1)
  736. (and (cdr type) (match-end (cdr type)) 0)
  737. 2)))
  738. (when (and compilation-auto-jump-to-next
  739. (>= type compilation-skip-threshold))
  740. (kill-local-variable 'compilation-auto-jump-to-next)
  741. (run-with-timer 0 nil 'compilation-auto-jump
  742. (current-buffer) (match-beginning 0)))
  743. (compilation-internal-error-properties file line end-line col end-col type fmt)))
  744. (defun compilation-move-to-column (col screen)
  745. "Go to column COL on the current line.
  746. If SCREEN is non-nil, columns are screen columns, otherwise, they are
  747. just char-counts."
  748. (if screen
  749. (move-to-column (max col 0))
  750. (goto-char (min (+ (line-beginning-position) col) (line-end-position)))))
  751. (defun compilation-internal-error-properties (file line end-line col end-col type fmts)
  752. "Get the meta-info that will be added as text-properties.
  753. LINE, END-LINE, COL, END-COL are integers or nil.
  754. TYPE can be 0, 1, or 2, meaning error, warning, or just info.
  755. FILE should be (FILENAME) or (RELATIVE-FILENAME . DIRNAME) or nil.
  756. FMTS is a list of format specs for transforming the file name.
  757. (See `compilation-error-regexp-alist'.)"
  758. (unless file (setq file '("*unknown*")))
  759. (let* ((file-struct (compilation-get-file-structure file fmts))
  760. ;; Get first already existing marker (if any has one, all have one).
  761. ;; Do this first, as the compilation-assq`s may create new nodes.
  762. (marker-line (car (cddr file-struct))) ; a line structure
  763. (marker (nth 3 (cadr marker-line))) ; its marker
  764. (compilation-error-screen-columns compilation-error-screen-columns)
  765. end-marker loc end-loc)
  766. (if (not (and marker (marker-buffer marker)))
  767. (setq marker nil) ; no valid marker for this file
  768. (setq loc (or line 1)) ; normalize no linenumber to line 1
  769. (catch 'marker ; find nearest loc, at least one exists
  770. (dolist (x (nthcdr 3 file-struct)) ; loop over remaining lines
  771. (if (> (car x) loc) ; still bigger
  772. (setq marker-line x)
  773. (if (> (- (or (car marker-line) 1) loc)
  774. (- loc (car x))) ; current line is nearer
  775. (setq marker-line x))
  776. (throw 'marker t))))
  777. (setq marker (nth 3 (cadr marker-line))
  778. marker-line (or (car marker-line) 1))
  779. (with-current-buffer (marker-buffer marker)
  780. (save-excursion
  781. (save-restriction
  782. (widen)
  783. (goto-char (marker-position marker))
  784. (when (or end-col end-line)
  785. (beginning-of-line (- (or end-line line) marker-line -1))
  786. (if (or (null end-col) (< end-col 0))
  787. (end-of-line)
  788. (compilation-move-to-column
  789. end-col compilation-error-screen-columns))
  790. (setq end-marker (list (point-marker))))
  791. (beginning-of-line (if end-line
  792. (- line end-line -1)
  793. (- loc marker-line -1)))
  794. (if col
  795. (compilation-move-to-column
  796. col compilation-error-screen-columns)
  797. (forward-to-indentation 0))
  798. (setq marker (list (point-marker)))))))
  799. (setq loc (compilation-assq line (cdr file-struct)))
  800. (if end-line
  801. (setq end-loc (compilation-assq end-line (cdr file-struct))
  802. end-loc (compilation-assq end-col end-loc))
  803. (if end-col ; use same line element
  804. (setq end-loc (compilation-assq end-col loc))))
  805. (setq loc (compilation-assq col loc))
  806. ;; If they are new, make the loc(s) reference the file they point to.
  807. (or (cdr loc) (setcdr loc `(,line ,file-struct ,@marker)))
  808. (if end-loc
  809. (or (cdr end-loc)
  810. (setcdr end-loc `(,(or end-line line) ,file-struct ,@end-marker))))
  811. ;; Must start with face
  812. `(face ,compilation-message-face
  813. message (,loc ,type ,end-loc)
  814. ,@(if compilation-debug
  815. `(debug (,(assoc (with-no-warnings matcher) font-lock-keywords)
  816. ,@(match-data))))
  817. help-echo ,(if col
  818. "mouse-2: visit this file, line and column"
  819. (if line
  820. "mouse-2: visit this file and line"
  821. "mouse-2: visit this file"))
  822. keymap compilation-button-map
  823. mouse-face highlight)))
  824. (defun compilation-mode-font-lock-keywords ()
  825. "Return expressions to highlight in Compilation mode."
  826. (if compilation-parse-errors-function
  827. ;; An old package! Try the compatibility code.
  828. '((compilation-compat-parse-errors))
  829. (append
  830. ;; make directory tracking
  831. (if compilation-directory-matcher
  832. `((,(car compilation-directory-matcher)
  833. ,@(mapcar (lambda (elt)
  834. `(,(car elt)
  835. (compilation-directory-properties
  836. ,(car elt) ,(cdr elt))
  837. t t))
  838. (cdr compilation-directory-matcher)))))
  839. ;; Compiler warning/error lines.
  840. (mapcar
  841. (lambda (item)
  842. (if (symbolp item)
  843. (setq item (cdr (assq item
  844. compilation-error-regexp-alist-alist))))
  845. (let ((file (nth 1 item))
  846. (line (nth 2 item))
  847. (col (nth 3 item))
  848. (type (nth 4 item))
  849. (pat (car item))
  850. end-line end-col fmt)
  851. ;; omake reports some error indented, so skip the indentation.
  852. ;; another solution is to modify (some?) regexps in
  853. ;; `compilation-error-regexp-alist'.
  854. ;; note that omake usage is not limited to ocaml and C (for stubs).
  855. (when (and (= ?^ (aref pat 0)) ; anchored: starts with "^"
  856. ;; but does not allow an arbitrary number of leading spaces
  857. (not (and (= ? (aref pat 1)) (= ?* (aref pat 2)))))
  858. (setq pat (concat "^ *" (substring pat 1))))
  859. (if (consp file) (setq fmt (cdr file) file (car file)))
  860. (if (consp line) (setq end-line (cdr line) line (car line)))
  861. (if (consp col) (setq end-col (cdr col) col (car col)))
  862. (if (functionp line)
  863. ;; The old compile.el had here an undocumented hook that
  864. ;; allowed `line' to be a function that computed the actual
  865. ;; error location. Let's do our best.
  866. `(,pat
  867. (0 (save-match-data
  868. (compilation-compat-error-properties
  869. (funcall ',line (cons (match-string ,file)
  870. (cons default-directory
  871. ',(nthcdr 4 item)))
  872. ,(if col `(match-string ,col))))))
  873. (,file compilation-error-face t))
  874. (unless (or (null (nth 5 item)) (integerp (nth 5 item)))
  875. (error "HYPERLINK should be an integer: %s" (nth 5 item)))
  876. `(,pat
  877. ,@(when (integerp file)
  878. `((,file ,(if (consp type)
  879. `(compilation-face ',type)
  880. (aref [compilation-info-face
  881. compilation-warning-face
  882. compilation-error-face]
  883. (or type 2))))))
  884. ,@(when line
  885. `((,line compilation-line-face nil t)))
  886. ,@(when end-line
  887. `((,end-line compilation-line-face nil t)))
  888. ,@(when (integerp col)
  889. `((,col compilation-column-face nil t)))
  890. ,@(when (integerp end-col)
  891. `((,end-col compilation-column-face nil t)))
  892. ,@(nthcdr 6 item)
  893. (,(or (nth 5 item) 0)
  894. (compilation-error-properties ',file ,line ,end-line
  895. ,col ,end-col ',(or type 2)
  896. ',fmt)
  897. append))))) ; for compilation-message-face
  898. compilation-error-regexp-alist)
  899. compilation-mode-font-lock-keywords)))
  900. (defun compilation-read-command (command)
  901. (read-shell-command "Compile command: " command
  902. (if (equal (car compile-history) command)
  903. '(compile-history . 1)
  904. 'compile-history)))
  905. ;;;###autoload
  906. (defun compile (command &optional comint)
  907. "Compile the program including the current buffer. Default: run `make'.
  908. Runs COMMAND, a shell command, in a separate process asynchronously
  909. with output going to the buffer `*compilation*'.
  910. You can then use the command \\[next-error] to find the next error message
  911. and move to the source code that caused it.
  912. If optional second arg COMINT is t the buffer will be in Comint mode with
  913. `compilation-shell-minor-mode'.
  914. Interactively, prompts for the command if `compilation-read-command' is
  915. non-nil; otherwise uses `compile-command'. With prefix arg, always prompts.
  916. Additionally, with universal prefix arg, compilation buffer will be in
  917. comint mode, i.e. interactive.
  918. To run more than one compilation at once, start one then rename
  919. the \`*compilation*' buffer to some other name with
  920. \\[rename-buffer]. Then _switch buffers_ and start the new compilation.
  921. It will create a new \`*compilation*' buffer.
  922. On most systems, termination of the main compilation process
  923. kills its subprocesses.
  924. The name used for the buffer is actually whatever is returned by
  925. the function in `compilation-buffer-name-function', so you can set that
  926. to a function that generates a unique name."
  927. (interactive
  928. (list
  929. (let ((command (eval compile-command)))
  930. (if (or compilation-read-command current-prefix-arg)
  931. (compilation-read-command command)
  932. command))
  933. (consp current-prefix-arg)))
  934. (unless (equal command (eval compile-command))
  935. (setq compile-command command))
  936. (save-some-buffers (not compilation-ask-about-save) nil)
  937. (setq-default compilation-directory default-directory)
  938. (compilation-start command comint))
  939. ;; run compile with the default command line
  940. (defun recompile (&optional edit-command)
  941. "Re-compile the program including the current buffer.
  942. If this is run in a Compilation mode buffer, re-use the arguments from the
  943. original use. Otherwise, recompile using `compile-command'.
  944. If the optional argument `edit-command' is non-nil, the command can be edited."
  945. (interactive "P")
  946. (save-some-buffers (not compilation-ask-about-save) nil)
  947. (let ((default-directory (or compilation-directory default-directory)))
  948. (when edit-command
  949. (setcar compilation-arguments
  950. (compilation-read-command (car compilation-arguments))))
  951. (apply 'compilation-start (or compilation-arguments
  952. `(,(eval compile-command))))))
  953. (defcustom compilation-scroll-output nil
  954. "Non-nil to scroll the *compilation* buffer window as output appears.
  955. Setting it causes the Compilation mode commands to put point at the
  956. end of their output window so that the end of the output is always
  957. visible rather than the beginning.
  958. The value `first-error' stops scrolling at the first error, and leaves
  959. point on its location in the *compilation* buffer."
  960. :type '(choice (const :tag "No scrolling" nil)
  961. (const :tag "Scroll compilation output" t)
  962. (const :tag "Stop scrolling at the first error" first-error))
  963. :version "20.3"
  964. :group 'compilation)
  965. (defun compilation-buffer-name (mode-name mode-command name-function)
  966. "Return the name of a compilation buffer to use.
  967. If NAME-FUNCTION is non-nil, call it with one argument MODE-NAME
  968. to determine the buffer name.
  969. Likewise if `compilation-buffer-name-function' is non-nil.
  970. If current buffer has the major mode MODE-COMMAND,
  971. return the name of the current buffer, so that it gets reused.
  972. Otherwise, construct a buffer name from MODE-NAME."
  973. (cond (name-function
  974. (funcall name-function mode-name))
  975. (compilation-buffer-name-function
  976. (funcall compilation-buffer-name-function mode-name))
  977. ((eq mode-command major-mode)
  978. (buffer-name))
  979. (t
  980. (concat "*" (downcase mode-name) "*"))))
  981. ;; This is a rough emulation of the old hack, until the transition to new
  982. ;; compile is complete.
  983. (defun compile-internal (command error-message
  984. &optional name-of-mode parser
  985. error-regexp-alist name-function
  986. enter-regexp-alist leave-regexp-alist
  987. file-regexp-alist nomessage-regexp-alist
  988. no-async highlight-regexp local-map)
  989. (if parser
  990. (error "Compile now works very differently, see `compilation-error-regexp-alist'"))
  991. (let ((compilation-error-regexp-alist
  992. (append file-regexp-alist (or error-regexp-alist
  993. compilation-error-regexp-alist)))
  994. (compilation-error (replace-regexp-in-string "^No more \\(.+\\)s\\.?"
  995. "\\1" error-message)))
  996. (compilation-start command nil name-function highlight-regexp)))
  997. (make-obsolete 'compile-internal 'compilation-start "22.1")
  998. ;;;###autoload
  999. (defun compilation-start (command &optional mode name-function highlight-regexp)
  1000. "Run compilation command COMMAND (low level interface).
  1001. If COMMAND starts with a cd command, that becomes the `default-directory'.
  1002. The rest of the arguments are optional; for them, nil means use the default.
  1003. MODE is the major mode to set in the compilation buffer. Mode
  1004. may also be t meaning use `compilation-shell-minor-mode' under `comint-mode'.
  1005. If NAME-FUNCTION is non-nil, call it with one argument (the mode name)
  1006. to determine the buffer name. Otherwise, the default is to
  1007. reuses the current buffer if it has the proper major mode,
  1008. else use or create a buffer with name based on the major mode.
  1009. If HIGHLIGHT-REGEXP is non-nil, `next-error' will temporarily highlight
  1010. the matching section of the visited source line; the default is to use the
  1011. global value of `compilation-highlight-regexp'.
  1012. Returns the compilation buffer created."
  1013. (or mode (setq mode 'compilation-mode))
  1014. (let* ((name-of-mode
  1015. (if (eq mode t)
  1016. "compilation"
  1017. (replace-regexp-in-string "-mode$" "" (symbol-name mode))))
  1018. (thisdir default-directory)
  1019. outwin outbuf)
  1020. (with-current-buffer
  1021. (setq outbuf
  1022. (get-buffer-create
  1023. (compilation-buffer-name name-of-mode mode name-function)))
  1024. (let ((comp-proc (get-buffer-process (current-buffer))))
  1025. (if comp-proc
  1026. (if (or (not (eq (process-status comp-proc) 'run))
  1027. (yes-or-no-p
  1028. (format "A %s process is running; kill it? "
  1029. name-of-mode)))
  1030. (condition-case ()
  1031. (progn
  1032. (interrupt-process comp-proc)
  1033. (sit-for 1)
  1034. (delete-process comp-proc))
  1035. (error nil))
  1036. (error "Cannot have two processes in `%s' at once"
  1037. (buffer-name)))))
  1038. ;; first transfer directory from where M-x compile was called
  1039. (setq default-directory thisdir)
  1040. ;; Make compilation buffer read-only. The filter can still write it.
  1041. ;; Clear out the compilation buffer.
  1042. (let ((inhibit-read-only t)
  1043. (default-directory thisdir))
  1044. ;; Then evaluate a cd command if any, but don't perform it yet, else
  1045. ;; start-command would do it again through the shell: (cd "..") AND
  1046. ;; sh -c "cd ..; make"
  1047. (cd (if (string-match "^\\s *cd\\(?:\\s +\\(\\S +?\\)\\)?\\s *[;&\n]" command)
  1048. (if (match-end 1)
  1049. (substitute-env-vars (match-string 1 command))
  1050. "~")
  1051. default-directory))
  1052. (erase-buffer)
  1053. ;; Select the desired mode.
  1054. (if (not (eq mode t))
  1055. (progn
  1056. (buffer-disable-undo)
  1057. (funcall mode))
  1058. (setq buffer-read-only nil)
  1059. (with-no-warnings (comint-mode))
  1060. (compilation-shell-minor-mode))
  1061. ;; Remember the original dir, so we can use it when we recompile.
  1062. ;; default-directory' can't be used reliably for that because it may be
  1063. ;; affected by the special handling of "cd ...;".
  1064. ;; NB: must be fone after (funcall mode) as that resets local variables
  1065. (set (make-local-variable 'compilation-directory) thisdir)
  1066. (if highlight-regexp
  1067. (set (make-local-variable 'compilation-highlight-regexp)
  1068. highlight-regexp))
  1069. (if (or compilation-auto-jump-to-first-error
  1070. (eq compilation-scroll-output 'first-error))
  1071. (set (make-local-variable 'compilation-auto-jump-to-next) t))
  1072. ;; Output a mode setter, for saving and later reloading this buffer.
  1073. (insert "-*- mode: " name-of-mode
  1074. "; default-directory: " (prin1-to-string default-directory)
  1075. " -*-\n"
  1076. (format "%s started at %s\n\n"
  1077. mode-name
  1078. (substring (current-time-string) 0 19))
  1079. command "\n")
  1080. (setq thisdir default-directory))
  1081. (set-buffer-modified-p nil))
  1082. ;; Pop up the compilation buffer.
  1083. ;; http://lists.gnu.org/archive/html/emacs-devel/2007-11/msg01638.html
  1084. (setq outwin (display-buffer outbuf))
  1085. (with-current-buffer outbuf
  1086. (let ((process-environment
  1087. (append
  1088. compilation-environment
  1089. (if (if (boundp 'system-uses-terminfo) ; `if' for compiler warning
  1090. system-uses-terminfo)
  1091. (list "TERM=dumb" "TERMCAP="
  1092. (format "COLUMNS=%d" (window-width)))
  1093. (list "TERM=emacs"
  1094. (format "TERMCAP=emacs:co#%d:tc=unknown:"
  1095. (window-width))))
  1096. ;; Set the EMACS variable, but
  1097. ;; don't override users' setting of $EMACS.
  1098. (unless (getenv "EMACS")
  1099. (list "EMACS=t"))
  1100. (list "INSIDE_EMACS=t")
  1101. (copy-sequence process-environment))))
  1102. (set (make-local-variable 'compilation-arguments)
  1103. (list command mode name-function highlight-regexp))
  1104. (set (make-local-variable 'revert-buffer-function)
  1105. 'compilation-revert-buffer)
  1106. (set-window-start outwin (point-min))
  1107. ;; Position point as the user will see it.
  1108. (let ((desired-visible-point
  1109. ;; Put it at the end if `compilation-scroll-output' is set.
  1110. (if compilation-scroll-output
  1111. (point-max)
  1112. ;; Normally put it at the top.
  1113. (point-min))))
  1114. (if (eq outwin (selected-window))
  1115. (goto-char desired-visible-point)
  1116. (set-window-point outwin desired-visible-point)))
  1117. ;; The setup function is called before compilation-set-window-height
  1118. ;; so it can set the compilation-window-height buffer locally.
  1119. (if compilation-process-setup-function
  1120. (funcall compilation-process-setup-function))
  1121. (compilation-set-window-height outwin)
  1122. ;; Start the compilation.
  1123. (if (fboundp 'start-process)
  1124. (let ((proc
  1125. (if (eq mode t)
  1126. ;; comint uses `start-file-process'.
  1127. (get-buffer-process
  1128. (with-no-warnings
  1129. (comint-exec
  1130. outbuf (downcase mode-name)
  1131. (if (file-remote-p default-directory)
  1132. "/bin/sh"
  1133. shell-file-name)
  1134. nil `("-c" ,command))))
  1135. (start-file-process-shell-command (downcase mode-name)
  1136. outbuf command))))
  1137. ;; Make the buffer's mode line show process state.
  1138. (setq mode-line-process
  1139. (list (propertize ":%s" 'face 'compilation-warning)))
  1140. (set-process-sentinel proc 'compilation-sentinel)
  1141. (unless (eq mode t)
  1142. ;; Keep the comint filter, since it's needed for proper handling
  1143. ;; of the prompts.
  1144. (set-process-filter proc 'compilation-filter))
  1145. ;; Use (point-max) here so that output comes in
  1146. ;; after the initial text,
  1147. ;; regardless of where the user sees point.
  1148. (set-marker (process-mark proc) (point-max) outbuf)
  1149. (when compilation-disable-input
  1150. (condition-case nil
  1151. (process-send-eof proc)
  1152. ;; The process may have exited already.
  1153. (error nil)))
  1154. (run-hook-with-args 'compilation-start-hook proc)
  1155. (setq compilation-in-progress
  1156. (cons proc compilation-in-progress)))
  1157. ;; No asynchronous processes available.
  1158. (message "Executing `%s'..." command)
  1159. ;; Fake modeline display as if `start-process' were run.
  1160. (setq mode-line-process
  1161. (list (propertize ":run" 'face 'compilation-warning)))
  1162. (force-mode-line-update)
  1163. (sit-for 0) ; Force redisplay
  1164. (save-excursion
  1165. ;; Insert the output at the end, after the initial text,
  1166. ;; regardless of where the user sees point.
  1167. (goto-char (point-max))
  1168. (let* ((buffer-read-only nil) ; call-process needs to modify outbuf
  1169. (status (call-process shell-file-name nil outbuf nil "-c"
  1170. command)))
  1171. (cond ((numberp status)
  1172. (compilation-handle-exit
  1173. 'exit status
  1174. (if (zerop status)
  1175. "finished\n"
  1176. (format "exited abnormally with code %d\n" status))))
  1177. ((stringp status)
  1178. (compilation-handle-exit 'signal status
  1179. (concat status "\n")))
  1180. (t
  1181. (compilation-handle-exit 'bizarre status status)))))
  1182. ;; Without async subprocesses, the buffer is not yet
  1183. ;; fontified, so fontify it now.
  1184. (let ((font-lock-verbose nil)) ; shut up font-lock messages
  1185. (font-lock-fontify-buffer))
  1186. (set-buffer-modified-p nil)
  1187. (message "Executing `%s'...done" command)))
  1188. ;; Now finally cd to where the shell started make/grep/...
  1189. (setq default-directory thisdir)
  1190. ;; The following form selected outwin ever since revision 1.183,
  1191. ;; so possibly messing up point in some other window (bug#1073).
  1192. ;; Moved into the scope of with-current-buffer, though still with
  1193. ;; complete disregard for the case when compilation-scroll-output
  1194. ;; equals 'first-error (martin 2008-10-04).
  1195. (when compilation-scroll-output
  1196. (goto-char (point-max))))
  1197. ;; Make it so the next C-x ` will use this buffer.
  1198. (setq next-error-last-buffer outbuf)))
  1199. (defun compilation-set-window-height (window)
  1200. "Set the height of WINDOW according to `compilation-window-height'."
  1201. (let ((height (buffer-local-value 'compilation-window-height (window-buffer window))))
  1202. (and height
  1203. (window-full-width-p window)
  1204. ;; If window is alone in its frame, aside from a minibuffer,
  1205. ;; don't change its height.
  1206. (not (eq window (frame-root-window (window-frame window))))
  1207. ;; Stef said that doing the saves in this order is safer:
  1208. (save-excursion
  1209. (save-selected-window
  1210. (select-window window)
  1211. (enlarge-window (- height (window-height))))))))
  1212. (defvar compilation-menu-map
  1213. (let ((map (make-sparse-keymap "Errors"))
  1214. (opt-map (make-sparse-keymap "Skip")))
  1215. (define-key map [stop-subjob]
  1216. '(menu-item "Stop Compilation" kill-compilation
  1217. :help "Kill the process made by the M-x compile or M-x grep commands"))
  1218. (define-key map [compilation-mode-separator3]
  1219. '("----" . nil))
  1220. (define-key map [compilation-next-error-follow-minor-mode]
  1221. '(menu-item
  1222. "Auto Error Display" next-error-follow-minor-mode
  1223. :help "Display the error under cursor when moving the cursor"
  1224. :button (:toggle . next-error-follow-minor-mode)))
  1225. (define-key map [compilation-skip]
  1226. (cons "Skip Less Important Messages" opt-map))
  1227. (define-key opt-map [compilation-skip-none]
  1228. '(menu-item "Don't Skip Any Messages"
  1229. (lambda ()
  1230. (interactive)
  1231. (customize-set-variable 'compilation-skip-threshold 0))
  1232. :help "Do not skip any type of messages"
  1233. :button (:radio . (eq compilation-skip-threshold 0))))
  1234. (define-key opt-map [compilation-skip-info]
  1235. '(menu-item "Skip Info"
  1236. (lambda ()
  1237. (interactive)
  1238. (customize-set-variable 'compilation-skip-threshold 1))
  1239. :help "Skip anything less than warning"
  1240. :button (:radio . (eq compilation-skip-threshold 1))))
  1241. (define-key opt-map [compilation-skip-warning-and-info]
  1242. '(menu-item "Skip Warnings and Info"
  1243. (lambda ()
  1244. (interactive)
  1245. (customize-set-variable 'compilation-skip-threshold 2))
  1246. :help "Skip over Warnings and Info, stop for errors"
  1247. :button (:radio . (eq compilation-skip-threshold 2))))
  1248. (define-key map [compilation-mode-separator2]
  1249. '("----" . nil))
  1250. (define-key map [compilation-first-error]
  1251. '(menu-item "First Error" first-error
  1252. :help "Restart at the first error, visit corresponding source code"))
  1253. (define-key map [compilation-previous-error]
  1254. '(menu-item "Previous Error" previous-error
  1255. :help "Visit previous `next-error' message and corresponding source code"))
  1256. (define-key map [compilation-next-error]
  1257. '(menu-item "Next Error" next-error
  1258. :help "Visit next `next-error' message and corresponding source code"))
  1259. map))
  1260. (defvar compilation-minor-mode-map
  1261. (let ((map (make-sparse-keymap)))
  1262. (define-key map [mouse-2] 'compile-goto-error)
  1263. (define-key map [follow-link] 'mouse-face)
  1264. (define-key map "\C-c\C-c" 'compile-goto-error)
  1265. (define-key map "\C-m" 'compile-goto-error)
  1266. (define-key map "\C-c\C-k" 'kill-compilation)
  1267. (define-key map "\M-n" 'compilation-next-error)
  1268. (define-key map "\M-p" 'compilation-previous-error)
  1269. (define-key map "\M-{" 'compilation-previous-file)
  1270. (define-key map "\M-}" 'compilation-next-file)
  1271. (define-key map "g" 'recompile) ; revert
  1272. (define-key map "q" 'quit-window)
  1273. ;; Set up the menu-bar
  1274. (define-key map [menu-bar compilation]
  1275. (cons "Errors" compilation-menu-map))
  1276. map)
  1277. "Keymap for `compilation-minor-mode'.")
  1278. (defvar compilation-shell-minor-mode-map
  1279. (let ((map (make-sparse-keymap)))
  1280. (define-key map "\M-\C-m" 'compile-goto-error)
  1281. (define-key map "\M-\C-n" 'compilation-next-error)
  1282. (define-key map "\M-\C-p" 'compilation-previous-error)
  1283. (define-key map "\M-{" 'compilation-previous-file)
  1284. (define-key map "\M-}" 'compilation-next-file)
  1285. ;; Set up the menu-bar
  1286. (define-key map [menu-bar compilation]
  1287. (cons "Errors" compilation-menu-map))
  1288. map)
  1289. "Keymap for `compilation-shell-minor-mode'.")
  1290. (defvar compilation-button-map
  1291. (let ((map (make-sparse-keymap)))
  1292. (define-key map [mouse-2] 'compile-goto-error)
  1293. (define-key map [follow-link] 'mouse-face)
  1294. (define-key map "\C-m" 'compile-goto-error)
  1295. map)
  1296. "Keymap for compilation-message buttons.")
  1297. (fset 'compilation-button-map compilation-button-map)
  1298. (defvar compilation-mode-map
  1299. (let ((map (make-sparse-keymap)))
  1300. ;; Don't inherit from compilation-minor-mode-map,
  1301. ;; because that introduces a menu bar item we don't want.
  1302. ;; That confuses C-down-mouse-3.
  1303. (define-key map [mouse-2] 'compile-goto-error)
  1304. (define-key map [follow-link] 'mouse-face)
  1305. (define-key map "\C-c\C-c" 'compile-goto-error)
  1306. (define-key map "\C-m" 'compile-goto-error)
  1307. (define-key map "\C-c\C-k" 'kill-compilation)
  1308. (define-key map "\M-n" 'compilation-next-error)
  1309. (define-key map "\M-p" 'compilation-previous-error)
  1310. (define-key map "\M-{" 'compilation-previous-file)
  1311. (define-key map "\M-}" 'compilation-next-file)
  1312. (define-key map "\t" 'compilation-next-error)
  1313. (define-key map [backtab] 'compilation-previous-error)
  1314. (define-key map "g" 'recompile) ; revert
  1315. (define-key map "q" 'quit-window)
  1316. (define-key map " " 'scroll-up)
  1317. (define-key map "\^?" 'scroll-down)
  1318. (define-key map "\C-c\C-f" 'next-error-follow-minor-mode)
  1319. ;; Set up the menu-bar
  1320. (let ((submap (make-sparse-keymap "Compile")))
  1321. (define-key map [menu-bar compilation]
  1322. (cons "Compile" submap))
  1323. (set-keymap-parent submap compilation-menu-map))
  1324. (define-key map [menu-bar compilation compilation-separator2]
  1325. '("----" . nil))
  1326. (define-key map [menu-bar compilation compilation-grep]
  1327. '(menu-item "Search Files (grep)..." grep
  1328. :help "Run grep, with user-specified args, and collect output in a buffer"))
  1329. (define-key map [menu-bar compilation compilation-recompile]
  1330. '(menu-item "Recompile" recompile
  1331. :help "Re-compile the program including the current buffer"))
  1332. (define-key map [menu-bar compilation compilation-compile]
  1333. '(menu-item "Compile..." compile
  1334. :help "Compile the program including the current buffer. Default: run `make'"))
  1335. map)
  1336. "Keymap for compilation log buffers.
  1337. `compilation-minor-mode-map' is a parent of this.")
  1338. (defvar compilation-mode-tool-bar-map
  1339. ;; When bootstrapping, tool-bar-map is not properly initialized yet,
  1340. ;; so don't do anything.
  1341. (when (keymapp (butlast tool-bar-map))
  1342. (let ((map (butlast (copy-keymap tool-bar-map)))
  1343. (help (last tool-bar-map))) ;; Keep Help last in tool bar
  1344. (tool-bar-local-item
  1345. "left-arrow" 'previous-error-no-select 'previous-error-no-select map
  1346. :rtl "right-arrow"
  1347. :help "Goto previous error")
  1348. (tool-bar-local-item
  1349. "right-arrow" 'next-error-no-select 'next-error-no-select map
  1350. :rtl "left-arrow"
  1351. :help "Goto next error")
  1352. (tool-bar-local-item
  1353. "cancel" 'kill-compilation 'kill-compilation map
  1354. :enable '(let ((buffer (compilation-find-buffer)))
  1355. (get-buffer-process buffer))
  1356. :help "Stop compilation")
  1357. (tool-bar-local-item
  1358. "refresh" 'recompile 'recompile map
  1359. :help "Restart compilation")
  1360. (append map help))))
  1361. (put 'compilation-mode 'mode-class 'special)
  1362. ;;;###autoload
  1363. (defun compilation-mode (&optional name-of-mode)
  1364. "Major mode for compilation log buffers.
  1365. \\<compilation-mode-map>To visit the source for a line-numbered error,
  1366. move point to the error message line and type \\[compile-goto-error].
  1367. To kill the compilation, type \\[kill-compilation].
  1368. Runs `compilation-mode-hook' with `run-mode-hooks' (which see).
  1369. \\{compilation-mode-map}"
  1370. (interactive)
  1371. (kill-all-local-variables)
  1372. (use-local-map compilation-mode-map)
  1373. ;; Let windows scroll along with the output.
  1374. (set (make-local-variable 'window-point-insertion-type) t)
  1375. (set (make-local-variable 'tool-bar-map) compilation-mode-tool-bar-map)
  1376. (setq major-mode 'compilation-mode
  1377. mode-name (or name-of-mode "Compilation"))
  1378. (set (make-local-variable 'page-delimiter)
  1379. compilation-page-delimiter)
  1380. (compilation-setup)
  1381. (setq buffer-read-only t)
  1382. (run-mode-hooks 'compilation-mode-hook))
  1383. (defmacro define-compilation-mode (mode name doc &rest body)
  1384. "This is like `define-derived-mode' without the PARENT argument.
  1385. The parent is always `compilation-mode' and the customizable `compilation-...'
  1386. variables are also set from the name of the mode you have chosen,
  1387. by replacing the first word, e.g `compilation-scroll-output' from
  1388. `grep-scroll-output' if that variable exists."
  1389. (let ((mode-name (replace-regexp-in-string "-mode\\'" "" (symbol-name mode))))
  1390. `(define-derived-mode ,mode compilation-mode ,name
  1391. ,doc
  1392. ,@(mapcar (lambda (v)
  1393. (setq v (cons v
  1394. (intern-soft (replace-regexp-in-string
  1395. "^compilation" mode-name
  1396. (symbol-name v)))))
  1397. (and (cdr v)
  1398. (or (boundp (cdr v))
  1399. (if (boundp 'byte-compile-bound-variables)
  1400. (memq (cdr v) byte-compile-bound-variables)))
  1401. `(set (make-local-variable ',(car v)) ,(cdr v))))
  1402. '(compilation-buffer-name-function
  1403. compilation-directory-matcher
  1404. compilation-error
  1405. compilation-error-regexp-alist
  1406. compilation-error-regexp-alist-alist
  1407. compilation-error-screen-columns
  1408. compilation-finish-function
  1409. compilation-finish-functions
  1410. compilation-first-column
  1411. compilation-mode-font-lock-keywords
  1412. compilation-page-delimiter
  1413. compilation-parse-errors-filename-function
  1414. compilation-process-setup-function
  1415. compilation-scroll-output
  1416. compilation-search-path
  1417. compilation-skip-threshold
  1418. compilation-window-height))
  1419. ,@body)))
  1420. (defun compilation-revert-buffer (ignore-auto noconfirm)
  1421. (if buffer-file-name
  1422. (let (revert-buffer-function)
  1423. (revert-buffer ignore-auto noconfirm))
  1424. (if (or noconfirm (yes-or-no-p (format "Restart compilation? ")))
  1425. (apply 'compilation-start compilation-arguments))))
  1426. (defvar compilation-current-error nil
  1427. "Marker to the location from where the next error will be found.
  1428. The global commands next/previous/first-error/goto-error use this.")
  1429. (defvar compilation-messages-start nil
  1430. "Buffer position of the beginning of the compilation messages.
  1431. If nil, use the beginning of buffer.")
  1432. ;; A function name can't be a hook, must be something with a value.
  1433. (defconst compilation-turn-on-font-lock 'turn-on-font-lock)
  1434. (defun compilation-setup (&optional minor)
  1435. "Prepare the buffer for the compilation parsing commands to work.
  1436. Optional argument MINOR indicates this is called from
  1437. `compilation-minor-mode'."
  1438. (make-local-variable 'compilation-current-error)
  1439. (make-local-variable 'compilation-messages-start)
  1440. (make-local-variable 'compilation-error-screen-columns)
  1441. (make-local-variable 'overlay-arrow-position)
  1442. (set (make-local-variable 'overlay-arrow-string) "")
  1443. (setq next-error-overlay-arrow-position nil)
  1444. (add-hook 'kill-buffer-hook
  1445. (lambda () (setq next-error-overlay-arrow-position nil)) nil t)
  1446. ;; Note that compilation-next-error-function is for interfacing
  1447. ;; with the next-error function in simple.el, and it's only
  1448. ;; coincidentally named similarly to compilation-next-error.
  1449. (setq next-error-function 'compilation-next-error-function)
  1450. (set (make-local-variable 'comint-file-name-prefix)
  1451. (or (file-remote-p default-directory) ""))
  1452. (set (make-local-variable 'font-lock-extra-managed-props)
  1453. '(directory message help-echo mouse-face debug))
  1454. (set (make-local-variable 'compilation-locs)
  1455. (make-hash-table :test 'equal :weakness 'value))
  1456. ;; lazy-lock would never find the message unless it's scrolled to.
  1457. ;; jit-lock might fontify some things too late.
  1458. (set (make-local-variable 'font-lock-support-mode) nil)
  1459. (set (make-local-variable 'font-lock-maximum-size) nil)
  1460. (if minor
  1461. (let ((fld font-lock-defaults))
  1462. (font-lock-add-keywords nil (compilation-mode-font-lock-keywords))
  1463. (if font-lock-mode
  1464. (if fld
  1465. (font-lock-fontify-buffer)
  1466. (font-lock-change-mode)
  1467. (turn-on-font-lock))
  1468. (turn-on-font-lock)))
  1469. (setq font-lock-defaults '(compilation-mode-font-lock-keywords t))
  1470. ;; maybe defer font-lock till after derived mode is set up
  1471. (run-mode-hooks 'compilation-turn-on-font-lock)))
  1472. ;;;###autoload
  1473. (define-minor-mode compilation-shell-minor-mode
  1474. "Toggle compilation shell minor mode.
  1475. With arg, turn compilation mode on if and only if arg is positive.
  1476. In this minor mode, all the error-parsing commands of the
  1477. Compilation major mode are available but bound to keys that don't
  1478. collide with Shell mode. See `compilation-mode'.
  1479. Turning the mode on runs the normal hook `compilation-shell-minor-mode-hook'."
  1480. nil " Shell-Compile"
  1481. :group 'compilation
  1482. (if compilation-shell-minor-mode
  1483. (compilation-setup t)
  1484. (font-lock-remove-keywords nil (compilation-mode-font-lock-keywords))
  1485. (font-lock-fontify-buffer)))
  1486. ;;;###autoload
  1487. (define-minor-mode compilation-minor-mode
  1488. "Toggle compilation minor mode.
  1489. With arg, turn compilation mode on if and only if arg is positive.
  1490. In this minor mode, all the error-parsing commands of the
  1491. Compilation major mode are available. See `compilation-mode'.
  1492. Turning the mode on runs the normal hook `compilation-minor-mode-hook'."
  1493. nil " Compilation"
  1494. :group 'compilation
  1495. (if compilation-minor-mode
  1496. (compilation-setup t)
  1497. (font-lock-remove-keywords nil (compilation-mode-font-lock-keywords))
  1498. (font-lock-fontify-buffer)))
  1499. (defun compilation-handle-exit (process-status exit-status msg)
  1500. "Write MSG in the current buffer and hack its `mode-line-process'."
  1501. (let ((inhibit-read-only t)
  1502. (status (if compilation-exit-message-function
  1503. (funcall compilation-exit-message-function
  1504. process-status exit-status msg)
  1505. (cons msg exit-status)))
  1506. (omax (point-max))
  1507. (opoint (point))
  1508. (cur-buffer (current-buffer)))
  1509. ;; Record where we put the message, so we can ignore it later on.
  1510. (goto-char omax)
  1511. (insert ?\n mode-name " " (car status))
  1512. (if (and (numberp compilation-window-height)
  1513. (zerop compilation-window-height))
  1514. (message "%s" (cdr status)))
  1515. (if (bolp)
  1516. (forward-char -1))
  1517. (insert " at " (substring (current-time-string) 0 19))
  1518. (goto-char (point-max))
  1519. ;; Prevent that message from being recognized as a compilation error.
  1520. (add-text-properties omax (point)
  1521. (append '(compilation-handle-exit t) nil))
  1522. (setq mode-line-process
  1523. (let ((out-string (format ":%s [%s]" process-status (cdr status)))
  1524. (msg (format "%s %s" mode-name
  1525. (replace-regexp-in-string "\n?$" "" (car status)))))
  1526. (message "%s" msg)
  1527. (propertize out-string
  1528. 'help-echo msg 'face (if (> exit-status 0)
  1529. 'compilation-error
  1530. 'compilation-info))))
  1531. ;; Force mode line redisplay soon.
  1532. (force-mode-line-update)
  1533. (if (and opoint (< opoint omax))
  1534. (goto-char opoint))
  1535. (with-no-warnings
  1536. (if compilation-finish-function
  1537. (funcall compilation-finish-function cur-buffer msg)))
  1538. (run-hook-with-args 'compilation-finish-functions cur-buffer msg)))
  1539. ;; Called when compilation process changes state.
  1540. (defun compilation-sentinel (proc msg)
  1541. "Sentinel for compilation buffers."
  1542. (if (memq (process-status proc) '(exit signal))
  1543. (let ((buffer (process-buffer proc)))
  1544. (if (null (buffer-name buffer))
  1545. ;; buffer killed
  1546. (set-process-buffer proc nil)
  1547. (with-current-buffer buffer
  1548. ;; Write something in the compilation buffer
  1549. ;; and hack its mode line.
  1550. (compilation-handle-exit (process-status proc)
  1551. (process-exit-status proc)
  1552. msg)
  1553. ;; Since the buffer and mode line will show that the
  1554. ;; process is dead, we can delete it now. Otherwise it
  1555. ;; will stay around until M-x list-processes.
  1556. (delete-process proc)))
  1557. (setq compilation-in-progress (delq proc compilation-in-progress)))))
  1558. (defun compilation-filter (proc string)
  1559. "Process filter for compilation buffers.
  1560. Just inserts the text,
  1561. handles carriage motion (see `comint-inhibit-carriage-motion'),
  1562. and runs `compilation-filter-hook'."
  1563. (when (buffer-live-p (process-buffer proc))
  1564. (with-current-buffer (process-buffer proc)
  1565. (let ((inhibit-read-only t)
  1566. ;; `save-excursion' doesn't use the right insertion-type for us.
  1567. (pos (copy-marker (point) t))
  1568. (min (point-min-marker))
  1569. (max (point-max-marker)))
  1570. (unwind-protect
  1571. (progn
  1572. ;; If we are inserting at the end of the accessible part
  1573. ;; of the buffer, keep the inserted text visible.
  1574. (set-marker-insertion-type max t)
  1575. (widen)
  1576. (goto-char (process-mark proc))
  1577. ;; We used to use `insert-before-markers', so that windows with
  1578. ;; point at `process-mark' scroll along with the output, but we
  1579. ;; now use window-point-insertion-type instead.
  1580. (insert string)
  1581. (unless comint-inhibit-carriage-motion
  1582. (comint-carriage-motion (process-mark proc) (point)))
  1583. (set-marker (process-mark proc) (point))
  1584. (run-hooks 'compilation-filter-hook))
  1585. (goto-char pos)
  1586. (narrow-to-region min max)
  1587. (set-marker min nil)
  1588. (set-marker max nil))))))
  1589. ;;; test if a buffer is a compilation buffer, assuming we're in the buffer
  1590. (defsubst compilation-buffer-internal-p ()
  1591. "Test if inside a compilation buffer."
  1592. (local-variable-p 'compilation-locs))
  1593. ;;; test if a buffer is a compilation buffer, using compilation-buffer-internal-p
  1594. (defsubst compilation-buffer-p (buffer)
  1595. "Test if BUFFER is a compilation buffer."
  1596. (with-current-buffer buffer
  1597. (compilation-buffer-internal-p)))
  1598. (defmacro compilation-loop (< property-change 1+ error limit)
  1599. `(let (opt)
  1600. (while (,< n 0)
  1601. (setq opt pt)
  1602. (or (setq pt (,property-change pt 'message))
  1603. ;; Handle the case where where the first error message is
  1604. ;; at the start of the buffer, and n < 0.
  1605. (if (or (eq (get-text-property ,limit 'message)
  1606. (get-text-property opt 'message))
  1607. (eq pt opt))
  1608. (error ,error compilation-error)
  1609. (setq pt ,limit)))
  1610. ;; prop 'message usually has 2 changes, on and off, so
  1611. ;; re-search if off
  1612. (or (setq msg (get-text-property pt 'message))
  1613. (if (setq pt (,property-change pt 'message nil ,limit))
  1614. (setq msg (get-text-property pt 'message)))
  1615. (error ,error compilation-error))
  1616. (or (< (cadr msg) compilation-skip-threshold)
  1617. (if different-file
  1618. (eq (prog1 last (setq last (nth 2 (car msg))))
  1619. last))
  1620. (if compilation-skip-visited
  1621. (nthcdr 5 (car msg)))
  1622. (if compilation-skip-to-next-location
  1623. (eq (car msg) loc))
  1624. ;; count this message only if none of the above are true
  1625. (setq n (,1+ n))))))
  1626. (defun compilation-next-error (n &optional different-file pt)
  1627. "Move point to the next error in the compilation buffer.
  1628. This function does NOT find the source line like \\[next-error].
  1629. Prefix arg N says how many error messages to move forwards (or
  1630. backwards, if negative).
  1631. Optional arg DIFFERENT-FILE, if non-nil, means find next error for a
  1632. file that is different from the current one.
  1633. Optional arg PT, if non-nil, specifies the value of point to start
  1634. looking for the next message."
  1635. (interactive "p")
  1636. (or (compilation-buffer-p (current-buffer))
  1637. (error "Not in a compilation buffer"))
  1638. (or pt (setq pt (point)))
  1639. (let* ((msg (get-text-property pt 'message))
  1640. ;; `loc' is used by the compilation-loop macro.
  1641. (loc (car msg))
  1642. last)
  1643. (if (zerop n)
  1644. (unless (or msg ; find message near here
  1645. (setq msg (get-text-property (max (1- pt) (point-min))
  1646. 'message)))
  1647. (setq pt (previous-single-property-change pt 'message nil
  1648. (line-beginning-position)))
  1649. (unless (setq msg (get-text-property (max (1- pt) (point-min)) 'message))
  1650. (setq pt (next-single-property-change pt 'message nil
  1651. (line-end-position)))
  1652. (or (setq msg (get-text-property pt 'message))
  1653. (setq pt (point)))))
  1654. (setq last (nth 2 (car msg)))
  1655. (if (>= n 0)
  1656. (compilation-loop > next-single-property-change 1-
  1657. (if (get-buffer-process (current-buffer))
  1658. "No more %ss yet"
  1659. "Moved past last %s")
  1660. (point-max))
  1661. ;; Don't move "back" to message at or before point.
  1662. ;; Pass an explicit (point-min) to make sure pt is non-nil.
  1663. (setq pt (previous-single-property-change pt 'message nil (point-min)))
  1664. (compilation-loop < previous-single-property-change 1+
  1665. "Moved back before first %s" (point-min))))
  1666. (goto-char pt)
  1667. (or msg
  1668. (error "No %s here" compilation-error))))
  1669. (defun compilation-previous-error (n)
  1670. "Move point to the previous error in the compilation buffer.
  1671. Prefix arg N says how many error messages to move backwards (or
  1672. forwards, if negative).
  1673. Does NOT find the source line like \\[previous-error]."
  1674. (interactive "p")
  1675. (compilation-next-error (- n)))
  1676. (defun compilation-next-file (n)
  1677. "Move point to the next error for a different file than the current one.
  1678. Prefix arg N says how many files to move forwards (or backwards, if negative)."
  1679. (interactive "p")
  1680. (compilation-next-error n t))
  1681. (defun compilation-previous-file (n)
  1682. "Move point to the previous error for a different file than the current one.
  1683. Prefix arg N says how many files to move backwards (or forwards, if negative)."
  1684. (interactive "p")
  1685. (compilation-next-file (- n)))
  1686. (defun kill-compilation ()
  1687. "Kill the process made by the \\[compile] or \\[grep] commands."
  1688. (interactive)
  1689. (let ((buffer (compilation-find-buffer)))
  1690. (if (get-buffer-process buffer)
  1691. (interrupt-process (get-buffer-process buffer))
  1692. (error "The %s process is not running" (downcase mode-name)))))
  1693. (defalias 'compile-mouse-goto-error 'compile-goto-error)
  1694. (defun compile-goto-error (&optional event)
  1695. "Visit the source for the error message at point.
  1696. Use this command in a compilation log buffer. Sets the mark at point there."
  1697. (interactive (list last-input-event))
  1698. (if event (posn-set-point (event-end event)))
  1699. (or (compilation-buffer-p (current-buffer))
  1700. (error "Not in a compilation buffer"))
  1701. (if (get-text-property (point) 'directory)
  1702. (dired-other-window (car (get-text-property (point) 'directory)))
  1703. (push-mark)
  1704. (setq compilation-current-error (point))
  1705. (next-error-internal)))
  1706. (defun compilation-find-buffer (&optional avoid-current)
  1707. "Return a compilation buffer.
  1708. If AVOID-CURRENT is nil, and the current buffer is a compilation buffer,
  1709. return it. If AVOID-CURRENT is non-nil, return the current buffer only
  1710. as a last resort."
  1711. (if (and (compilation-buffer-internal-p) (not avoid-current))
  1712. (current-buffer)
  1713. (next-error-find-buffer avoid-current 'compilation-buffer-internal-p)))
  1714. ;;;###autoload
  1715. (defun compilation-next-error-function (n &optional reset)
  1716. "Advance to the next error message and visit the file where the error was.
  1717. This is the value of `next-error-function' in Compilation buffers."
  1718. (interactive "p")
  1719. (when reset
  1720. (setq compilation-current-error nil))
  1721. (let* ((columns compilation-error-screen-columns) ; buffer's local value
  1722. (last 1) timestamp
  1723. (loc (compilation-next-error (or n 1) nil
  1724. (or compilation-current-error
  1725. compilation-messages-start
  1726. (point-min))))
  1727. (end-loc (nth 2 loc))
  1728. (marker (point-marker)))
  1729. (setq compilation-current-error (point-marker)
  1730. overlay-arrow-position
  1731. (if (bolp)
  1732. compilation-current-error
  1733. (copy-marker (line-beginning-position)))
  1734. loc (car loc))
  1735. ;; If loc contains no marker, no error in that file has been visited.
  1736. ;; If the marker is invalid the buffer has been killed.
  1737. ;; If the file is newer than the timestamp, it has been modified
  1738. ;; (`omake -P' polls filesystem for changes and recompiles when needed
  1739. ;; in the same process and buffer).
  1740. ;; So, recalculate all markers for that file.
  1741. (unless (and (nth 3 loc) (marker-buffer (nth 3 loc)) (nthcdr 4 loc)
  1742. ;; There may be no timestamp info if the loc is a `fake-loc',
  1743. ;; but we just checked that the file has been visited before!
  1744. (equal (nth 4 loc)
  1745. (setq timestamp
  1746. (with-current-buffer (marker-buffer (nth 3 loc))
  1747. (visited-file-modtime)))))
  1748. (with-current-buffer (compilation-find-file marker (caar (nth 2 loc))
  1749. (cadr (car (nth 2 loc))))
  1750. (save-restriction
  1751. (widen)
  1752. (goto-char (point-min))
  1753. ;; Treat file's found lines in forward order, 1 by 1.
  1754. (dolist (line (reverse (cddr (nth 2 loc))))
  1755. (when (car line) ; else this is a filename w/o a line#
  1756. (beginning-of-line (- (car line) last -1))
  1757. (setq last (car line)))
  1758. ;; Treat line's found columns and store/update a marker for each.
  1759. (dolist (col (cdr line))
  1760. (if (car col)
  1761. (if (eq (car col) -1) ; special case for range end
  1762. (end-of-line)
  1763. (compilation-move-to-column (car col) columns))
  1764. (beginning-of-line)
  1765. (skip-chars-forward " \t"))
  1766. (if (nth 3 col)
  1767. (set-marker (nth 3 col) (point))
  1768. (setcdr (nthcdr 2 col) `(,(point-marker)))))))))
  1769. (compilation-goto-locus marker (nth 3 loc) (nth 3 end-loc))
  1770. (setcdr (nthcdr 3 loc) (list timestamp))
  1771. (setcdr (nthcdr 4 loc) t))) ; Set this one as visited.
  1772. (defvar compilation-gcpro nil
  1773. "Internal variable used to keep some values from being GC'd.")
  1774. (make-variable-buffer-local 'compilation-gcpro)
  1775. (defun compilation-fake-loc (marker file &optional line col)
  1776. "Preassociate MARKER with FILE.
  1777. FILE should be ABSOLUTE-FILENAME or (RELATIVE-FILENAME . DIRNAME).
  1778. This is useful when you compile temporary files, but want
  1779. automatic translation of the messages to the real buffer from
  1780. which the temporary file came. This only works if done before a
  1781. message about FILE appears!
  1782. Optional args LINE and COL default to 1 and beginning of
  1783. indentation respectively. The marker is expected to reflect
  1784. this. In the simplest case the marker points to the first line
  1785. of the region that was saved to the temp file.
  1786. If you concatenate several regions into the temp file (e.g. a
  1787. header with variable assignments and a code region), you must
  1788. call this several times, once each for the last line of one
  1789. region and the first line of the next region."
  1790. (or (consp file) (setq file (list file)))
  1791. (setq file (compilation-get-file-structure file))
  1792. ;; Between the current call to compilation-fake-loc and the first occurrence
  1793. ;; of an error message referring to `file', the data is only kept in the
  1794. ;; weak hash-table compilation-locs, so we need to prevent this entry
  1795. ;; in compilation-locs from being GC'd away. --Stef
  1796. (push file compilation-gcpro)
  1797. (let ((loc (compilation-assq (or line 1) (cdr file))))
  1798. (setq loc (compilation-assq col loc))
  1799. (if (cdr loc)
  1800. (setcdr (cddr loc) (list marker))
  1801. (setcdr loc (list line file marker)))
  1802. loc))
  1803. (defcustom compilation-context-lines nil
  1804. "Display this many lines of leading context before the current message.
  1805. If nil and the left fringe is displayed, don't scroll the
  1806. compilation output window; an arrow in the left fringe points to
  1807. the current message. If nil and there is no left fringe, the message
  1808. displays at the top of the window; there is no arrow."
  1809. :type '(choice integer (const :tag "No window scrolling" nil))
  1810. :group 'compilation
  1811. :version "22.1")
  1812. (defsubst compilation-set-window (w mk)
  1813. "Align the compilation output window W with marker MK near top."
  1814. (if (integerp compilation-context-lines)
  1815. (set-window-start w (save-excursion
  1816. (goto-char mk)
  1817. (beginning-of-line
  1818. (- 1 compilation-context-lines))
  1819. (point)))
  1820. ;; If there is no left fringe.
  1821. (if (equal (car (window-fringes)) 0)
  1822. (set-window-start w (save-excursion
  1823. (goto-char mk)
  1824. (beginning-of-line 1)
  1825. (point)))))
  1826. (set-window-point w mk))
  1827. (defvar next-error-highlight-timer)
  1828. (defun compilation-goto-locus (msg mk end-mk)
  1829. "Jump to an error corresponding to MSG at MK.
  1830. All arguments are markers. If END-MK is non-nil, mark is set there
  1831. and overlay is highlighted between MK and END-MK."
  1832. ;; Show compilation buffer in other window, scrolled to this error.
  1833. (let* ((from-compilation-buffer (eq (window-buffer (selected-window))
  1834. (marker-buffer msg)))
  1835. ;; Use an existing window if it is in a visible frame.
  1836. (pre-existing (get-buffer-window (marker-buffer msg) 0))
  1837. (w (if (and from-compilation-buffer pre-existing)
  1838. ;; Calling display-buffer here may end up (partly) hiding
  1839. ;; the error location if the two buffers are in two
  1840. ;; different frames. So don't do it if it's not necessary.
  1841. pre-existing
  1842. (let ((display-buffer-reuse-frames t)
  1843. (pop-up-windows t))
  1844. ;; Pop up a window.
  1845. (display-buffer (marker-buffer msg)))))
  1846. (highlight-regexp (with-current-buffer (marker-buffer msg)
  1847. ;; also do this while we change buffer
  1848. (compilation-set-window w msg)
  1849. compilation-highlight-regexp)))
  1850. ;; Ideally, the window-size should be passed to `display-buffer' (via
  1851. ;; something like special-display-buffer) so it's only used when
  1852. ;; creating a new window.
  1853. (unless pre-existing (compilation-set-window-height w))
  1854. (if from-compilation-buffer
  1855. ;; If the compilation buffer window was selected,
  1856. ;; keep the compilation buffer in this window;
  1857. ;; display the source in another window.
  1858. (let ((pop-up-windows t))
  1859. (pop-to-buffer (marker-buffer mk) 'other-window))
  1860. (if (window-dedicated-p (selected-window))
  1861. (pop-to-buffer (marker-buffer mk))
  1862. (switch-to-buffer (marker-buffer mk))))
  1863. (unless (eq (goto-char mk) (point))
  1864. ;; If narrowing gets in the way of going to the right place, widen.
  1865. (widen)
  1866. (if next-error-move-function
  1867. (funcall next-error-move-function msg mk)
  1868. (goto-char mk)))
  1869. (if end-mk
  1870. (push-mark end-mk t)
  1871. (if mark-active (setq mark-active)))
  1872. ;; If hideshow got in the way of
  1873. ;; seeing the right place, open permanently.
  1874. (dolist (ov (overlays-at (point)))
  1875. (when (eq 'hs (overlay-get ov 'invisible))
  1876. (delete-overlay ov)
  1877. (goto-char mk)))
  1878. (when highlight-regexp
  1879. (if (timerp next-error-highlight-timer)
  1880. (cancel-timer next-error-highlight-timer))
  1881. (unless compilation-highlight-overlay
  1882. (setq compilation-highlight-overlay
  1883. (make-overlay (point-min) (point-min)))
  1884. (overlay-put compilation-highlight-overlay 'face 'next-error))
  1885. (with-current-buffer (marker-buffer mk)
  1886. (save-excursion
  1887. (if end-mk (goto-char end-mk) (end-of-line))
  1888. (let ((end (point)))
  1889. (if mk (goto-char mk) (beginning-of-line))
  1890. (if (and (stringp highlight-regexp)
  1891. (re-search-forward highlight-regexp end t))
  1892. (progn
  1893. (goto-char (match-beginning 0))
  1894. (move-overlay compilation-highlight-overlay
  1895. (match-beginning 0) (match-end 0)
  1896. (current-buffer)))
  1897. (move-overlay compilation-highlight-overlay
  1898. (point) end (current-buffer)))
  1899. (if (or (eq next-error-highlight t)
  1900. (numberp next-error-highlight))
  1901. ;; We want highlighting: delete overlay on next input.
  1902. (add-hook 'pre-command-hook
  1903. 'compilation-goto-locus-delete-o)
  1904. ;; We don't want highlighting: delete overlay now.
  1905. (delete-overlay compilation-highlight-overlay))
  1906. ;; We want highlighting for a limited time:
  1907. ;; set up a timer to delete it.
  1908. (when (numberp next-error-highlight)
  1909. (setq next-error-highlight-timer
  1910. (run-at-time next-error-highlight nil
  1911. 'compilation-goto-locus-delete-o)))))))
  1912. (when (and (eq next-error-highlight 'fringe-arrow))
  1913. ;; We want a fringe arrow (instead of highlighting).
  1914. (setq next-error-overlay-arrow-position
  1915. (copy-marker (line-beginning-position))))))
  1916. (defun compilation-goto-locus-delete-o ()
  1917. (delete-overlay compilation-highlight-overlay)
  1918. ;; Get rid of timer and hook that would try to do this again.
  1919. (if (timerp next-error-highlight-timer)
  1920. (cancel-timer next-error-highlight-timer))
  1921. (remove-hook 'pre-command-hook
  1922. 'compilation-goto-locus-delete-o))
  1923. (defun compilation-find-file (marker filename directory &rest formats)
  1924. "Find a buffer for file FILENAME.
  1925. If FILENAME is not found at all, ask the user where to find it.
  1926. Pop up the buffer containing MARKER and scroll to MARKER if we ask
  1927. the user where to find the file.
  1928. Search the directories in `compilation-search-path'.
  1929. A nil in `compilation-search-path' means to try the
  1930. \"current\" directory, which is passed in DIRECTORY.
  1931. If DIRECTORY is relative, it is combined with `default-directory'.
  1932. If DIRECTORY is nil, that means use `default-directory'.
  1933. FORMATS, if given, is a list of formats to reformat FILENAME when
  1934. looking for it: for each element FMT in FORMATS, this function
  1935. attempts to find a file whose name is produced by (format FMT FILENAME)."
  1936. (or formats (setq formats '("%s")))
  1937. (let ((dirs compilation-search-path)
  1938. (spec-dir (if directory
  1939. (expand-file-name directory)
  1940. default-directory))
  1941. buffer thisdir fmts name)
  1942. (if (file-name-absolute-p filename)
  1943. ;; The file name is absolute. Use its explicit directory as
  1944. ;; the first in the search path, and strip it from FILENAME.
  1945. (setq filename (abbreviate-file-name (expand-file-name filename))
  1946. dirs (cons (file-name-directory filename) dirs)
  1947. filename (file-name-nondirectory filename)))
  1948. ;; Now search the path.
  1949. (while (and dirs (null buffer))
  1950. (setq thisdir (or (car dirs) spec-dir)
  1951. fmts formats)
  1952. ;; For each directory, try each format string.
  1953. (while (and fmts (null buffer))
  1954. (setq name (expand-file-name (format (car fmts) filename) thisdir)
  1955. buffer (and (file-exists-p name)
  1956. (find-file-noselect name))
  1957. fmts (cdr fmts)))
  1958. (setq dirs (cdr dirs)))
  1959. (while (null buffer) ;Repeat until the user selects an existing file.
  1960. ;; The file doesn't exist. Ask the user where to find it.
  1961. (save-excursion ;This save-excursion is probably not right.
  1962. (let ((pop-up-windows t))
  1963. (compilation-set-window (display-buffer (marker-buffer marker))
  1964. marker)
  1965. (let* ((name (read-file-name
  1966. (format "Find this %s in (default %s): "
  1967. compilation-error filename)
  1968. spec-dir filename t nil
  1969. ;; The predicate below is fine when called from
  1970. ;; minibuffer-complete-and-exit, but it's too
  1971. ;; restrictive otherwise, since it also prevents the
  1972. ;; user from completing "fo" to "foo/" when she
  1973. ;; wants to enter "foo/bar".
  1974. ;;
  1975. ;; Try to make sure the user can only select
  1976. ;; a valid answer. This predicate may be ignored,
  1977. ;; tho, so we still have to double-check afterwards.
  1978. ;; TODO: We should probably fix read-file-name so
  1979. ;; that it never ignores this predicate, even when
  1980. ;; using popup dialog boxes.
  1981. ;; (lambda (name)
  1982. ;; (if (file-directory-p name)
  1983. ;; (setq name (expand-file-name filename name)))
  1984. ;; (file-exists-p name))
  1985. ))
  1986. (origname name))
  1987. (cond
  1988. ((not (file-exists-p name))
  1989. (message "Cannot find file `%s'" name)
  1990. (ding) (sit-for 2))
  1991. ((and (file-directory-p name)
  1992. (not (file-exists-p
  1993. (setq name (expand-file-name filename name)))))
  1994. (message "No `%s' in directory %s" filename origname)
  1995. (ding) (sit-for 2))
  1996. (t
  1997. (setq buffer (find-file-noselect name))))))))
  1998. ;; Make intangible overlays tangible.
  1999. ;; This is weird: it's not even clear which is the current buffer,
  2000. ;; so the code below can't be expected to DTRT here. -- Stef
  2001. (dolist (ov (overlays-in (point-min) (point-max)))
  2002. (when (overlay-get ov 'intangible)
  2003. (overlay-put ov 'intangible nil)))
  2004. buffer))
  2005. (defun compilation-get-file-structure (file &optional fmt)
  2006. "Retrieve FILE's file-structure or create a new one.
  2007. FILE should be (FILENAME) or (RELATIVE-FILENAME . DIRNAME).
  2008. In the former case, FILENAME may be relative or absolute.
  2009. The file-structure looks like this:
  2010. (list (list FILENAME [DIR-FROM-PREV-MSG]) FMT LINE-STRUCT...)"
  2011. (or (gethash file compilation-locs)
  2012. ;; File was not previously encountered, at least not in the form passed.
  2013. ;; Let's normalize it and look again.
  2014. (let ((filename (car file))
  2015. ;; Get the specified directory from FILE.
  2016. (spec-directory (if (cdr file)
  2017. (file-truename (cdr file)))))
  2018. ;; Check for a comint-file-name-prefix and prepend it if appropriate.
  2019. ;; (This is very useful for compilation-minor-mode in an rlogin-mode
  2020. ;; buffer.)
  2021. (when (and (boundp 'comint-file-name-prefix)
  2022. (not (equal comint-file-name-prefix "")))
  2023. (if (file-name-absolute-p filename)
  2024. (setq filename
  2025. (concat comint-file-name-prefix filename))
  2026. (if spec-directory
  2027. (setq spec-directory
  2028. (file-truename
  2029. (concat comint-file-name-prefix spec-directory))))))
  2030. ;; If compilation-parse-errors-filename-function is
  2031. ;; defined, use it to process the filename.
  2032. (when compilation-parse-errors-filename-function
  2033. (setq filename
  2034. (funcall compilation-parse-errors-filename-function
  2035. filename)))
  2036. ;; Some compilers (e.g. Sun's java compiler, reportedly) produce bogus
  2037. ;; file names like "./bar//foo.c" for file "bar/foo.c";
  2038. ;; expand-file-name will collapse these into "/foo.c" and fail to find
  2039. ;; the appropriate file. So we look for doubled slashes in the file
  2040. ;; name and fix them.
  2041. (setq filename (command-line-normalize-file-name filename))
  2042. ;; Store it for the possibly unnormalized name
  2043. (puthash file
  2044. ;; Retrieve or create file-structure for normalized name
  2045. ;; The gethash used to not use spec-directory, but
  2046. ;; this leads to errors when files in different
  2047. ;; directories have the same name:
  2048. ;; http://lists.gnu.org/archive/html/emacs-devel/2007-08/msg00463.html
  2049. (or (gethash (cons filename spec-directory) compilation-locs)
  2050. (puthash (cons filename spec-directory)
  2051. (list (list filename spec-directory) fmt)
  2052. compilation-locs))
  2053. compilation-locs))))
  2054. (add-to-list 'debug-ignored-errors "^No more [-a-z ]+s yet$")
  2055. ;;; Compatibility with the old compile.el.
  2056. (defun compile-buffer-substring (n) (if n (match-string n)))
  2057. (defun compilation-compat-error-properties (err)
  2058. "Map old-style error ERR to new-style message."
  2059. ;; Old-style structure is (MARKER (FILE DIR) LINE COL) or
  2060. ;; (MARKER . MARKER).
  2061. (let ((dst (cdr err)))
  2062. (if (markerp dst)
  2063. ;; Must start with a face, for font-lock.
  2064. `(face nil
  2065. message ,(list (list nil nil nil dst) 2)
  2066. help-echo "mouse-2: visit the source location"
  2067. keymap compilation-button-map
  2068. mouse-face highlight)
  2069. ;; Too difficult to do it by hand: dispatch to the normal code.
  2070. (let* ((file (pop dst))
  2071. (line (pop dst))
  2072. (col (pop dst))
  2073. (filename (pop file))
  2074. (dirname (pop file))
  2075. (fmt (pop file)))
  2076. (compilation-internal-error-properties
  2077. (cons filename dirname) line nil col nil 2 fmt)))))
  2078. (defun compilation-compat-parse-errors (limit)
  2079. (when compilation-parse-errors-function
  2080. ;; FIXME: We should remove the rest of the compilation keywords
  2081. ;; but we can't do that from here because font-lock is using
  2082. ;; the value right now. --stef
  2083. (save-excursion
  2084. (setq compilation-error-list nil)
  2085. ;; Reset compilation-parsing-end each time because font-lock
  2086. ;; might force us the re-parse many times (typically because
  2087. ;; some code adds some text-property to the output that we
  2088. ;; already parsed). You might say "why reparse", well:
  2089. ;; because font-lock has just removed the `message' property so
  2090. ;; have to do it all over again.
  2091. (if compilation-parsing-end
  2092. (set-marker compilation-parsing-end (point))
  2093. (setq compilation-parsing-end (point-marker)))
  2094. (condition-case nil
  2095. ;; Ignore any error: we're calling this function earlier than
  2096. ;; in the old compile.el so things might not all be setup yet.
  2097. (funcall compilation-parse-errors-function limit nil)
  2098. (error nil))
  2099. (dolist (err (if (listp compilation-error-list) compilation-error-list))
  2100. (let* ((src (car err))
  2101. (dst (cdr err))
  2102. (loc (cond ((markerp dst) (list nil nil nil dst))
  2103. ((consp dst)
  2104. (list (nth 2 dst) (nth 1 dst)
  2105. (cons (cdar dst) (caar dst)))))))
  2106. (when loc
  2107. (goto-char src)
  2108. ;; (put-text-property src (line-end-position) 'font-lock-face 'font-lock-warning-face)
  2109. (put-text-property src (line-end-position)
  2110. 'message (list loc 2)))))))
  2111. (goto-char limit)
  2112. nil)
  2113. ;; Beware: this is not only compatibility code. New code stil uses it. --Stef
  2114. (defun compilation-forget-errors ()
  2115. ;; In case we hit the same file/line specs, we want to recompute a new
  2116. ;; marker for them, so flush our cache.
  2117. (setq compilation-locs (make-hash-table :test 'equal :weakness 'value))
  2118. (setq compilation-gcpro nil)
  2119. ;; FIXME: the old code reset the directory-stack, so maybe we should
  2120. ;; put a `directory change' marker of some sort, but where? -stef
  2121. ;;
  2122. ;; FIXME: The old code moved compilation-current-error (which was
  2123. ;; virtually represented by a mix of compilation-parsing-end and
  2124. ;; compilation-error-list) to point-min, but that was only meaningful for
  2125. ;; the internal uses of compilation-forget-errors: all calls from external
  2126. ;; packages seem to be followed by a move of compilation-parsing-end to
  2127. ;; something equivalent to point-max. So we heuristically move
  2128. ;; compilation-current-error to point-max (since the external package
  2129. ;; won't know that it should do it). --Stef
  2130. (setq compilation-current-error nil)
  2131. (let* ((proc (get-buffer-process (current-buffer)))
  2132. (mark (if proc (process-mark proc)))
  2133. (pos (or mark (point-max))))
  2134. (setq compilation-messages-start
  2135. ;; In the future, ignore the text already present in the buffer.
  2136. ;; Since many process filter functions insert before markers,
  2137. ;; we need to put ours just before the insertion point rather
  2138. ;; than at the insertion point. If that's not possible, then
  2139. ;; don't use a marker. --Stef
  2140. (if (> pos (point-min)) (copy-marker (1- pos)) pos)))
  2141. ;; Again, since this command is used in buffers that contain several
  2142. ;; compilations, to set the beginning of "this compilation", it's a good
  2143. ;; place to reset compilation-auto-jump-to-next.
  2144. (set (make-local-variable 'compilation-auto-jump-to-next)
  2145. (or compilation-auto-jump-to-first-error
  2146. (eq compilation-scroll-output 'first-error))))
  2147. ;;;###autoload
  2148. (add-to-list 'auto-mode-alist (cons (purecopy "\\.gcov\\'") 'compilation-mode))
  2149. (provide 'compile)
  2150. ;; arch-tag: 12465727-7382-4f72-b234-79855a00dd8c
  2151. ;;; compile.el ends here