PageRenderTime 71ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/lisp/progmodes/compile.el

https://bitbucket.org/danchr/emacs
Emacs Lisp | 2411 lines | 1765 code | 234 blank | 412 comment | 77 complexity | 7a30a5aa71ba715eddb7acebe5beda71 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, 2010
  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. "^[ \t]*\\(\\(?:[a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\)): ?\
  282. \\(?:\\(Error! E[0-9]+\\)\\|\\(Warning! W[0-9]+\\)\\):"
  283. 1 2 nil (4))
  284. (4bsd
  285. "\\(?:^\\|:: \\|\\S ( \\)\\(/[^ \n\t()]+\\)(\\([0-9]+\\))\
  286. \\(?:: \\(warning:\\)?\\|$\\| ),\\)" 1 2 nil (3))
  287. (gcov-file
  288. "^ *-: *\\(0\\):Source:\\(.+\\)$"
  289. 2 1 nil 0 nil
  290. (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. Note that changing this to nil may be a security risk, because a
  480. file might define a malicious `compile-command' as a file local
  481. variable, and you might not notice. Therefore, `compile-command'
  482. is considered unsafe if this variable is nil."
  483. :type 'boolean
  484. :group 'compilation)
  485. ;;;###autoload
  486. (defcustom compilation-ask-about-save t
  487. "Non-nil means \\[compile] asks which buffers to save before compiling.
  488. Otherwise, it saves all modified buffers without asking."
  489. :type 'boolean
  490. :group 'compilation)
  491. (defcustom compilation-save-buffers-predicate nil
  492. "The second argument (PRED) passed to `save-some-buffers' before compiling.
  493. E.g., one can set this to
  494. (lambda ()
  495. (string-prefix-p my-compilation-root (file-truename (buffer-file-name))))
  496. to limit saving to files located under `my-compilation-root'.
  497. Note, that, in general, `compilation-directory' cannot be used instead
  498. of `my-compilation-root' here."
  499. :type '(choice
  500. (const :tag "Default (save all file-visiting buffers)" nil)
  501. (const :tag "Save all buffers" t)
  502. function)
  503. :group 'compilation
  504. :version "24.1")
  505. ;;;###autoload
  506. (defcustom compilation-search-path '(nil)
  507. "List of directories to search for source files named in error messages.
  508. Elements should be directory names, not file names of directories.
  509. The value nil as an element means to try the default directory."
  510. :type '(repeat (choice (const :tag "Default" nil)
  511. (string :tag "Directory")))
  512. :group 'compilation)
  513. ;;;###autoload
  514. (defcustom compile-command (purecopy "make -k ")
  515. "Last shell command used to do a compilation; default for next compilation.
  516. Sometimes it is useful for files to supply local values for this variable.
  517. You might also use mode hooks to specify it in certain modes, like this:
  518. (add-hook 'c-mode-hook
  519. (lambda ()
  520. (unless (or (file-exists-p \"makefile\")
  521. (file-exists-p \"Makefile\"))
  522. (set (make-local-variable 'compile-command)
  523. (concat \"make -k \"
  524. (file-name-sans-extension buffer-file-name))))))"
  525. :type 'string
  526. :group 'compilation)
  527. ;;;###autoload(put 'compile-command 'safe-local-variable (lambda (a) (and (stringp a) (or (not (boundp 'compilation-read-command)) compilation-read-command))))
  528. ;;;###autoload
  529. (defcustom compilation-disable-input nil
  530. "If non-nil, send end-of-file as compilation process input.
  531. This only affects platforms that support asynchronous processes (see
  532. `start-process'); synchronous compilation processes never accept input."
  533. :type 'boolean
  534. :group 'compilation
  535. :version "22.1")
  536. ;; A weak per-compilation-buffer hash indexed by (FILENAME . DIRECTORY). Each
  537. ;; value is a FILE-STRUCTURE as described above, with the car eq to the hash
  538. ;; key. This holds the tree seen from root, for storing new nodes.
  539. (defvar compilation-locs ())
  540. (defvar compilation-debug nil
  541. "*Set this to t before creating a *compilation* buffer.
  542. Then every error line will have a debug text property with the matcher that
  543. fit this line and the match data. Use `describe-text-properties'.")
  544. (defvar compilation-exit-message-function nil "\
  545. If non-nil, called when a compilation process dies to return a status message.
  546. This should be a function of three arguments: process status, exit status,
  547. and exit message; it returns a cons (MESSAGE . MODELINE) of the strings to
  548. write into the compilation buffer, and to put in its mode line.")
  549. (defvar compilation-environment nil
  550. "*List of environment variables for compilation to inherit.
  551. Each element should be a string of the form ENVVARNAME=VALUE.
  552. This list is temporarily prepended to `process-environment' prior to
  553. starting the compilation process.")
  554. ;; History of compile commands.
  555. (defvar compile-history nil)
  556. (defface compilation-error
  557. '((t :inherit font-lock-warning-face))
  558. "Face used to highlight compiler errors."
  559. :group 'compilation
  560. :version "22.1")
  561. (defface compilation-warning
  562. '((((class color) (min-colors 16)) (:foreground "Orange" :weight bold))
  563. (((class color)) (:foreground "cyan" :weight bold))
  564. (t (:weight bold)))
  565. "Face used to highlight compiler warnings."
  566. :group 'compilation
  567. :version "22.1")
  568. (defface compilation-info
  569. '((((class color) (min-colors 16) (background light))
  570. (:foreground "Green3" :weight bold))
  571. (((class color) (min-colors 88) (background dark))
  572. (:foreground "Green1" :weight bold))
  573. (((class color) (min-colors 16) (background dark))
  574. (:foreground "Green" :weight bold))
  575. (((class color)) (:foreground "green" :weight bold))
  576. (t (:weight bold)))
  577. "Face used to highlight compiler information."
  578. :group 'compilation
  579. :version "22.1")
  580. (defface compilation-line-number
  581. '((t :inherit font-lock-variable-name-face))
  582. "Face for displaying line numbers in compiler messages."
  583. :group 'compilation
  584. :version "22.1")
  585. (defface compilation-column-number
  586. '((t :inherit font-lock-type-face))
  587. "Face for displaying column numbers in compiler messages."
  588. :group 'compilation
  589. :version "22.1")
  590. (defcustom compilation-message-face 'underline
  591. "Face name to use for whole messages.
  592. Faces `compilation-error-face', `compilation-warning-face',
  593. `compilation-info-face', `compilation-line-face' and
  594. `compilation-column-face' get prepended to this, when applicable."
  595. :type 'face
  596. :group 'compilation
  597. :version "22.1")
  598. (defvar compilation-error-face 'compilation-error
  599. "Face name to use for file name in error messages.")
  600. (defvar compilation-warning-face 'compilation-warning
  601. "Face name to use for file name in warning messages.")
  602. (defvar compilation-info-face 'compilation-info
  603. "Face name to use for file name in informational messages.")
  604. (defvar compilation-line-face 'compilation-line-number
  605. "Face name to use for line numbers in compiler messages.")
  606. (defvar compilation-column-face 'compilation-column-number
  607. "Face name to use for column numbers in compiler messages.")
  608. ;; same faces as dired uses
  609. (defvar compilation-enter-directory-face 'font-lock-function-name-face
  610. "Face name to use for entering directory messages.")
  611. (defvar compilation-leave-directory-face 'font-lock-type-face
  612. "Face name to use for leaving directory messages.")
  613. ;; Used for compatibility with the old compile.el.
  614. (defvaralias 'compilation-last-buffer 'next-error-last-buffer)
  615. (defvar compilation-parsing-end (make-marker))
  616. (defvar compilation-parse-errors-function nil)
  617. (defvar compilation-error-list nil)
  618. (defvar compilation-old-error-list nil)
  619. (defcustom compilation-auto-jump-to-first-error nil
  620. "If non-nil, automatically jump to the first error during compilation."
  621. :type 'boolean
  622. :group 'compilation
  623. :version "23.1")
  624. (defvar compilation-auto-jump-to-next nil
  625. "If non-nil, automatically jump to the next error encountered.")
  626. (make-variable-buffer-local 'compilation-auto-jump-to-next)
  627. (defvar buffer-modtime nil
  628. "The buffer modification time, for buffers not associated with files.")
  629. (make-variable-buffer-local 'buffer-modtime)
  630. (defvar compilation-skip-to-next-location t
  631. "*If non-nil, skip multiple error messages for the same source location.")
  632. (defcustom compilation-skip-threshold 1
  633. "Compilation motion commands skip less important messages.
  634. The value can be either 2 -- skip anything less than error, 1 --
  635. skip anything less than warning or 0 -- don't skip any messages.
  636. Note that all messages not positively identified as warning or
  637. info, are considered errors."
  638. :type '(choice (const :tag "Warnings and info" 2)
  639. (const :tag "Info" 1)
  640. (const :tag "None" 0))
  641. :group 'compilation
  642. :version "22.1")
  643. (defcustom compilation-skip-visited nil
  644. "Compilation motion commands skip visited messages if this is t.
  645. Visited messages are ones for which the file, line and column have been jumped
  646. to from the current content in the current compilation buffer, even if it was
  647. from a different message."
  648. :type 'boolean
  649. :group 'compilation
  650. :version "22.1")
  651. (defun compilation-face (type)
  652. (or (and (car type) (match-end (car type)) compilation-warning-face)
  653. (and (cdr type) (match-end (cdr type)) compilation-info-face)
  654. compilation-error-face))
  655. ;; Internal function for calculating the text properties of a directory
  656. ;; change message. The directory property is important, because it is
  657. ;; the stack of nested enter-messages. Relative filenames on the following
  658. ;; lines are relative to the top of the stack.
  659. (defun compilation-directory-properties (idx leave)
  660. (if leave (setq leave (match-end leave)))
  661. ;; find previous stack, and push onto it, or if `leave' pop it
  662. (let ((dir (previous-single-property-change (point) 'directory)))
  663. (setq dir (if dir (or (get-text-property (1- dir) 'directory)
  664. (get-text-property dir 'directory))))
  665. `(face ,(if leave
  666. compilation-leave-directory-face
  667. compilation-enter-directory-face)
  668. directory ,(if leave
  669. (or (cdr dir)
  670. '(nil)) ; nil only isn't a property-change
  671. (cons (match-string-no-properties idx) dir))
  672. mouse-face highlight
  673. keymap compilation-button-map
  674. help-echo "mouse-2: visit destination directory")))
  675. ;; Data type `reverse-ordered-alist' retriever. This function retrieves the
  676. ;; KEY element from the ALIST, creating it in the right position if not already
  677. ;; present. ALIST structure is
  678. ;; '(ANCHOR (KEY1 ...) (KEY2 ...)... (KEYn ALIST ...))
  679. ;; ANCHOR is ignored, but necessary so that elements can be inserted. KEY1
  680. ;; may be nil. The other KEYs are ordered backwards so that growing line
  681. ;; numbers can be inserted in front and searching can abort after half the
  682. ;; list on average.
  683. (eval-when-compile ;Don't keep it at runtime if not needed.
  684. (defmacro compilation-assq (key alist)
  685. `(let* ((l1 ,alist)
  686. (l2 (cdr l1)))
  687. (car (if (if (null ,key)
  688. (if l2 (null (caar l2)))
  689. (while (if l2 (if (caar l2) (< ,key (caar l2)) t))
  690. (setq l1 l2
  691. l2 (cdr l1)))
  692. (if l2 (eq ,key (caar l2))))
  693. l2
  694. (setcdr l1 (cons (list ,key) l2)))))))
  695. (defun compilation-auto-jump (buffer pos)
  696. (with-current-buffer buffer
  697. (goto-char pos)
  698. (let ((win (get-buffer-window buffer 0)))
  699. (if win (set-window-point win pos)))
  700. (if compilation-auto-jump-to-first-error
  701. (compile-goto-error))))
  702. ;; This function is the central driver, called when font-locking to gather
  703. ;; all information needed to later jump to corresponding source code.
  704. ;; Return a property list with all meta information on this error location.
  705. (defun compilation-error-properties (file line end-line col end-col type fmt)
  706. (unless (< (next-single-property-change (match-beginning 0)
  707. 'directory nil (point))
  708. (point))
  709. (if file
  710. (if (functionp file)
  711. (setq file (funcall file))
  712. (let (dir)
  713. (setq file (match-string-no-properties file))
  714. (unless (file-name-absolute-p file)
  715. (setq dir (previous-single-property-change (point) 'directory)
  716. dir (if dir (or (get-text-property (1- dir) 'directory)
  717. (get-text-property dir 'directory)))))
  718. (setq file (cons file (car dir)))))
  719. ;; This message didn't mention one, get it from previous
  720. (let ((prev-pos
  721. ;; Find the previous message.
  722. (previous-single-property-change (point) 'message)))
  723. (if prev-pos
  724. ;; Get the file structure that belongs to it.
  725. (let* ((prev
  726. (or (get-text-property (1- prev-pos) 'message)
  727. (get-text-property prev-pos 'message)))
  728. (prev-struct
  729. (car (nth 2 (car prev)))))
  730. ;; Construct FILE . DIR from that.
  731. (if prev-struct
  732. (setq file (cons (car prev-struct)
  733. (cadr prev-struct))))))
  734. (unless file
  735. (setq file '("*unknown*")))))
  736. ;; All of these fields are optional, get them only if we have an index, and
  737. ;; it matched some part of the message.
  738. (and line
  739. (setq line (match-string-no-properties line))
  740. (setq line (string-to-number line)))
  741. (and end-line
  742. (setq end-line (match-string-no-properties end-line))
  743. (setq end-line (string-to-number end-line)))
  744. (if col
  745. (if (functionp col)
  746. (setq col (funcall col))
  747. (and
  748. (setq col (match-string-no-properties col))
  749. (setq col (- (string-to-number col) compilation-first-column)))))
  750. (if (and end-col (functionp end-col))
  751. (setq end-col (funcall end-col))
  752. (if (and end-col (setq end-col (match-string-no-properties end-col)))
  753. (setq end-col (- (string-to-number end-col) compilation-first-column -1))
  754. (if end-line (setq end-col -1))))
  755. (if (consp type) ; not a static type, check what it is.
  756. (setq type (or (and (car type) (match-end (car type)) 1)
  757. (and (cdr type) (match-end (cdr type)) 0)
  758. 2)))
  759. (when (and compilation-auto-jump-to-next
  760. (>= type compilation-skip-threshold))
  761. (kill-local-variable 'compilation-auto-jump-to-next)
  762. (run-with-timer 0 nil 'compilation-auto-jump
  763. (current-buffer) (match-beginning 0)))
  764. (compilation-internal-error-properties file line end-line col end-col type fmt)))
  765. (defun compilation-move-to-column (col screen)
  766. "Go to column COL on the current line.
  767. If SCREEN is non-nil, columns are screen columns, otherwise, they are
  768. just char-counts."
  769. (if screen
  770. (move-to-column (max col 0))
  771. (goto-char (min (+ (line-beginning-position) col) (line-end-position)))))
  772. (defun compilation-internal-error-properties (file line end-line col end-col type fmts)
  773. "Get the meta-info that will be added as text-properties.
  774. LINE, END-LINE, COL, END-COL are integers or nil.
  775. TYPE can be 0, 1, or 2, meaning error, warning, or just info.
  776. FILE should be (FILENAME) or (RELATIVE-FILENAME . DIRNAME) or nil.
  777. FMTS is a list of format specs for transforming the file name.
  778. (See `compilation-error-regexp-alist'.)"
  779. (unless file (setq file '("*unknown*")))
  780. (let* ((file-struct (compilation-get-file-structure file fmts))
  781. ;; Get first already existing marker (if any has one, all have one).
  782. ;; Do this first, as the compilation-assq`s may create new nodes.
  783. (marker-line (car (cddr file-struct))) ; a line structure
  784. (marker (nth 3 (cadr marker-line))) ; its marker
  785. (compilation-error-screen-columns compilation-error-screen-columns)
  786. end-marker loc end-loc)
  787. (if (not (and marker (marker-buffer marker)))
  788. (setq marker nil) ; no valid marker for this file
  789. (setq loc (or line 1)) ; normalize no linenumber to line 1
  790. (catch 'marker ; find nearest loc, at least one exists
  791. (dolist (x (nthcdr 3 file-struct)) ; loop over remaining lines
  792. (if (> (car x) loc) ; still bigger
  793. (setq marker-line x)
  794. (if (> (- (or (car marker-line) 1) loc)
  795. (- loc (car x))) ; current line is nearer
  796. (setq marker-line x))
  797. (throw 'marker t))))
  798. (setq marker (nth 3 (cadr marker-line))
  799. marker-line (or (car marker-line) 1))
  800. (with-current-buffer (marker-buffer marker)
  801. (save-excursion
  802. (save-restriction
  803. (widen)
  804. (goto-char (marker-position marker))
  805. (when (or end-col end-line)
  806. (beginning-of-line (- (or end-line line) marker-line -1))
  807. (if (or (null end-col) (< end-col 0))
  808. (end-of-line)
  809. (compilation-move-to-column
  810. end-col compilation-error-screen-columns))
  811. (setq end-marker (list (point-marker))))
  812. (beginning-of-line (if end-line
  813. (- line end-line -1)
  814. (- loc marker-line -1)))
  815. (if col
  816. (compilation-move-to-column
  817. col compilation-error-screen-columns)
  818. (forward-to-indentation 0))
  819. (setq marker (list (point-marker)))))))
  820. (setq loc (compilation-assq line (cdr file-struct)))
  821. (if end-line
  822. (setq end-loc (compilation-assq end-line (cdr file-struct))
  823. end-loc (compilation-assq end-col end-loc))
  824. (if end-col ; use same line element
  825. (setq end-loc (compilation-assq end-col loc))))
  826. (setq loc (compilation-assq col loc))
  827. ;; If they are new, make the loc(s) reference the file they point to.
  828. (or (cdr loc) (setcdr loc `(,line ,file-struct ,@marker)))
  829. (if end-loc
  830. (or (cdr end-loc)
  831. (setcdr end-loc `(,(or end-line line) ,file-struct ,@end-marker))))
  832. ;; Must start with face
  833. `(face ,compilation-message-face
  834. message (,loc ,type ,end-loc)
  835. ,@(if compilation-debug
  836. `(debug (,(assoc (with-no-warnings matcher) font-lock-keywords)
  837. ,@(match-data))))
  838. help-echo ,(if col
  839. "mouse-2: visit this file, line and column"
  840. (if line
  841. "mouse-2: visit this file and line"
  842. "mouse-2: visit this file"))
  843. keymap compilation-button-map
  844. mouse-face highlight)))
  845. (defun compilation-mode-font-lock-keywords ()
  846. "Return expressions to highlight in Compilation mode."
  847. (if compilation-parse-errors-function
  848. ;; An old package! Try the compatibility code.
  849. '((compilation-compat-parse-errors))
  850. (append
  851. ;; make directory tracking
  852. (if compilation-directory-matcher
  853. `((,(car compilation-directory-matcher)
  854. ,@(mapcar (lambda (elt)
  855. `(,(car elt)
  856. (compilation-directory-properties
  857. ,(car elt) ,(cdr elt))
  858. t t))
  859. (cdr compilation-directory-matcher)))))
  860. ;; Compiler warning/error lines.
  861. (mapcar
  862. (lambda (item)
  863. (if (symbolp item)
  864. (setq item (cdr (assq item
  865. compilation-error-regexp-alist-alist))))
  866. (let ((file (nth 1 item))
  867. (line (nth 2 item))
  868. (col (nth 3 item))
  869. (type (nth 4 item))
  870. (pat (car item))
  871. end-line end-col fmt)
  872. ;; omake reports some error indented, so skip the indentation.
  873. ;; another solution is to modify (some?) regexps in
  874. ;; `compilation-error-regexp-alist'.
  875. ;; note that omake usage is not limited to ocaml and C (for stubs).
  876. (when (and (= ?^ (aref pat 0)) ; anchored: starts with "^"
  877. ;; but does not allow an arbitrary number of leading spaces
  878. (not (and (= ? (aref pat 1)) (= ?* (aref pat 2)))))
  879. (setq pat (concat "^ *" (substring pat 1))))
  880. (if (consp file) (setq fmt (cdr file) file (car file)))
  881. (if (consp line) (setq end-line (cdr line) line (car line)))
  882. (if (consp col) (setq end-col (cdr col) col (car col)))
  883. (if (functionp line)
  884. ;; The old compile.el had here an undocumented hook that
  885. ;; allowed `line' to be a function that computed the actual
  886. ;; error location. Let's do our best.
  887. `(,pat
  888. (0 (save-match-data
  889. (compilation-compat-error-properties
  890. (funcall ',line (cons (match-string ,file)
  891. (cons default-directory
  892. ',(nthcdr 4 item)))
  893. ,(if col `(match-string ,col))))))
  894. (,file compilation-error-face t))
  895. (unless (or (null (nth 5 item)) (integerp (nth 5 item)))
  896. (error "HYPERLINK should be an integer: %s" (nth 5 item)))
  897. `(,pat
  898. ,@(when (integerp file)
  899. `((,file ,(if (consp type)
  900. `(compilation-face ',type)
  901. (aref [compilation-info-face
  902. compilation-warning-face
  903. compilation-error-face]
  904. (or type 2))))))
  905. ,@(when line
  906. `((,line compilation-line-face nil t)))
  907. ,@(when end-line
  908. `((,end-line compilation-line-face nil t)))
  909. ,@(when (integerp col)
  910. `((,col compilation-column-face nil t)))
  911. ,@(when (integerp end-col)
  912. `((,end-col compilation-column-face nil t)))
  913. ,@(nthcdr 6 item)
  914. (,(or (nth 5 item) 0)
  915. (compilation-error-properties ',file ,line ,end-line
  916. ,col ,end-col ',(or type 2)
  917. ',fmt)
  918. append))))) ; for compilation-message-face
  919. compilation-error-regexp-alist)
  920. compilation-mode-font-lock-keywords)))
  921. (defun compilation-read-command (command)
  922. (read-shell-command "Compile command: " command
  923. (if (equal (car compile-history) command)
  924. '(compile-history . 1)
  925. 'compile-history)))
  926. ;;;###autoload
  927. (defun compile (command &optional comint)
  928. "Compile the program including the current buffer. Default: run `make'.
  929. Runs COMMAND, a shell command, in a separate process asynchronously
  930. with output going to the buffer `*compilation*'.
  931. You can then use the command \\[next-error] to find the next error message
  932. and move to the source code that caused it.
  933. If optional second arg COMINT is t the buffer will be in Comint mode with
  934. `compilation-shell-minor-mode'.
  935. Interactively, prompts for the command if `compilation-read-command' is
  936. non-nil; otherwise uses `compile-command'. With prefix arg, always prompts.
  937. Additionally, with universal prefix arg, compilation buffer will be in
  938. comint mode, i.e. interactive.
  939. To run more than one compilation at once, start one then rename
  940. the \`*compilation*' buffer to some other name with
  941. \\[rename-buffer]. Then _switch buffers_ and start the new compilation.
  942. It will create a new \`*compilation*' buffer.
  943. On most systems, termination of the main compilation process
  944. kills its subprocesses.
  945. The name used for the buffer is actually whatever is returned by
  946. the function in `compilation-buffer-name-function', so you can set that
  947. to a function that generates a unique name."
  948. (interactive
  949. (list
  950. (let ((command (eval compile-command)))
  951. (if (or compilation-read-command current-prefix-arg)
  952. (compilation-read-command command)
  953. command))
  954. (consp current-prefix-arg)))
  955. (unless (equal command (eval compile-command))
  956. (setq compile-command command))
  957. (save-some-buffers (not compilation-ask-about-save)
  958. compilation-save-buffers-predicate)
  959. (setq-default compilation-directory default-directory)
  960. (compilation-start command comint))
  961. ;; run compile with the default command line
  962. (defun recompile (&optional edit-command)
  963. "Re-compile the program including the current buffer.
  964. If this is run in a Compilation mode buffer, re-use the arguments from the
  965. original use. Otherwise, recompile using `compile-command'.
  966. If the optional argument `edit-command' is non-nil, the command can be edited."
  967. (interactive "P")
  968. (save-some-buffers (not compilation-ask-about-save)
  969. compilation-save-buffers-predicate)
  970. (let ((default-directory (or compilation-directory default-directory)))
  971. (when edit-command
  972. (setcar compilation-arguments
  973. (compilation-read-command (car compilation-arguments))))
  974. (apply 'compilation-start (or compilation-arguments
  975. `(,(eval compile-command))))))
  976. (defcustom compilation-scroll-output nil
  977. "Non-nil to scroll the *compilation* buffer window as output appears.
  978. Setting it causes the Compilation mode commands to put point at the
  979. end of their output window so that the end of the output is always
  980. visible rather than the beginning.
  981. The value `first-error' stops scrolling at the first error, and leaves
  982. point on its location in the *compilation* buffer."
  983. :type '(choice (const :tag "No scrolling" nil)
  984. (const :tag "Scroll compilation output" t)
  985. (const :tag "Stop scrolling at the first error" first-error))
  986. :version "20.3"
  987. :group 'compilation)
  988. (defun compilation-buffer-name (mode-name mode-command name-function)
  989. "Return the name of a compilation buffer to use.
  990. If NAME-FUNCTION is non-nil, call it with one argument MODE-NAME
  991. to determine the buffer name.
  992. Likewise if `compilation-buffer-name-function' is non-nil.
  993. If current buffer has the major mode MODE-COMMAND,
  994. return the name of the current buffer, so that it gets reused.
  995. Otherwise, construct a buffer name from MODE-NAME."
  996. (cond (name-function
  997. (funcall name-function mode-name))
  998. (compilation-buffer-name-function
  999. (funcall compilation-buffer-name-function mode-name))
  1000. ((eq mode-command major-mode)
  1001. (buffer-name))
  1002. (t
  1003. (concat "*" (downcase mode-name) "*"))))
  1004. ;; This is a rough emulation of the old hack, until the transition to new
  1005. ;; compile is complete.
  1006. (defun compile-internal (command error-message
  1007. &optional name-of-mode parser
  1008. error-regexp-alist name-function
  1009. enter-regexp-alist leave-regexp-alist
  1010. file-regexp-alist nomessage-regexp-alist
  1011. no-async highlight-regexp local-map)
  1012. (if parser
  1013. (error "Compile now works very differently, see `compilation-error-regexp-alist'"))
  1014. (let ((compilation-error-regexp-alist
  1015. (append file-regexp-alist (or error-regexp-alist
  1016. compilation-error-regexp-alist)))
  1017. (compilation-error (replace-regexp-in-string "^No more \\(.+\\)s\\.?"
  1018. "\\1" error-message)))
  1019. (compilation-start command nil name-function highlight-regexp)))
  1020. (make-obsolete 'compile-internal 'compilation-start "22.1")
  1021. ;;;###autoload
  1022. (defun compilation-start (command &optional mode name-function highlight-regexp)
  1023. "Run compilation command COMMAND (low level interface).
  1024. If COMMAND starts with a cd command, that becomes the `default-directory'.
  1025. The rest of the arguments are optional; for them, nil means use the default.
  1026. MODE is the major mode to set in the compilation buffer. Mode
  1027. may also be t meaning use `compilation-shell-minor-mode' under `comint-mode'.
  1028. If NAME-FUNCTION is non-nil, call it with one argument (the mode name)
  1029. to determine the buffer name. Otherwise, the default is to
  1030. reuses the current buffer if it has the proper major mode,
  1031. else use or create a buffer with name based on the major mode.
  1032. If HIGHLIGHT-REGEXP is non-nil, `next-error' will temporarily highlight
  1033. the matching section of the visited source line; the default is to use the
  1034. global value of `compilation-highlight-regexp'.
  1035. Returns the compilation buffer created."
  1036. (or mode (setq mode 'compilation-mode))
  1037. (let* ((name-of-mode
  1038. (if (eq mode t)
  1039. "compilation"
  1040. (replace-regexp-in-string "-mode$" "" (symbol-name mode))))
  1041. (thisdir default-directory)
  1042. outwin outbuf)
  1043. (with-current-buffer
  1044. (setq outbuf
  1045. (get-buffer-create
  1046. (compilation-buffer-name name-of-mode mode name-function)))
  1047. (let ((comp-proc (get-buffer-process (current-buffer))))
  1048. (if comp-proc
  1049. (if (or (not (eq (process-status comp-proc) 'run))
  1050. (yes-or-no-p
  1051. (format "A %s process is running; kill it? "
  1052. name-of-mode)))
  1053. (condition-case ()
  1054. (progn
  1055. (interrupt-process comp-proc)
  1056. (sit-for 1)
  1057. (delete-process comp-proc))
  1058. (error nil))
  1059. (error "Cannot have two processes in `%s' at once"
  1060. (buffer-name)))))
  1061. ;; first transfer directory from where M-x compile was called
  1062. (setq default-directory thisdir)
  1063. ;; Make compilation buffer read-only. The filter can still write it.
  1064. ;; Clear out the compilation buffer.
  1065. (let ((inhibit-read-only t)
  1066. (default-directory thisdir))
  1067. ;; Then evaluate a cd command if any, but don't perform it yet, else
  1068. ;; start-command would do it again through the shell: (cd "..") AND
  1069. ;; sh -c "cd ..; make"
  1070. (cd (if (string-match "\\`\\s *cd\\(?:\\s +\\(\\S +?\\)\\)?\\s *[;&\n]"
  1071. command)
  1072. (if (match-end 1)
  1073. (substitute-env-vars (match-string 1 command))
  1074. "~")
  1075. default-directory))
  1076. (erase-buffer)
  1077. ;; Select the desired mode.
  1078. (if (not (eq mode t))
  1079. (progn
  1080. (buffer-disable-undo)
  1081. (funcall mode))
  1082. (setq buffer-read-only nil)
  1083. (with-no-warnings (comint-mode))
  1084. (compilation-shell-minor-mode))
  1085. ;; Remember the original dir, so we can use it when we recompile.
  1086. ;; default-directory' can't be used reliably for that because it may be
  1087. ;; affected by the special handling of "cd ...;".
  1088. ;; NB: must be fone after (funcall mode) as that resets local variables
  1089. (set (make-local-variable 'compilation-directory) thisdir)
  1090. (if highlight-regexp
  1091. (set (make-local-variable 'compilation-highlight-regexp)
  1092. highlight-regexp))
  1093. (if (or compilation-auto-jump-to-first-error
  1094. (eq compilation-scroll-output 'first-error))
  1095. (set (make-local-variable 'compilation-auto-jump-to-next) t))
  1096. ;; Output a mode setter, for saving and later reloading this buffer.
  1097. (insert "-*- mode: " name-of-mode
  1098. "; default-directory: " (prin1-to-string default-directory)
  1099. " -*-\n"
  1100. (format "%s started at %s\n\n"
  1101. mode-name
  1102. (substring (current-time-string) 0 19))
  1103. command "\n")
  1104. (setq thisdir default-directory))
  1105. (set-buffer-modified-p nil))
  1106. ;; Pop up the compilation buffer.
  1107. ;; http://lists.gnu.org/archive/html/emacs-devel/2007-11/msg01638.html
  1108. (setq outwin (display-buffer outbuf))
  1109. (with-current-buffer outbuf
  1110. (let ((process-environment
  1111. (append
  1112. compilation-environment
  1113. (if (if (boundp 'system-uses-terminfo) ; `if' for compiler warning
  1114. system-uses-terminfo)
  1115. (list "TERM=dumb" "TERMCAP="
  1116. (format "COLUMNS=%d" (window-width)))
  1117. (list "TERM=emacs"
  1118. (format "TERMCAP=emacs:co#%d:tc=unknown:"
  1119. (window-width))))
  1120. ;; Set the EMACS variable, but
  1121. ;; don't override users' setting of $EMACS.
  1122. (unless (getenv "EMACS")
  1123. (list "EMACS=t"))
  1124. (list "INSIDE_EMACS=t")
  1125. (copy-sequence process-environment))))
  1126. (set (make-local-variable 'compilation-arguments)
  1127. (list command mode name-function highlight-regexp))
  1128. (set (make-local-variable 'revert-buffer-function)
  1129. 'compilation-revert-buffer)
  1130. (set-window-start outwin (point-min))
  1131. ;; Position point as the user will see it.
  1132. (let ((desired-visible-point
  1133. ;; Put it at the end if `compilation-scroll-output' is set.
  1134. (if compilation-scroll-output
  1135. (point-max)
  1136. ;; Normally put it at the top.
  1137. (point-min))))
  1138. (if (eq outwin (selected-window))
  1139. (goto-char desired-visible-point)
  1140. (set-window-point outwin desired-visible-point)))
  1141. ;; The setup function is called before compilation-set-window-height
  1142. ;; so it can set the compilation-window-height buffer locally.
  1143. (if compilation-process-setup-function
  1144. (funcall compilation-process-setup-function))
  1145. (compilation-set-window-height outwin)
  1146. ;; Start the compilation.
  1147. (if (fboundp 'start-process)
  1148. (let ((proc
  1149. (if (eq mode t)
  1150. ;; comint uses `start-file-process'.
  1151. (get-buffer-process
  1152. (with-no-warnings
  1153. (comint-exec
  1154. outbuf (downcase mode-name)
  1155. (if (file-remote-p default-directory)
  1156. "/bin/sh"
  1157. shell-file-name)
  1158. nil `("-c" ,command))))
  1159. (start-file-process-shell-command (downcase mode-name)
  1160. outbuf command))))
  1161. ;; Make the buffer's mode line show process state.
  1162. (setq mode-line-process
  1163. (list (propertize ":%s" 'face 'compilation-warning)))
  1164. (set-process-sentinel proc 'compilation-sentinel)
  1165. (unless (eq mode t)
  1166. ;; Keep the comint filter, since it's needed for proper handling
  1167. ;; of the prompts.
  1168. (set-process-filter proc 'compilation-filter))
  1169. ;; Use (point-max) here so that output comes in
  1170. ;; after the initial text,
  1171. ;; regardless of where the user sees point.
  1172. (set-marker (process-mark proc) (point-max) outbuf)
  1173. (when compilation-disable-input
  1174. (condition-case nil
  1175. (process-send-eof proc)
  1176. ;; The process may have exited already.
  1177. (error nil)))
  1178. (run-hook-with-args 'compilation-start-hook proc)
  1179. (setq compilation-in-progress
  1180. (cons proc compilation-in-progress)))
  1181. ;; No asynchronous processes available.
  1182. (message "Executing `%s'..." command)
  1183. ;; Fake modeline display as if `start-process' were run.
  1184. (setq mode-line-process
  1185. (list (propertize ":run" 'face 'compilation-warning)))
  1186. (force-mode-line-update)
  1187. (sit-for 0) ; Force redisplay
  1188. (save-excursion
  1189. ;; Insert the output at the end, after the initial text,
  1190. ;; regardless of where the user sees point.
  1191. (goto-char (point-max))
  1192. (let* ((buffer-read-only nil) ; call-process needs to modify outbuf
  1193. (status (call-process shell-file-name nil outbuf nil "-c"
  1194. command)))
  1195. (cond ((numberp status)
  1196. (compilation-handle-exit
  1197. 'exit status
  1198. (if (zerop status)
  1199. "finished\n"
  1200. (format "exited abnormally with code %d\n" status))))
  1201. ((stringp status)
  1202. (compilation-handle-exit 'signal status
  1203. (concat status "\n")))
  1204. (t
  1205. (compilation-handle-exit 'bizarre status status)))))
  1206. ;; Without async subprocesses, the buffer is not yet
  1207. ;; fontified, so fontify it now.
  1208. (let ((font-lock-verbose nil)) ; shut up font-lock messages
  1209. (font-lock-fontify-buffer))
  1210. (set-buffer-modified-p nil)
  1211. (message "Executing `%s'...done" command)))
  1212. ;; Now finally cd to where the shell started make/grep/...
  1213. (setq default-directory thisdir)
  1214. ;; The following form selected outwin ever since revision 1.183,
  1215. ;; so possibly messing up point in some other window (bug#1073).
  1216. ;; Moved into the scope of with-current-buffer, though still with
  1217. ;; complete disregard for the case when compilation-scroll-output
  1218. ;; equals 'first-error (martin 2008-10-04).
  1219. (when compilation-scroll-output
  1220. (goto-char (point-max))))
  1221. ;; Make it so the next C-x ` will use this buffer.
  1222. (setq next-error-last-buffer outbuf)))
  1223. (defun compilation-set-window-height (window)
  1224. "Set the height of WINDOW according to `compilation-window-height'."
  1225. (let ((height (buffer-local-value 'compilation-window-height (window-buffer window))))
  1226. (and height
  1227. (window-full-width-p window)
  1228. ;; If window is alone in its frame, aside from a minibuffer,
  1229. ;; don't change its height.
  1230. (not (eq window (frame-root-window (window-frame window))))
  1231. ;; Stef said that doing the saves in this order is safer:
  1232. (save-excursion
  1233. (save-selected-window
  1234. (select-window window)
  1235. (enlarge-window (- height (window-height))))))))
  1236. (defvar compilation-menu-map
  1237. (let ((map (make-sparse-keymap "Errors"))
  1238. (opt-map (make-sparse-keymap "Skip")))
  1239. (define-key map [stop-subjob]
  1240. '(menu-item "Stop Compilation" kill-compilation
  1241. :help "Kill the process made by the M-x compile or M-x grep commands"))
  1242. (define-key map [compilation-mode-separator3]
  1243. '("----" . nil))
  1244. (define-key map [compilation-next-error-follow-minor-mode]
  1245. '(menu-item
  1246. "Auto Error Display" next-error-follow-minor-mode
  1247. :help "Display the error under cursor when moving the cursor"
  1248. :button (:toggle . next-error-follow-minor-mode)))
  1249. (define-key map [compilation-skip]
  1250. (cons "Skip Less Important Messages" opt-map))
  1251. (define-key opt-map [compilation-skip-none]
  1252. '(menu-item "Don't Skip Any Messages"
  1253. (lambda ()
  1254. (interactive)
  1255. (customize-set-variable 'compilation-skip-threshold 0))
  1256. :help "Do not skip any type of messages"
  1257. :button (:radio . (eq compilation-skip-threshold 0))))
  1258. (define-key opt-map [compilation-skip-info]
  1259. '(menu-item "Skip Info"
  1260. (lambda ()
  1261. (interactive)
  1262. (customize-set-variable 'compilation-skip-threshold 1))
  1263. :help "Skip anything less than warning"
  1264. :button (:radio . (eq compilation-skip-threshold 1))))
  1265. (define-key opt-map [compilation-skip-warning-and-info]
  1266. '(menu-item "Skip Warnings and Info"
  1267. (lambda ()
  1268. (interactive)
  1269. (customize-set-variable 'compilation-skip-threshold 2))
  1270. :help "Skip over Warnings and Info, stop for errors"
  1271. :button (:radio . (eq compilation-skip-threshold 2))))
  1272. (define-key map [compilation-mode-separator2]
  1273. '("----" . nil))
  1274. (define-key map [compilation-first-error]
  1275. '(menu-item "First Error" first-error
  1276. :help "Restart at the first error, visit corresponding source code"))
  1277. (define-key map [compilation-previous-error]
  1278. '(menu-item "Previous Error" previous-error
  1279. :help "Visit previous `next-error' message and corresponding source code"))
  1280. (define-key map [compilation-next-error]
  1281. '(menu-item "Next Error" next-error
  1282. :help "Visit next `next-error' message and corresponding source code"))
  1283. map))
  1284. (defvar compilation-minor-mode-map
  1285. (let ((map (make-sparse-keymap)))
  1286. (define-key map [mouse-2] 'compile-goto-error)
  1287. (define-key map [follow-link] 'mouse-face)
  1288. (define-key map "\C-c\C-c" 'compile-goto-error)
  1289. (define-key map "\C-m" 'compile-goto-error)
  1290. (define-key map "\C-c\C-k" 'kill-compilation)
  1291. (define-key map "\M-n" 'compilation-next-error)
  1292. (define-key map "\M-p" 'compilation-previous-error)
  1293. (define-key map "\M-{" 'compilation-previous-file)
  1294. (define-key map "\M-}" 'compilation-next-file)
  1295. (define-key map "g" 'recompile) ; revert
  1296. (define-key map "q" 'quit-window)
  1297. ;; Set up the menu-bar
  1298. (define-key map [menu-bar compilation]
  1299. (cons "Errors" compilation-menu-map))
  1300. map)
  1301. "Keymap for `compilation-minor-mode'.")
  1302. (defvar compilation-shell-minor-mode-map
  1303. (let ((map (make-sparse-keymap)))
  1304. (define-key map "\M-\C-m" 'compile-goto-error)
  1305. (define-key map "\M-\C-n" 'compilation-next-error)
  1306. (define-key map "\M-\C-p" 'compilation-previous-error)
  1307. (define-key map "\M-{" 'compilation-previous-file)
  1308. (define-key map "\M-}" 'compilation-next-file)
  1309. ;; Set up the menu-bar
  1310. (define-key map [menu-bar compilation]
  1311. (cons "Errors" compilation-menu-map))
  1312. map)
  1313. "Keymap for `compilation-shell-minor-mode'.")
  1314. (defvar compilation-button-map
  1315. (let ((map (make-sparse-keymap)))
  1316. (define-key map [mouse-2] 'compile-goto-error)
  1317. (define-key map [follow-link] 'mouse-face)
  1318. (define-key map "\C-m" 'compile-goto-error)
  1319. map)
  1320. "Keymap for compilation-message buttons.")
  1321. (fset 'compilation-button-map compilation-button-map)
  1322. (defvar compilation-mode-map
  1323. (let ((map (make-sparse-keymap)))
  1324. ;; Don't inherit from compilation-minor-mode-map,
  1325. ;; because that introduces a menu bar item we don't want.
  1326. ;; That confuses C-down-mouse-3.
  1327. (define-key map [mouse-2] 'compile-goto-error)
  1328. (define-key map [follow-link] 'mouse-face)
  1329. (define-key map "\C-c\C-c" 'compile-goto-error)
  1330. (define-key map "\C-m" 'compile-goto-error)
  1331. (define-key map "\C-c\C-k" 'kill-compilation)
  1332. (define-key map "\M-n" 'compilation-next-error)
  1333. (define-key map "\M-p" 'compilation-previous-error)
  1334. (define-key map "\M-{" 'compilation-previous-file)
  1335. (define-key map "\M-}" 'compilation-next-file)
  1336. (define-key map "\t" 'compilation-next-error)
  1337. (define-key map [backtab] 'compilation-previous-error)
  1338. (define-key map "g" 'recompile) ; revert
  1339. (define-key map "q" 'quit-window)
  1340. (define-key map " " 'scroll-up)
  1341. (define-key map "\^?" 'scroll-down)
  1342. (define-key map "\C-c\C-f" 'next-error-follow-minor-mode)
  1343. ;; Set up the menu-bar
  1344. (let ((submap (make-sparse-keymap "Compile")))
  1345. (define-key map [menu-bar compilation]
  1346. (cons "Compile" submap))
  1347. (set-keymap-parent submap compilation-menu-map))
  1348. (define-key map [menu-bar compilation compilation-separator2]
  1349. '("----" . nil))
  1350. (define-key map [menu-bar compilation compilation-grep]
  1351. '(menu-item "Search Files (grep)..." grep
  1352. :help "Run grep, with user-specified args, and collect output in a buffer"))
  1353. (define-key map [menu-bar compilation compilation-recompile]
  1354. '(menu-item "Recompile" recompile
  1355. :help "Re-compile the program including the current buffer"))
  1356. (define-key map [menu-bar compilation compilation-compile]
  1357. '(menu-item "Compile..." compile
  1358. :help "Compile the program including the current buffer. Default: run `make'"))
  1359. map)
  1360. "Keymap for compilation log buffers.
  1361. `compilation-minor-mode-map' is a parent of this.")
  1362. (defvar compilation-mode-tool-bar-map
  1363. ;; When bootstrapping, tool-bar-map is not properly initialized yet,
  1364. ;; so don't do anything.
  1365. (when (keymapp (butlast tool-bar-map))
  1366. (let ((map (butlast (copy-keymap tool-bar-map)))
  1367. (help (last tool-bar-map))) ;; Keep Help last in tool bar
  1368. (tool-bar-local-item
  1369. "left-arrow" 'previous-error-no-select 'previous-error-no-select map
  1370. :rtl "right-arrow"
  1371. :help "Goto previous error")
  1372. (tool-bar-local-item
  1373. "right-arrow" 'next-error-no-select 'next-error-no-select map
  1374. :rtl "left-arrow"
  1375. :help "Goto next error")
  1376. (tool-bar-local-item
  1377. "cancel" 'kill-compilation 'kill-compilation map
  1378. :enable '(let ((buffer (compilation-find-buffer)))
  1379. (get-buffer-process buffer))
  1380. :help "Stop compilation")
  1381. (tool-bar-local-item
  1382. "refresh" 'recompile 'recompile map
  1383. :help "Restart compilation")
  1384. (append map help))))
  1385. (put 'compilation-mode 'mode-class 'special)
  1386. ;;;###autoload
  1387. (defun compilation-mode (&optional name-of-mode)
  1388. "Major mode for compilation log buffers.
  1389. \\<compilation-mode-map>To visit the source for a line-numbered error,
  1390. move point to the error message line and type \\[compile-goto-error].
  1391. To kill the compilation, type \\[kill-compilation].
  1392. Runs `compilation-mode-hook' with `run-mode-hooks' (which see).
  1393. \\{compilation-mode-map}"
  1394. (interactive)
  1395. (kill-all-local-variables)
  1396. (use-local-map compilation-mode-map)
  1397. ;; Let windows scroll along with the output.
  1398. (set (make-local-variable 'window-point-insertion-type) t)
  1399. (set (make-local-variable 'tool-bar-map) compilation-mode-tool-bar-map)
  1400. (setq major-mode 'compilation-mode
  1401. mode-name (or name-of-mode "Compilation"))
  1402. (set (make-local-variable 'page-delimiter)
  1403. compilation-page-delimiter)
  1404. (set (make-local-variable 'buffer-modtime) nil)
  1405. (compilation-setup)
  1406. (setq buffer-read-only t)
  1407. (run-mode-hooks 'compilation-mode-hook))
  1408. (defmacro define-compilation-mode (mode name doc &rest body)
  1409. "This is like `define-derived-mode' without the PARENT argument.
  1410. The parent is always `compilation-mode' and the customizable `compilation-...'
  1411. variables are also set from the name of the mode you have chosen,
  1412. by replacing the first word, e.g `compilation-scroll-output' from
  1413. `grep-scroll-output' if that variable exists."
  1414. (let ((mode-name (replace-regexp-in-string "-mode\\'" "" (symbol-name mode))))
  1415. `(define-derived-mode ,mode compilation-mode ,name
  1416. ,doc
  1417. ,@(mapcar (lambda (v)
  1418. (setq v (cons v
  1419. (intern-soft (replace-regexp-in-string
  1420. "^compilation" mode-name
  1421. (symbol-name v)))))
  1422. (and (cdr v)
  1423. (or (boundp (cdr v))
  1424. (if (boundp 'byte-compile-bound-variables)
  1425. (memq (cdr v) byte-compile-bound-variables)))
  1426. `(set (make-local-variable ',(car v)) ,(cdr v))))
  1427. '(compilation-buffer-name-function
  1428. compilation-directory-matcher
  1429. compilation-error
  1430. compilation-error-regexp-alist
  1431. compilation-error-regexp-alist-alist
  1432. compilation-error-screen-columns
  1433. compilation-finish-function
  1434. compilation-finish-functions
  1435. compilation-first-column
  1436. compilation-mode-font-lock-keywords
  1437. compilation-page-delimiter
  1438. compilation-parse-errors-filename-function
  1439. compilation-process-setup-function
  1440. compilation-scroll-output
  1441. compilation-search-path
  1442. compilation-skip-threshold
  1443. compilation-window-height))
  1444. ,@body)))
  1445. (defun compilation-revert-buffer (ignore-auto noconfirm)
  1446. (if buffer-file-name
  1447. (let (revert-buffer-function)
  1448. (revert-buffer ignore-auto noconfirm))
  1449. (if (or noconfirm (yes-or-no-p (format "Restart compilation? ")))
  1450. (apply 'compilation-start compilation-arguments))))
  1451. (defvar compilation-current-error nil
  1452. "Marker to the location from where the next error will be found.
  1453. The global commands next/previous/first-error/goto-error use this.")
  1454. (defvar compilation-messages-start nil
  1455. "Buffer position of the beginning of the compilation messages.
  1456. If nil, use the beginning of buffer.")
  1457. ;; A function name can't be a hook, must be something with a value.
  1458. (defconst compilation-turn-on-font-lock 'turn-on-font-lock)
  1459. (defun compilation-setup (&optional minor)
  1460. "Prepare the buffer for the compilation parsing commands to work.
  1461. Optional argument MINOR indicates this is called from
  1462. `compilation-minor-mode'."
  1463. (make-local-variable 'compilation-current-error)
  1464. (make-local-variable 'compilation-messages-start)
  1465. (make-local-variable 'compilation-error-screen-columns)
  1466. (make-local-variable 'overlay-arrow-position)
  1467. (set (make-local-variable 'overlay-arrow-string) "")
  1468. (setq next-error-overlay-arrow-position nil)
  1469. (add-hook 'kill-buffer-hook
  1470. (lambda () (setq next-error-overlay-arrow-position nil)) nil t)
  1471. ;; Note that compilation-next-error-function is for interfacing
  1472. ;; with the next-error function in simple.el, and it's only
  1473. ;; coincidentally named similarly to compilation-next-error.
  1474. (setq next-error-function 'compilation-next-error-function)
  1475. (set (make-local-variable 'comint-file-name-prefix)
  1476. (or (file-remote-p default-directory) ""))
  1477. (set (make-local-variable 'font-lock-extra-managed-props)
  1478. '(directory message help-echo mouse-face debug))
  1479. (set (make-local-variable 'compilation-locs)
  1480. (make-hash-table :test 'equal :weakness 'value))
  1481. ;; lazy-lock would never find the message unless it's scrolled to.
  1482. ;; jit-lock might fontify some things too late.
  1483. (set (make-local-variable 'font-lock-support-mode) nil)
  1484. (set (make-local-variable 'font-lock-maximum-size) nil)
  1485. (if minor
  1486. (let ((fld font-lock-defaults))
  1487. (font-lock-add-keywords nil (compilation-mode-font-lock-keywords))
  1488. (if font-lock-mode
  1489. (if fld
  1490. (font-lock-fontify-buffer)
  1491. (font-lock-change-mode)
  1492. (turn-on-font-lock))
  1493. (turn-on-font-lock)))
  1494. (setq font-lock-defaults '(compilation-mode-font-lock-keywords t))
  1495. ;; maybe defer font-lock till after derived mode is set up
  1496. (run-mode-hooks 'compilation-turn-on-font-lock)))
  1497. ;;;###autoload
  1498. (define-minor-mode compilation-shell-minor-mode
  1499. "Toggle compilation shell minor mode.
  1500. With arg, turn compilation mode on if and only if arg is positive.
  1501. In this minor mode, all the error-parsing commands of the
  1502. Compilation major mode are available but bound to keys that don't
  1503. collide with Shell mode. See `compilation-mode'.
  1504. Turning the mode on runs the normal hook `compilation-shell-minor-mode-hook'."
  1505. nil " Shell-Compile"
  1506. :group 'compilation
  1507. (if compilation-shell-minor-mode
  1508. (compilation-setup t)
  1509. (font-lock-remove-keywords nil (compilation-mode-font-lock-keywords))
  1510. (font-lock-fontify-buffer)))
  1511. ;;;###autoload
  1512. (define-minor-mode compilation-minor-mode
  1513. "Toggle compilation minor mode.
  1514. With arg, turn compilation mode on if and only if arg is positive.
  1515. In this minor mode, all the error-parsing commands of the
  1516. Compilation major mode are available. See `compilation-mode'.
  1517. Turning the mode on runs the normal hook `compilation-minor-mode-hook'."
  1518. nil " Compilation"
  1519. :group 'compilation
  1520. (if compilation-minor-mode
  1521. (compilation-setup t)
  1522. (font-lock-remove-keywords nil (compilation-mode-font-lock-keywords))
  1523. (font-lock-fontify-buffer)))
  1524. (defun compilation-handle-exit (process-status exit-status msg)
  1525. "Write MSG in the current buffer and hack its `mode-line-process'."
  1526. (let ((inhibit-read-only t)
  1527. (status (if compilation-exit-message-function
  1528. (funcall compilation-exit-message-function
  1529. process-status exit-status msg)
  1530. (cons msg exit-status)))
  1531. (omax (point-max))
  1532. (opoint (point))
  1533. (cur-buffer (current-buffer)))
  1534. ;; Record where we put the message, so we can ignore it later on.
  1535. (goto-char omax)
  1536. (insert ?\n mode-name " " (car status))
  1537. (if (and (numberp compilation-window-height)
  1538. (zerop compilation-window-height))
  1539. (message "%s" (cdr status)))
  1540. (if (bolp)
  1541. (forward-char -1))
  1542. (insert " at " (substring (current-time-string) 0 19))
  1543. (goto-char (point-max))
  1544. ;; Prevent that message from being recognized as a compilation error.
  1545. (add-text-properties omax (point)
  1546. (append '(compilation-handle-exit t) nil))
  1547. (setq mode-line-process
  1548. (let ((out-string (format ":%s [%s]" process-status (cdr status)))
  1549. (msg (format "%s %s" mode-name
  1550. (replace-regexp-in-string "\n?$" "" (car status)))))
  1551. (message "%s" msg)
  1552. (propertize out-string
  1553. 'help-echo msg 'face (if (> exit-status 0)
  1554. 'compilation-error
  1555. 'compilation-info))))
  1556. ;; Force mode line redisplay soon.
  1557. (force-mode-line-update)
  1558. (if (and opoint (< opoint omax))
  1559. (goto-char opoint))
  1560. (with-no-warnings
  1561. (if compilation-finish-function
  1562. (funcall compilation-finish-function cur-buffer msg)))
  1563. (run-hook-with-args 'compilation-finish-functions cur-buffer msg)))
  1564. ;; Called when compilation process changes state.
  1565. (defun compilation-sentinel (proc msg)
  1566. "Sentinel for compilation buffers."
  1567. (if (memq (process-status proc) '(exit signal))
  1568. (let ((buffer (process-buffer proc)))
  1569. (if (null (buffer-name buffer))
  1570. ;; buffer killed
  1571. (set-process-buffer proc nil)
  1572. (with-current-buffer buffer
  1573. ;; Write something in the compilation buffer
  1574. ;; and hack its mode line.
  1575. (compilation-handle-exit (process-status proc)
  1576. (process-exit-status proc)
  1577. msg)
  1578. ;; Since the buffer and mode line will show that the
  1579. ;; process is dead, we can delete it now. Otherwise it
  1580. ;; will stay around until M-x list-processes.
  1581. (delete-process proc)))
  1582. (setq compilation-in-progress (delq proc compilation-in-progress)))))
  1583. (defun compilation-filter (proc string)
  1584. "Process filter for compilation buffers.
  1585. Just inserts the text,
  1586. handles carriage motion (see `comint-inhibit-carriage-motion'),
  1587. and runs `compilation-filter-hook'."
  1588. (when (buffer-live-p (process-buffer proc))
  1589. (with-current-buffer (process-buffer proc)
  1590. (let ((inhibit-read-only t)
  1591. ;; `save-excursion' doesn't use the right insertion-type for us.
  1592. (pos (copy-marker (point) t))
  1593. (min (point-min-marker))
  1594. (max (point-max-marker)))
  1595. (unwind-protect
  1596. (progn
  1597. ;; If we are inserting at the end of the accessible part
  1598. ;; of the buffer, keep the inserted text visible.
  1599. (set-marker-insertion-type max t)
  1600. (widen)
  1601. (goto-char (process-mark proc))
  1602. ;; We used to use `insert-before-markers', so that windows with
  1603. ;; point at `process-mark' scroll along with the output, but we
  1604. ;; now use window-point-insertion-type instead.
  1605. (insert string)
  1606. (unless comint-inhibit-carriage-motion
  1607. (comint-carriage-motion (process-mark proc) (point)))
  1608. (set-marker (process-mark proc) (point))
  1609. (set (make-local-variable 'buffer-modtime) (current-time))
  1610. (run-hooks 'compilation-filter-hook))
  1611. (goto-char pos)
  1612. (narrow-to-region min max)
  1613. (set-marker min nil)
  1614. (set-marker max nil))))))
  1615. ;;; test if a buffer is a compilation buffer, assuming we're in the buffer
  1616. (defsubst compilation-buffer-internal-p ()
  1617. "Test if inside a compilation buffer."
  1618. (local-variable-p 'compilation-locs))
  1619. ;;; test if a buffer is a compilation buffer, using compilation-buffer-internal-p
  1620. (defsubst compilation-buffer-p (buffer)
  1621. "Test if BUFFER is a compilation buffer."
  1622. (with-current-buffer buffer
  1623. (compilation-buffer-internal-p)))
  1624. (defmacro compilation-loop (< property-change 1+ error limit)
  1625. `(let (opt)
  1626. (while (,< n 0)
  1627. (setq opt pt)
  1628. (or (setq pt (,property-change pt 'message))
  1629. ;; Handle the case where where the first error message is
  1630. ;; at the start of the buffer, and n < 0.
  1631. (if (or (eq (get-text-property ,limit 'message)
  1632. (get-text-property opt 'message))
  1633. (eq pt opt))
  1634. (error ,error compilation-error)
  1635. (setq pt ,limit)))
  1636. ;; prop 'message usually has 2 changes, on and off, so
  1637. ;; re-search if off
  1638. (or (setq msg (get-text-property pt 'message))
  1639. (if (setq pt (,property-change pt 'message nil ,limit))
  1640. (setq msg (get-text-property pt 'message)))
  1641. (error ,error compilation-error))
  1642. (or (< (cadr msg) compilation-skip-threshold)
  1643. (if different-file
  1644. (eq (prog1 last (setq last (nth 2 (car msg))))
  1645. last))
  1646. (if compilation-skip-visited
  1647. (nthcdr 5 (car msg)))
  1648. (if compilation-skip-to-next-location
  1649. (eq (car msg) loc))
  1650. ;; count this message only if none of the above are true
  1651. (setq n (,1+ n))))))
  1652. (defun compilation-next-error (n &optional different-file pt)
  1653. "Move point to the next error in the compilation buffer.
  1654. This function does NOT find the source line like \\[next-error].
  1655. Prefix arg N says how many error messages to move forwards (or
  1656. backwards, if negative).
  1657. Optional arg DIFFERENT-FILE, if non-nil, means find next error for a
  1658. file that is different from the current one.
  1659. Optional arg PT, if non-nil, specifies the value of point to start
  1660. looking for the next message."
  1661. (interactive "p")
  1662. (or (compilation-buffer-p (current-buffer))
  1663. (error "Not in a compilation buffer"))
  1664. (or pt (setq pt (point)))
  1665. (let* ((msg (get-text-property pt 'message))
  1666. ;; `loc' is used by the compilation-loop macro.
  1667. (loc (car msg))
  1668. last)
  1669. (if (zerop n)
  1670. (unless (or msg ; find message near here
  1671. (setq msg (get-text-property (max (1- pt) (point-min))
  1672. 'message)))
  1673. (setq pt (previous-single-property-change pt 'message nil
  1674. (line-beginning-position)))
  1675. (unless (setq msg (get-text-property (max (1- pt) (point-min)) 'message))
  1676. (setq pt (next-single-property-change pt 'message nil
  1677. (line-end-position)))
  1678. (or (setq msg (get-text-property pt 'message))
  1679. (setq pt (point)))))
  1680. (setq last (nth 2 (car msg)))
  1681. (if (>= n 0)
  1682. (compilation-loop > next-single-property-change 1-
  1683. (if (get-buffer-process (current-buffer))
  1684. "No more %ss yet"
  1685. "Moved past last %s")
  1686. (point-max))
  1687. ;; Don't move "back" to message at or before point.
  1688. ;; Pass an explicit (point-min) to make sure pt is non-nil.
  1689. (setq pt (previous-single-property-change pt 'message nil (point-min)))
  1690. (compilation-loop < previous-single-property-change 1+
  1691. "Moved back before first %s" (point-min))))
  1692. (goto-char pt)
  1693. (or msg
  1694. (error "No %s here" compilation-error))))
  1695. (defun compilation-previous-error (n)
  1696. "Move point to the previous error in the compilation buffer.
  1697. Prefix arg N says how many error messages to move backwards (or
  1698. forwards, if negative).
  1699. Does NOT find the source line like \\[previous-error]."
  1700. (interactive "p")
  1701. (compilation-next-error (- n)))
  1702. (defun compilation-next-file (n)
  1703. "Move point to the next error for a different file than the current one.
  1704. Prefix arg N says how many files to move forwards (or backwards, if negative)."
  1705. (interactive "p")
  1706. (compilation-next-error n t))
  1707. (defun compilation-previous-file (n)
  1708. "Move point to the previous error for a different file than the current one.
  1709. Prefix arg N says how many files to move backwards (or forwards, if negative)."
  1710. (interactive "p")
  1711. (compilation-next-file (- n)))
  1712. (defun kill-compilation ()
  1713. "Kill the process made by the \\[compile] or \\[grep] commands."
  1714. (interactive)
  1715. (let ((buffer (compilation-find-buffer)))
  1716. (if (get-buffer-process buffer)
  1717. (interrupt-process (get-buffer-process buffer))
  1718. (error "The %s process is not running" (downcase mode-name)))))
  1719. (defalias 'compile-mouse-goto-error 'compile-goto-error)
  1720. (defun compile-goto-error (&optional event)
  1721. "Visit the source for the error message at point.
  1722. Use this command in a compilation log buffer. Sets the mark at point there."
  1723. (interactive (list last-input-event))
  1724. (if event (posn-set-point (event-end event)))
  1725. (or (compilation-buffer-p (current-buffer))
  1726. (error "Not in a compilation buffer"))
  1727. (if (get-text-property (point) 'directory)
  1728. (dired-other-window (car (get-text-property (point) 'directory)))
  1729. (push-mark)
  1730. (setq compilation-current-error (point))
  1731. (next-error-internal)))
  1732. (defun compilation-find-buffer (&optional avoid-current)
  1733. "Return a compilation buffer.
  1734. If AVOID-CURRENT is nil, and the current buffer is a compilation buffer,
  1735. return it. If AVOID-CURRENT is non-nil, return the current buffer only
  1736. as a last resort."
  1737. (if (and (compilation-buffer-internal-p) (not avoid-current))
  1738. (current-buffer)
  1739. (next-error-find-buffer avoid-current 'compilation-buffer-internal-p)))
  1740. ;;;###autoload
  1741. (defun compilation-next-error-function (n &optional reset)
  1742. "Advance to the next error message and visit the file where the error was.
  1743. This is the value of `next-error-function' in Compilation buffers."
  1744. (interactive "p")
  1745. (when reset
  1746. (setq compilation-current-error nil))
  1747. (let* ((columns compilation-error-screen-columns) ; buffer's local value
  1748. (last 1) timestamp
  1749. (loc (compilation-next-error (or n 1) nil
  1750. (or compilation-current-error
  1751. compilation-messages-start
  1752. (point-min))))
  1753. (end-loc (nth 2 loc))
  1754. (marker (point-marker)))
  1755. (setq compilation-current-error (point-marker)
  1756. overlay-arrow-position
  1757. (if (bolp)
  1758. compilation-current-error
  1759. (copy-marker (line-beginning-position)))
  1760. loc (car loc))
  1761. ;; If loc contains no marker, no error in that file has been visited.
  1762. ;; If the marker is invalid the buffer has been killed.
  1763. ;; If the file is newer than the timestamp, it has been modified
  1764. ;; (`omake -P' polls filesystem for changes and recompiles when needed
  1765. ;; in the same process and buffer).
  1766. ;; So, recalculate all markers for that file.
  1767. (unless (and (nth 3 loc) (marker-buffer (nth 3 loc)) (nthcdr 4 loc)
  1768. ;; There may be no timestamp info if the loc is a `fake-loc',
  1769. ;; but we just checked that the file has been visited before!
  1770. (equal (nth 4 loc)
  1771. (setq timestamp buffer-modtime)))
  1772. (with-current-buffer (compilation-find-file marker (caar (nth 2 loc))
  1773. (cadr (car (nth 2 loc))))
  1774. (save-restriction
  1775. (widen)
  1776. (goto-char (point-min))
  1777. ;; Treat file's found lines in forward order, 1 by 1.
  1778. (dolist (line (reverse (cddr (nth 2 loc))))
  1779. (when (car line) ; else this is a filename w/o a line#
  1780. (beginning-of-line (- (car line) last -1))
  1781. (setq last (car line)))
  1782. ;; Treat line's found columns and store/update a marker for each.
  1783. (dolist (col (cdr line))
  1784. (if (car col)
  1785. (if (eq (car col) -1) ; special case for range end
  1786. (end-of-line)
  1787. (compilation-move-to-column (car col) columns))
  1788. (beginning-of-line)
  1789. (skip-chars-forward " \t"))
  1790. (if (nth 3 col)
  1791. (set-marker (nth 3 col) (point))
  1792. (setcdr (nthcdr 2 col) `(,(point-marker)))))))))
  1793. (compilation-goto-locus marker (nth 3 loc) (nth 3 end-loc))
  1794. (setcdr (nthcdr 3 loc) (list timestamp))
  1795. (setcdr (nthcdr 4 loc) t))) ; Set this one as visited.
  1796. (defvar compilation-gcpro nil
  1797. "Internal variable used to keep some values from being GC'd.")
  1798. (make-variable-buffer-local 'compilation-gcpro)
  1799. (defun compilation-fake-loc (marker file &optional line col)
  1800. "Preassociate MARKER with FILE.
  1801. FILE should be ABSOLUTE-FILENAME or (RELATIVE-FILENAME . DIRNAME).
  1802. This is useful when you compile temporary files, but want
  1803. automatic translation of the messages to the real buffer from
  1804. which the temporary file came. This only works if done before a
  1805. message about FILE appears!
  1806. Optional args LINE and COL default to 1 and beginning of
  1807. indentation respectively. The marker is expected to reflect
  1808. this. In the simplest case the marker points to the first line
  1809. of the region that was saved to the temp file.
  1810. If you concatenate several regions into the temp file (e.g. a
  1811. header with variable assignments and a code region), you must
  1812. call this several times, once each for the last line of one
  1813. region and the first line of the next region."
  1814. (or (consp file) (setq file (list file)))
  1815. (setq file (compilation-get-file-structure file))
  1816. ;; Between the current call to compilation-fake-loc and the first occurrence
  1817. ;; of an error message referring to `file', the data is only kept in the
  1818. ;; weak hash-table compilation-locs, so we need to prevent this entry
  1819. ;; in compilation-locs from being GC'd away. --Stef
  1820. (push file compilation-gcpro)
  1821. (let ((loc (compilation-assq (or line 1) (cdr file))))
  1822. (setq loc (compilation-assq col loc))
  1823. (if (cdr loc)
  1824. (setcdr (cddr loc) (list marker))
  1825. (setcdr loc (list line file marker)))
  1826. loc))
  1827. (defcustom compilation-context-lines nil
  1828. "Display this many lines of leading context before the current message.
  1829. If nil and the left fringe is displayed, don't scroll the
  1830. compilation output window; an arrow in the left fringe points to
  1831. the current message. If nil and there is no left fringe, the message
  1832. displays at the top of the window; there is no arrow."
  1833. :type '(choice integer (const :tag "No window scrolling" nil))
  1834. :group 'compilation
  1835. :version "22.1")
  1836. (defsubst compilation-set-window (w mk)
  1837. "Align the compilation output window W with marker MK near top."
  1838. (if (integerp compilation-context-lines)
  1839. (set-window-start w (save-excursion
  1840. (goto-char mk)
  1841. (beginning-of-line
  1842. (- 1 compilation-context-lines))
  1843. (point)))
  1844. ;; If there is no left fringe.
  1845. (if (equal (car (window-fringes)) 0)
  1846. (set-window-start w (save-excursion
  1847. (goto-char mk)
  1848. (beginning-of-line 1)
  1849. (point)))))
  1850. (set-window-point w mk))
  1851. (defvar next-error-highlight-timer)
  1852. (defun compilation-goto-locus (msg mk end-mk)
  1853. "Jump to an error corresponding to MSG at MK.
  1854. All arguments are markers. If END-MK is non-nil, mark is set there
  1855. and overlay is highlighted between MK and END-MK."
  1856. ;; Show compilation buffer in other window, scrolled to this error.
  1857. (let* ((from-compilation-buffer (eq (window-buffer (selected-window))
  1858. (marker-buffer msg)))
  1859. ;; Use an existing window if it is in a visible frame.
  1860. (pre-existing (get-buffer-window (marker-buffer msg) 0))
  1861. (w (if (and from-compilation-buffer pre-existing)
  1862. ;; Calling display-buffer here may end up (partly) hiding
  1863. ;; the error location if the two buffers are in two
  1864. ;; different frames. So don't do it if it's not necessary.
  1865. pre-existing
  1866. (let ((display-buffer-reuse-frames t)
  1867. (pop-up-windows t))
  1868. ;; Pop up a window.
  1869. (display-buffer (marker-buffer msg)))))
  1870. (highlight-regexp (with-current-buffer (marker-buffer msg)
  1871. ;; also do this while we change buffer
  1872. (compilation-set-window w msg)
  1873. compilation-highlight-regexp)))
  1874. ;; Ideally, the window-size should be passed to `display-buffer' (via
  1875. ;; something like special-display-buffer) so it's only used when
  1876. ;; creating a new window.
  1877. (unless pre-existing (compilation-set-window-height w))
  1878. (if from-compilation-buffer
  1879. ;; If the compilation buffer window was selected,
  1880. ;; keep the compilation buffer in this window;
  1881. ;; display the source in another window.
  1882. (let ((pop-up-windows t))
  1883. (pop-to-buffer (marker-buffer mk) 'other-window))
  1884. (if (window-dedicated-p (selected-window))
  1885. (pop-to-buffer (marker-buffer mk))
  1886. (switch-to-buffer (marker-buffer mk))))
  1887. (unless (eq (goto-char mk) (point))
  1888. ;; If narrowing gets in the way of going to the right place, widen.
  1889. (widen)
  1890. (if next-error-move-function
  1891. (funcall next-error-move-function msg mk)
  1892. (goto-char mk)))
  1893. (if end-mk
  1894. (push-mark end-mk t)
  1895. (if mark-active (setq mark-active)))
  1896. ;; If hideshow got in the way of
  1897. ;; seeing the right place, open permanently.
  1898. (dolist (ov (overlays-at (point)))
  1899. (when (eq 'hs (overlay-get ov 'invisible))
  1900. (delete-overlay ov)
  1901. (goto-char mk)))
  1902. (when highlight-regexp
  1903. (if (timerp next-error-highlight-timer)
  1904. (cancel-timer next-error-highlight-timer))
  1905. (unless compilation-highlight-overlay
  1906. (setq compilation-highlight-overlay
  1907. (make-overlay (point-min) (point-min)))
  1908. (overlay-put compilation-highlight-overlay 'face 'next-error))
  1909. (with-current-buffer (marker-buffer mk)
  1910. (save-excursion
  1911. (if end-mk (goto-char end-mk) (end-of-line))
  1912. (let ((end (point)))
  1913. (if mk (goto-char mk) (beginning-of-line))
  1914. (if (and (stringp highlight-regexp)
  1915. (re-search-forward highlight-regexp end t))
  1916. (progn
  1917. (goto-char (match-beginning 0))
  1918. (move-overlay compilation-highlight-overlay
  1919. (match-beginning 0) (match-end 0)
  1920. (current-buffer)))
  1921. (move-overlay compilation-highlight-overlay
  1922. (point) end (current-buffer)))
  1923. (if (or (eq next-error-highlight t)
  1924. (numberp next-error-highlight))
  1925. ;; We want highlighting: delete overlay on next input.
  1926. (add-hook 'pre-command-hook
  1927. 'compilation-goto-locus-delete-o)
  1928. ;; We don't want highlighting: delete overlay now.
  1929. (delete-overlay compilation-highlight-overlay))
  1930. ;; We want highlighting for a limited time:
  1931. ;; set up a timer to delete it.
  1932. (when (numberp next-error-highlight)
  1933. (setq next-error-highlight-timer
  1934. (run-at-time next-error-highlight nil
  1935. 'compilation-goto-locus-delete-o)))))))
  1936. (when (and (eq next-error-highlight 'fringe-arrow))
  1937. ;; We want a fringe arrow (instead of highlighting).
  1938. (setq next-error-overlay-arrow-position
  1939. (copy-marker (line-beginning-position))))))
  1940. (defun compilation-goto-locus-delete-o ()
  1941. (delete-overlay compilation-highlight-overlay)
  1942. ;; Get rid of timer and hook that would try to do this again.
  1943. (if (timerp next-error-highlight-timer)
  1944. (cancel-timer next-error-highlight-timer))
  1945. (remove-hook 'pre-command-hook
  1946. 'compilation-goto-locus-delete-o))
  1947. (defun compilation-find-file (marker filename directory &rest formats)
  1948. "Find a buffer for file FILENAME.
  1949. If FILENAME is not found at all, ask the user where to find it.
  1950. Pop up the buffer containing MARKER and scroll to MARKER if we ask
  1951. the user where to find the file.
  1952. Search the directories in `compilation-search-path'.
  1953. A nil in `compilation-search-path' means to try the
  1954. \"current\" directory, which is passed in DIRECTORY.
  1955. If DIRECTORY is relative, it is combined with `default-directory'.
  1956. If DIRECTORY is nil, that means use `default-directory'.
  1957. FORMATS, if given, is a list of formats to reformat FILENAME when
  1958. looking for it: for each element FMT in FORMATS, this function
  1959. attempts to find a file whose name is produced by (format FMT FILENAME)."
  1960. (or formats (setq formats '("%s")))
  1961. (let ((dirs compilation-search-path)
  1962. (spec-dir (if directory
  1963. (expand-file-name directory)
  1964. default-directory))
  1965. buffer thisdir fmts name)
  1966. (if (file-name-absolute-p filename)
  1967. ;; The file name is absolute. Use its explicit directory as
  1968. ;; the first in the search path, and strip it from FILENAME.
  1969. (setq filename (abbreviate-file-name (expand-file-name filename))
  1970. dirs (cons (file-name-directory filename) dirs)
  1971. filename (file-name-nondirectory filename)))
  1972. ;; Now search the path.
  1973. (while (and dirs (null buffer))
  1974. (setq thisdir (or (car dirs) spec-dir)
  1975. fmts formats)
  1976. ;; For each directory, try each format string.
  1977. (while (and fmts (null buffer))
  1978. (setq name (expand-file-name (format (car fmts) filename) thisdir)
  1979. buffer (and (file-exists-p name)
  1980. (find-file-noselect name))
  1981. fmts (cdr fmts)))
  1982. (setq dirs (cdr dirs)))
  1983. (while (null buffer) ;Repeat until the user selects an existing file.
  1984. ;; The file doesn't exist. Ask the user where to find it.
  1985. (save-excursion ;This save-excursion is probably not right.
  1986. (let ((pop-up-windows t))
  1987. (compilation-set-window (display-buffer (marker-buffer marker))
  1988. marker)
  1989. (let* ((name (read-file-name
  1990. (format "Find this %s in (default %s): "
  1991. compilation-error filename)
  1992. spec-dir filename t nil
  1993. ;; The predicate below is fine when called from
  1994. ;; minibuffer-complete-and-exit, but it's too
  1995. ;; restrictive otherwise, since it also prevents the
  1996. ;; user from completing "fo" to "foo/" when she
  1997. ;; wants to enter "foo/bar".
  1998. ;;
  1999. ;; Try to make sure the user can only select
  2000. ;; a valid answer. This predicate may be ignored,
  2001. ;; tho, so we still have to double-check afterwards.
  2002. ;; TODO: We should probably fix read-file-name so
  2003. ;; that it never ignores this predicate, even when
  2004. ;; using popup dialog boxes.
  2005. ;; (lambda (name)
  2006. ;; (if (file-directory-p name)
  2007. ;; (setq name (expand-file-name filename name)))
  2008. ;; (file-exists-p name))
  2009. ))
  2010. (origname name))
  2011. (cond
  2012. ((not (file-exists-p name))
  2013. (message "Cannot find file `%s'" name)
  2014. (ding) (sit-for 2))
  2015. ((and (file-directory-p name)
  2016. (not (file-exists-p
  2017. (setq name (expand-file-name filename name)))))
  2018. (message "No `%s' in directory %s" filename origname)
  2019. (ding) (sit-for 2))
  2020. (t
  2021. (setq buffer (find-file-noselect name))))))))
  2022. ;; Make intangible overlays tangible.
  2023. ;; This is weird: it's not even clear which is the current buffer,
  2024. ;; so the code below can't be expected to DTRT here. -- Stef
  2025. (dolist (ov (overlays-in (point-min) (point-max)))
  2026. (when (overlay-get ov 'intangible)
  2027. (overlay-put ov 'intangible nil)))
  2028. buffer))
  2029. (defun compilation-get-file-structure (file &optional fmt)
  2030. "Retrieve FILE's file-structure or create a new one.
  2031. FILE should be (FILENAME) or (RELATIVE-FILENAME . DIRNAME).
  2032. In the former case, FILENAME may be relative or absolute.
  2033. The file-structure looks like this:
  2034. (list (list FILENAME [DIR-FROM-PREV-MSG]) FMT LINE-STRUCT...)"
  2035. (or (gethash file compilation-locs)
  2036. ;; File was not previously encountered, at least not in the form passed.
  2037. ;; Let's normalize it and look again.
  2038. (let ((filename (car file))
  2039. ;; Get the specified directory from FILE.
  2040. (spec-directory (if (cdr file)
  2041. (file-truename (cdr file)))))
  2042. ;; Check for a comint-file-name-prefix and prepend it if appropriate.
  2043. ;; (This is very useful for compilation-minor-mode in an rlogin-mode
  2044. ;; buffer.)
  2045. (when (and (boundp 'comint-file-name-prefix)
  2046. (not (equal comint-file-name-prefix "")))
  2047. (if (file-name-absolute-p filename)
  2048. (setq filename
  2049. (concat comint-file-name-prefix filename))
  2050. (if spec-directory
  2051. (setq spec-directory
  2052. (file-truename
  2053. (concat comint-file-name-prefix spec-directory))))))
  2054. ;; If compilation-parse-errors-filename-function is
  2055. ;; defined, use it to process the filename.
  2056. (when compilation-parse-errors-filename-function
  2057. (setq filename
  2058. (funcall compilation-parse-errors-filename-function
  2059. filename)))
  2060. ;; Some compilers (e.g. Sun's java compiler, reportedly) produce bogus
  2061. ;; file names like "./bar//foo.c" for file "bar/foo.c";
  2062. ;; expand-file-name will collapse these into "/foo.c" and fail to find
  2063. ;; the appropriate file. So we look for doubled slashes in the file
  2064. ;; name and fix them.
  2065. (setq filename (command-line-normalize-file-name filename))
  2066. ;; Store it for the possibly unnormalized name
  2067. (puthash file
  2068. ;; Retrieve or create file-structure for normalized name
  2069. ;; The gethash used to not use spec-directory, but
  2070. ;; this leads to errors when files in different
  2071. ;; directories have the same name:
  2072. ;; http://lists.gnu.org/archive/html/emacs-devel/2007-08/msg00463.html
  2073. (or (gethash (cons filename spec-directory) compilation-locs)
  2074. (puthash (cons filename spec-directory)
  2075. (list (list filename spec-directory) fmt)
  2076. compilation-locs))
  2077. compilation-locs))))
  2078. (add-to-list 'debug-ignored-errors "^No more [-a-z ]+s yet$")
  2079. ;;; Compatibility with the old compile.el.
  2080. (defun compile-buffer-substring (n) (if n (match-string n)))
  2081. (defun compilation-compat-error-properties (err)
  2082. "Map old-style error ERR to new-style message."
  2083. ;; Old-style structure is (MARKER (FILE DIR) LINE COL) or
  2084. ;; (MARKER . MARKER).
  2085. (let ((dst (cdr err)))
  2086. (if (markerp dst)
  2087. ;; Must start with a face, for font-lock.
  2088. `(face nil
  2089. message ,(list (list nil nil nil dst) 2)
  2090. help-echo "mouse-2: visit the source location"
  2091. keymap compilation-button-map
  2092. mouse-face highlight)
  2093. ;; Too difficult to do it by hand: dispatch to the normal code.
  2094. (let* ((file (pop dst))
  2095. (line (pop dst))
  2096. (col (pop dst))
  2097. (filename (pop file))
  2098. (dirname (pop file))
  2099. (fmt (pop file)))
  2100. (compilation-internal-error-properties
  2101. (cons filename dirname) line nil col nil 2 fmt)))))
  2102. (defun compilation-compat-parse-errors (limit)
  2103. (when compilation-parse-errors-function
  2104. ;; FIXME: We should remove the rest of the compilation keywords
  2105. ;; but we can't do that from here because font-lock is using
  2106. ;; the value right now. --stef
  2107. (save-excursion
  2108. (setq compilation-error-list nil)
  2109. ;; Reset compilation-parsing-end each time because font-lock
  2110. ;; might force us the re-parse many times (typically because
  2111. ;; some code adds some text-property to the output that we
  2112. ;; already parsed). You might say "why reparse", well:
  2113. ;; because font-lock has just removed the `message' property so
  2114. ;; have to do it all over again.
  2115. (if compilation-parsing-end
  2116. (set-marker compilation-parsing-end (point))
  2117. (setq compilation-parsing-end (point-marker)))
  2118. (condition-case nil
  2119. ;; Ignore any error: we're calling this function earlier than
  2120. ;; in the old compile.el so things might not all be setup yet.
  2121. (funcall compilation-parse-errors-function limit nil)
  2122. (error nil))
  2123. (dolist (err (if (listp compilation-error-list) compilation-error-list))
  2124. (let* ((src (car err))
  2125. (dst (cdr err))
  2126. (loc (cond ((markerp dst) (list nil nil nil dst))
  2127. ((consp dst)
  2128. (list (nth 2 dst) (nth 1 dst)
  2129. (cons (cdar dst) (caar dst)))))))
  2130. (when loc
  2131. (goto-char src)
  2132. ;; (put-text-property src (line-end-position) 'font-lock-face 'font-lock-warning-face)
  2133. (put-text-property src (line-end-position)
  2134. 'message (list loc 2)))))))
  2135. (goto-char limit)
  2136. nil)
  2137. ;; Beware: this is not only compatibility code. New code stil uses it. --Stef
  2138. (defun compilation-forget-errors ()
  2139. ;; In case we hit the same file/line specs, we want to recompute a new
  2140. ;; marker for them, so flush our cache.
  2141. (setq compilation-locs (make-hash-table :test 'equal :weakness 'value))
  2142. (setq compilation-gcpro nil)
  2143. ;; FIXME: the old code reset the directory-stack, so maybe we should
  2144. ;; put a `directory change' marker of some sort, but where? -stef
  2145. ;;
  2146. ;; FIXME: The old code moved compilation-current-error (which was
  2147. ;; virtually represented by a mix of compilation-parsing-end and
  2148. ;; compilation-error-list) to point-min, but that was only meaningful for
  2149. ;; the internal uses of compilation-forget-errors: all calls from external
  2150. ;; packages seem to be followed by a move of compilation-parsing-end to
  2151. ;; something equivalent to point-max. So we heuristically move
  2152. ;; compilation-current-error to point-max (since the external package
  2153. ;; won't know that it should do it). --Stef
  2154. (setq compilation-current-error nil)
  2155. (let* ((proc (get-buffer-process (current-buffer)))
  2156. (mark (if proc (process-mark proc)))
  2157. (pos (or mark (point-max))))
  2158. (setq compilation-messages-start
  2159. ;; In the future, ignore the text already present in the buffer.
  2160. ;; Since many process filter functions insert before markers,
  2161. ;; we need to put ours just before the insertion point rather
  2162. ;; than at the insertion point. If that's not possible, then
  2163. ;; don't use a marker. --Stef
  2164. (if (> pos (point-min)) (copy-marker (1- pos)) pos)))
  2165. ;; Again, since this command is used in buffers that contain several
  2166. ;; compilations, to set the beginning of "this compilation", it's a good
  2167. ;; place to reset compilation-auto-jump-to-next.
  2168. (set (make-local-variable 'compilation-auto-jump-to-next)
  2169. (or compilation-auto-jump-to-first-error
  2170. (eq compilation-scroll-output 'first-error))))
  2171. ;;;###autoload
  2172. (add-to-list 'auto-mode-alist (cons (purecopy "\\.gcov\\'") 'compilation-mode))
  2173. (provide 'compile)
  2174. ;; arch-tag: 12465727-7382-4f72-b234-79855a00dd8c
  2175. ;;; compile.el ends here