PageRenderTime 67ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

/raw-elisp/yinwm/elisp/20/emacslib/compile.el

https://bitbucket.org/yinwm/usemacs/
Emacs Lisp | 1955 lines | 1330 code | 192 blank | 433 comment | 44 complexity | 46105ea1b81b6d4169289493b84129b8 MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0

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

  1. ;;; compile.el --- run compiler as inferior of Emacs, parse error messages.
  2. ;; Copyright (C) 1985, 86, 87, 93, 94, 95, 96, 97, 1998 Free Software Foundation, Inc.
  3. ;; Author: Roland McGrath <roland@prep.ai.mit.edu>
  4. ;; Maintainer: FSF
  5. ;; Keywords: tools, processes
  6. ;; This file is part of GNU Emacs.
  7. ;; GNU Emacs is free software; you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation; either version 2, or (at your option)
  10. ;; any later version.
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with GNU Emacs; see the file COPYING. If not, write to the
  17. ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  18. ;; Boston, MA 02111-1307, USA.
  19. ;;; Commentary:
  20. ;; This package provides the compile and grep facilities documented in
  21. ;; the Emacs user's manual.
  22. ;;; Code:
  23. (defgroup compilation nil
  24. "Run compiler as inferior of Emacs, parse error messages."
  25. :group 'tools
  26. :group 'processes)
  27. ;;;###autoload
  28. (defcustom compilation-mode-hook nil
  29. "*List of hook functions run by `compilation-mode' (see `run-hooks')."
  30. :type 'hook
  31. :group 'compilation)
  32. ;;;###autoload
  33. (defcustom compilation-window-height nil
  34. "*Number of lines in a compilation window. If nil, use Emacs default."
  35. :type '(choice (const :tag "Default" nil)
  36. integer)
  37. :group 'compilation)
  38. (defvar compile-auto-highlight nil
  39. "*Specify how many compiler errors to highlight (and parse) initially.
  40. \(Highlighting applies to an error message when the mouse is over it.)
  41. If this is a number N, all compiler error messages in the first N lines
  42. are highlighted and parsed as soon as they arrive in Emacs.
  43. If t, highlight and parse the whole compilation output as soon as it arrives.
  44. If nil, don't highlight or parse any of the buffer until you try to
  45. move to the error messages.
  46. Those messages which are not parsed and highlighted initially
  47. will be parsed and highlighted as soon as you try to move to them.")
  48. (defvar compilation-error-list nil
  49. "List of error message descriptors for visiting erring functions.
  50. Each error descriptor is a cons (or nil). Its car is a marker pointing to
  51. an error message. If its cdr is a marker, it points to the text of the
  52. line the message is about. If its cdr is a cons, it is a list
  53. \(\(DIRECTORY . FILE\) LINE [COLUMN]\). Or its cdr may be nil if that
  54. error is not interesting.
  55. The value may be t instead of a list; this means that the buffer of
  56. error messages should be reparsed the next time the list of errors is wanted.
  57. Some other commands (like `diff') use this list to control the error
  58. message tracking facilities; if you change its structure, you should make
  59. sure you also change those packages. Perhaps it is better not to change
  60. it at all.")
  61. (defvar compilation-old-error-list nil
  62. "Value of `compilation-error-list' after errors were parsed.")
  63. (defvar compilation-parse-errors-function 'compilation-parse-errors
  64. "Function to call to parse error messages from a compilation.
  65. It takes args LIMIT-SEARCH and FIND-AT-LEAST.
  66. If LIMIT-SEARCH is non-nil, don't bother parsing past that location.
  67. If FIND-AT-LEAST is non-nil, don't bother parsing after finding that
  68. many new errors.
  69. It should read in the source files which have errors and set
  70. `compilation-error-list' to a list with an element for each error message
  71. found. See that variable for more info.")
  72. ;;;###autoload
  73. (defvar compilation-process-setup-function nil
  74. "*Function to call to customize the compilation process.
  75. This functions is called immediately before the compilation process is
  76. started. It can be used to set any variables or functions that are used
  77. while processing the output of the compilation process.")
  78. ;;;###autoload
  79. (defvar compilation-buffer-name-function nil
  80. "Function to compute the name of a compilation buffer.
  81. The function receives one argument, the name of the major mode of the
  82. compilation buffer. It should return a string.
  83. nil means compute the name with `(concat \"*\" (downcase major-mode) \"*\")'.")
  84. ;;;###autoload
  85. (defvar compilation-finish-function nil
  86. "Function to call when a compilation process finishes.
  87. It is called with two arguments: the compilation buffer, and a string
  88. describing how the process finished.")
  89. ;;;###autoload
  90. (defvar compilation-finish-functions nil
  91. "Functions to call when a compilation process finishes.
  92. Each function is called with two arguments: the compilation buffer,
  93. and a string describing how the process finished.")
  94. (defvar compilation-last-buffer nil
  95. "The most recent compilation buffer.
  96. A buffer becomes most recent when its compilation is started
  97. or when it is used with \\[next-error] or \\[compile-goto-error].")
  98. (defvar compilation-in-progress nil
  99. "List of compilation processes now running.")
  100. (or (assq 'compilation-in-progress minor-mode-alist)
  101. (setq minor-mode-alist (cons '(compilation-in-progress " Compiling")
  102. minor-mode-alist)))
  103. (defvar compilation-parsing-end nil
  104. "Position of end of buffer when last error messages were parsed.")
  105. (defvar compilation-error-message "No more errors"
  106. "Message to print when no more matches are found.")
  107. (defvar compilation-arguments nil
  108. "Arguments that were given to `compile-internal'.")
  109. (defvar compilation-num-errors-found)
  110. (defvar compilation-error-regexp-alist
  111. '(
  112. ;; NOTE! See also grep-regexp-alist, below.
  113. ;; 4.3BSD grep, cc, lint pass 1:
  114. ;; /usr/src/foo/foo.c(8): warning: w may be used before set
  115. ;; or GNU utilities:
  116. ;; foo.c:8: error message
  117. ;; or HP-UX 7.0 fc:
  118. ;; foo.f :16 some horrible error message
  119. ;; or GNU utilities with column (GNAT 1.82):
  120. ;; foo.adb:2:1: Unit name does not match file name
  121. ;; or with column and program name:
  122. ;; jade:dbcommon.dsl:133:17:E: missing argument for function call
  123. ;;
  124. ;; We'll insist that the number be followed by a colon or closing
  125. ;; paren, because otherwise this matches just about anything
  126. ;; containing a number with spaces around it.
  127. ("\\([a-zA-Z]+:\\)?\\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\
  128. \\([) \t]\\|:\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 2 3 6)
  129. ;; Microsoft C/C++:
  130. ;; keyboard.c(537) : warning C4005: 'min' : macro redefinition
  131. ;; d:\tmp\test.c(23) : error C2143: syntax error : missing ';' before 'if'
  132. ;; This used to be less selective and allow characters other than
  133. ;; parens around the line number, but that caused confusion for
  134. ;; GNU-style error messages.
  135. ;; This used to reject spaces and dashes in file names,
  136. ;; but they are valudnow; so I made it more strict about the error
  137. ;; message that follows.
  138. ("\\(\\([a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\)) \
  139. : \\(error\\|warning\\) C[0-9]+:" 1 3)
  140. ;; Borland C++:
  141. ;; Error ping.c 15: Unable to open include file 'sys/types.h'
  142. ;; Warning ping.c 68: Call to function 'func' with no prototype
  143. ("\\(Error\\|Warning\\) \\([a-zA-Z]?:?[^:( \t\n]+\\)\
  144. \\([0-9]+\\)\\([) \t]\\|:[^0-9\n]\\)" 2 3)
  145. ;; 4.3BSD lint pass 2
  146. ;; strcmp: variable # of args. llib-lc(359) :: /usr/src/foo/foo.c(8)
  147. (".*[ \t:]\\([a-zA-Z]?:?[^:( \t\n]+\\)[:(](+[ \t]*\\([0-9]+\\))[:) \t]*$"
  148. 1 2)
  149. ;; 4.3BSD lint pass 3
  150. ;; bloofle defined( /users/wolfgang/foo.c(4) ), but never used
  151. ;; This used to be
  152. ;; ("[ \t(]+\\([a-zA-Z]?:?[^:( \t\n]+\\)[:( \t]+\\([0-9]+\\)[:) \t]+" 1 2)
  153. ;; which is regexp Impressionism - it matches almost anything!
  154. (".*([ \t]*\\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\))" 1 2)
  155. ;; MIPS lint pass<n>; looks good for SunPro lint also
  156. ;; TrimMask (255) in solomon.c may be indistinguishable from TrimMasks (93) in solomon.c due to truncation
  157. ("[^\n ]+ (\\([0-9]+\\)) in \\([^ \n]+\\)" 2 1)
  158. ;; name defined but never used: LinInt in cmap_calc.c(199)
  159. (".*in \\([^(\n]+\\)(\\([0-9]+\\))$" 1 2)
  160. ;; Ultrix 3.0 f77:
  161. ;; fort: Severe: addstf.f, line 82: Missing operator or delimiter symbol
  162. ;; Some SGI cc version:
  163. ;; cfe: Warning 835: foo.c, line 2: something
  164. ("\\(cfe\\|fort\\): [^:\n]*: \\([^ \n]*\\), line \\([0-9]+\\):" 2 3)
  165. ;; Error on line 3 of t.f: Execution error unclassifiable statement
  166. ;; Unknown who does this:
  167. ;; Line 45 of "foo.c": bloofle undefined
  168. ;; Absoft FORTRAN 77 Compiler 3.1.3
  169. ;; error on line 19 of fplot.f: spelling error?
  170. ;; warning on line 17 of fplot.f: data type is undefined for variable d
  171. ("\\(.* on \\)?[Ll]ine[ \t]+\\([0-9]+\\)[ \t]+\
  172. of[ \t]+\"?\\([a-zA-Z]?:?[^\":\n]+\\)\"?:" 3 2)
  173. ;; Apollo cc, 4.3BSD fc:
  174. ;; "foo.f", line 3: Error: syntax error near end of statement
  175. ;; IBM RS6000:
  176. ;; "vvouch.c", line 19.5: 1506-046 (S) Syntax error.
  177. ;; Microtec mcc68k:
  178. ;; "foo.c", line 32 pos 1; (E) syntax error; unexpected symbol: "lossage"
  179. ;; GNAT (as of July 94):
  180. ;; "foo.adb", line 2(11): warning: file name does not match ...
  181. ;; IBM AIX xlc compiler:
  182. ;; "src/swapping.c", line 30.34: 1506-342 (W) "/*" detected in comment.
  183. (".*\"\\([^,\" \n\t]+\\)\", lines? \
  184. \\([0-9]+\\)\\([\(.]\\([0-9]+\\)\)?\\)?[:., (-]" 1 2 4)
  185. ;; Caml compiler:
  186. ;; File "foobar.ml", lines 5-8, characters 20-155: blah blah
  187. ("^File \"\\([^,\" \n\t]+\\)\", lines? \\([0-9]+\\)[-0-9]*, characters? \\([0-9]+\\)" 1 2 3)
  188. ;; MIPS RISC CC - the one distributed with Ultrix:
  189. ;; ccom: Error: foo.c, line 2: syntax error
  190. ;; DEC AXP OSF/1 cc
  191. ;; /usr/lib/cmplrs/cc/cfe: Error: foo.c: 1: blah blah
  192. ("[a-z0-9/]+: \\([eE]rror\\|[wW]arning\\): \\([^,\" \n\t]+\\)[,:] \\(line \\)?\\([0-9]+\\):" 2 4)
  193. ;; IBM AIX PS/2 C version 1.1:
  194. ;; ****** Error number 140 in line 8 of file errors.c ******
  195. (".*in line \\([0-9]+\\) of file \\([^ \n]+[^. \n]\\)\\.? " 2 1)
  196. ;; IBM AIX lint is too painful to do right this way. File name
  197. ;; prefixes entire sections rather than being on each line.
  198. ;; SPARCcompiler Pascal:
  199. ;; 20 linjer : array[1..4] of linje;
  200. ;; e 18480-----------^--- Inserted ';'
  201. ;; and
  202. ;; E 18520 line 61 - 0 is undefined
  203. ;; These messages don't contain a file name. Instead the compiler gives
  204. ;; a message whenever the file being compiled is changed.
  205. (" +\\([0-9]+\\) +.*\n[ew] [0-9]+-+" nil 1)
  206. ("[Ew] +[0-9]+ line \\([0-9]+\\) - " nil 1)
  207. ;; Lucid Compiler, lcc 3.x
  208. ;; E, file.cc(35,52) Illegal operation on pointers
  209. ("[EW], \\([^(\n]*\\)(\\([0-9]+\\),[ \t]*\\([0-9]+\\)" 1 2 3)
  210. ;;; This seems to be superfluous because the first pattern matches it.
  211. ;;; ;; GNU messages with program name and optional column number.
  212. ;;; ("[a-zA-Z]?:?[^0-9 \n\t:]+[^ \n\t:]*:[ \t]*\\([^ \n\t:]+\\):\
  213. ;;;\\([0-9]+\\):\\(\\([0-9]+\\)[: \t]\\)?" 1 2 4)
  214. ;; Cray C compiler error messages
  215. ("\\(cc\\| cft\\)-[0-9]+ c\\(c\\|f77\\): ERROR \\([^,\n]+, \\)* File = \
  216. \\([^,\n]+\\), Line = \\([0-9]+\\)" 4 5)
  217. ;; IBM C/C++ Tools 2.01:
  218. ;; foo.c(2:0) : informational EDC0804: Function foo is not referenced.
  219. ;; foo.c(3:8) : warning EDC0833: Implicit return statement encountered.
  220. ;; foo.c(5:5) : error EDC0350: Syntax error.
  221. ("\\([^( \n\t]+\\)(\\([0-9]+\\):\\([0-9]+\\)) : " 1 2 3)
  222. ;; IAR Systems C Compiler:
  223. ;; "foo.c",3 Error[32]: Error message
  224. ;; "foo.c",3 Warning[32]: Error message
  225. ("\"\\(.*\\)\",\\([0-9]+\\)\\s-+\\(Error\\|Warning\\)\\[[0-9]+\\]:" 1 2)
  226. ;; Sun ada (VADS, Solaris):
  227. ;; /home3/xdhar/rcds_rc/main.a, line 361, char 6:syntax error: "," inserted
  228. ("\\([^, \n\t]+\\), line \\([0-9]+\\), char \\([0-9]+\\)[:., \(-]" 1 2 3)
  229. ;; Perl -w:
  230. ;; syntax error at automake line 922, near "':'"
  231. (".* at \\([^ ]+\\) line \\([0-9]+\\)," 1 2)
  232. ;; Oracle pro*c:
  233. ;; Semantic error at line 528, column 5, file erosacqdb.pc:
  234. ("Semantic error at line \\([0-9]+\\), column \\([0-9]+\\), file \\(.*\\):"
  235. 3 1 2)
  236. ;; EPC F90 compiler:
  237. ;; Error 24 at (2:progran.f90) : syntax error
  238. ("Error [0-9]+ at (\\([0-9]*\\):\\([^)\n]+\\))" 2 1)
  239. ;; Sun F90 error messages:
  240. ;; cf90-113 f90comp: ERROR NSE, File = Hoved.f90, Line = 16, Column = 3
  241. (".* ERROR [a-zA-Z0-9 ]+, File = \\(.+\\), Line = \\([0-9]+\\), Column = \\([0-9]+\\)"
  242. 1 2 3)
  243. )
  244. "Alist that specifies how to match errors in compiler output.
  245. Each elt has the form (REGEXP FILE-IDX LINE-IDX [COLUMN-IDX FILE-FORMAT...])
  246. If REGEXP matches, the FILE-IDX'th subexpression gives the file name, and
  247. the LINE-IDX'th subexpression gives the line number. If COLUMN-IDX is
  248. given, the COLUMN-IDX'th subexpression gives the column number on that line.
  249. If any FILE-FORMAT is given, each is a format string to produce a file name to
  250. try; %s in the string is replaced by the text matching the FILE-IDX'th
  251. subexpression.")
  252. (defvar compilation-enter-directory-regexp-alist
  253. '(
  254. ;; Matches lines printed by the `-w' option of GNU Make.
  255. (".*: Entering directory `\\(.*\\)'$" 1)
  256. )
  257. "Alist specifying how to match lines that indicate a new current directory.
  258. Note that the match is done at the beginning of lines.
  259. Each elt has the form (REGEXP IDX).
  260. If REGEXP matches, the IDX'th subexpression gives the directory name.
  261. The default value matches lines printed by the `-w' option of GNU Make.")
  262. (defvar compilation-leave-directory-regexp-alist
  263. '(
  264. ;; Matches lines printed by the `-w' option of GNU Make.
  265. (".*: Leaving directory `\\(.*\\)'$" 1)
  266. )
  267. "Alist specifying how to match lines that indicate restoring current directory.
  268. Note that the match is done at the beginning of lines.
  269. Each elt has the form (REGEXP IDX).
  270. If REGEXP matches, the IDX'th subexpression gives the name of the directory
  271. being moved from. If IDX is nil, the last directory entered \(by a line
  272. matching `compilation-enter-directory-regexp-alist'\) is assumed.
  273. The default value matches lines printed by the `-w' option of GNU Make.")
  274. (defvar compilation-file-regexp-alist
  275. '(
  276. ;; This matches entries with date time year file-name: like
  277. ;; Thu May 14 10:46:12 1992 mom3.p:
  278. ("\\w\\w\\w \\w\\w\\w +[0-9]+ [0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9][0-9][0-9][0-9] \\(.*\\):$" 1)
  279. )
  280. "Alist specifying how to match lines that indicate a new current file.
  281. Note that the match is done at the beginning of lines.
  282. Each elt has the form (REGEXP IDX).
  283. If REGEXP matches, the IDX'th subexpression gives the file name. This is
  284. used with compilers that don't indicate file name in every error message.")
  285. ;; There is no generally useful regexp that will match non messages, but
  286. ;; in special cases there might be one. The lines that are not matched by
  287. ;; a regexp take much longer time than the ones that are recognized so if
  288. ;; you have same regexeps here, parsing is faster.
  289. (defvar compilation-nomessage-regexp-alist
  290. '(
  291. )
  292. "Alist specifying how to match lines that have no message.
  293. Note that the match is done at the beginning of lines.
  294. Each elt has the form (REGEXP). This alist is by default empty, but if
  295. you have some good regexps here, the parsing of messages will be faster.")
  296. (defcustom compilation-read-command t
  297. "*If not nil, M-x compile reads the compilation command to use.
  298. Otherwise, M-x compile just uses the value of `compile-command'."
  299. :type 'boolean
  300. :group 'compilation)
  301. ;;;###autoload
  302. (defcustom compilation-ask-about-save t
  303. "*If not nil, M-x compile asks which buffers to save before compiling.
  304. Otherwise, it saves all modified buffers without asking."
  305. :type 'boolean
  306. :group 'compilation)
  307. (defvar grep-regexp-alist
  308. '(("\\([a-zA-Z]?:?[^:( \t\n]+\\)[:( \t]+\\([0-9]+\\)[:) \t]" 1 2))
  309. "Regexp used to match grep hits. See `compilation-error-regexp-alist'.")
  310. (defvar grep-program
  311. ;; Currently zgrep has trouble. It runs egrep instead of grep,
  312. ;; and it doesn't pass along long options right.
  313. "grep"
  314. ;;; (if (equal (condition-case nil ; in case "zgrep" isn't in exec-path
  315. ;;; (call-process "zgrep" nil nil nil
  316. ;;; "foo" null-device)
  317. ;;; (error nil))
  318. ;;; 1)
  319. ;;; "zgrep"
  320. ;;; "grep")
  321. "The default grep program for `grep-command' and `grep-find-command'.
  322. This variable's value takes effect when `grep-compute-defaults' is called.")
  323. ;; Use -e if grep supports it,
  324. ;; because that avoids lossage if the pattern starts with `-'.
  325. (defvar grep-command nil
  326. "The default grep command for \\[grep].
  327. The real default value of this variable is set up by `grep-compute-defaults';
  328. call that function before using this variable.")
  329. (defvar grep-find-use-xargs nil
  330. "Whether \\[grep-find] uses the `xargs' utility by default.
  331. If nil, it uses `grep -exec'; if `gnu', it uses `find -print0' and `xargs -0';
  332. if not nil and not `gnu', it uses `find -print' and `xargs'.
  333. This variable's value takes effect when `grep-compute-defaults' is called.")
  334. (defvar grep-find-command nil
  335. "The default find command for \\[grep-find].
  336. The default value of this variable is set up by `grep-compute-defaults';
  337. call that function before using this variable.")
  338. ;;;###autoload
  339. (defcustom compilation-search-path '(nil)
  340. "*List of directories to search for source files named in error messages.
  341. Elements should be directory names, not file names of directories.
  342. nil as an element means to try the default directory."
  343. :type '(repeat (choice (const :tag "Default" nil)
  344. (string :tag "Directory")))
  345. :group 'compilation)
  346. (defcustom compile-command "make -k "
  347. "*Last shell command used to do a compilation; default for next compilation.
  348. Sometimes it is useful for files to supply local values for this variable.
  349. You might also use mode hooks to specify it in certain modes, like this:
  350. (add-hook 'c-mode-hook
  351. (function
  352. (lambda ()
  353. (unless (or (file-exists-p \"makefile\")
  354. (file-exists-p \"Makefile\"))
  355. (make-local-variable 'compile-command)
  356. (setq compile-command
  357. (concat \"make -k \"
  358. (file-name-sans-extension buffer-file-name)))))))"
  359. :type 'string
  360. :group 'compilation)
  361. (defvar compilation-directory-stack nil
  362. "Stack of previous directories for `compilation-leave-directory-regexp'.
  363. The last element is the directory the compilation was started in.")
  364. (defvar compilation-exit-message-function nil "\
  365. If non-nil, called when a compilation process dies to return a status message.
  366. This should be a function of three arguments: process status, exit status,
  367. and exit message; it returns a cons (MESSAGE . MODELINE) of the strings to
  368. write into the compilation buffer, and to put in its mode line.")
  369. ;; History of compile commands.
  370. (defvar compile-history nil)
  371. ;; History of grep commands.
  372. (defvar grep-history nil)
  373. (defvar grep-find-history nil)
  374. (defun compilation-mode-font-lock-keywords ()
  375. "Return expressions to highlight in Compilation mode."
  376. (nconc
  377. ;;
  378. ;; Compiler warning/error lines.
  379. (mapcar (function
  380. (lambda (item)
  381. ;; Prepend "^", adjusting FILE-IDX and LINE-IDX accordingly.
  382. (let ((file-idx (nth 1 item))
  383. (line-idx (nth 2 item))
  384. (col-idx (nth 3 item))
  385. keyword)
  386. (when (numberp col-idx)
  387. (setq keyword
  388. (cons (list (1+ col-idx) 'font-lock-type-face nil t)
  389. keyword)))
  390. (when (numberp line-idx)
  391. (setq keyword
  392. (cons (list (1+ line-idx) 'font-lock-variable-name-face)
  393. keyword)))
  394. (when (numberp file-idx)
  395. (setq keyword
  396. (cons (list (1+ file-idx) 'font-lock-warning-face)
  397. keyword)))
  398. (cons (concat "^\\(" (nth 0 item) "\\)") keyword))))
  399. compilation-error-regexp-alist)
  400. (list
  401. ;;
  402. ;; Compiler output lines. Recognize `make[n]:' lines too.
  403. '("^\\([A-Za-z_0-9/\.+-]+\\)\\(\\[\\([0-9]+\\)\\]\\)?[ \t]*:"
  404. (1 font-lock-function-name-face) (3 font-lock-comment-face nil t)))
  405. ))
  406. ;;;###autoload
  407. (defun compile (command)
  408. "Compile the program including the current buffer. Default: run `make'.
  409. Runs COMMAND, a shell command, in a separate process asynchronously
  410. with output going to the buffer `*compilation*'.
  411. You can then use the command \\[next-error] to find the next error message
  412. and move to the source code that caused it.
  413. Interactively, prompts for the command if `compilation-read-command' is
  414. non-nil; otherwise uses `compile-command'. With prefix arg, always prompts.
  415. To run more than one compilation at once, start one and rename the
  416. \`*compilation*' buffer to some other name with \\[rename-buffer].
  417. Then start the next one.
  418. The name used for the buffer is actually whatever is returned by
  419. the function in `compilation-buffer-name-function', so you can set that
  420. to a function that generates a unique name."
  421. (interactive
  422. (if (or compilation-read-command current-prefix-arg)
  423. (list (read-from-minibuffer "Compile command: "
  424. compile-command nil nil
  425. '(compile-history . 1)))
  426. (list compile-command)))
  427. (setq compile-command command)
  428. (save-some-buffers (not compilation-ask-about-save) nil)
  429. (compile-internal compile-command "No more errors"))
  430. ;;; run compile with the default command line
  431. (defun recompile ()
  432. "Re-compile the program including the current buffer."
  433. (interactive)
  434. (save-some-buffers (not compilation-ask-about-save) nil)
  435. (compile-internal compile-command "No more errors"))
  436. (defun grep-process-setup ()
  437. "Set up `compilation-exit-message-function' for `grep'."
  438. (set (make-local-variable 'compilation-exit-message-function)
  439. (lambda (status code msg)
  440. (if (eq status 'exit)
  441. (cond ((zerop code)
  442. '("finished (matches found)\n" . "matched"))
  443. ((= code 1)
  444. '("finished with no matches found\n" . "no match"))
  445. (t
  446. (cons msg code)))
  447. (cons msg code)))))
  448. (defun grep-compute-defaults ()
  449. (setq grep-command
  450. (if (equal (condition-case nil ; in case "grep" isn't in exec-path
  451. (call-process grep-program nil nil nil
  452. "-e" "foo" null-device)
  453. (error nil))
  454. 1)
  455. (format "%s -n -e " grep-program)
  456. (format "%s -n " grep-program)))
  457. (unless grep-find-use-xargs
  458. (setq grep-find-use-xargs
  459. (if (equal (call-process "find" nil nil nil
  460. null-device "-print0")
  461. 0)
  462. 'gnu)))
  463. (setq grep-find-command
  464. (cond ((eq grep-find-use-xargs 'gnu)
  465. (format "find . -type f -print0 | xargs -0 -e %s"
  466. grep-command))
  467. (grep-find-use-xargs
  468. (format "find . -type f -print | xargs %s" grep-command))
  469. (t (cons (format "find . -type f -exec %s {} /dev/null \\;"
  470. grep-command)
  471. (+ 22 (length grep-command)))))))
  472. ;;;###autoload
  473. (defun grep (command-args)
  474. "Run grep, with user-specified args, and collect output in a buffer.
  475. While grep runs asynchronously, you can use \\[next-error] (M-x next-error),
  476. or \\<compilation-minor-mode-map>\\[compile-goto-error] in the grep \
  477. output buffer, to go to the lines
  478. where grep found matches.
  479. This command uses a special history list for its arguments, so you can
  480. easily repeat a grep command.
  481. A prefix argument says to default the argument based upon the current
  482. tag the cursor is over, substituting it into the last grep command
  483. in the grep command history (or into `grep-command'
  484. if that history list is empty)."
  485. (interactive
  486. (let (grep-default (arg current-prefix-arg))
  487. (unless grep-command
  488. (grep-compute-defaults))
  489. (when arg
  490. (let* ((tag-default
  491. (funcall (or find-tag-default-function
  492. (get major-mode 'find-tag-default-function)
  493. ;; We use grep-tag-default instead of
  494. ;; find-tag-default, to avoid loading etags.
  495. 'grep-tag-default))))
  496. (setq grep-default (or (car grep-history) grep-command))
  497. ;; Replace the thing matching for with that around cursor
  498. (if (string-match "[^ ]+\\s +\\(-[^ ]+\\s +\\)*\\(\"[^\"]+\"\\|[^ ]+\\)" grep-default)
  499. (setq grep-default (replace-match tag-default t t
  500. grep-default 2)))))
  501. (list (read-from-minibuffer "Run grep (like this): "
  502. (or grep-default grep-command)
  503. nil nil 'grep-history))))
  504. ;; Setting process-setup-function makes exit-message-function work
  505. ;; even when async processes aren't supported.
  506. (let* ((compilation-process-setup-function 'grep-process-setup)
  507. (buf (compile-internal (if null-device
  508. (concat command-args " " null-device)
  509. command-args)
  510. "No more grep hits" "grep"
  511. ;; Give it a simpler regexp to match.
  512. nil grep-regexp-alist)))))
  513. ;; This is a copy of find-tag-default from etags.el.
  514. (defun grep-tag-default ()
  515. (save-excursion
  516. (while (looking-at "\\sw\\|\\s_")
  517. (forward-char 1))
  518. (when (or (re-search-backward "\\sw\\|\\s_"
  519. (save-excursion (beginning-of-line) (point))
  520. t)
  521. (re-search-forward "\\(\\sw\\|\\s_\\)+"
  522. (save-excursion (end-of-line) (point))
  523. t))
  524. (goto-char (match-end 0))
  525. (buffer-substring (point)
  526. (progn (forward-sexp -1)
  527. (while (looking-at "\\s'")
  528. (forward-char 1))
  529. (point))))))
  530. ;;;###autoload
  531. (defun grep-find (command-args)
  532. "Run grep via find, with user-specified args, and collect output in a buffer.
  533. While find runs asynchronously, you can use the \\[next-error] command
  534. to find the text that grep hits refer to.
  535. This command uses a special history list for its arguments, so you can
  536. easily repeat a find command."
  537. (interactive
  538. (progn
  539. (unless grep-find-command
  540. (grep-compute-defaults))
  541. (list (read-from-minibuffer "Run find (like this): "
  542. grep-find-command nil nil
  543. 'grep-find-history))))
  544. (let ((null-device nil)) ; see grep
  545. (grep command-args)))
  546. (defcustom compilation-scroll-output nil
  547. "*Non-nil to scroll the *compilation* buffer window as output appears.
  548. Setting it causes the compilation-mode commands to put point at the
  549. end of their output window so that the end of the output is always
  550. visible rather than the begining."
  551. :type 'boolean
  552. :version "20.3"
  553. :group 'compilation)
  554. (defun compile-internal (command error-message
  555. &optional name-of-mode parser
  556. error-regexp-alist name-function
  557. enter-regexp-alist leave-regexp-alist
  558. file-regexp-alist nomessage-regexp-alist)
  559. "Run compilation command COMMAND (low level interface).
  560. ERROR-MESSAGE is a string to print if the user asks to see another error
  561. and there are no more errors. The rest of the arguments, 3-10 are optional.
  562. For them nil means use the default.
  563. NAME-OF-MODE is the name to display as the major mode in the compilation
  564. buffer. PARSER is the error parser function. ERROR-REGEXP-ALIST is the error
  565. message regexp alist to use. NAME-FUNCTION is a function called to name the
  566. buffer. ENTER-REGEXP-ALIST is the enter directory message regexp alist to use.
  567. LEAVE-REGEXP-ALIST is the leave directory message regexp alist to use.
  568. FILE-REGEXP-ALIST is the change current file message regexp alist to use.
  569. NOMESSAGE-REGEXP-ALIST is the nomessage regexp alist to use.
  570. The defaults for these variables are the global values of
  571. \`compilation-parse-errors-function', `compilation-error-regexp-alist',
  572. \`compilation-buffer-name-function', `compilation-enter-directory-regexp-alist',
  573. \`compilation-leave-directory-regexp-alist', `compilation-file-regexp-alist',
  574. \ and `compilation-nomessage-regexp-alist', respectively.
  575. For arg 7-10 a value `t' means an empty alist.
  576. Returns the compilation buffer created."
  577. (let (outbuf)
  578. (save-excursion
  579. (or name-of-mode
  580. (setq name-of-mode "Compilation"))
  581. (setq outbuf
  582. (get-buffer-create
  583. (funcall (or name-function compilation-buffer-name-function
  584. (function (lambda (mode)
  585. (concat "*" (downcase mode) "*"))))
  586. name-of-mode)))
  587. (set-buffer outbuf)
  588. (let ((comp-proc (get-buffer-process (current-buffer))))
  589. (if comp-proc
  590. (if (or (not (eq (process-status comp-proc) 'run))
  591. (yes-or-no-p
  592. (format "A %s process is running; kill it? "
  593. name-of-mode)))
  594. (condition-case ()
  595. (progn
  596. (interrupt-process comp-proc)
  597. (sit-for 1)
  598. (delete-process comp-proc))
  599. (error nil))
  600. (error "Cannot have two processes in `%s' at once"
  601. (buffer-name))
  602. )))
  603. ;; In case the compilation buffer is current, make sure we get the global
  604. ;; values of compilation-error-regexp-alist, etc.
  605. (kill-all-local-variables))
  606. (or error-regexp-alist
  607. (setq error-regexp-alist compilation-error-regexp-alist))
  608. (or enter-regexp-alist
  609. (setq enter-regexp-alist compilation-enter-directory-regexp-alist))
  610. (or leave-regexp-alist
  611. (setq leave-regexp-alist compilation-leave-directory-regexp-alist))
  612. (or file-regexp-alist
  613. (setq file-regexp-alist compilation-file-regexp-alist))
  614. (or nomessage-regexp-alist
  615. (setq nomessage-regexp-alist compilation-nomessage-regexp-alist))
  616. (or parser (setq parser compilation-parse-errors-function))
  617. (let ((thisdir default-directory)
  618. outwin)
  619. (save-excursion
  620. ;; Clear out the compilation buffer and make it writable.
  621. ;; Change its default-directory to the directory where the compilation
  622. ;; will happen, and insert a `cd' command to indicate this.
  623. (set-buffer outbuf)
  624. (setq buffer-read-only nil)
  625. (buffer-disable-undo (current-buffer))
  626. (erase-buffer)
  627. (buffer-enable-undo (current-buffer))
  628. (setq default-directory thisdir)
  629. (insert "cd " thisdir "\n" command "\n")
  630. (set-buffer-modified-p nil))
  631. ;; If we're already in the compilation buffer, go to the end
  632. ;; of the buffer, so point will track the compilation output.
  633. (if (eq outbuf (current-buffer))
  634. (goto-char (point-max)))
  635. ;; Pop up the compilation buffer.
  636. (setq outwin (display-buffer outbuf))
  637. (save-excursion
  638. (set-buffer outbuf)
  639. (compilation-mode name-of-mode)
  640. ;; (setq buffer-read-only t) ;;; Non-ergonomic.
  641. (set (make-local-variable 'compilation-parse-errors-function) parser)
  642. (set (make-local-variable 'compilation-error-message) error-message)
  643. (set (make-local-variable 'compilation-error-regexp-alist)
  644. error-regexp-alist)
  645. (set (make-local-variable 'compilation-enter-directory-regexp-alist)
  646. enter-regexp-alist)
  647. (set (make-local-variable 'compilation-leave-directory-regexp-alist)
  648. leave-regexp-alist)
  649. (set (make-local-variable 'compilation-file-regexp-alist)
  650. file-regexp-alist)
  651. (set (make-local-variable 'compilation-nomessage-regexp-alist)
  652. nomessage-regexp-alist)
  653. (set (make-local-variable 'compilation-arguments)
  654. (list command error-message
  655. name-of-mode parser
  656. error-regexp-alist name-function
  657. enter-regexp-alist leave-regexp-alist
  658. file-regexp-alist nomessage-regexp-alist))
  659. (make-local-variable 'lazy-lock-defer-on-scrolling)
  660. ;; This proves a good idea if the buffer's going to scroll
  661. ;; with lazy-lock on.
  662. (setq lazy-lock-defer-on-scrolling t)
  663. (setq default-directory thisdir
  664. compilation-directory-stack (list default-directory))
  665. (set-window-start outwin (point-min))
  666. (or (eq outwin (selected-window))
  667. (set-window-point outwin (point-min)))
  668. (compilation-set-window-height outwin)
  669. (if compilation-process-setup-function
  670. (funcall compilation-process-setup-function))
  671. ;; Start the compilation.
  672. (if (fboundp 'start-process)
  673. (let* ((process-environment (cons "EMACS=t" process-environment))
  674. (proc (start-process-shell-command (downcase mode-name)
  675. outbuf
  676. command)))
  677. (set-process-sentinel proc 'compilation-sentinel)
  678. (set-process-filter proc 'compilation-filter)
  679. (set-marker (process-mark proc) (point) outbuf)
  680. (setq compilation-in-progress
  681. (cons proc compilation-in-progress)))
  682. ;; No asynchronous processes available.
  683. (message "Executing `%s'..." command)
  684. ;; Fake modeline display as if `start-process' were run.
  685. (setq mode-line-process ":run")
  686. (force-mode-line-update)
  687. (sit-for 0) ; Force redisplay
  688. (let ((status (call-process shell-file-name nil outbuf nil "-c"
  689. command)))
  690. (cond ((numberp status)
  691. (compilation-handle-exit 'exit status
  692. (if (zerop status)
  693. "finished\n"
  694. (format "\
  695. exited abnormally with code %d\n"
  696. status))))
  697. ((stringp status)
  698. (compilation-handle-exit 'signal status
  699. (concat status "\n")))
  700. (t
  701. (compilation-handle-exit 'bizarre status status))))
  702. (message "Executing `%s'...done" command)))
  703. (if compilation-scroll-output
  704. (let ((currbuf (current-buffer)))
  705. (select-window outwin)
  706. (goto-char (point-max))
  707. (select-window (get-buffer-window currbuf)))))
  708. ;; Make it so the next C-x ` will use this buffer.
  709. (setq compilation-last-buffer outbuf)))
  710. ;; Set the height of WINDOW according to compilation-window-height.
  711. (defun compilation-set-window-height (window)
  712. (and compilation-window-height
  713. (= (window-width window) (frame-width (window-frame window)))
  714. ;; If window is alone in its frame, aside from a minibuffer,
  715. ;; don't change its height.
  716. (not (eq window (frame-root-window (window-frame window))))
  717. ;; This save-excursion prevents us from changing the current buffer,
  718. ;; which might not be the same as the selected window's buffer.
  719. (save-excursion
  720. (let ((w (selected-window)))
  721. (unwind-protect
  722. (progn
  723. (select-window window)
  724. (enlarge-window (- compilation-window-height
  725. (window-height))))
  726. (select-window w))))))
  727. (defvar compilation-minor-mode-map
  728. (let ((map (make-sparse-keymap)))
  729. (define-key map [mouse-2] 'compile-mouse-goto-error)
  730. (define-key map "\C-c\C-c" 'compile-goto-error)
  731. (define-key map "\C-m" 'compile-goto-error)
  732. (define-key map "\C-c\C-k" 'kill-compilation)
  733. (define-key map "\M-n" 'compilation-next-error)
  734. (define-key map "\M-p" 'compilation-previous-error)
  735. (define-key map "\M-{" 'compilation-previous-file)
  736. (define-key map "\M-}" 'compilation-next-file)
  737. map)
  738. "Keymap for `compilation-minor-mode'.")
  739. (defvar compilation-shell-minor-mode-map
  740. (let ((map (make-sparse-keymap)))
  741. (define-key map [mouse-2] 'compile-mouse-goto-error)
  742. (define-key map "\M-\C-m" 'compile-goto-error)
  743. (define-key map "\M-\C-n" 'compilation-next-error)
  744. (define-key map "\M-\C-p" 'compilation-previous-error)
  745. (define-key map "\M-{" 'compilation-previous-file)
  746. (define-key map "\M-}" 'compilation-next-file)
  747. ;; Set up the menu-bar
  748. (define-key map [menu-bar errors-menu]
  749. (cons "Errors" (make-sparse-keymap "Errors")))
  750. (define-key map [menu-bar errors-menu stop-subjob]
  751. '("Stop" . comint-interrupt-subjob))
  752. (define-key map [menu-bar errors-menu compilation-mode-separator2]
  753. '("----" . nil))
  754. (define-key map [menu-bar errors-menu compilation-mode-first-error]
  755. '("First Error" . first-error))
  756. (define-key map [menu-bar errors-menu compilation-mode-previous-error]
  757. '("Previous Error" . previous-error))
  758. (define-key map [menu-bar errors-menu compilation-mode-next-error]
  759. '("Next Error" . next-error))
  760. map)
  761. "Keymap for `compilation-shell-minor-mode'.")
  762. (defvar compilation-mode-map
  763. (let ((map (cons 'keymap compilation-minor-mode-map)))
  764. (define-key map " " 'scroll-up)
  765. (define-key map "\^?" 'scroll-down)
  766. ;; Set up the menu-bar
  767. (define-key map [menu-bar compilation-menu]
  768. (cons "Compile" (make-sparse-keymap "Compile")))
  769. (define-key map [menu-bar compilation-menu compilation-mode-kill-compilation]
  770. '("Stop Compilation" . kill-compilation))
  771. (define-key map [menu-bar compilation-menu compilation-mode-separator2]
  772. '("----" . nil))
  773. (define-key map [menu-bar compilation-menu compilation-mode-first-error]
  774. '("First Error" . first-error))
  775. (define-key map [menu-bar compilation-menu compilation-mode-previous-error]
  776. '("Previous Error" . previous-error))
  777. (define-key map [menu-bar compilation-menu compilation-mode-next-error]
  778. '("Next Error" . next-error))
  779. (define-key map [menu-bar compilation-menu compilation-separator2]
  780. '("----" . nil))
  781. (define-key map [menu-bar compilation-menu compilation-mode-grep]
  782. '("Search Files (grep)" . grep))
  783. (define-key map [menu-bar compilation-menu compilation-mode-recompile]
  784. '("Recompile" . recompile))
  785. (define-key map [menu-bar compilation-menu compilation-mode-compile]
  786. '("Compile..." . compile))
  787. map)
  788. "Keymap for compilation log buffers.
  789. `compilation-minor-mode-map' is a cdr of this.")
  790. (put 'compilation-mode 'mode-class 'special)
  791. ;;;###autoload
  792. (defun compilation-mode (&optional name-of-mode)
  793. "Major mode for compilation log buffers.
  794. \\<compilation-mode-map>To visit the source for a line-numbered error,
  795. move point to the error message line and type \\[compile-goto-error].
  796. To kill the compilation, type \\[kill-compilation].
  797. Runs `compilation-mode-hook' with `run-hooks' (which see)."
  798. (interactive)
  799. (kill-all-local-variables)
  800. (use-local-map compilation-mode-map)
  801. (setq major-mode 'compilation-mode
  802. mode-name (or name-of-mode "Compilation"))
  803. (compilation-setup)
  804. (set (make-local-variable 'font-lock-defaults)
  805. '(compilation-mode-font-lock-keywords t))
  806. (set (make-local-variable 'revert-buffer-function)
  807. 'compilation-revert-buffer)
  808. (run-hooks 'compilation-mode-hook))
  809. (defun compilation-revert-buffer (ignore-auto noconfirm)
  810. (if (or noconfirm (yes-or-no-p (format "Restart compilation? ")))
  811. (apply 'compile-internal compilation-arguments)))
  812. ;; Prepare the buffer for the compilation parsing commands to work.
  813. (defun compilation-setup ()
  814. ;; Make the buffer's mode line show process state.
  815. (setq mode-line-process '(":%s"))
  816. (set (make-local-variable 'compilation-error-list) nil)
  817. (set (make-local-variable 'compilation-old-error-list) nil)
  818. (set (make-local-variable 'compilation-parsing-end) 1)
  819. (set (make-local-variable 'compilation-directory-stack) nil)
  820. (setq compilation-last-buffer (current-buffer)))
  821. (defvar compilation-shell-minor-mode nil
  822. "Non-nil when in compilation-shell-minor-mode.
  823. In this minor mode, all the error-parsing commands of the
  824. Compilation major mode are available but bound to keys that don't
  825. collide with Shell mode.")
  826. (make-variable-buffer-local 'compilation-shell-minor-mode)
  827. (or (assq 'compilation-shell-minor-mode minor-mode-alist)
  828. (setq minor-mode-alist
  829. (cons '(compilation-shell-minor-mode " Shell-Compile")
  830. minor-mode-alist)))
  831. (or (assq 'compilation-shell-minor-mode minor-mode-map-alist)
  832. (setq minor-mode-map-alist (cons (cons 'compilation-shell-minor-mode
  833. compilation-shell-minor-mode-map)
  834. minor-mode-map-alist)))
  835. (defvar compilation-minor-mode nil
  836. "Non-nil when in compilation-minor-mode.
  837. In this minor mode, all the error-parsing commands of the
  838. Compilation major mode are available.")
  839. (make-variable-buffer-local 'compilation-minor-mode)
  840. (or (assq 'compilation-minor-mode minor-mode-alist)
  841. (setq minor-mode-alist (cons '(compilation-minor-mode " Compilation")
  842. minor-mode-alist)))
  843. (or (assq 'compilation-minor-mode minor-mode-map-alist)
  844. (setq minor-mode-map-alist (cons (cons 'compilation-minor-mode
  845. compilation-minor-mode-map)
  846. minor-mode-map-alist)))
  847. ;;;###autoload
  848. (defun compilation-minor-mode (&optional arg)
  849. "Toggle compilation minor mode.
  850. With arg, turn compilation mode on if and only if arg is positive.
  851. See `compilation-mode'.
  852. Turning the mode on runs the normal hook `compilation-minor-mode-hook'."
  853. (interactive "P")
  854. (if (setq compilation-minor-mode (if (null arg)
  855. (null compilation-minor-mode)
  856. (> (prefix-numeric-value arg) 0)))
  857. (let ((mode-line-process))
  858. (compilation-setup)
  859. (run-hooks 'compilation-minor-mode-hook))))
  860. ;; Write msg in the current buffer and hack its mode-line-process.
  861. (defun compilation-handle-exit (process-status exit-status msg)
  862. (let ((buffer-read-only nil)
  863. (status (if compilation-exit-message-function
  864. (funcall compilation-exit-message-function
  865. process-status exit-status msg)
  866. (cons msg exit-status)))
  867. (omax (point-max))
  868. (opoint (point)))
  869. ;; Record where we put the message, so we can ignore it
  870. ;; later on.
  871. (goto-char omax)
  872. (insert ?\n mode-name " " (car status))
  873. (forward-char -1)
  874. (insert " at " (substring (current-time-string) 0 19))
  875. (forward-char 1)
  876. (setq mode-line-process (format ":%s [%s]" process-status (cdr status)))
  877. ;; Force mode line redisplay soon.
  878. (force-mode-line-update)
  879. (if (and opoint (< opoint omax))
  880. (goto-char opoint))
  881. ;; Automatically parse (and mouse-highlight) error messages:
  882. (cond ((eq compile-auto-highlight t)
  883. (compile-reinitialize-errors nil (point-max)))
  884. ((numberp compile-auto-highlight)
  885. (compile-reinitialize-errors nil
  886. (save-excursion
  887. (goto-line compile-auto-highlight)
  888. (point)))))
  889. (if compilation-finish-function
  890. (funcall compilation-finish-function (current-buffer) msg))
  891. (let ((functions compilation-finish-functions))
  892. (while functions
  893. (funcall (car functions) (current-buffer) msg)
  894. (setq functions (cdr functions))))))
  895. ;; Called when compilation process changes state.
  896. (defun compilation-sentinel (proc msg)
  897. "Sentinel for compilation buffers."
  898. (let ((buffer (process-buffer proc)))
  899. (if (memq (process-status proc) '(signal exit))
  900. (progn
  901. (if (null (buffer-name buffer))
  902. ;; buffer killed
  903. (set-process-buffer proc nil)
  904. (let ((obuf (current-buffer)))
  905. ;; save-excursion isn't the right thing if
  906. ;; process-buffer is current-buffer
  907. (unwind-protect
  908. (progn
  909. ;; Write something in the compilation buffer
  910. ;; and hack its mode line.
  911. (set-buffer buffer)
  912. (compilation-handle-exit (process-status proc)
  913. (process-exit-status proc)
  914. msg)
  915. ;; Since the buffer and mode line will show that the
  916. ;; process is dead, we can delete it now. Otherwise it
  917. ;; will stay around until M-x list-processes.
  918. (delete-process proc))
  919. (set-buffer obuf))))
  920. (setq compilation-in-progress (delq proc compilation-in-progress))
  921. ))))
  922. (defun compilation-filter (proc string)
  923. "Process filter for compilation buffers.
  924. Just inserts the text, but uses `insert-before-markers'."
  925. (if (buffer-name (process-buffer proc))
  926. (save-excursion
  927. (set-buffer (process-buffer proc))
  928. (let ((buffer-read-only nil))
  929. (save-excursion
  930. (goto-char (process-mark proc))
  931. (insert-before-markers string)
  932. (run-hooks 'compilation-filter-hook)
  933. (set-marker (process-mark proc) (point)))))))
  934. ;; Return the cdr of compilation-old-error-list for the error containing point.
  935. (defun compile-error-at-point ()
  936. (compile-reinitialize-errors nil (point))
  937. (let ((errors compilation-old-error-list))
  938. (while (and errors
  939. (> (point) (car (car errors))))
  940. (setq errors (cdr errors)))
  941. errors))
  942. (defsubst compilation-buffer-p (buffer)
  943. (save-excursion
  944. (set-buffer buffer)
  945. (or compilation-shell-minor-mode compilation-minor-mode
  946. (eq major-mode 'compilation-mode))))
  947. (defun compilation-next-error (n)
  948. "Move point to the next error in the compilation buffer.
  949. Does NOT find the source line like \\[next-error]."
  950. (interactive "p")
  951. (or (compilation-buffer-p (current-buffer))
  952. (error "Not in a compilation buffer."))
  953. (setq compilation-last-buffer (current-buffer))
  954. (let ((errors (compile-error-at-point)))
  955. ;; Move to the error after the one containing point.
  956. (goto-char (car (if (< n 0)
  957. (let ((i 0)
  958. (e compilation-old-error-list))
  959. ;; See how many cdrs away ERRORS is from the start.
  960. (while (not (eq e errors))
  961. (setq i (1+ i)
  962. e (cdr e)))
  963. (if (> (- n) i)
  964. (error "Moved back past first error")
  965. (nth (+ i n) compilation-old-error-list)))
  966. (let ((compilation-error-list (cdr errors)))
  967. (compile-reinitialize-errors nil nil n)
  968. (if compilation-error-list
  969. (nth (1- n) compilation-error-list)
  970. (error "Moved past last error"))))))))
  971. (defun compilation-previous-error (n)
  972. "Move point to the previous error in the compilation buffer.
  973. Does NOT find the source line like \\[next-error]."
  974. (interactive "p")
  975. (compilation-next-error (- n)))
  976. ;; Given an elt of `compilation-error-list', return an object representing
  977. ;; the referenced file which is equal to (but not necessarily eq to) what
  978. ;; this function would return for another error in the same file.
  979. (defsubst compilation-error-filedata (data)
  980. (setq data (cdr data))
  981. (if (markerp data)
  982. (marker-buffer data)
  983. (car data)))
  984. ;; Return a string describing a value from compilation-error-filedata.
  985. ;; This value is not necessarily useful as a file name, but should be
  986. ;; indicative to the user of what file's errors are being referred to.
  987. (defsubst compilation-error-filedata-file-name (filedata)
  988. (if (bufferp filedata)
  989. (buffer-file-name filedata)
  990. (car filedata)))
  991. (defun compilation-next-file (n)
  992. "Move point to the next error for a different file than the current one."
  993. (interactive "p")
  994. (or (compilation-buffer-p (current-buffer))
  995. (error "Not in a compilation buffer."))
  996. (setq compilation-last-buffer (current-buffer))
  997. (let ((reversed (< n 0))
  998. errors filedata)
  999. (if (not reversed)
  1000. (setq errors (or (compile-error-at-point)
  1001. (error "Moved past last error")))
  1002. ;; Get a reversed list of the errors up through the one containing point.
  1003. (compile-reinitialize-errors nil (point))
  1004. (setq errors (reverse compilation-old-error-list)
  1005. n (- n))
  1006. ;; Ignore errors after point. (car ERRORS) will be the error
  1007. ;; containing point, (cadr ERRORS) the one before it.
  1008. (while (and errors
  1009. (< (point) (car (car errors))))
  1010. (setq errors (cdr errors))))
  1011. (while (> n 0)
  1012. (setq filedata (compilation-error-filedata (car errors)))
  1013. ;; Skip past the following errors for this file.
  1014. (while (equal filedata
  1015. (compilation-error-filedata
  1016. (car (or errors
  1017. (if reversed
  1018. (error "%s the first erring file"
  1019. (compilation-error-filedata-file-name
  1020. filedata))
  1021. (let ((compilation-error-list nil))
  1022. ;; Parse some more.
  1023. (compile-reinitialize-errors nil nil 2)
  1024. (setq errors compilation-error-list)))
  1025. (error "%s is the last erring file"
  1026. (compilation-error-filedata-file-name
  1027. filedata))))))
  1028. (setq errors (cdr errors)))
  1029. (setq n (1- n)))
  1030. ;; Move to the following error.
  1031. (goto-char (car (car (or errors
  1032. (if reversed
  1033. (error "This is the first erring file")
  1034. (let ((compilation-error-list nil))
  1035. ;; Parse the last one.
  1036. (compile-reinitialize-errors nil nil 1)
  1037. compilation-error-list))))))))
  1038. (defun compilation-previous-file (n)
  1039. "Move point to the previous error for a different file than the current one."
  1040. (interactive "p")
  1041. (compilation-next-file (- n)))
  1042. (defun kill-compilation ()
  1043. "Kill the process made by the \\[compile] command."
  1044. (interactive)
  1045. (let ((buffer (compilation-find-buffer)))
  1046. (if (get-buffer-process buffer)
  1047. (interrupt-process (get-buffer-process buffer))
  1048. (error "The compilation process is not running."))))
  1049. ;; Parse any new errors in the compilation buffer,
  1050. ;; or reparse from the beginning if the user has asked for that.
  1051. (defun compile-reinitialize-errors (reparse
  1052. &optional limit-search find-at-least)
  1053. (save-excursion
  1054. (set-buffer compilation-last-buffer)
  1055. ;; If we are out of errors, or if user says "reparse",
  1056. ;; discard the info we have, to force reparsing.
  1057. (if (or (eq compilation-error-list t)
  1058. reparse)
  1059. (compilation-forget-errors))
  1060. (if (and compilation-error-list
  1061. (or (not limit-search)
  1062. (> compilation-parsing-end limit-search))
  1063. (or (not find-at-least)
  1064. (>= (length compilation-error-list) find-at-least)))
  1065. ;; Since compilation-error-list is non-nil, it points to a specific
  1066. ;; error the user wanted. So don't move it around.
  1067. nil
  1068. ;; This was here for a long time (before my rewrite); why? --roland
  1069. ;;(switch-to-buffer compilation-last-buffer)
  1070. (set-buffer-modified-p nil)
  1071. (if (< compilation-parsing-end (point-max))
  1072. ;; compilation-error-list might be non-nil if we have a non-nil
  1073. ;; LIMIT-SEARCH or FIND-AT-LEAST arg. In that case its value
  1074. ;; records the current position in the error list, and we must
  1075. ;; preserve that after reparsing.
  1076. (let ((error-list-pos compilation-error-list))
  1077. (funcall compilation-parse-errors-function
  1078. limit-search
  1079. (and find-at-least
  1080. ;; We only need enough new parsed errors to reach
  1081. ;; FIND-AT-LEAST errors past the current
  1082. ;; position.
  1083. (- find-at-least (length compilation-error-list))))
  1084. ;; Remember the entire list for compilation-forget-errors. If
  1085. ;; this is an incremental parse, append to previous list. If
  1086. ;; we are parsing anew, compilation-forget-errors cleared
  1087. ;; compilation-old-error-list above.
  1088. (setq compilation-old-error-list
  1089. (nconc compilation-old-error-list compilation-error-list))
  1090. (if error-list-pos
  1091. ;; We started in the middle of an existing list of parsed
  1092. ;; errors before parsing more; restore that position.
  1093. (setq compilation-error-list error-list-pos))
  1094. ;; Mouse-Highlight (the first line of) each error message when the
  1095. ;; mouse pointer moves over it:
  1096. (let ((inhibit-read-only t)
  1097. (error-list compilation-error-list))
  1098. (while error-list
  1099. (save-excursion
  1100. (put-text-property (goto-char (car (car error-list)))
  1101. (progn (end-of-line) (point))
  1102. 'mouse-face 'highlight))
  1103. (setq error-list (cdr error-list))))
  1104. )))))
  1105. (defun compile-mouse-goto-error (event)
  1106. (interactive "e")
  1107. (save-excursion
  1108. (set-buffer (window-buffer (posn-window (event-end event))))
  1109. (goto-char (posn-point (event-end event)))
  1110. (or (compilation-buffer-p (current-buf

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