compile.el 122 KB

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