font-lock.el 104 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373
  1. ;;; font-lock.el --- Electric font lock mode
  2. ;; Copyright (C) 1992-2012 Free Software Foundation, Inc.
  3. ;; Author: Jamie Zawinski
  4. ;; Richard Stallman
  5. ;; Stefan Monnier
  6. ;; Maintainer: FSF
  7. ;; Keywords: languages, faces
  8. ;; Package: emacs
  9. ;; This file is part of GNU Emacs.
  10. ;; GNU Emacs is free software: you can redistribute it and/or modify
  11. ;; it under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation, either version 3 of the License, or
  13. ;; (at your option) any later version.
  14. ;; GNU Emacs is distributed in the hope that it will be useful,
  15. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;; GNU General Public License for more details.
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  20. ;;; Commentary:
  21. ;; Font Lock mode is a minor mode that causes your comments to be displayed in
  22. ;; one face, strings in another, reserved words in another, and so on.
  23. ;;
  24. ;; Comments will be displayed in `font-lock-comment-face'.
  25. ;; Strings will be displayed in `font-lock-string-face'.
  26. ;; Regexps are used to display selected patterns in other faces.
  27. ;;
  28. ;; To make the text you type be fontified, use M-x font-lock-mode RET.
  29. ;; When this minor mode is on, the faces of the current line are updated with
  30. ;; every insertion or deletion.
  31. ;;
  32. ;; To turn Font Lock mode on automatically, add this to your ~/.emacs file:
  33. ;;
  34. ;; (add-hook 'emacs-lisp-mode-hook 'turn-on-font-lock)
  35. ;;
  36. ;; Or if you want to turn Font Lock mode on in many modes:
  37. ;;
  38. ;; (global-font-lock-mode t)
  39. ;;
  40. ;; Fontification for a particular mode may be available in a number of levels
  41. ;; of decoration. The higher the level, the more decoration, but the more time
  42. ;; it takes to fontify. See the variable `font-lock-maximum-decoration', and
  43. ;; also the variable `font-lock-maximum-size'. Support modes for Font Lock
  44. ;; mode can be used to speed up Font Lock mode. See `font-lock-support-mode'.
  45. ;;; How Font Lock mode fontifies:
  46. ;; When Font Lock mode is turned on in a buffer, it (a) fontifies the entire
  47. ;; buffer and (b) installs one of its fontification functions on one of the
  48. ;; hook variables that are run by Emacs after every buffer change (i.e., an
  49. ;; insertion or deletion). Fontification means the replacement of `face' text
  50. ;; properties in a given region; Emacs displays text with these `face' text
  51. ;; properties appropriately.
  52. ;;
  53. ;; Fontification normally involves syntactic (i.e., strings and comments) and
  54. ;; regexp (i.e., keywords and everything else) passes. There are actually
  55. ;; three passes; (a) the syntactic keyword pass, (b) the syntactic pass and (c)
  56. ;; the keyword pass. Confused?
  57. ;;
  58. ;; The syntactic keyword pass places `syntax-table' text properties in the
  59. ;; buffer according to the variable `font-lock-syntactic-keywords'. It is
  60. ;; necessary because Emacs's syntax table is not powerful enough to describe all
  61. ;; the different syntactic constructs required by the sort of people who decide
  62. ;; that a single quote can be syntactic or not depending on the time of day.
  63. ;; (What sort of person could decide to overload the meaning of a quote?)
  64. ;; Obviously the syntactic keyword pass must occur before the syntactic pass.
  65. ;;
  66. ;; The syntactic pass places `face' text properties in the buffer according to
  67. ;; syntactic context, i.e., according to the buffer's syntax table and buffer
  68. ;; text's `syntax-table' text properties. It involves using a syntax parsing
  69. ;; function to determine the context of different parts of a region of text. A
  70. ;; syntax parsing function is necessary because generally strings and/or
  71. ;; comments can span lines, and so the context of a given region is not
  72. ;; necessarily apparent from the content of that region. Because the keyword
  73. ;; pass only works within a given region, it is not generally appropriate for
  74. ;; syntactic fontification. This is the first fontification pass that makes
  75. ;; changes visible to the user; it fontifies strings and comments.
  76. ;;
  77. ;; The keyword pass places `face' text properties in the buffer according to
  78. ;; the variable `font-lock-keywords'. It involves searching for given regexps
  79. ;; (or calling given search functions) within the given region. This is the
  80. ;; second fontification pass that makes changes visible to the user; it
  81. ;; fontifies language reserved words, etc.
  82. ;;
  83. ;; Oh, and the answer is, "Yes, obviously just about everything should be done
  84. ;; in a single syntactic pass, but the only syntactic parser available
  85. ;; understands only strings and comments." Perhaps one day someone will write
  86. ;; some syntactic parsers for common languages and a son-of-font-lock.el could
  87. ;; use them rather then relying so heavily on the keyword (regexp) pass.
  88. ;;; How Font Lock mode supports modes or is supported by modes:
  89. ;; Modes that support Font Lock mode do so by defining one or more variables
  90. ;; whose values specify the fontification. Font Lock mode knows of these
  91. ;; variable names from the buffer local variable `font-lock-defaults'.
  92. ;; (Font Lock mode is set up via (a) where a mode's patterns are
  93. ;; distributed with the mode's package library, and (b) where a mode's
  94. ;; patterns are distributed with font-lock.el itself. An example of (a)
  95. ;; is Pascal mode, an example of (b) is Lisp mode. Normally, the mechanism is
  96. ;; (a); (b) is used where it is not clear which package library should contain
  97. ;; the pattern definitions.) Font Lock mode chooses which variable to use for
  98. ;; fontification based on `font-lock-maximum-decoration'.
  99. ;;
  100. ;; Font Lock mode fontification behavior can be modified in a number of ways.
  101. ;; See the below comments and the comments distributed throughout this file.
  102. ;;; Constructing patterns:
  103. ;; See the documentation for the variable `font-lock-keywords'.
  104. ;;
  105. ;; Efficient regexps for use as MATCHERs for `font-lock-keywords' and
  106. ;; `font-lock-syntactic-keywords' can be generated via the function
  107. ;; `regexp-opt'.
  108. ;;; Adding patterns for modes that already support Font Lock:
  109. ;; Though Font Lock highlighting patterns already exist for many modes, it's
  110. ;; likely there's something that you want fontified that currently isn't, even
  111. ;; at the maximum fontification level. You can add highlighting patterns via
  112. ;; `font-lock-add-keywords'. For example, say in some C
  113. ;; header file you #define the token `and' to expand to `&&', etc., to make
  114. ;; your C code almost readable. In your ~/.emacs there could be:
  115. ;;
  116. ;; (font-lock-add-keywords 'c-mode '("\\<\\(and\\|or\\|not\\)\\>"))
  117. ;;
  118. ;; Some modes provide specific ways to modify patterns based on the values of
  119. ;; other variables. For example, additional C types can be specified via the
  120. ;; variable `c-font-lock-extra-types'.
  121. ;;; Adding patterns for modes that do not support Font Lock:
  122. ;; Not all modes support Font Lock mode. If you (as a user of the mode) add
  123. ;; patterns for a new mode, you must define in your ~/.emacs a variable or
  124. ;; variables that specify regexp fontification. Then, you should indicate to
  125. ;; Font Lock mode, via the mode hook setting `font-lock-defaults', exactly what
  126. ;; support is required. For example, say Foo mode should have the following
  127. ;; regexps fontified case-sensitively, and comments and strings should not be
  128. ;; fontified automagically. In your ~/.emacs there could be:
  129. ;;
  130. ;; (defvar foo-font-lock-keywords
  131. ;; '(("\\<\\(one\\|two\\|three\\)\\>" . font-lock-keyword-face)
  132. ;; ("\\<\\(four\\|five\\|six\\)\\>" . font-lock-type-face))
  133. ;; "Default expressions to highlight in Foo mode.")
  134. ;;
  135. ;; (add-hook 'foo-mode-hook
  136. ;; (lambda ()
  137. ;; (set (make-local-variable 'font-lock-defaults)
  138. ;; '(foo-font-lock-keywords t))))
  139. ;;; Adding Font Lock support for modes:
  140. ;; Of course, it would be better that the mode already supports Font Lock mode.
  141. ;; The package author would do something similar to above. The mode must
  142. ;; define at the top-level a variable or variables that specify regexp
  143. ;; fontification. Then, the mode command should indicate to Font Lock mode,
  144. ;; via `font-lock-defaults', exactly what support is required. For example,
  145. ;; say Bar mode should have the following regexps fontified case-insensitively,
  146. ;; and comments and strings should be fontified automagically. In bar.el there
  147. ;; could be:
  148. ;;
  149. ;; (defvar bar-font-lock-keywords
  150. ;; '(("\\<\\(uno\\|due\\|tre\\)\\>" . font-lock-keyword-face)
  151. ;; ("\\<\\(quattro\\|cinque\\|sei\\)\\>" . font-lock-type-face))
  152. ;; "Default expressions to highlight in Bar mode.")
  153. ;;
  154. ;; and within `bar-mode' there could be:
  155. ;;
  156. ;; (set (make-local-variable 'font-lock-defaults)
  157. ;; '(bar-font-lock-keywords nil t))
  158. ;; What is fontification for? You might say, "It's to make my code look nice."
  159. ;; I think it should be for adding information in the form of cues. These cues
  160. ;; should provide you with enough information to both (a) distinguish between
  161. ;; different items, and (b) identify the item meanings, without having to read
  162. ;; the items and think about it. Therefore, fontification allows you to think
  163. ;; less about, say, the structure of code, and more about, say, why the code
  164. ;; doesn't work. Or maybe it allows you to think less and drift off to sleep.
  165. ;;
  166. ;; So, here are my opinions/advice/guidelines:
  167. ;;
  168. ;; - Highlight conceptual objects, such as function and variable names, and
  169. ;; different objects types differently, i.e., (a) and (b) above, highlight
  170. ;; function names differently to variable names.
  171. ;; - Keep the faces distinct from each other as far as possible.
  172. ;; i.e., (a) above.
  173. ;; - Use the same face for the same conceptual object, across all modes.
  174. ;; i.e., (b) above, all modes that have items that can be thought of as, say,
  175. ;; keywords, should be highlighted with the same face, etc.
  176. ;; - Make the face attributes fit the concept as far as possible.
  177. ;; i.e., function names might be a bold color such as blue, comments might
  178. ;; be a bright color such as red, character strings might be brown, because,
  179. ;; err, strings are brown (that was not the reason, please believe me).
  180. ;; - Don't use a non-nil OVERRIDE unless you have a good reason.
  181. ;; Only use OVERRIDE for special things that are easy to define, such as the
  182. ;; way `...' quotes are treated in strings and comments in Emacs Lisp mode.
  183. ;; Don't use it to, say, highlight keywords in commented out code or strings.
  184. ;; - Err, that's it.
  185. ;;; Code:
  186. (require 'syntax)
  187. (eval-when-compile (require 'cl))
  188. ;; Define core `font-lock' group.
  189. (defgroup font-lock '((jit-lock custom-group))
  190. "Font Lock mode text highlighting package."
  191. :link '(custom-manual :tag "Emacs Manual" "(emacs)Font Lock")
  192. :link '(custom-manual :tag "Elisp Manual" "(elisp)Font Lock Mode")
  193. :group 'faces)
  194. (defgroup font-lock-faces nil
  195. "Faces for highlighting text."
  196. :prefix "font-lock-"
  197. :group 'font-lock)
  198. (defgroup font-lock-extra-types nil
  199. "Extra mode-specific type names for highlighting declarations."
  200. :group 'font-lock)
  201. ;; User variables.
  202. (defcustom font-lock-maximum-size 256000
  203. "Maximum buffer size for unsupported buffer fontification.
  204. When `font-lock-support-mode' is nil, only buffers smaller than
  205. this are fontified. This variable has no effect if a Font Lock
  206. support mode (usually `jit-lock-mode') is enabled.
  207. If nil, means size is irrelevant.
  208. If a list, each element should be a cons pair of the form (MAJOR-MODE . SIZE),
  209. where MAJOR-MODE is a symbol or t (meaning the default). For example:
  210. ((c-mode . 256000) (c++-mode . 256000) (rmail-mode . 1048576))
  211. means that the maximum size is 250K for buffers in C or C++ modes, one megabyte
  212. for buffers in Rmail mode, and size is irrelevant otherwise."
  213. :type '(choice (const :tag "none" nil)
  214. (integer :tag "size")
  215. (repeat :menu-tag "mode specific" :tag "mode specific"
  216. :value ((t . nil))
  217. (cons :tag "Instance"
  218. (radio :tag "Mode"
  219. (const :tag "all" t)
  220. (symbol :tag "name"))
  221. (radio :tag "Size"
  222. (const :tag "none" nil)
  223. (integer :tag "size")))))
  224. :group 'font-lock)
  225. (make-obsolete-variable 'font-lock-maximum-size nil "24.1")
  226. (defcustom font-lock-maximum-decoration t
  227. "Maximum decoration level for fontification.
  228. If nil, use the default decoration (typically the minimum available).
  229. If t, use the maximum decoration available.
  230. If a number, use that level of decoration (or if not available the maximum).
  231. The higher the number, the more decoration is done.
  232. If a list, each element should be a cons pair of the form (MAJOR-MODE . LEVEL),
  233. where MAJOR-MODE is a symbol or t (meaning the default). For example:
  234. ((c-mode . t) (c++-mode . 2) (t . 1))
  235. means use the maximum decoration available for buffers in C mode, level 2
  236. decoration for buffers in C++ mode, and level 1 decoration otherwise."
  237. :type '(choice (const :tag "default" nil)
  238. (const :tag "maximum" t)
  239. (integer :tag "level" 1)
  240. (repeat :menu-tag "mode specific" :tag "mode specific"
  241. :value ((t . t))
  242. (cons :tag "Instance"
  243. (radio :tag "Mode"
  244. (const :tag "all" t)
  245. (symbol :tag "name"))
  246. (radio :tag "Decoration"
  247. (const :tag "default" nil)
  248. (const :tag "maximum" t)
  249. (integer :tag "level" 1)))))
  250. :group 'font-lock)
  251. (defcustom font-lock-verbose nil
  252. "If non-nil, means show status messages for buffer fontification.
  253. If a number, only buffers greater than this size have fontification messages."
  254. :type '(choice (const :tag "never" nil)
  255. (other :tag "always" t)
  256. (integer :tag "size"))
  257. :group 'font-lock
  258. :version "24.1")
  259. ;; Originally these variable values were face names such as `bold' etc.
  260. ;; Now we create our own faces, but we keep these variables for compatibility
  261. ;; and they give users another mechanism for changing face appearance.
  262. ;; We now allow a FACENAME in `font-lock-keywords' to be any expression that
  263. ;; returns a face. So the easiest thing is to continue using these variables,
  264. ;; rather than sometimes evalling FACENAME and sometimes not. sm.
  265. ;; Note that in new code, in the vast majority of cases there is no
  266. ;; need to create variables that specify face names. Simply using
  267. ;; faces directly is enough. Font-lock is not a template to be
  268. ;; followed in this area.
  269. (defvar font-lock-comment-face 'font-lock-comment-face
  270. "Face name to use for comments.")
  271. (defvar font-lock-comment-delimiter-face 'font-lock-comment-delimiter-face
  272. "Face name to use for comment delimiters.")
  273. (defvar font-lock-string-face 'font-lock-string-face
  274. "Face name to use for strings.")
  275. (defvar font-lock-doc-face 'font-lock-doc-face
  276. "Face name to use for documentation.")
  277. (defvar font-lock-keyword-face 'font-lock-keyword-face
  278. "Face name to use for keywords.")
  279. (defvar font-lock-builtin-face 'font-lock-builtin-face
  280. "Face name to use for builtins.")
  281. (defvar font-lock-function-name-face 'font-lock-function-name-face
  282. "Face name to use for function names.")
  283. (defvar font-lock-variable-name-face 'font-lock-variable-name-face
  284. "Face name to use for variable names.")
  285. (defvar font-lock-type-face 'font-lock-type-face
  286. "Face name to use for type and class names.")
  287. (defvar font-lock-constant-face 'font-lock-constant-face
  288. "Face name to use for constant and label names.")
  289. (defvar font-lock-warning-face 'font-lock-warning-face
  290. "Face name to use for things that should stand out.")
  291. (defvar font-lock-negation-char-face 'font-lock-negation-char-face
  292. "Face name to use for easy to overlook negation.
  293. This can be an \"!\" or the \"n\" in \"ifndef\".")
  294. (defvar font-lock-preprocessor-face 'font-lock-preprocessor-face
  295. "Face name to use for preprocessor directives.")
  296. (defvar font-lock-reference-face 'font-lock-constant-face)
  297. (make-obsolete-variable 'font-lock-reference-face 'font-lock-constant-face "20.3")
  298. ;; Fontification variables:
  299. (defvar font-lock-keywords nil
  300. "A list of the keywords to highlight.
  301. There are two kinds of values: user-level, and compiled.
  302. A user-level keywords list is what a major mode or the user would
  303. set up. Normally the list would come from `font-lock-defaults'.
  304. through selection of a fontification level and evaluation of any
  305. contained expressions. You can also alter it by calling
  306. `font-lock-add-keywords' or `font-lock-remove-keywords' with MODE = nil.
  307. Each element in a user-level keywords list should have one of these forms:
  308. MATCHER
  309. (MATCHER . SUBEXP)
  310. (MATCHER . FACENAME)
  311. (MATCHER . HIGHLIGHT)
  312. (MATCHER HIGHLIGHT ...)
  313. (eval . FORM)
  314. where MATCHER can be either the regexp to search for, or the function name to
  315. call to make the search (called with one argument, the limit of the search;
  316. it should return non-nil, move point, and set `match-data' appropriately if
  317. it succeeds; like `re-search-forward' would).
  318. MATCHER regexps can be generated via the function `regexp-opt'.
  319. FORM is an expression, whose value should be a keyword element, evaluated when
  320. the keyword is (first) used in a buffer. This feature can be used to provide a
  321. keyword that can only be generated when Font Lock mode is actually turned on.
  322. HIGHLIGHT should be either MATCH-HIGHLIGHT or MATCH-ANCHORED.
  323. For highlighting single items, for example each instance of the word \"foo\",
  324. typically only MATCH-HIGHLIGHT is required.
  325. However, if an item or (typically) items are to be highlighted following the
  326. instance of another item (the anchor), for example each instance of the
  327. word \"bar\" following the word \"anchor\" then MATCH-ANCHORED may be required.
  328. MATCH-HIGHLIGHT should be of the form:
  329. (SUBEXP FACENAME [OVERRIDE [LAXMATCH]])
  330. SUBEXP is the number of the subexpression of MATCHER to be highlighted.
  331. FACENAME is an expression whose value is the face name to use.
  332. Instead of a face, FACENAME can evaluate to a property list
  333. of the form (face FACE PROP1 VAL1 PROP2 VAL2 ...)
  334. in which case all the listed text-properties will be set rather than
  335. just FACE. In such a case, you will most likely want to put those
  336. properties in `font-lock-extra-managed-props' or to override
  337. `font-lock-unfontify-region-function'.
  338. OVERRIDE and LAXMATCH are flags. If OVERRIDE is t, existing fontification can
  339. be overwritten. If `keep', only parts not already fontified are highlighted.
  340. If `prepend' or `append', existing fontification is merged with the new, in
  341. which the new or existing fontification, respectively, takes precedence.
  342. If LAXMATCH is non-nil, that means don't signal an error if there is
  343. no match for SUBEXP in MATCHER.
  344. For example, an element of the form highlights (if not already highlighted):
  345. \"\\\\\\=<foo\\\\\\=>\" discrete occurrences of \"foo\" in the value of the
  346. variable `font-lock-keyword-face'.
  347. (\"fu\\\\(bar\\\\)\" . 1) substring \"bar\" within all occurrences of \"fubar\" in
  348. the value of `font-lock-keyword-face'.
  349. (\"fubar\" . fubar-face) Occurrences of \"fubar\" in the value of `fubar-face'.
  350. (\"foo\\\\|bar\" 0 foo-bar-face t)
  351. occurrences of either \"foo\" or \"bar\" in the value
  352. of `foo-bar-face', even if already highlighted.
  353. (fubar-match 1 fubar-face)
  354. the first subexpression within all occurrences of
  355. whatever the function `fubar-match' finds and matches
  356. in the value of `fubar-face'.
  357. MATCH-ANCHORED should be of the form:
  358. (MATCHER PRE-MATCH-FORM POST-MATCH-FORM MATCH-HIGHLIGHT ...)
  359. where MATCHER is a regexp to search for or the function name to call to make
  360. the search, as for MATCH-HIGHLIGHT above, but with one exception; see below.
  361. PRE-MATCH-FORM and POST-MATCH-FORM are evaluated before the first, and after
  362. the last, instance MATCH-ANCHORED's MATCHER is used. Therefore they can be
  363. used to initialize before, and cleanup after, MATCHER is used. Typically,
  364. PRE-MATCH-FORM is used to move to some position relative to the original
  365. MATCHER, before starting with MATCH-ANCHORED's MATCHER. POST-MATCH-FORM might
  366. be used to move back, before resuming with MATCH-ANCHORED's parent's MATCHER.
  367. For example, an element of the form highlights (if not already highlighted):
  368. (\"\\\\\\=<anchor\\\\\\=>\" (0 anchor-face) (\"\\\\\\=<item\\\\\\=>\" nil nil (0 item-face)))
  369. discrete occurrences of \"anchor\" in the value of `anchor-face', and subsequent
  370. discrete occurrences of \"item\" (on the same line) in the value of `item-face'.
  371. (Here PRE-MATCH-FORM and POST-MATCH-FORM are nil. Therefore \"item\" is
  372. initially searched for starting from the end of the match of \"anchor\", and
  373. searching for subsequent instances of \"anchor\" resumes from where searching
  374. for \"item\" concluded.)
  375. The above-mentioned exception is as follows. The limit of the MATCHER search
  376. defaults to the end of the line after PRE-MATCH-FORM is evaluated.
  377. However, if PRE-MATCH-FORM returns a position greater than the position after
  378. PRE-MATCH-FORM is evaluated, that position is used as the limit of the search.
  379. It is generally a bad idea to return a position greater than the end of the
  380. line, i.e., cause the MATCHER search to span lines.
  381. These regular expressions can match text which spans lines, although
  382. it is better to avoid it if possible since updating them while editing
  383. text is slower, and it is not guaranteed to be always correct when using
  384. support modes like jit-lock or lazy-lock.
  385. This variable is set by major modes via the variable `font-lock-defaults'.
  386. Be careful when composing regexps for this list; a poorly written pattern can
  387. dramatically slow things down!
  388. A compiled keywords list starts with t. It is produced internal
  389. by `font-lock-compile-keywords' from a user-level keywords list.
  390. Its second element is the user-level keywords list that was
  391. compiled. The remaining elements have the same form as
  392. user-level keywords, but normally their values have been
  393. optimized.")
  394. (defvar font-lock-keywords-alist nil
  395. "Alist of additional `font-lock-keywords' elements for major modes.
  396. Each element has the form (MODE KEYWORDS . HOW).
  397. `font-lock-set-defaults' adds the elements in the list KEYWORDS to
  398. `font-lock-keywords' when Font Lock is turned on in major mode MODE.
  399. If HOW is nil, KEYWORDS are added at the beginning of
  400. `font-lock-keywords'. If it is `set', they are used to replace the
  401. value of `font-lock-keywords'. If HOW is any other non-nil value,
  402. they are added at the end.
  403. This is normally set via `font-lock-add-keywords' and
  404. `font-lock-remove-keywords'.")
  405. (put 'font-lock-keywords-alist 'risky-local-variable t)
  406. (defvar font-lock-removed-keywords-alist nil
  407. "Alist of `font-lock-keywords' elements to be removed for major modes.
  408. Each element has the form (MODE . KEYWORDS). `font-lock-set-defaults'
  409. removes the elements in the list KEYWORDS from `font-lock-keywords'
  410. when Font Lock is turned on in major mode MODE.
  411. This is normally set via `font-lock-add-keywords' and
  412. `font-lock-remove-keywords'.")
  413. (defvar font-lock-keywords-only nil
  414. "*Non-nil means Font Lock should not fontify comments or strings.
  415. This is normally set via `font-lock-defaults'.")
  416. (defvar font-lock-keywords-case-fold-search nil
  417. "*Non-nil means the patterns in `font-lock-keywords' are case-insensitive.
  418. This is set via the function `font-lock-set-defaults', based on
  419. the CASE-FOLD argument of `font-lock-defaults'.")
  420. (make-variable-buffer-local 'font-lock-keywords-case-fold-search)
  421. (defvar font-lock-syntactically-fontified 0
  422. "Point up to which `font-lock-syntactic-keywords' has been applied.
  423. If nil, this is ignored, in which case the syntactic fontification may
  424. sometimes be slightly incorrect.")
  425. (make-variable-buffer-local 'font-lock-syntactically-fontified)
  426. (defvar font-lock-syntactic-face-function
  427. (lambda (state)
  428. (if (nth 3 state) font-lock-string-face font-lock-comment-face))
  429. "Function to determine which face to use when fontifying syntactically.
  430. The function is called with a single parameter (the state as returned by
  431. `parse-partial-sexp' at the beginning of the region to highlight) and
  432. should return a face. This is normally set via `font-lock-defaults'.")
  433. (defvar font-lock-syntactic-keywords nil
  434. "A list of the syntactic keywords to put syntax properties on.
  435. The value can be the list itself, or the name of a function or variable
  436. whose value is the list.
  437. See `font-lock-keywords' for a description of the form of this list;
  438. only the differences are stated here. MATCH-HIGHLIGHT should be of the form:
  439. (SUBEXP SYNTAX OVERRIDE LAXMATCH)
  440. where SYNTAX can be a string (as taken by `modify-syntax-entry'), a syntax
  441. table, a cons cell (as returned by `string-to-syntax') or an expression whose
  442. value is such a form. OVERRIDE cannot be `prepend' or `append'.
  443. Here are two examples of elements of `font-lock-syntactic-keywords'
  444. and what they do:
  445. (\"\\\\$\\\\(#\\\\)\" 1 \".\")
  446. gives a hash character punctuation syntax (\".\") when following a
  447. dollar-sign character. Hash characters in other contexts will still
  448. follow whatever the syntax table says about the hash character.
  449. (\"\\\\('\\\\).\\\\('\\\\)\"
  450. (1 \"\\\"\")
  451. (2 \"\\\"\"))
  452. gives a pair single-quotes, which surround a single character, a SYNTAX of
  453. \"\\\"\" (meaning string quote syntax). Single-quote characters in other
  454. contexts will not be affected.
  455. This is normally set via `font-lock-defaults'.")
  456. (make-obsolete-variable 'font-lock-syntactic-keywords
  457. 'syntax-propertize-function "24.1")
  458. (defvar font-lock-syntax-table nil
  459. "Non-nil means use this syntax table for fontifying.
  460. If this is nil, the major mode's syntax table is used.
  461. This is normally set via `font-lock-defaults'.")
  462. (defvar font-lock-beginning-of-syntax-function nil
  463. "*Non-nil means use this function to move back outside all constructs.
  464. When called with no args it should move point backward to a place which
  465. is not in a string or comment and not within any bracket-pairs (or else,
  466. a place such that any bracket-pairs outside it can be ignored for Emacs
  467. syntax analysis and fontification).
  468. If this is nil, Font Lock uses `syntax-begin-function' to move back
  469. outside of any comment, string, or sexp. This variable is semi-obsolete;
  470. we recommend setting `syntax-begin-function' instead.
  471. This is normally set via `font-lock-defaults'.")
  472. (make-obsolete-variable 'font-lock-beginning-of-syntax-function
  473. 'syntax-begin-function "23.3" 'set)
  474. (defvar font-lock-mark-block-function nil
  475. "*Non-nil means use this function to mark a block of text.
  476. When called with no args it should leave point at the beginning of any
  477. enclosing textual block and mark at the end.
  478. This is normally set via `font-lock-defaults'.")
  479. (defvar font-lock-fontify-buffer-function 'font-lock-default-fontify-buffer
  480. "Function to use for fontifying the buffer.
  481. This is normally set via `font-lock-defaults'.")
  482. (defvar font-lock-unfontify-buffer-function 'font-lock-default-unfontify-buffer
  483. "Function to use for unfontifying the buffer.
  484. This is used when turning off Font Lock mode.
  485. This is normally set via `font-lock-defaults'.")
  486. (defvar font-lock-fontify-region-function 'font-lock-default-fontify-region
  487. "Function to use for fontifying a region.
  488. It should take two args, the beginning and end of the region, and an optional
  489. third arg VERBOSE. If VERBOSE is non-nil, the function should print status
  490. messages. This is normally set via `font-lock-defaults'.")
  491. (defvar font-lock-unfontify-region-function 'font-lock-default-unfontify-region
  492. "Function to use for unfontifying a region.
  493. It should take two args, the beginning and end of the region.
  494. This is normally set via `font-lock-defaults'.")
  495. (defvar font-lock-inhibit-thing-lock nil
  496. "List of Font Lock mode related modes that should not be turned on.
  497. Currently, valid mode names are `fast-lock-mode', `jit-lock-mode' and
  498. `lazy-lock-mode'. This is normally set via `font-lock-defaults'.")
  499. (defvar font-lock-multiline nil
  500. "Whether font-lock should cater to multiline keywords.
  501. If nil, don't try to handle multiline patterns.
  502. If t, always handle multiline patterns.
  503. If `undecided', don't try to handle multiline patterns until you see one.
  504. Major/minor modes can set this variable if they know which option applies.")
  505. (defvar font-lock-fontified nil) ; Whether we have fontified the buffer.
  506. ;; Font Lock mode.
  507. (eval-when-compile
  508. ;;
  509. ;; We don't do this at the top-level as we only use non-autoloaded macros.
  510. (require 'cl)
  511. ;;
  512. ;; Borrowed from lazy-lock.el.
  513. ;; We use this to preserve or protect things when modifying text properties.
  514. (defmacro save-buffer-state (&rest body)
  515. "Bind variables according to VARLIST and eval BODY restoring buffer state."
  516. (declare (indent 0) (debug t))
  517. `(let ((inhibit-point-motion-hooks t))
  518. (with-silent-modifications
  519. ,@body)))
  520. ;;
  521. ;; Shut up the byte compiler.
  522. (defvar font-lock-face-attributes)) ; Obsolete but respected if set.
  523. (defun font-lock-specified-p (mode)
  524. "Return non-nil if the current buffer is ready for fontification.
  525. The MODE argument, if non-nil, means Font Lock mode is about to
  526. be enabled."
  527. (or font-lock-defaults
  528. (and (boundp 'font-lock-keywords)
  529. font-lock-keywords)
  530. (and mode
  531. (boundp 'font-lock-set-defaults)
  532. font-lock-set-defaults
  533. font-lock-major-mode
  534. (not (eq font-lock-major-mode major-mode)))))
  535. (defun font-lock-initial-fontify ()
  536. ;; The first fontification after turning the mode on. This must
  537. ;; only be called after the mode hooks have been run.
  538. (when (and font-lock-mode
  539. (font-lock-specified-p t))
  540. (let ((max-size (font-lock-value-in-major-mode font-lock-maximum-size)))
  541. (cond (font-lock-fontified
  542. nil)
  543. ((or (null max-size) (> max-size (buffer-size)))
  544. (font-lock-fontify-buffer))
  545. (font-lock-verbose
  546. (message "Fontifying %s...buffer size greater than font-lock-maximum-size"
  547. (buffer-name)))))))
  548. (defun font-lock-mode-internal (arg)
  549. ;; Turn on Font Lock mode.
  550. (when arg
  551. (add-hook 'after-change-functions 'font-lock-after-change-function t t)
  552. (font-lock-set-defaults)
  553. (font-lock-turn-on-thing-lock))
  554. ;; Turn off Font Lock mode.
  555. (unless font-lock-mode
  556. (remove-hook 'after-change-functions 'font-lock-after-change-function t)
  557. (font-lock-unfontify-buffer)
  558. (font-lock-turn-off-thing-lock)))
  559. (defun font-lock-add-keywords (mode keywords &optional how)
  560. "Add highlighting KEYWORDS for MODE.
  561. MODE should be a symbol, the major mode command name, such as `c-mode'
  562. or nil. If nil, highlighting keywords are added for the current buffer.
  563. KEYWORDS should be a list; see the variable `font-lock-keywords'.
  564. By default they are added at the beginning of the current highlighting list.
  565. If optional argument HOW is `set', they are used to replace the current
  566. highlighting list. If HOW is any other non-nil value, they are added at the
  567. end of the current highlighting list.
  568. For example:
  569. (font-lock-add-keywords 'c-mode
  570. '((\"\\\\\\=<\\\\(FIXME\\\\):\" 1 font-lock-warning-face prepend)
  571. (\"\\\\\\=<\\\\(and\\\\|or\\\\|not\\\\)\\\\\\=>\" . font-lock-keyword-face)))
  572. adds two fontification patterns for C mode, to fontify `FIXME:' words, even in
  573. comments, and to fontify `and', `or' and `not' words as keywords.
  574. The above procedure will only add the keywords for C mode, not
  575. for modes derived from C mode. To add them for derived modes too,
  576. pass nil for MODE and add the call to c-mode-hook.
  577. For example:
  578. (add-hook 'c-mode-hook
  579. (lambda ()
  580. (font-lock-add-keywords nil
  581. '((\"\\\\\\=<\\\\(FIXME\\\\):\" 1 font-lock-warning-face prepend)
  582. (\"\\\\\\=<\\\\(and\\\\|or\\\\|not\\\\)\\\\\\=>\" .
  583. font-lock-keyword-face)))))
  584. The above procedure may fail to add keywords to derived modes if
  585. some involved major mode does not follow the standard conventions.
  586. File a bug report if this happens, so the major mode can be corrected.
  587. Note that some modes have specialized support for additional patterns, e.g.,
  588. see the variables `c-font-lock-extra-types', `c++-font-lock-extra-types',
  589. `objc-font-lock-extra-types' and `java-font-lock-extra-types'."
  590. (cond (mode
  591. ;; If MODE is non-nil, add the KEYWORDS and HOW spec to
  592. ;; `font-lock-keywords-alist' so `font-lock-set-defaults' uses them.
  593. (let ((spec (cons keywords how)) cell)
  594. (if (setq cell (assq mode font-lock-keywords-alist))
  595. (if (eq how 'set)
  596. (setcdr cell (list spec))
  597. (setcdr cell (append (cdr cell) (list spec))))
  598. (push (list mode spec) font-lock-keywords-alist)))
  599. ;; Make sure that `font-lock-removed-keywords-alist' does not
  600. ;; contain the new keywords.
  601. (font-lock-update-removed-keyword-alist mode keywords how))
  602. (t
  603. (when (and font-lock-mode
  604. (not (or font-lock-keywords font-lock-defaults)))
  605. ;; The major mode has not set any keywords, so when we enabled
  606. ;; font-lock-mode it only enabled the font-core.el part, not the
  607. ;; font-lock-mode-internal. Try again.
  608. (font-lock-mode -1)
  609. (set (make-local-variable 'font-lock-defaults) '(nil t))
  610. (font-lock-mode 1))
  611. ;; Otherwise set or add the keywords now.
  612. ;; This is a no-op if it has been done already in this buffer
  613. ;; for the correct major mode.
  614. (font-lock-set-defaults)
  615. (let ((was-compiled (eq (car font-lock-keywords) t)))
  616. ;; Bring back the user-level (uncompiled) keywords.
  617. (if was-compiled
  618. (setq font-lock-keywords (cadr font-lock-keywords)))
  619. ;; Now modify or replace them.
  620. (if (eq how 'set)
  621. (setq font-lock-keywords keywords)
  622. (font-lock-remove-keywords nil keywords) ;to avoid duplicates
  623. (let ((old (if (eq (car-safe font-lock-keywords) t)
  624. (cdr font-lock-keywords)
  625. font-lock-keywords)))
  626. (setq font-lock-keywords (if how
  627. (append old keywords)
  628. (append keywords old)))))
  629. ;; If the keywords were compiled before, compile them again.
  630. (if was-compiled
  631. (setq font-lock-keywords
  632. (font-lock-compile-keywords font-lock-keywords)))))))
  633. (defun font-lock-update-removed-keyword-alist (mode keywords how)
  634. "Update `font-lock-removed-keywords-alist' when adding new KEYWORDS to MODE."
  635. ;; When font-lock is enabled first all keywords in the list
  636. ;; `font-lock-keywords-alist' are added, then all keywords in the
  637. ;; list `font-lock-removed-keywords-alist' are removed. If a
  638. ;; keyword was once added, removed, and then added again it must be
  639. ;; removed from the removed-keywords list. Otherwise the second add
  640. ;; will not take effect.
  641. (let ((cell (assq mode font-lock-removed-keywords-alist)))
  642. (if cell
  643. (if (eq how 'set)
  644. ;; A new set of keywords is defined. Forget all about
  645. ;; our old keywords that should be removed.
  646. (setq font-lock-removed-keywords-alist
  647. (delq cell font-lock-removed-keywords-alist))
  648. ;; Delete all previously removed keywords.
  649. (dolist (kword keywords)
  650. (setcdr cell (delete kword (cdr cell))))
  651. ;; Delete the mode cell if empty.
  652. (if (null (cdr cell))
  653. (setq font-lock-removed-keywords-alist
  654. (delq cell font-lock-removed-keywords-alist)))))))
  655. ;; Written by Anders Lindgren <andersl@andersl.com>.
  656. ;;
  657. ;; Case study:
  658. ;; (I) The keywords are removed from a major mode.
  659. ;; In this case the keyword could be local (i.e. added earlier by
  660. ;; `font-lock-add-keywords'), global, or both.
  661. ;;
  662. ;; (a) In the local case we remove the keywords from the variable
  663. ;; `font-lock-keywords-alist'.
  664. ;;
  665. ;; (b) The actual global keywords are not known at this time.
  666. ;; All keywords are added to `font-lock-removed-keywords-alist',
  667. ;; when font-lock is enabled those keywords are removed.
  668. ;;
  669. ;; Note that added keywords are taken out of the list of removed
  670. ;; keywords. This ensure correct operation when the same keyword
  671. ;; is added and removed several times.
  672. ;;
  673. ;; (II) The keywords are removed from the current buffer.
  674. (defun font-lock-remove-keywords (mode keywords)
  675. "Remove highlighting KEYWORDS for MODE.
  676. MODE should be a symbol, the major mode command name, such as `c-mode'
  677. or nil. If nil, highlighting keywords are removed for the current buffer.
  678. To make the removal apply to modes derived from MODE as well,
  679. pass nil for MODE and add the call to MODE-hook. This may fail
  680. for some derived modes if some involved major mode does not
  681. follow the standard conventions. File a bug report if this
  682. happens, so the major mode can be corrected."
  683. (cond (mode
  684. ;; Remove one keyword at the time.
  685. (dolist (keyword keywords)
  686. (let ((top-cell (assq mode font-lock-keywords-alist)))
  687. ;; If MODE is non-nil, remove the KEYWORD from
  688. ;; `font-lock-keywords-alist'.
  689. (when top-cell
  690. (dolist (keyword-list-how-pair (cdr top-cell))
  691. ;; `keywords-list-how-pair' is a cons with a list of
  692. ;; keywords in the car top-cell and the original how
  693. ;; argument in the cdr top-cell.
  694. (setcar keyword-list-how-pair
  695. (delete keyword (car keyword-list-how-pair))))
  696. ;; Remove keyword list/how pair when the keyword list
  697. ;; is empty and how doesn't specify `set'. (If it
  698. ;; should be deleted then previously deleted keywords
  699. ;; would appear again.)
  700. (let ((cell top-cell))
  701. (while (cdr cell)
  702. (if (and (null (car (car (cdr cell))))
  703. (not (eq (cdr (car (cdr cell))) 'set)))
  704. (setcdr cell (cdr (cdr cell)))
  705. (setq cell (cdr cell)))))
  706. ;; Final cleanup, remove major mode cell if last keyword
  707. ;; was deleted.
  708. (if (null (cdr top-cell))
  709. (setq font-lock-keywords-alist
  710. (delq top-cell font-lock-keywords-alist))))
  711. ;; Remember the keyword in case it is not local.
  712. (let ((cell (assq mode font-lock-removed-keywords-alist)))
  713. (if cell
  714. (unless (member keyword (cdr cell))
  715. (nconc cell (list keyword)))
  716. (push (cons mode (list keyword))
  717. font-lock-removed-keywords-alist))))))
  718. (t
  719. ;; Otherwise remove it immediately.
  720. (font-lock-set-defaults)
  721. (let ((was-compiled (eq (car font-lock-keywords) t)))
  722. ;; Bring back the user-level (uncompiled) keywords.
  723. (if was-compiled
  724. (setq font-lock-keywords (cadr font-lock-keywords)))
  725. ;; Edit them.
  726. (setq font-lock-keywords (copy-sequence font-lock-keywords))
  727. (dolist (keyword keywords)
  728. (setq font-lock-keywords
  729. (delete keyword font-lock-keywords)))
  730. ;; If the keywords were compiled before, compile them again.
  731. (if was-compiled
  732. (setq font-lock-keywords
  733. (font-lock-compile-keywords font-lock-keywords)))))))
  734. ;;; Font Lock Support mode.
  735. ;; This is the code used to interface font-lock.el with any of its add-on
  736. ;; packages, and provide the user interface. Packages that have their own
  737. ;; local buffer fontification functions (see below) may have to call
  738. ;; `font-lock-after-fontify-buffer' and/or `font-lock-after-unfontify-buffer'
  739. ;; themselves.
  740. (defcustom font-lock-support-mode 'jit-lock-mode
  741. "Support mode for Font Lock mode.
  742. Support modes speed up Font Lock mode by being choosy about when fontification
  743. occurs. The default support mode, Just-in-time Lock mode (symbol
  744. `jit-lock-mode'), is recommended.
  745. Other, older support modes are Fast Lock mode (symbol `fast-lock-mode') and
  746. Lazy Lock mode (symbol `lazy-lock-mode'). See those modes for more info.
  747. However, they are no longer recommended, as Just-in-time Lock mode is better.
  748. If nil, means support for Font Lock mode is never performed.
  749. If a symbol, use that support mode.
  750. If a list, each element should be of the form (MAJOR-MODE . SUPPORT-MODE),
  751. where MAJOR-MODE is a symbol or t (meaning the default). For example:
  752. ((c-mode . fast-lock-mode) (c++-mode . fast-lock-mode) (t . lazy-lock-mode))
  753. means that Fast Lock mode is used to support Font Lock mode for buffers in C or
  754. C++ modes, and Lazy Lock mode is used to support Font Lock mode otherwise.
  755. The value of this variable is used when Font Lock mode is turned on."
  756. :type '(choice (const :tag "none" nil)
  757. (const :tag "fast lock" fast-lock-mode)
  758. (const :tag "lazy lock" lazy-lock-mode)
  759. (const :tag "jit lock" jit-lock-mode)
  760. (repeat :menu-tag "mode specific" :tag "mode specific"
  761. :value ((t . jit-lock-mode))
  762. (cons :tag "Instance"
  763. (radio :tag "Mode"
  764. (const :tag "all" t)
  765. (symbol :tag "name"))
  766. (radio :tag "Support"
  767. (const :tag "none" nil)
  768. (const :tag "fast lock" fast-lock-mode)
  769. (const :tag "lazy lock" lazy-lock-mode)
  770. (const :tag "JIT lock" jit-lock-mode)))
  771. ))
  772. :version "21.1"
  773. :group 'font-lock)
  774. (defvar fast-lock-mode)
  775. (defvar lazy-lock-mode)
  776. (defvar jit-lock-mode)
  777. (declare-function fast-lock-after-fontify-buffer "fast-lock")
  778. (declare-function fast-lock-after-unfontify-buffer "fast-lock")
  779. (declare-function fast-lock-mode "fast-lock")
  780. (declare-function lazy-lock-after-fontify-buffer "lazy-lock")
  781. (declare-function lazy-lock-after-unfontify-buffer "lazy-lock")
  782. (declare-function lazy-lock-mode "lazy-lock")
  783. (defun font-lock-turn-on-thing-lock ()
  784. (case (font-lock-value-in-major-mode font-lock-support-mode)
  785. (fast-lock-mode (fast-lock-mode t))
  786. (lazy-lock-mode (lazy-lock-mode t))
  787. (jit-lock-mode
  788. ;; Prepare for jit-lock
  789. (remove-hook 'after-change-functions
  790. 'font-lock-after-change-function t)
  791. (set (make-local-variable 'font-lock-fontify-buffer-function)
  792. 'jit-lock-refontify)
  793. ;; Don't fontify eagerly (and don't abort if the buffer is large).
  794. (set (make-local-variable 'font-lock-fontified) t)
  795. ;; Use jit-lock.
  796. (jit-lock-register 'font-lock-fontify-region
  797. (not font-lock-keywords-only))
  798. ;; Tell jit-lock how we extend the region to refontify.
  799. (add-hook 'jit-lock-after-change-extend-region-functions
  800. 'font-lock-extend-jit-lock-region-after-change
  801. nil t))))
  802. (defun font-lock-turn-off-thing-lock ()
  803. (cond ((bound-and-true-p fast-lock-mode)
  804. (fast-lock-mode -1))
  805. ((bound-and-true-p jit-lock-mode)
  806. (jit-lock-unregister 'font-lock-fontify-region)
  807. ;; Reset local vars to the non-jit-lock case.
  808. (kill-local-variable 'font-lock-fontify-buffer-function))
  809. ((bound-and-true-p lazy-lock-mode)
  810. (lazy-lock-mode -1))))
  811. (defun font-lock-after-fontify-buffer ()
  812. (cond ((bound-and-true-p fast-lock-mode)
  813. (fast-lock-after-fontify-buffer))
  814. ;; Useless now that jit-lock intercepts font-lock-fontify-buffer. -sm
  815. ;; (jit-lock-mode
  816. ;; (jit-lock-after-fontify-buffer))
  817. ((bound-and-true-p lazy-lock-mode)
  818. (lazy-lock-after-fontify-buffer))))
  819. (defun font-lock-after-unfontify-buffer ()
  820. (cond ((bound-and-true-p fast-lock-mode)
  821. (fast-lock-after-unfontify-buffer))
  822. ;; Useless as well. It's only called when:
  823. ;; - turning off font-lock: it does not matter if we leave spurious
  824. ;; `fontified' text props around since jit-lock-mode is also off.
  825. ;; - font-lock-default-fontify-buffer fails: this is not run
  826. ;; any more anyway. -sm
  827. ;;
  828. ;; (jit-lock-mode
  829. ;; (jit-lock-after-unfontify-buffer))
  830. ((bound-and-true-p lazy-lock-mode)
  831. (lazy-lock-after-unfontify-buffer))))
  832. ;;; End of Font Lock Support mode.
  833. ;;; Fontification functions.
  834. ;; Rather than the function, e.g., `font-lock-fontify-region' containing the
  835. ;; code to fontify a region, the function runs the function whose name is the
  836. ;; value of the variable, e.g., `font-lock-fontify-region-function'. Normally,
  837. ;; the value of this variable is, e.g., `font-lock-default-fontify-region'
  838. ;; which does contain the code to fontify a region. However, the value of the
  839. ;; variable could be anything and thus, e.g., `font-lock-fontify-region' could
  840. ;; do anything. The indirection of the fontification functions gives major
  841. ;; modes the capability of modifying the way font-lock.el fontifies. Major
  842. ;; modes can modify the values of, e.g., `font-lock-fontify-region-function',
  843. ;; via the variable `font-lock-defaults'.
  844. ;;
  845. ;; For example, Rmail mode sets the variable `font-lock-defaults' so that
  846. ;; font-lock.el uses its own function for buffer fontification. This function
  847. ;; makes fontification be on a message-by-message basis and so visiting an
  848. ;; RMAIL file is much faster. A clever implementation of the function might
  849. ;; fontify the headers differently than the message body. (It should, and
  850. ;; correspondingly for Mail mode, but I can't be bothered to do the work. Can
  851. ;; you?) This hints at a more interesting use...
  852. ;;
  853. ;; Languages that contain text normally contained in different major modes
  854. ;; could define their own fontification functions that treat text differently
  855. ;; depending on its context. For example, Perl mode could arrange that here
  856. ;; docs are fontified differently than Perl code. Or Yacc mode could fontify
  857. ;; rules one way and C code another. Neat!
  858. ;;
  859. ;; A further reason to use the fontification indirection feature is when the
  860. ;; default syntactic fontification, or the default fontification in general,
  861. ;; is not flexible enough for a particular major mode. For example, perhaps
  862. ;; comments are just too hairy for `font-lock-fontify-syntactically-region' to
  863. ;; cope with. You need to write your own version of that function, e.g.,
  864. ;; `hairy-fontify-syntactically-region', and make your own version of
  865. ;; `hairy-fontify-region' call that function before calling
  866. ;; `font-lock-fontify-keywords-region' for the normal regexp fontification
  867. ;; pass. And Hairy mode would set `font-lock-defaults' so that font-lock.el
  868. ;; would call your region fontification function instead of its own. For
  869. ;; example, TeX modes could fontify {\foo ...} and \bar{...} etc. multi-line
  870. ;; directives correctly and cleanly. (It is the same problem as fontifying
  871. ;; multi-line strings and comments; regexps are not appropriate for the job.)
  872. (defvar font-lock-extend-after-change-region-function nil
  873. "A function that determines the region to refontify after a change.
  874. This variable is either nil, or is a function that determines the
  875. region to refontify after a change.
  876. It is usually set by the major mode via `font-lock-defaults'.
  877. Font-lock calls this function after each buffer change.
  878. The function is given three parameters, the standard BEG, END, and OLD-LEN
  879. from `after-change-functions'. It should return either a cons of the beginning
  880. and end buffer positions \(in that order) of the region to refontify, or nil
  881. \(which directs the caller to fontify a default region).
  882. This function should preserve the match-data.
  883. The region it returns may start or end in the middle of a line.")
  884. (make-variable-buffer-local 'font-lock-extend-after-change-region-function)
  885. (defun font-lock-fontify-buffer ()
  886. "Fontify the current buffer the way the function `font-lock-mode' would."
  887. (interactive)
  888. (font-lock-set-defaults)
  889. (let ((font-lock-verbose (or font-lock-verbose
  890. (called-interactively-p 'interactive))))
  891. (funcall font-lock-fontify-buffer-function)))
  892. (defun font-lock-unfontify-buffer ()
  893. (funcall font-lock-unfontify-buffer-function))
  894. (defun font-lock-fontify-region (beg end &optional loudly)
  895. "Fontify the text between BEG and END.
  896. If LOUDLY is non-nil, print status messages while fontifying.
  897. This works by calling `font-lock-fontify-region-function'."
  898. (font-lock-set-defaults)
  899. (funcall font-lock-fontify-region-function beg end loudly))
  900. (defun font-lock-unfontify-region (beg end)
  901. "Unfontify the text between BEG and END.
  902. This works by calling `font-lock-unfontify-region-function'."
  903. (save-buffer-state
  904. (funcall font-lock-unfontify-region-function beg end)))
  905. (defun font-lock-default-fontify-buffer ()
  906. "Fontify the whole buffer using `font-lock-fontify-region-function'."
  907. (let ((verbose (if (numberp font-lock-verbose)
  908. (> (buffer-size) font-lock-verbose)
  909. font-lock-verbose)))
  910. (with-temp-message
  911. (when verbose
  912. (format "Fontifying %s..." (buffer-name)))
  913. ;; Make sure we fontify etc. in the whole buffer.
  914. (save-restriction
  915. (widen)
  916. (condition-case nil
  917. (save-excursion
  918. (save-match-data
  919. (font-lock-fontify-region (point-min) (point-max) verbose)
  920. (font-lock-after-fontify-buffer)
  921. (setq font-lock-fontified t)))
  922. ;; We don't restore the old fontification, so it's best to unfontify.
  923. (quit (font-lock-unfontify-buffer)))))))
  924. (defun font-lock-default-unfontify-buffer ()
  925. "Unfontify the whole buffer using `font-lock-unfontify-region-function'."
  926. ;; Make sure we unfontify etc. in the whole buffer.
  927. (save-restriction
  928. (widen)
  929. (font-lock-unfontify-region (point-min) (point-max))
  930. (font-lock-after-unfontify-buffer)
  931. (setq font-lock-fontified nil)))
  932. (defvar font-lock-dont-widen nil
  933. "If non-nil, font-lock will work on the non-widened buffer.
  934. Useful for things like RMAIL and Info where the whole buffer is not
  935. a very meaningful entity to highlight.")
  936. (defvar font-lock-beg) (defvar font-lock-end)
  937. (defvar font-lock-extend-region-functions
  938. '(font-lock-extend-region-wholelines
  939. ;; This use of font-lock-multiline property is unreliable but is just
  940. ;; a handy heuristic: in case you don't have a function that does
  941. ;; /identification/ of multiline elements, you may still occasionally
  942. ;; discover them by accident (or you may /identify/ them but not in all
  943. ;; cases), in which case the font-lock-multiline property can help make
  944. ;; sure you will properly *re*identify them during refontification.
  945. font-lock-extend-region-multiline)
  946. "Special hook run just before proceeding to fontify a region.
  947. This is used to allow major modes to help font-lock find safe buffer positions
  948. as beginning and end of the fontified region. Its most common use is to solve
  949. the problem of /identification/ of multiline elements by providing a function
  950. that tries to find such elements and move the boundaries such that they do
  951. not fall in the middle of one.
  952. Each function is called with no argument; it is expected to adjust the
  953. dynamically bound variables `font-lock-beg' and `font-lock-end'; and return
  954. non-nil if it did make such an adjustment.
  955. These functions are run in turn repeatedly until they all return nil.
  956. Put first the functions more likely to cause a change and cheaper to compute.")
  957. ;; Mark it as a special hook which doesn't use any global setting
  958. ;; (i.e. doesn't obey the element t in the buffer-local value).
  959. (make-variable-buffer-local 'font-lock-extend-region-functions)
  960. (defun font-lock-extend-region-multiline ()
  961. "Move fontification boundaries away from any `font-lock-multiline' property."
  962. (let ((changed nil))
  963. (when (and (> font-lock-beg (point-min))
  964. (get-text-property (1- font-lock-beg) 'font-lock-multiline))
  965. (setq changed t)
  966. (setq font-lock-beg (or (previous-single-property-change
  967. font-lock-beg 'font-lock-multiline)
  968. (point-min))))
  969. ;;
  970. (when (get-text-property font-lock-end 'font-lock-multiline)
  971. (setq changed t)
  972. (setq font-lock-end (or (text-property-any font-lock-end (point-max)
  973. 'font-lock-multiline nil)
  974. (point-max))))
  975. changed))
  976. (defun font-lock-extend-region-wholelines ()
  977. "Move fontification boundaries to beginning of lines."
  978. (let ((changed nil))
  979. (goto-char font-lock-beg)
  980. (unless (bolp)
  981. (setq changed t font-lock-beg (line-beginning-position)))
  982. (goto-char font-lock-end)
  983. (unless (bolp)
  984. (unless (eq font-lock-end
  985. (setq font-lock-end (line-beginning-position 2)))
  986. (setq changed t)))
  987. changed))
  988. (defun font-lock-default-fontify-region (beg end loudly)
  989. "Fontify the text between BEG and END.
  990. If LOUDLY is non-nil, print status messages while fontifying.
  991. This function is the default `font-lock-fontify-region-function'."
  992. (save-buffer-state
  993. ;; Use the fontification syntax table, if any.
  994. (with-syntax-table (or font-lock-syntax-table (syntax-table))
  995. (save-restriction
  996. (unless font-lock-dont-widen (widen))
  997. ;; Extend the region to fontify so that it starts and ends at
  998. ;; safe places.
  999. (let ((funs font-lock-extend-region-functions)
  1000. (font-lock-beg beg)
  1001. (font-lock-end end))
  1002. (while funs
  1003. (setq funs (if (or (not (funcall (car funs)))
  1004. (eq funs font-lock-extend-region-functions))
  1005. (cdr funs)
  1006. ;; If there's been a change, we should go through
  1007. ;; the list again since this new position may
  1008. ;; warrant a different answer from one of the fun
  1009. ;; we've already seen.
  1010. font-lock-extend-region-functions)))
  1011. (setq beg font-lock-beg end font-lock-end))
  1012. ;; Now do the fontification.
  1013. (font-lock-unfontify-region beg end)
  1014. (when (and font-lock-syntactic-keywords
  1015. (null syntax-propertize-function))
  1016. ;; Ensure the beginning of the file is properly syntactic-fontified.
  1017. (let ((start beg))
  1018. (when (< font-lock-syntactically-fontified start)
  1019. (setq start (max font-lock-syntactically-fontified (point-min)))
  1020. (setq font-lock-syntactically-fontified end))
  1021. (font-lock-fontify-syntactic-keywords-region start end)))
  1022. (unless font-lock-keywords-only
  1023. (font-lock-fontify-syntactically-region beg end loudly))
  1024. (font-lock-fontify-keywords-region beg end loudly)))))
  1025. ;; The following must be rethought, since keywords can override fontification.
  1026. ;; ;; Now scan for keywords, but not if we are inside a comment now.
  1027. ;; (or (and (not font-lock-keywords-only)
  1028. ;; (let ((state (parse-partial-sexp beg end nil nil
  1029. ;; font-lock-cache-state)))
  1030. ;; (or (nth 4 state) (nth 7 state))))
  1031. ;; (font-lock-fontify-keywords-region beg end))
  1032. (defvar font-lock-extra-managed-props nil
  1033. "Additional text properties managed by font-lock.
  1034. This is used by `font-lock-default-unfontify-region' to decide
  1035. what properties to clear before refontifying a region.")
  1036. (defun font-lock-default-unfontify-region (beg end)
  1037. "Unfontify the text between BEG and END.
  1038. This function is the default `font-lock-unfontify-region-function'."
  1039. (remove-list-of-text-properties
  1040. beg end (append
  1041. font-lock-extra-managed-props
  1042. (if font-lock-syntactic-keywords
  1043. '(syntax-table face font-lock-multiline)
  1044. '(face font-lock-multiline)))))
  1045. ;; Called when any modification is made to buffer text.
  1046. (defun font-lock-after-change-function (beg end old-len)
  1047. (save-excursion
  1048. (let ((inhibit-point-motion-hooks t)
  1049. (inhibit-quit t)
  1050. (region (if font-lock-extend-after-change-region-function
  1051. (funcall font-lock-extend-after-change-region-function
  1052. beg end old-len))))
  1053. (save-match-data
  1054. (if region
  1055. ;; Fontify the region the major mode has specified.
  1056. (setq beg (car region) end (cdr region))
  1057. ;; Fontify the whole lines which enclose the region.
  1058. ;; Actually, this is not needed because
  1059. ;; font-lock-default-fontify-region already rounds up to a whole
  1060. ;; number of lines.
  1061. ;; (setq beg (progn (goto-char beg) (line-beginning-position))
  1062. ;; end (progn (goto-char end) (line-beginning-position 2)))
  1063. (unless (eq end (point-max))
  1064. ;; Rounding up to a whole number of lines should include the
  1065. ;; line right after `end'. Typical case: the first char of
  1066. ;; the line was deleted. Or a \n was inserted in the middle
  1067. ;; of a line.
  1068. (setq end (1+ end))))
  1069. (font-lock-fontify-region beg end)))))
  1070. (defvar jit-lock-start) (defvar jit-lock-end)
  1071. (defun font-lock-extend-jit-lock-region-after-change (beg end old-len)
  1072. "Function meant for `jit-lock-after-change-extend-region-functions'.
  1073. This function does 2 things:
  1074. - extend the region so that it not only includes the part that was modified
  1075. but also the surrounding text whose highlighting may change as a consequence.
  1076. - anticipate (part of) the region extension that will happen later in
  1077. `font-lock-default-fontify-region', in order to avoid the need for
  1078. double-redisplay in `jit-lock-fontify-now'."
  1079. (save-excursion
  1080. ;; First extend the region as font-lock-after-change-function would.
  1081. (let ((region (if font-lock-extend-after-change-region-function
  1082. (funcall font-lock-extend-after-change-region-function
  1083. beg end old-len))))
  1084. (if region
  1085. (setq beg (min jit-lock-start (car region))
  1086. end (max jit-lock-end (cdr region))))
  1087. ;; Then extend the region obeying font-lock-multiline properties,
  1088. ;; indicating which part of the buffer needs to be refontified.
  1089. ;; !!! This is the *main* user of font-lock-multiline property !!!
  1090. ;; font-lock-after-change-function could/should also do that, but it
  1091. ;; doesn't need to because font-lock-default-fontify-region does
  1092. ;; it anyway. Here OTOH we have no guarantee that
  1093. ;; font-lock-default-fontify-region will be executed on this region
  1094. ;; any time soon.
  1095. ;; Note: contrary to font-lock-default-fontify-region, we do not do
  1096. ;; any loop here because we are not looking for a safe spot: we just
  1097. ;; mark the text whose appearance may need to change as a result of
  1098. ;; the buffer modification.
  1099. (when (and (> beg (point-min))
  1100. (get-text-property (1- beg) 'font-lock-multiline))
  1101. (setq beg (or (previous-single-property-change
  1102. beg 'font-lock-multiline)
  1103. (point-min))))
  1104. (when (< end (point-max))
  1105. (setq end
  1106. (if (get-text-property end 'font-lock-multiline)
  1107. (or (text-property-any end (point-max)
  1108. 'font-lock-multiline nil)
  1109. (point-max))
  1110. ;; Rounding up to a whole number of lines should include the
  1111. ;; line right after `end'. Typical case: the first char of
  1112. ;; the line was deleted. Or a \n was inserted in the middle
  1113. ;; of a line.
  1114. (1+ end))))
  1115. ;; Finally, pre-enlarge the region to a whole number of lines, to try
  1116. ;; and anticipate what font-lock-default-fontify-region will do, so as to
  1117. ;; avoid double-redisplay.
  1118. ;; We could just run `font-lock-extend-region-functions', but since
  1119. ;; the only purpose is to avoid the double-redisplay, we prefer to
  1120. ;; do here only the part that is cheap and most likely to be useful.
  1121. (when (memq 'font-lock-extend-region-wholelines
  1122. font-lock-extend-region-functions)
  1123. (goto-char beg)
  1124. (setq jit-lock-start (min jit-lock-start (line-beginning-position)))
  1125. (goto-char end)
  1126. (setq jit-lock-end
  1127. (max jit-lock-end
  1128. (if (bolp) (point) (line-beginning-position 2))))))))
  1129. (defun font-lock-fontify-block (&optional arg)
  1130. "Fontify some lines the way `font-lock-fontify-buffer' would.
  1131. The lines could be a function or paragraph, or a specified number of lines.
  1132. If ARG is given, fontify that many lines before and after point, or 16 lines if
  1133. no ARG is given and `font-lock-mark-block-function' is nil.
  1134. If `font-lock-mark-block-function' non-nil and no ARG is given, it is used to
  1135. delimit the region to fontify."
  1136. (interactive "P")
  1137. (let ((inhibit-point-motion-hooks t) font-lock-beginning-of-syntax-function
  1138. deactivate-mark)
  1139. ;; Make sure we have the right `font-lock-keywords' etc.
  1140. (if (not font-lock-mode) (font-lock-set-defaults))
  1141. (save-excursion
  1142. (save-match-data
  1143. (condition-case error-data
  1144. (if (or arg (not font-lock-mark-block-function))
  1145. (let ((lines (if arg (prefix-numeric-value arg) 16)))
  1146. (font-lock-fontify-region
  1147. (save-excursion (forward-line (- lines)) (point))
  1148. (save-excursion (forward-line lines) (point))))
  1149. (funcall font-lock-mark-block-function)
  1150. (font-lock-fontify-region (point) (mark)))
  1151. ((error quit) (message "Fontifying block...%s" error-data)))))))
  1152. ;;; End of Fontification functions.
  1153. ;;; Additional text property functions.
  1154. ;; The following text property functions should be builtins. This means they
  1155. ;; should be written in C and put with all the other text property functions.
  1156. ;; In the meantime, those that are used by font-lock.el are defined in Lisp
  1157. ;; below and given a `font-lock-' prefix. Those that are not used are defined
  1158. ;; in Lisp below and commented out. sm.
  1159. (defun font-lock-prepend-text-property (start end prop value &optional object)
  1160. "Prepend to one property of the text from START to END.
  1161. Arguments PROP and VALUE specify the property and value to prepend to the value
  1162. already in place. The resulting property values are always lists.
  1163. Optional argument OBJECT is the string or buffer containing the text."
  1164. (let ((val (if (listp value) value (list value))) next prev)
  1165. (while (/= start end)
  1166. (setq next (next-single-property-change start prop object end)
  1167. prev (get-text-property start prop object))
  1168. ;; Canonicalize old forms of face property.
  1169. (and (memq prop '(face font-lock-face))
  1170. (listp prev)
  1171. (or (keywordp (car prev))
  1172. (memq (car prev) '(foreground-color background-color)))
  1173. (setq prev (list prev)))
  1174. (put-text-property start next prop
  1175. (append val (if (listp prev) prev (list prev)))
  1176. object)
  1177. (setq start next))))
  1178. (defun font-lock-append-text-property (start end prop value &optional object)
  1179. "Append to one property of the text from START to END.
  1180. Arguments PROP and VALUE specify the property and value to append to the value
  1181. already in place. The resulting property values are always lists.
  1182. Optional argument OBJECT is the string or buffer containing the text."
  1183. (let ((val (if (listp value) value (list value))) next prev)
  1184. (while (/= start end)
  1185. (setq next (next-single-property-change start prop object end)
  1186. prev (get-text-property start prop object))
  1187. ;; Canonicalize old forms of face property.
  1188. (and (memq prop '(face font-lock-face))
  1189. (listp prev)
  1190. (or (keywordp (car prev))
  1191. (memq (car prev) '(foreground-color background-color)))
  1192. (setq prev (list prev)))
  1193. (put-text-property start next prop
  1194. (append (if (listp prev) prev (list prev)) val)
  1195. object)
  1196. (setq start next))))
  1197. (defun font-lock-fillin-text-property (start end prop value &optional object)
  1198. "Fill in one property of the text from START to END.
  1199. Arguments PROP and VALUE specify the property and value to put where none are
  1200. already in place. Therefore existing property values are not overwritten.
  1201. Optional argument OBJECT is the string or buffer containing the text."
  1202. (let ((start (text-property-any start end prop nil object)) next)
  1203. (while start
  1204. (setq next (next-single-property-change start prop object end))
  1205. (put-text-property start next prop value object)
  1206. (setq start (text-property-any next end prop nil object)))))
  1207. ;; For completeness: this is to `remove-text-properties' as `put-text-property'
  1208. ;; is to `add-text-properties', etc.
  1209. ;;(defun remove-text-property (start end property &optional object)
  1210. ;; "Remove a property from text from START to END.
  1211. ;;Argument PROPERTY is the property to remove.
  1212. ;;Optional argument OBJECT is the string or buffer containing the text.
  1213. ;;Return t if the property was actually removed, nil otherwise."
  1214. ;; (remove-text-properties start end (list property) object))
  1215. ;; For consistency: maybe this should be called `remove-single-property' like
  1216. ;; `next-single-property-change' (not `next-single-text-property-change'), etc.
  1217. ;;(defun remove-single-text-property (start end prop value &optional object)
  1218. ;; "Remove a specific property value from text from START to END.
  1219. ;;Arguments PROP and VALUE specify the property and value to remove. The
  1220. ;;resulting property values are not equal to VALUE nor lists containing VALUE.
  1221. ;;Optional argument OBJECT is the string or buffer containing the text."
  1222. ;; (let ((start (text-property-not-all start end prop nil object)) next prev)
  1223. ;; (while start
  1224. ;; (setq next (next-single-property-change start prop object end)
  1225. ;; prev (get-text-property start prop object))
  1226. ;; (cond ((and (symbolp prev) (eq value prev))
  1227. ;; (remove-text-property start next prop object))
  1228. ;; ((and (listp prev) (memq value prev))
  1229. ;; (let ((new (delq value prev)))
  1230. ;; (cond ((null new)
  1231. ;; (remove-text-property start next prop object))
  1232. ;; ((= (length new) 1)
  1233. ;; (put-text-property start next prop (car new) object))
  1234. ;; (t
  1235. ;; (put-text-property start next prop new object))))))
  1236. ;; (setq start (text-property-not-all next end prop nil object)))))
  1237. ;;; End of Additional text property functions.
  1238. ;;; Syntactic regexp fontification functions.
  1239. ;; These syntactic keyword pass functions are identical to those keyword pass
  1240. ;; functions below, with the following exceptions; (a) they operate on
  1241. ;; `font-lock-syntactic-keywords' of course, (b) they are all `defun' as speed
  1242. ;; is less of an issue, (c) eval of property value does not occur JIT as speed
  1243. ;; is less of an issue, (d) OVERRIDE cannot be `prepend' or `append' as it
  1244. ;; makes no sense for `syntax-table' property values, (e) they do not do it
  1245. ;; LOUDLY as it is not likely to be intensive.
  1246. (defun font-lock-apply-syntactic-highlight (highlight)
  1247. "Apply HIGHLIGHT following a match.
  1248. HIGHLIGHT should be of the form MATCH-HIGHLIGHT,
  1249. see `font-lock-syntactic-keywords'."
  1250. (let* ((match (nth 0 highlight))
  1251. (start (match-beginning match)) (end (match-end match))
  1252. (value (nth 1 highlight))
  1253. (override (nth 2 highlight)))
  1254. (if (not start)
  1255. ;; No match but we might not signal an error.
  1256. (or (nth 3 highlight)
  1257. (error "No match %d in highlight %S" match highlight))
  1258. (when (and (consp value) (not (numberp (car value))))
  1259. (setq value (eval value)))
  1260. (when (stringp value) (setq value (string-to-syntax value)))
  1261. ;; Flush the syntax-cache. I believe this is not necessary for
  1262. ;; font-lock's use of syntax-ppss, but I'm not 100% sure and it can
  1263. ;; still be necessary for other users of syntax-ppss anyway.
  1264. (syntax-ppss-after-change-function start)
  1265. (cond
  1266. ((not override)
  1267. ;; Cannot override existing fontification.
  1268. (or (text-property-not-all start end 'syntax-table nil)
  1269. (put-text-property start end 'syntax-table value)))
  1270. ((eq override t)
  1271. ;; Override existing fontification.
  1272. (put-text-property start end 'syntax-table value))
  1273. ((eq override 'keep)
  1274. ;; Keep existing fontification.
  1275. (font-lock-fillin-text-property start end 'syntax-table value))))))
  1276. (defun font-lock-fontify-syntactic-anchored-keywords (keywords limit)
  1277. "Fontify according to KEYWORDS until LIMIT.
  1278. KEYWORDS should be of the form MATCH-ANCHORED, see `font-lock-keywords',
  1279. LIMIT can be modified by the value of its PRE-MATCH-FORM."
  1280. (let ((matcher (nth 0 keywords)) (lowdarks (nthcdr 3 keywords)) highlights
  1281. ;; Evaluate PRE-MATCH-FORM.
  1282. (pre-match-value (eval (nth 1 keywords))))
  1283. ;; Set LIMIT to value of PRE-MATCH-FORM or the end of line.
  1284. (if (and (numberp pre-match-value) (> pre-match-value (point)))
  1285. (setq limit pre-match-value)
  1286. (setq limit (line-end-position)))
  1287. (save-match-data
  1288. ;; Find an occurrence of `matcher' before `limit'.
  1289. (while (if (stringp matcher)
  1290. (re-search-forward matcher limit t)
  1291. (funcall matcher limit))
  1292. ;; Apply each highlight to this instance of `matcher'.
  1293. (setq highlights lowdarks)
  1294. (while highlights
  1295. (font-lock-apply-syntactic-highlight (car highlights))
  1296. (setq highlights (cdr highlights)))))
  1297. ;; Evaluate POST-MATCH-FORM.
  1298. (eval (nth 2 keywords))))
  1299. (defun font-lock-fontify-syntactic-keywords-region (start end)
  1300. "Fontify according to `font-lock-syntactic-keywords' between START and END.
  1301. START should be at the beginning of a line."
  1302. (unless parse-sexp-lookup-properties
  1303. ;; We wouldn't go through so much trouble if we didn't intend to use those
  1304. ;; properties, would we?
  1305. (set (make-local-variable 'parse-sexp-lookup-properties) t))
  1306. ;; If `font-lock-syntactic-keywords' is a symbol, get the real keywords.
  1307. (when (symbolp font-lock-syntactic-keywords)
  1308. (setq font-lock-syntactic-keywords (font-lock-eval-keywords
  1309. font-lock-syntactic-keywords)))
  1310. ;; If `font-lock-syntactic-keywords' is not compiled, compile it.
  1311. (unless (eq (car font-lock-syntactic-keywords) t)
  1312. (setq font-lock-syntactic-keywords (font-lock-compile-keywords
  1313. font-lock-syntactic-keywords
  1314. t)))
  1315. ;; Get down to business.
  1316. (let ((case-fold-search font-lock-keywords-case-fold-search)
  1317. (keywords (cddr font-lock-syntactic-keywords))
  1318. keyword matcher highlights)
  1319. (while keywords
  1320. ;; Find an occurrence of `matcher' from `start' to `end'.
  1321. (setq keyword (car keywords) matcher (car keyword))
  1322. (goto-char start)
  1323. (while (and (< (point) end)
  1324. (if (stringp matcher)
  1325. (re-search-forward matcher end t)
  1326. (funcall matcher end)))
  1327. ;; Apply each highlight to this instance of `matcher', which may be
  1328. ;; specific highlights or more keywords anchored to `matcher'.
  1329. (setq highlights (cdr keyword))
  1330. (while highlights
  1331. (if (numberp (car (car highlights)))
  1332. (font-lock-apply-syntactic-highlight (car highlights))
  1333. (font-lock-fontify-syntactic-anchored-keywords (car highlights)
  1334. end))
  1335. (setq highlights (cdr highlights))))
  1336. (setq keywords (cdr keywords)))))
  1337. ;;; End of Syntactic regexp fontification functions.
  1338. ;;; Syntactic fontification functions.
  1339. (defvar font-lock-comment-start-skip nil
  1340. "If non-nil, Font Lock mode uses this instead of `comment-start-skip'.")
  1341. (defvar font-lock-comment-end-skip nil
  1342. "If non-nil, Font Lock mode uses this instead of `comment-end'.")
  1343. (defun font-lock-fontify-syntactically-region (start end &optional loudly)
  1344. "Put proper face on each string and comment between START and END.
  1345. START should be at the beginning of a line."
  1346. (syntax-propertize end) ; Apply any needed syntax-table properties.
  1347. (let ((comment-end-regexp
  1348. (or font-lock-comment-end-skip
  1349. (regexp-quote
  1350. (replace-regexp-in-string "^ *" "" comment-end))))
  1351. ;; Find the `start' state.
  1352. (state (syntax-ppss start))
  1353. face beg)
  1354. (if loudly (message "Fontifying %s... (syntactically...)" (buffer-name)))
  1355. ;;
  1356. ;; Find each interesting place between here and `end'.
  1357. (while
  1358. (progn
  1359. (when (or (nth 3 state) (nth 4 state))
  1360. (setq face (funcall font-lock-syntactic-face-function state))
  1361. (setq beg (max (nth 8 state) start))
  1362. (setq state (parse-partial-sexp (point) end nil nil state
  1363. 'syntax-table))
  1364. (when face (put-text-property beg (point) 'face face))
  1365. (when (and (eq face 'font-lock-comment-face)
  1366. (or font-lock-comment-start-skip
  1367. comment-start-skip))
  1368. ;; Find the comment delimiters
  1369. ;; and use font-lock-comment-delimiter-face for them.
  1370. (save-excursion
  1371. (goto-char beg)
  1372. (if (looking-at (or font-lock-comment-start-skip
  1373. comment-start-skip))
  1374. (put-text-property beg (match-end 0) 'face
  1375. font-lock-comment-delimiter-face)))
  1376. (if (looking-back comment-end-regexp (point-at-bol) t)
  1377. (put-text-property (match-beginning 0) (point) 'face
  1378. font-lock-comment-delimiter-face))))
  1379. (< (point) end))
  1380. (setq state (parse-partial-sexp (point) end nil nil state
  1381. 'syntax-table)))))
  1382. ;;; End of Syntactic fontification functions.
  1383. ;;; Keyword regexp fontification functions.
  1384. (defsubst font-lock-apply-highlight (highlight)
  1385. "Apply HIGHLIGHT following a match.
  1386. HIGHLIGHT should be of the form MATCH-HIGHLIGHT, see `font-lock-keywords'."
  1387. (let* ((match (nth 0 highlight))
  1388. (start (match-beginning match)) (end (match-end match))
  1389. (override (nth 2 highlight)))
  1390. (if (not start)
  1391. ;; No match but we might not signal an error.
  1392. (or (nth 3 highlight)
  1393. (error "No match %d in highlight %S" match highlight))
  1394. (let ((val (eval (nth 1 highlight))))
  1395. (when (eq (car-safe val) 'face)
  1396. (add-text-properties start end (cddr val))
  1397. (setq val (cadr val)))
  1398. (cond
  1399. ((not (or val (eq override t)))
  1400. ;; If `val' is nil, don't do anything. It is important to do it
  1401. ;; explicitly, because when adding nil via things like
  1402. ;; font-lock-append-text-property, the property is actually
  1403. ;; changed from <face> to (<face>) which is undesirable. --Stef
  1404. nil)
  1405. ((not override)
  1406. ;; Cannot override existing fontification.
  1407. (or (text-property-not-all start end 'face nil)
  1408. (put-text-property start end 'face val)))
  1409. ((eq override t)
  1410. ;; Override existing fontification.
  1411. (put-text-property start end 'face val))
  1412. ((eq override 'prepend)
  1413. ;; Prepend to existing fontification.
  1414. (font-lock-prepend-text-property start end 'face val))
  1415. ((eq override 'append)
  1416. ;; Append to existing fontification.
  1417. (font-lock-append-text-property start end 'face val))
  1418. ((eq override 'keep)
  1419. ;; Keep existing fontification.
  1420. (font-lock-fillin-text-property start end 'face val)))))))
  1421. (defsubst font-lock-fontify-anchored-keywords (keywords limit)
  1422. "Fontify according to KEYWORDS until LIMIT.
  1423. KEYWORDS should be of the form MATCH-ANCHORED, see `font-lock-keywords',
  1424. LIMIT can be modified by the value of its PRE-MATCH-FORM."
  1425. (let ((matcher (nth 0 keywords)) (lowdarks (nthcdr 3 keywords)) highlights
  1426. (lead-start (match-beginning 0))
  1427. ;; Evaluate PRE-MATCH-FORM.
  1428. (pre-match-value (eval (nth 1 keywords))))
  1429. ;; Set LIMIT to value of PRE-MATCH-FORM or the end of line.
  1430. (if (not (and (numberp pre-match-value) (> pre-match-value (point))))
  1431. (setq limit (line-end-position))
  1432. (setq limit pre-match-value)
  1433. (when (and font-lock-multiline (>= limit (line-beginning-position 2)))
  1434. ;; this is a multiline anchored match
  1435. ;; (setq font-lock-multiline t)
  1436. (put-text-property (if (= limit (line-beginning-position 2))
  1437. (1- limit)
  1438. (min lead-start (point)))
  1439. limit
  1440. 'font-lock-multiline t)))
  1441. (save-match-data
  1442. ;; Find an occurrence of `matcher' before `limit'.
  1443. (while (and (< (point) limit)
  1444. (if (stringp matcher)
  1445. (re-search-forward matcher limit t)
  1446. (funcall matcher limit)))
  1447. ;; Apply each highlight to this instance of `matcher'.
  1448. (setq highlights lowdarks)
  1449. (while highlights
  1450. (font-lock-apply-highlight (car highlights))
  1451. (setq highlights (cdr highlights)))))
  1452. ;; Evaluate POST-MATCH-FORM.
  1453. (eval (nth 2 keywords))))
  1454. (defun font-lock-fontify-keywords-region (start end &optional loudly)
  1455. "Fontify according to `font-lock-keywords' between START and END.
  1456. START should be at the beginning of a line.
  1457. LOUDLY, if non-nil, allows progress-meter bar."
  1458. (unless (eq (car font-lock-keywords) t)
  1459. (setq font-lock-keywords
  1460. (font-lock-compile-keywords font-lock-keywords)))
  1461. (let ((case-fold-search font-lock-keywords-case-fold-search)
  1462. (keywords (cddr font-lock-keywords))
  1463. (bufname (buffer-name)) (count 0)
  1464. (pos (make-marker))
  1465. keyword matcher highlights)
  1466. ;;
  1467. ;; Fontify each item in `font-lock-keywords' from `start' to `end'.
  1468. (while keywords
  1469. (if loudly (message "Fontifying %s... (regexps..%s)" bufname
  1470. (make-string (incf count) ?.)))
  1471. ;;
  1472. ;; Find an occurrence of `matcher' from `start' to `end'.
  1473. (setq keyword (car keywords) matcher (car keyword))
  1474. (goto-char start)
  1475. (while (and (< (point) end)
  1476. (if (stringp matcher)
  1477. (re-search-forward matcher end t)
  1478. (funcall matcher end))
  1479. ;; Beware empty string matches since they will
  1480. ;; loop indefinitely.
  1481. (or (> (point) (match-beginning 0))
  1482. (progn (forward-char 1) t)))
  1483. (when (and font-lock-multiline
  1484. (>= (point)
  1485. (save-excursion (goto-char (match-beginning 0))
  1486. (forward-line 1) (point))))
  1487. ;; this is a multiline regexp match
  1488. ;; (setq font-lock-multiline t)
  1489. (put-text-property (if (= (point)
  1490. (save-excursion
  1491. (goto-char (match-beginning 0))
  1492. (forward-line 1) (point)))
  1493. (1- (point))
  1494. (match-beginning 0))
  1495. (point)
  1496. 'font-lock-multiline t))
  1497. ;; Apply each highlight to this instance of `matcher', which may be
  1498. ;; specific highlights or more keywords anchored to `matcher'.
  1499. (setq highlights (cdr keyword))
  1500. (while highlights
  1501. (if (numberp (car (car highlights)))
  1502. (font-lock-apply-highlight (car highlights))
  1503. (set-marker pos (point))
  1504. (font-lock-fontify-anchored-keywords (car highlights) end)
  1505. ;; Ensure forward progress. `pos' is a marker because anchored
  1506. ;; keyword may add/delete text (this happens e.g. in grep.el).
  1507. (if (< (point) pos) (goto-char pos)))
  1508. (setq highlights (cdr highlights))))
  1509. (setq keywords (cdr keywords)))
  1510. (set-marker pos nil)))
  1511. ;;; End of Keyword regexp fontification functions.
  1512. ;; Various functions.
  1513. (defun font-lock-compile-keywords (keywords &optional syntactic-keywords)
  1514. "Compile KEYWORDS into the form (t KEYWORDS COMPILED...)
  1515. Here each COMPILED is of the form (MATCHER HIGHLIGHT ...) as shown in the
  1516. `font-lock-keywords' doc string.
  1517. If SYNTACTIC-KEYWORDS is non-nil, it means these keywords are used for
  1518. `font-lock-syntactic-keywords' rather than for `font-lock-keywords'."
  1519. (if (not font-lock-set-defaults)
  1520. ;; This should never happen. But some external packages sometimes
  1521. ;; call font-lock in unexpected and incorrect ways. It's important to
  1522. ;; stop processing at this point, otherwise we may end up changing the
  1523. ;; global value of font-lock-keywords and break highlighting in many
  1524. ;; other buffers.
  1525. (error "Font-lock trying to use keywords before setting them up"))
  1526. (if (eq (car-safe keywords) t)
  1527. keywords
  1528. (setq keywords
  1529. (cons t (cons keywords
  1530. (mapcar 'font-lock-compile-keyword keywords))))
  1531. (if (and (not syntactic-keywords)
  1532. (let ((beg-function
  1533. (or font-lock-beginning-of-syntax-function
  1534. syntax-begin-function)))
  1535. (or (eq beg-function 'beginning-of-defun)
  1536. (get beg-function 'font-lock-syntax-paren-check)))
  1537. (not beginning-of-defun-function))
  1538. ;; Try to detect when a string or comment contains something that
  1539. ;; looks like a defun and would thus confuse font-lock.
  1540. (nconc keywords
  1541. `((,(if defun-prompt-regexp
  1542. (concat "^\\(?:" defun-prompt-regexp "\\)?\\s(")
  1543. "^\\s(")
  1544. (0
  1545. (if (memq (get-text-property (match-beginning 0) 'face)
  1546. '(font-lock-string-face font-lock-doc-face
  1547. font-lock-comment-face))
  1548. (list 'face font-lock-warning-face
  1549. 'help-echo "Looks like a toplevel defun: escape the parenthesis"))
  1550. prepend)))))
  1551. keywords))
  1552. (defun font-lock-compile-keyword (keyword)
  1553. (cond ((nlistp keyword) ; MATCHER
  1554. (list keyword '(0 font-lock-keyword-face)))
  1555. ((eq (car keyword) 'eval) ; (eval . FORM)
  1556. (font-lock-compile-keyword (eval (cdr keyword))))
  1557. ((eq (car-safe (cdr keyword)) 'quote) ; (MATCHER . 'FORM)
  1558. ;; If FORM is a FACENAME then quote it. Otherwise ignore the quote.
  1559. (if (symbolp (nth 2 keyword))
  1560. (list (car keyword) (list 0 (cdr keyword)))
  1561. (font-lock-compile-keyword (cons (car keyword) (nth 2 keyword)))))
  1562. ((numberp (cdr keyword)) ; (MATCHER . MATCH)
  1563. (list (car keyword) (list (cdr keyword) 'font-lock-keyword-face)))
  1564. ((symbolp (cdr keyword)) ; (MATCHER . FACENAME)
  1565. (list (car keyword) (list 0 (cdr keyword))))
  1566. ((nlistp (nth 1 keyword)) ; (MATCHER . HIGHLIGHT)
  1567. (list (car keyword) (cdr keyword)))
  1568. (t ; (MATCHER HIGHLIGHT ...)
  1569. keyword)))
  1570. (defun font-lock-eval-keywords (keywords)
  1571. "Evaluate KEYWORDS if a function (funcall) or variable (eval) name."
  1572. (if (listp keywords)
  1573. keywords
  1574. (font-lock-eval-keywords (if (fboundp keywords)
  1575. (funcall keywords)
  1576. (eval keywords)))))
  1577. (defun font-lock-value-in-major-mode (alist)
  1578. "Return value in ALIST for `major-mode', or ALIST if it is not an alist.
  1579. Structure is ((MAJOR-MODE . VALUE) ...) where MAJOR-MODE may be t."
  1580. (if (consp alist)
  1581. (cdr (or (assq major-mode alist) (assq t alist)))
  1582. alist))
  1583. (defun font-lock-choose-keywords (keywords level)
  1584. "Return LEVELth element of KEYWORDS.
  1585. A LEVEL of nil is equal to a LEVEL of 0, a LEVEL of t is equal to
  1586. \(1- (length KEYWORDS))."
  1587. (cond ((not (and (listp keywords) (symbolp (car keywords))))
  1588. keywords)
  1589. ((numberp level)
  1590. (or (nth level keywords) (car (last keywords))))
  1591. ((eq level t)
  1592. (car (last keywords)))
  1593. (t
  1594. (car keywords))))
  1595. (defvar font-lock-set-defaults nil) ; Whether we have set up defaults.
  1596. (defun font-lock-refresh-defaults ()
  1597. "Restart fontification in current buffer after recomputing from defaults.
  1598. Recompute fontification variables using `font-lock-defaults' and
  1599. `font-lock-maximum-decoration'. Then restart fontification.
  1600. Use this function when you have changed any of the above
  1601. variables directly.
  1602. Note: This function will erase modifications done by
  1603. `font-lock-add-keywords' or `font-lock-remove-keywords', but will
  1604. preserve `hi-lock-mode' highlighting patterns."
  1605. (font-lock-mode -1)
  1606. (kill-local-variable 'font-lock-set-defaults)
  1607. (font-lock-mode 1))
  1608. (defvar font-lock-major-mode nil
  1609. "Major mode for which the font-lock settings have been setup.")
  1610. (make-variable-buffer-local 'font-lock-major-mode)
  1611. (defun font-lock-set-defaults ()
  1612. "Set fontification defaults appropriately for this mode.
  1613. Sets various variables using `font-lock-defaults' and
  1614. `font-lock-maximum-decoration'."
  1615. ;; Set fontification defaults if not previously set for correct major mode.
  1616. (unless (and font-lock-set-defaults
  1617. (eq font-lock-major-mode major-mode))
  1618. (setq font-lock-major-mode major-mode)
  1619. (set (make-local-variable 'font-lock-set-defaults) t)
  1620. (make-local-variable 'font-lock-fontified)
  1621. (make-local-variable 'font-lock-multiline)
  1622. (let* ((defaults font-lock-defaults)
  1623. (keywords
  1624. (font-lock-choose-keywords (nth 0 defaults)
  1625. (font-lock-value-in-major-mode font-lock-maximum-decoration)))
  1626. (local (cdr (assq major-mode font-lock-keywords-alist)))
  1627. (removed-keywords
  1628. (cdr-safe (assq major-mode font-lock-removed-keywords-alist))))
  1629. (set (make-local-variable 'font-lock-defaults) defaults)
  1630. ;; Syntactic fontification?
  1631. (if (nth 1 defaults)
  1632. (set (make-local-variable 'font-lock-keywords-only) t)
  1633. (kill-local-variable 'font-lock-keywords-only))
  1634. ;; Case fold during regexp fontification?
  1635. (if (nth 2 defaults)
  1636. (set (make-local-variable 'font-lock-keywords-case-fold-search) t)
  1637. (kill-local-variable 'font-lock-keywords-case-fold-search))
  1638. ;; Syntax table for regexp and syntactic fontification?
  1639. (if (null (nth 3 defaults))
  1640. (kill-local-variable 'font-lock-syntax-table)
  1641. (set (make-local-variable 'font-lock-syntax-table)
  1642. (copy-syntax-table (syntax-table)))
  1643. (dolist (selem (nth 3 defaults))
  1644. ;; The character to modify may be a single CHAR or a STRING.
  1645. (let ((syntax (cdr selem)))
  1646. (dolist (char (if (numberp (car selem))
  1647. (list (car selem))
  1648. (mapcar 'identity (car selem))))
  1649. (modify-syntax-entry char syntax font-lock-syntax-table)))))
  1650. ;; Syntax function for syntactic fontification?
  1651. (if (nth 4 defaults)
  1652. (set (make-local-variable 'font-lock-beginning-of-syntax-function)
  1653. (nth 4 defaults))
  1654. (kill-local-variable 'font-lock-beginning-of-syntax-function))
  1655. ;; Variable alist?
  1656. (dolist (x (nthcdr 5 defaults))
  1657. (set (make-local-variable (car x)) (cdr x)))
  1658. ;; Set up `font-lock-keywords' last because its value might depend
  1659. ;; on other settings (e.g. font-lock-compile-keywords uses
  1660. ;; font-lock-beginning-of-syntax-function).
  1661. (set (make-local-variable 'font-lock-keywords)
  1662. (font-lock-eval-keywords keywords))
  1663. ;; Local fontification?
  1664. (while local
  1665. (font-lock-add-keywords nil (car (car local)) (cdr (car local)))
  1666. (setq local (cdr local)))
  1667. (when removed-keywords
  1668. (font-lock-remove-keywords nil removed-keywords))
  1669. ;; Now compile the keywords.
  1670. (unless (eq (car font-lock-keywords) t)
  1671. (setq font-lock-keywords
  1672. (font-lock-compile-keywords font-lock-keywords))))))
  1673. ;;; Color etc. support.
  1674. ;; Note that `defface' will not overwrite any faces declared above via
  1675. ;; `custom-declare-face'.
  1676. (defface font-lock-comment-face
  1677. '((((class grayscale) (background light))
  1678. (:foreground "DimGray" :weight bold :slant italic))
  1679. (((class grayscale) (background dark))
  1680. (:foreground "LightGray" :weight bold :slant italic))
  1681. (((class color) (min-colors 88) (background light))
  1682. (:foreground "Firebrick"))
  1683. (((class color) (min-colors 88) (background dark))
  1684. (:foreground "chocolate1"))
  1685. (((class color) (min-colors 16) (background light))
  1686. (:foreground "red"))
  1687. (((class color) (min-colors 16) (background dark))
  1688. (:foreground "red1"))
  1689. (((class color) (min-colors 8) (background light))
  1690. (:foreground "red"))
  1691. (((class color) (min-colors 8) (background dark))
  1692. (:foreground "yellow"))
  1693. (t (:weight bold :slant italic)))
  1694. "Font Lock mode face used to highlight comments."
  1695. :group 'font-lock-faces)
  1696. (defface font-lock-comment-delimiter-face
  1697. '((default :inherit font-lock-comment-face))
  1698. "Font Lock mode face used to highlight comment delimiters."
  1699. :group 'font-lock-faces)
  1700. (defface font-lock-string-face
  1701. '((((class grayscale) (background light)) (:foreground "DimGray" :slant italic))
  1702. (((class grayscale) (background dark)) (:foreground "LightGray" :slant italic))
  1703. (((class color) (min-colors 88) (background light)) (:foreground "VioletRed4"))
  1704. (((class color) (min-colors 88) (background dark)) (:foreground "LightSalmon"))
  1705. (((class color) (min-colors 16) (background light)) (:foreground "RosyBrown"))
  1706. (((class color) (min-colors 16) (background dark)) (:foreground "LightSalmon"))
  1707. (((class color) (min-colors 8)) (:foreground "green"))
  1708. (t (:slant italic)))
  1709. "Font Lock mode face used to highlight strings."
  1710. :group 'font-lock-faces)
  1711. (defface font-lock-doc-face
  1712. '((t :inherit font-lock-string-face))
  1713. "Font Lock mode face used to highlight documentation."
  1714. :group 'font-lock-faces)
  1715. (defface font-lock-keyword-face
  1716. '((((class grayscale) (background light)) (:foreground "LightGray" :weight bold))
  1717. (((class grayscale) (background dark)) (:foreground "DimGray" :weight bold))
  1718. (((class color) (min-colors 88) (background light)) (:foreground "Purple"))
  1719. (((class color) (min-colors 88) (background dark)) (:foreground "Cyan1"))
  1720. (((class color) (min-colors 16) (background light)) (:foreground "Purple"))
  1721. (((class color) (min-colors 16) (background dark)) (:foreground "Cyan"))
  1722. (((class color) (min-colors 8)) (:foreground "cyan" :weight bold))
  1723. (t (:weight bold)))
  1724. "Font Lock mode face used to highlight keywords."
  1725. :group 'font-lock-faces)
  1726. (defface font-lock-builtin-face
  1727. '((((class grayscale) (background light)) (:foreground "LightGray" :weight bold))
  1728. (((class grayscale) (background dark)) (:foreground "DimGray" :weight bold))
  1729. (((class color) (min-colors 88) (background light)) (:foreground "dark slate blue"))
  1730. (((class color) (min-colors 88) (background dark)) (:foreground "LightSteelBlue"))
  1731. (((class color) (min-colors 16) (background light)) (:foreground "Orchid"))
  1732. (((class color) (min-colors 16) (background dark)) (:foreground "LightSteelBlue"))
  1733. (((class color) (min-colors 8)) (:foreground "blue" :weight bold))
  1734. (t (:weight bold)))
  1735. "Font Lock mode face used to highlight builtins."
  1736. :group 'font-lock-faces)
  1737. (defface font-lock-function-name-face
  1738. '((((class color) (min-colors 88) (background light)) (:foreground "Blue1"))
  1739. (((class color) (min-colors 88) (background dark)) (:foreground "LightSkyBlue"))
  1740. (((class color) (min-colors 16) (background light)) (:foreground "Blue"))
  1741. (((class color) (min-colors 16) (background dark)) (:foreground "LightSkyBlue"))
  1742. (((class color) (min-colors 8)) (:foreground "blue" :weight bold))
  1743. (t (:inverse-video t :weight bold)))
  1744. "Font Lock mode face used to highlight function names."
  1745. :group 'font-lock-faces)
  1746. (defface font-lock-variable-name-face
  1747. '((((class grayscale) (background light))
  1748. (:foreground "Gray90" :weight bold :slant italic))
  1749. (((class grayscale) (background dark))
  1750. (:foreground "DimGray" :weight bold :slant italic))
  1751. (((class color) (min-colors 88) (background light)) (:foreground "sienna"))
  1752. (((class color) (min-colors 88) (background dark)) (:foreground "LightGoldenrod"))
  1753. (((class color) (min-colors 16) (background light)) (:foreground "DarkGoldenrod"))
  1754. (((class color) (min-colors 16) (background dark)) (:foreground "LightGoldenrod"))
  1755. (((class color) (min-colors 8)) (:foreground "yellow" :weight light))
  1756. (t (:weight bold :slant italic)))
  1757. "Font Lock mode face used to highlight variable names."
  1758. :group 'font-lock-faces)
  1759. (defface font-lock-type-face
  1760. '((((class grayscale) (background light)) (:foreground "Gray90" :weight bold))
  1761. (((class grayscale) (background dark)) (:foreground "DimGray" :weight bold))
  1762. (((class color) (min-colors 88) (background light)) (:foreground "ForestGreen"))
  1763. (((class color) (min-colors 88) (background dark)) (:foreground "PaleGreen"))
  1764. (((class color) (min-colors 16) (background light)) (:foreground "ForestGreen"))
  1765. (((class color) (min-colors 16) (background dark)) (:foreground "PaleGreen"))
  1766. (((class color) (min-colors 8)) (:foreground "green"))
  1767. (t (:weight bold :underline t)))
  1768. "Font Lock mode face used to highlight type and classes."
  1769. :group 'font-lock-faces)
  1770. (defface font-lock-constant-face
  1771. '((((class grayscale) (background light))
  1772. (:foreground "LightGray" :weight bold :underline t))
  1773. (((class grayscale) (background dark))
  1774. (:foreground "Gray50" :weight bold :underline t))
  1775. (((class color) (min-colors 88) (background light)) (:foreground "dark cyan"))
  1776. (((class color) (min-colors 88) (background dark)) (:foreground "Aquamarine"))
  1777. (((class color) (min-colors 16) (background light)) (:foreground "CadetBlue"))
  1778. (((class color) (min-colors 16) (background dark)) (:foreground "Aquamarine"))
  1779. (((class color) (min-colors 8)) (:foreground "magenta"))
  1780. (t (:weight bold :underline t)))
  1781. "Font Lock mode face used to highlight constants and labels."
  1782. :group 'font-lock-faces)
  1783. (defface font-lock-warning-face
  1784. '((t :inherit error))
  1785. "Font Lock mode face used to highlight warnings."
  1786. :group 'font-lock-faces)
  1787. (defface font-lock-negation-char-face
  1788. '((t nil))
  1789. "Font Lock mode face used to highlight easy to overlook negation."
  1790. :group 'font-lock-faces)
  1791. (defface font-lock-preprocessor-face
  1792. '((t :inherit font-lock-builtin-face))
  1793. "Font Lock mode face used to highlight preprocessor directives."
  1794. :group 'font-lock-faces)
  1795. (defface font-lock-regexp-grouping-backslash
  1796. '((t :inherit bold))
  1797. "Font Lock mode face for backslashes in Lisp regexp grouping constructs."
  1798. :group 'font-lock-faces)
  1799. (defface font-lock-regexp-grouping-construct
  1800. '((t :inherit bold))
  1801. "Font Lock mode face used to highlight grouping constructs in Lisp regexps."
  1802. :group 'font-lock-faces)
  1803. ;;; End of Color etc. support.
  1804. ;;; Menu support.
  1805. ;; This section of code is commented out because Emacs does not have real menu
  1806. ;; buttons. (We can mimic them by putting "( ) " or "(X) " at the beginning of
  1807. ;; the menu entry text, but with Xt it looks both ugly and embarrassingly
  1808. ;; amateur.) If/When Emacs gets real menus buttons, put in menu-bar.el after
  1809. ;; the entry for "Text Properties" something like:
  1810. ;;
  1811. ;; (define-key menu-bar-edit-menu [font-lock]
  1812. ;; (cons "Syntax Highlighting" font-lock-menu))
  1813. ;;
  1814. ;; and remove a single ";" from the beginning of each line in the rest of this
  1815. ;; section. Probably the mechanism for telling the menu code what are menu
  1816. ;; buttons and when they are on or off needs tweaking. I have assumed that the
  1817. ;; mechanism is via `menu-toggle' and `menu-selected' symbol properties. sm.
  1818. ;;;;;###autoload
  1819. ;;(progn
  1820. ;; ;; Make the Font Lock menu.
  1821. ;; (defvar font-lock-menu (make-sparse-keymap "Syntax Highlighting"))
  1822. ;; ;; Add the menu items in reverse order.
  1823. ;; (define-key font-lock-menu [fontify-less]
  1824. ;; '("Less In Current Buffer" . font-lock-fontify-less))
  1825. ;; (define-key font-lock-menu [fontify-more]
  1826. ;; '("More In Current Buffer" . font-lock-fontify-more))
  1827. ;; (define-key font-lock-menu [font-lock-sep]
  1828. ;; '("--"))
  1829. ;; (define-key font-lock-menu [font-lock-mode]
  1830. ;; '("In Current Buffer" . font-lock-mode))
  1831. ;; (define-key font-lock-menu [global-font-lock-mode]
  1832. ;; '("In All Buffers" . global-font-lock-mode)))
  1833. ;;
  1834. ;;;;;###autoload
  1835. ;;(progn
  1836. ;; ;; We put the appropriate `menu-enable' etc. symbol property values on when
  1837. ;; ;; font-lock.el is loaded, so we don't need to autoload the three variables.
  1838. ;; (put 'global-font-lock-mode 'menu-toggle t)
  1839. ;; (put 'font-lock-mode 'menu-toggle t)
  1840. ;; (put 'font-lock-fontify-more 'menu-enable '(identity))
  1841. ;; (put 'font-lock-fontify-less 'menu-enable '(identity)))
  1842. ;;
  1843. ;; ;; Put the appropriate symbol property values on now. See above.
  1844. ;;(put 'global-font-lock-mode 'menu-selected 'global-font-lock-mode)
  1845. ;;(put 'font-lock-mode 'menu-selected 'font-lock-mode)
  1846. ;;(put 'font-lock-fontify-more 'menu-enable '(nth 2 font-lock-fontify-level))
  1847. ;;(put 'font-lock-fontify-less 'menu-enable '(nth 1 font-lock-fontify-level))
  1848. ;;
  1849. ;;(defvar font-lock-fontify-level nil) ; For less/more fontification.
  1850. ;;
  1851. ;;(defun font-lock-fontify-level (level)
  1852. ;; (let ((font-lock-maximum-decoration level))
  1853. ;; (when font-lock-mode
  1854. ;; (font-lock-mode))
  1855. ;; (font-lock-mode)
  1856. ;; (when font-lock-verbose
  1857. ;; (message "Fontifying %s... level %d" (buffer-name) level))))
  1858. ;;
  1859. ;;(defun font-lock-fontify-less ()
  1860. ;; "Fontify the current buffer with less decoration.
  1861. ;;See `font-lock-maximum-decoration'."
  1862. ;; (interactive)
  1863. ;; ;; Check in case we get called interactively.
  1864. ;; (if (nth 1 font-lock-fontify-level)
  1865. ;; (font-lock-fontify-level (1- (car font-lock-fontify-level)))
  1866. ;; (error "No less decoration")))
  1867. ;;
  1868. ;;(defun font-lock-fontify-more ()
  1869. ;; "Fontify the current buffer with more decoration.
  1870. ;;See `font-lock-maximum-decoration'."
  1871. ;; (interactive)
  1872. ;; ;; Check in case we get called interactively.
  1873. ;; (if (nth 2 font-lock-fontify-level)
  1874. ;; (font-lock-fontify-level (1+ (car font-lock-fontify-level)))
  1875. ;; (error "No more decoration")))
  1876. ;;
  1877. ;; ;; This should be called by `font-lock-set-defaults'.
  1878. ;;(defun font-lock-set-menu ()
  1879. ;; ;; Activate less/more fontification entries if there are multiple levels for
  1880. ;; ;; the current buffer. Sets `font-lock-fontify-level' to be of the form
  1881. ;; ;; (CURRENT-LEVEL IS-LOWER-LEVEL-P IS-HIGHER-LEVEL-P) for menu activation.
  1882. ;; (let ((keywords (nth 0 font-lock-defaults))
  1883. ;; (level (font-lock-value-in-major-mode font-lock-maximum-decoration)))
  1884. ;; (make-local-variable 'font-lock-fontify-level)
  1885. ;; (if (or (symbolp keywords) (= (length keywords) 1))
  1886. ;; (font-lock-unset-menu)
  1887. ;; (cond ((eq level t)
  1888. ;; (setq level (1- (length keywords))))
  1889. ;; ((or (null level) (zerop level))
  1890. ;; ;; The default level is usually, but not necessarily, level 1.
  1891. ;; (setq level (- (length keywords)
  1892. ;; (length (member (eval (car keywords))
  1893. ;; (mapcar 'eval (cdr keywords))))))))
  1894. ;; (setq font-lock-fontify-level (list level (> level 1)
  1895. ;; (< level (1- (length keywords))))))))
  1896. ;;
  1897. ;; ;; This should be called by `font-lock-unset-defaults'.
  1898. ;;(defun font-lock-unset-menu ()
  1899. ;; ;; Deactivate less/more fontification entries.
  1900. ;; (setq font-lock-fontify-level nil))
  1901. ;;; End of Menu support.
  1902. ;;; Various regexp information shared by several modes.
  1903. ;; ;; Information specific to a single mode should go in its load library.
  1904. ;; Font Lock support for C, C++, Objective-C and Java modes is now in
  1905. ;; cc-fonts.el (and required by cc-mode.el). However, the below function
  1906. ;; should stay in font-lock.el, since it is used by other libraries. sm.
  1907. (defun font-lock-match-c-style-declaration-item-and-skip-to-next (limit)
  1908. "Match, and move over, any declaration/definition item after point.
  1909. Matches after point, but ignores leading whitespace and `*' characters.
  1910. Does not move further than LIMIT.
  1911. The expected syntax of a declaration/definition item is `word' (preceded by
  1912. optional whitespace and `*' characters and proceeded by optional whitespace)
  1913. optionally followed by a `('. Everything following the item (but belonging to
  1914. it) is expected to be skip-able by `scan-sexps', and items are expected to be
  1915. separated with a `,' and to be terminated with a `;'.
  1916. Thus the regexp matches after point: word (
  1917. ^^^^ ^
  1918. Where the match subexpressions are: 1 2
  1919. The item is delimited by (match-beginning 1) and (match-end 1).
  1920. If (match-beginning 2) is non-nil, the item is followed by a `('.
  1921. This function could be MATCHER in a MATCH-ANCHORED `font-lock-keywords' item."
  1922. (when (looking-at "[ \n\t*]*\\(\\sw+\\)[ \t\n]*\\(((?\\)?")
  1923. (when (and (match-end 2) (> (- (match-end 2) (match-beginning 2)) 1))
  1924. ;; If `word' is followed by a double open-paren, it's probably
  1925. ;; a macro used for "int myfun P_ ((int arg1))". Let's go back one
  1926. ;; word to try and match `myfun' rather than `P_'.
  1927. (let ((pos (point)))
  1928. (skip-chars-backward " \t\n")
  1929. (skip-syntax-backward "w")
  1930. (unless (looking-at "\\(\\sw+\\)[ \t\n]*\\sw+[ \t\n]*\\(((?\\)?")
  1931. ;; Looks like it was something else, so go back to where we
  1932. ;; were and reset the match data by rematching.
  1933. (goto-char pos)
  1934. (looking-at "[ \n\t*]*\\(\\sw+\\)[ \t\n]*\\(((?\\)?"))))
  1935. (save-match-data
  1936. (condition-case nil
  1937. (save-restriction
  1938. ;; Restrict to the LIMIT.
  1939. (narrow-to-region (point-min) limit)
  1940. (goto-char (match-end 1))
  1941. ;; Move over any item value, etc., to the next item.
  1942. (while (not (looking-at "[ \t\n]*\\(\\(,\\)\\|;\\|\\'\\)"))
  1943. (goto-char (or (scan-sexps (point) 1) (point-max))))
  1944. (if (match-end 2)
  1945. (goto-char (match-end 2))))
  1946. (error t)))))
  1947. ;; C preprocessor(cpp) is used outside of C, C++ and Objective-C source file.
  1948. ;; e.g. assembler code and GNU linker script in Linux kernel.
  1949. ;; `cpp-font-lock-keywords' is handy for modes for the files.
  1950. ;;
  1951. ;; Here we cannot use `regexp-opt' because because regex-opt is not preloaded
  1952. ;; while font-lock.el is preloaded to emacs. So values pre-calculated with
  1953. ;; regexp-opt are used here.
  1954. ;; `cpp-font-lock-keywords-source-directives' is calculated from:
  1955. ;;
  1956. ;; (regexp-opt
  1957. ;; '("define" "elif" "else" "endif" "error" "file" "if" "ifdef"
  1958. ;; "ifndef" "import" "include" "line" "pragma" "undef" "warning"))
  1959. ;;
  1960. (defconst cpp-font-lock-keywords-source-directives
  1961. "define\\|e\\(?:l\\(?:if\\|se\\)\\|ndif\\|rror\\)\\|file\\|i\\(?:f\\(?:n?def\\)?\\|mport\\|nclude\\)\\|line\\|pragma\\|undef\\|warning"
  1962. "Regular expression used in `cpp-font-lock-keywords'.")
  1963. ;; `cpp-font-lock-keywords-source-depth' is calculated from:
  1964. ;;
  1965. ;; (regexp-opt-depth (regexp-opt
  1966. ;; '("define" "elif" "else" "endif" "error" "file" "if" "ifdef"
  1967. ;; "ifndef" "import" "include" "line" "pragma" "undef" "warning")))
  1968. ;;
  1969. (defconst cpp-font-lock-keywords-source-depth 0
  1970. "An integer representing regular expression depth of `cpp-font-lock-keywords-source-directives'.
  1971. Used in `cpp-font-lock-keywords'.")
  1972. (defconst cpp-font-lock-keywords
  1973. (let* ((directives cpp-font-lock-keywords-source-directives)
  1974. (directives-depth cpp-font-lock-keywords-source-depth))
  1975. (list
  1976. ;;
  1977. ;; Fontify error directives.
  1978. '("^#[ \t]*\\(?:error\\|warning\\)[ \t]+\\(.+\\)" 1 font-lock-warning-face prepend)
  1979. ;;
  1980. ;; Fontify filenames in #include <...> preprocessor directives as strings.
  1981. '("^#[ \t]*\\(?:import\\|include\\)[ \t]*\\(<[^>\"\n]*>?\\)"
  1982. 1 font-lock-string-face prepend)
  1983. ;;
  1984. ;; Fontify function macro names.
  1985. '("^#[ \t]*define[ \t]+\\([[:alpha:]_][[:alnum:]_$]*\\)("
  1986. (1 font-lock-function-name-face prepend)
  1987. ;;
  1988. ;; Macro arguments.
  1989. ((lambda (limit)
  1990. (re-search-forward
  1991. "\\(?:\\([[:alpha:]_][[:alnum:]_]*\\)[,]?\\)"
  1992. (or (save-excursion (re-search-forward ")" limit t))
  1993. limit)
  1994. t))
  1995. nil nil (1 font-lock-variable-name-face prepend)))
  1996. ;;
  1997. ;; Fontify symbol names in #elif or #if ... defined preprocessor directives.
  1998. '("^#[ \t]*\\(?:elif\\|if\\)\\>"
  1999. ("\\<\\(defined\\)\\>[ \t]*(?\\([[:alpha:]_][[:alnum:]_]*\\)?" nil nil
  2000. (1 font-lock-builtin-face prepend) (2 font-lock-variable-name-face prepend t)))
  2001. ;;
  2002. ;; Fontify otherwise as symbol names, and the preprocessor directive names.
  2003. (list
  2004. (concat "^\\(#[ \t]*\\(?:" directives
  2005. "\\)\\)\\>[ \t!]*\\([[:alpha:]_][[:alnum:]_]*\\)?")
  2006. '(1 font-lock-preprocessor-face prepend)
  2007. (list (+ 2 directives-depth)
  2008. 'font-lock-variable-name-face nil t))))
  2009. "Font lock keywords for C preprocessor directives.
  2010. `c-mode', `c++-mode' and `objc-mode' have their own font lock keywords
  2011. for C preprocessor directives. This definition is for the other modes
  2012. in which C preprocessor directives are used. e.g. `asm-mode' and
  2013. `ld-script-mode'.")
  2014. ;; Lisp.
  2015. (defconst lisp-font-lock-keywords-1
  2016. (eval-when-compile
  2017. `(;; Definitions.
  2018. (,(concat "(\\(def\\("
  2019. ;; Function declarations.
  2020. "\\(advice\\|alias\\|generic\\|macro\\*?\\|method\\|"
  2021. "setf\\|subst\\*?\\|un\\*?\\|"
  2022. "ine-\\(condition\\|"
  2023. "\\(?:derived\\|\\(?:global\\(?:ized\\)?-\\)?minor\\|generic\\)-mode\\|"
  2024. "method-combination\\|setf-expander\\|skeleton\\|widget\\|"
  2025. "function\\|\\(compiler\\|modify\\|symbol\\)-macro\\)\\)\\|"
  2026. ;; Variable declarations.
  2027. "\\(const\\(ant\\)?\\|custom\\|varalias\\|face\\|parameter\\|var\\)\\|"
  2028. ;; Structure declarations.
  2029. "\\(class\\|group\\|theme\\|package\\|struct\\|type\\)"
  2030. "\\)\\)\\>"
  2031. ;; Any whitespace and defined object.
  2032. "[ \t'\(]*"
  2033. "\\(setf[ \t]+\\sw+\\|\\sw+\\)?")
  2034. (1 font-lock-keyword-face)
  2035. (9 (cond ((match-beginning 3) font-lock-function-name-face)
  2036. ((match-beginning 6) font-lock-variable-name-face)
  2037. (t font-lock-type-face))
  2038. nil t))
  2039. ;; Emacs Lisp autoload cookies. Supports the slightly different
  2040. ;; forms used by mh-e, calendar, etc.
  2041. ("^;;;###\\([-a-z]*autoload\\)" 1 font-lock-warning-face prepend)
  2042. ;; Regexp negated char group.
  2043. ("\\[\\(\\^\\)" 1 font-lock-negation-char-face prepend)))
  2044. "Subdued level highlighting for Lisp modes.")
  2045. (defconst lisp-font-lock-keywords-2
  2046. (append lisp-font-lock-keywords-1
  2047. (eval-when-compile
  2048. `(;; Control structures. Emacs Lisp forms.
  2049. (,(concat
  2050. "(" (regexp-opt
  2051. '("cond" "if" "while" "while-no-input" "let" "let*" "letrec"
  2052. "prog" "progn" "progv" "prog1" "prog2" "prog*"
  2053. "inline" "lambda" "save-restriction" "save-excursion"
  2054. "save-selected-window" "save-window-excursion"
  2055. "save-match-data" "save-current-buffer"
  2056. "combine-after-change-calls" "unwind-protect"
  2057. "condition-case" "condition-case-unless-debug"
  2058. "track-mouse" "eval-after-load" "eval-and-compile"
  2059. "eval-when-compile" "eval-when" "eval-next-after-load"
  2060. "with-case-table" "with-category-table"
  2061. "with-current-buffer" "with-demoted-errors"
  2062. "with-electric-help"
  2063. "with-local-quit" "with-no-warnings"
  2064. "with-output-to-string" "with-output-to-temp-buffer"
  2065. "with-selected-window" "with-selected-frame"
  2066. "with-silent-modifications" "with-syntax-table"
  2067. "with-temp-buffer" "with-temp-file" "with-temp-message"
  2068. "with-timeout" "with-timeout-handler" "with-wrapper-hook") t)
  2069. "\\>")
  2070. . 1)
  2071. ;; Control structures. Common Lisp forms.
  2072. (,(concat
  2073. "(" (regexp-opt
  2074. '("when" "unless" "case" "ecase" "typecase" "etypecase"
  2075. "ccase" "ctypecase" "handler-case" "handler-bind"
  2076. "restart-bind" "restart-case" "in-package"
  2077. "break" "ignore-errors"
  2078. "loop" "do" "do*" "dotimes" "dolist" "the" "locally"
  2079. "proclaim" "declaim" "declare" "symbol-macrolet" "letf"
  2080. "lexical-let" "lexical-let*" "flet" "labels" "compiler-let"
  2081. "destructuring-bind" "macrolet" "tagbody" "block" "go"
  2082. "multiple-value-bind" "multiple-value-prog1"
  2083. "return" "return-from"
  2084. "with-accessors" "with-compilation-unit"
  2085. "with-condition-restarts" "with-hash-table-iterator"
  2086. "with-input-from-string" "with-open-file"
  2087. "with-open-stream" "with-output-to-string"
  2088. "with-package-iterator" "with-simple-restart"
  2089. "with-slots" "with-standard-io-syntax") t)
  2090. "\\>")
  2091. . 1)
  2092. ;; Exit/Feature symbols as constants.
  2093. (,(concat "(\\(catch\\|throw\\|featurep\\|provide\\|require\\)\\>"
  2094. "[ \t']*\\(\\sw+\\)?")
  2095. (1 font-lock-keyword-face)
  2096. (2 font-lock-constant-face nil t))
  2097. ;; Erroneous structures.
  2098. ("(\\(abort\\|assert\\|warn\\|check-type\\|cerror\\|error\\|signal\\)\\>" 1 font-lock-warning-face)
  2099. ;; Words inside \\[] tend to be for `substitute-command-keys'.
  2100. ("\\\\\\\\\\[\\(\\sw+\\)\\]" 1 font-lock-constant-face prepend)
  2101. ;; Words inside `' tend to be symbol names.
  2102. ("`\\(\\sw\\sw+\\)'" 1 font-lock-constant-face prepend)
  2103. ;; Constant values.
  2104. ("\\<:\\sw+\\>" 0 font-lock-builtin-face)
  2105. ;; ELisp and CLisp `&' keywords as types.
  2106. ("\\<\\&\\sw+\\>" . font-lock-type-face)
  2107. ;; ELisp regexp grouping constructs
  2108. ((lambda (bound)
  2109. (catch 'found
  2110. ;; The following loop is needed to continue searching after matches
  2111. ;; that do not occur in strings. The associated regexp matches one
  2112. ;; of `\\\\' `\\(' `\\(?:' `\\|' `\\)'. `\\\\' has been included to
  2113. ;; avoid highlighting, for example, `\\(' in `\\\\('.
  2114. (while (re-search-forward "\\(\\\\\\\\\\)\\(?:\\(\\\\\\\\\\)\\|\\((\\(?:\\?[0-9]*:\\)?\\|[|)]\\)\\)" bound t)
  2115. (unless (match-beginning 2)
  2116. (let ((face (get-text-property (1- (point)) 'face)))
  2117. (when (or (and (listp face)
  2118. (memq 'font-lock-string-face face))
  2119. (eq 'font-lock-string-face face))
  2120. (throw 'found t)))))))
  2121. (1 'font-lock-regexp-grouping-backslash prepend)
  2122. (3 'font-lock-regexp-grouping-construct prepend))
  2123. ;;; This is too general -- rms.
  2124. ;;; A user complained that he has functions whose names start with `do'
  2125. ;;; and that they get the wrong color.
  2126. ;;; ;; CL `with-' and `do-' constructs
  2127. ;;; ("(\\(\\(do-\\|with-\\)\\(\\s_\\|\\w\\)*\\)" 1 font-lock-keyword-face)
  2128. )))
  2129. "Gaudy level highlighting for Lisp modes.")
  2130. (defvar lisp-font-lock-keywords lisp-font-lock-keywords-1
  2131. "Default expressions to highlight in Lisp modes.")
  2132. (provide 'font-lock)
  2133. ;;; font-lock.el ends here