comparison lisp/font-lock.el @ 32216:82e4865603dd

(font-lock-defaults-alist): Remove the TeX entries. (tex-font-lock-keywords, tex-font-lock-keywords-2) (tex-font-lock-keywords-1): Remove. (font-lock-turn-on-thing-lock): Use jit-lock-register. (font-lock-turn-off-thing-lock): Use jit-lock-unregister. (font-lock-default-fontify-region): Expand beg..end correctly when just following a multiline region. (font-lock-fontify-anchored-keywords): Include the anchor text as part of the multiline.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Fri, 06 Oct 2000 16:02:27 +0000
parents 9ef4cd44aaab
children ad080e900685
comparison
equal deleted inserted replaced
32215:2769976809f1 32216:82e4865603dd
472 (font-lock-mark-block-function . mark-defun))) 472 (font-lock-mark-block-function . mark-defun)))
473 (lisp-mode-defaults 473 (lisp-mode-defaults
474 '((lisp-font-lock-keywords 474 '((lisp-font-lock-keywords
475 lisp-font-lock-keywords-1 lisp-font-lock-keywords-2) 475 lisp-font-lock-keywords-1 lisp-font-lock-keywords-2)
476 nil nil (("+-*/.<>=!?$%_&~^:" . "w")) beginning-of-defun 476 nil nil (("+-*/.<>=!?$%_&~^:" . "w")) beginning-of-defun
477 (font-lock-mark-block-function . mark-defun))) 477 (font-lock-mark-block-function . mark-defun))))
478 ;; For TeX modes we could use `backward-paragraph' for the same reason.
479 ;; But we don't, because paragraph breaks are arguably likely enough to
480 ;; occur within a genuine syntactic block to make it too risky.
481 ;; However, we do specify a MARK-BLOCK function as that cannot result
482 ;; in a mis-fontification even if it might not fontify enough. sm.
483 (tex-mode-defaults
484 '((tex-font-lock-keywords
485 tex-font-lock-keywords-1 tex-font-lock-keywords-2)
486 nil nil ((?$ . "\"")) nil
487 (font-lock-mark-block-function . mark-paragraph)))
488 )
489 (list 478 (list
490 (cons 'c-mode c-mode-defaults) 479 (cons 'c-mode c-mode-defaults)
491 (cons 'c++-mode c++-mode-defaults) 480 (cons 'c++-mode c++-mode-defaults)
492 (cons 'objc-mode objc-mode-defaults) 481 (cons 'objc-mode objc-mode-defaults)
493 (cons 'java-mode java-mode-defaults) 482 (cons 'java-mode java-mode-defaults)
494 (cons 'emacs-lisp-mode lisp-mode-defaults) 483 (cons 'emacs-lisp-mode lisp-mode-defaults)
495 (cons 'latex-mode tex-mode-defaults)
496 (cons 'lisp-mode lisp-mode-defaults) 484 (cons 'lisp-mode lisp-mode-defaults)
497 (cons 'lisp-interaction-mode lisp-mode-defaults) 485 (cons 'lisp-interaction-mode lisp-mode-defaults)))
498 (cons 'plain-tex-mode tex-mode-defaults)
499 (cons 'slitex-mode tex-mode-defaults)
500 (cons 'tex-mode tex-mode-defaults)))
501 "Alist of fall-back Font Lock defaults for major modes. 486 "Alist of fall-back Font Lock defaults for major modes.
502 Each item should be a list of the form: 487 Each item should be a list of the form:
503 488
504 (MAJOR-MODE . FONT-LOCK-DEFAULTS) 489 (MAJOR-MODE . FONT-LOCK-DEFAULTS)
505 490
1085 (cond ((eq thing-mode 'fast-lock-mode) 1070 (cond ((eq thing-mode 'fast-lock-mode)
1086 (fast-lock-mode t)) 1071 (fast-lock-mode t))
1087 ((eq thing-mode 'lazy-lock-mode) 1072 ((eq thing-mode 'lazy-lock-mode)
1088 (lazy-lock-mode t)) 1073 (lazy-lock-mode t))
1089 ((eq thing-mode 'jit-lock-mode) 1074 ((eq thing-mode 'jit-lock-mode)
1090 (jit-lock-mode t))))) 1075 ;; Prepare for jit-lock
1076 (remove-hook 'after-change-functions
1077 'font-lock-after-change-function t)
1078 (set (make-local-variable 'font-lock-fontify-buffer-function)
1079 'jit-lock-fontify-buffer)
1080 ;; Don't fontify eagerly (and don't abort is the buffer is large).
1081 (set (make-local-variable 'font-lock-fontified) t)
1082 ;; Use jit-lock.
1083 (jit-lock-register 'font-lock-fontify-region
1084 (not font-lock-keywords-only))))))
1091 1085
1092 (defun font-lock-turn-off-thing-lock () 1086 (defun font-lock-turn-off-thing-lock ()
1093 (cond (fast-lock-mode 1087 (cond (fast-lock-mode
1094 (fast-lock-mode nil)) 1088 (fast-lock-mode nil))
1095 (jit-lock-mode 1089 (jit-lock-mode
1096 (jit-lock-mode nil)) 1090 (jit-lock-unregister 'font-lock-fontify-region)
1091 ;; Reset local vars to the non-jit-lock case.
1092 (kill-local-variable 'font-lock-fontify-buffer-function))
1097 (lazy-lock-mode 1093 (lazy-lock-mode
1098 (lazy-lock-mode nil)))) 1094 (lazy-lock-mode nil))))
1099 1095
1100 (defun font-lock-after-fontify-buffer () 1096 (defun font-lock-after-fontify-buffer ()
1101 (cond (fast-lock-mode 1097 (cond (fast-lock-mode
1222 ;; Use the fontification syntax table, if any. 1218 ;; Use the fontification syntax table, if any.
1223 (when font-lock-syntax-table 1219 (when font-lock-syntax-table
1224 (set-syntax-table font-lock-syntax-table)) 1220 (set-syntax-table font-lock-syntax-table))
1225 ;; check to see if we should expand the beg/end area for 1221 ;; check to see if we should expand the beg/end area for
1226 ;; proper multiline matches 1222 ;; proper multiline matches
1227 (setq beg (if (get-text-property beg 'font-lock-multiline) 1223 (when (and (> beg (point-min))
1228 ;; if the text-property is non-nil, (1+ beg) 1224 (get-text-property (1- beg) 'font-lock-multiline))
1229 ;; is valid. We need to use (1+ beg) for the 1225 ;; We are just after or in a multiline match.
1230 ;; case where (get-text-property (1- beg)) is nil 1226 (setq beg (or (previous-single-property-change
1231 ;; in which case we want to keep BEG but 1227 beg 'font-lock-multiline)
1232 ;; previous-single-property-change will return 1228 (point-min))))
1233 ;; the previous change (if any) rather than
1234 ;; the one at BEG.
1235 (or (previous-single-property-change
1236 (1+ beg) 'font-lock-multiline)
1237 (point-min))
1238 beg))
1239 (setq end (or (text-property-any end (point-max) 1229 (setq end (or (text-property-any end (point-max)
1240 'font-lock-multiline nil) 1230 'font-lock-multiline nil)
1241 (point-max))) 1231 (point-max)))
1242 ;; Now do the fontification. 1232 ;; Now do the fontification.
1243 (font-lock-unfontify-region beg end) 1233 (font-lock-unfontify-region beg end)
1585 (funcall (if (eq font-lock-multiline t) '>= '>) 1575 (funcall (if (eq font-lock-multiline t) '>= '>)
1586 pre-match-value 1576 pre-match-value
1587 (line-beginning-position 2))) 1577 (line-beginning-position 2)))
1588 ;; this is a multiline anchored match 1578 ;; this is a multiline anchored match
1589 (setq font-lock-multiline t) 1579 (setq font-lock-multiline t)
1590 (put-text-property (point) limit 'font-lock-multiline t))) 1580 (put-text-property (min lead-start (point)) limit
1581 'font-lock-multiline t)))
1591 (save-match-data 1582 (save-match-data
1592 ;; Find an occurrence of `matcher' before `limit'. 1583 ;; Find an occurrence of `matcher' before `limit'.
1593 (while (and (< (point) limit) 1584 (while (and (< (point) limit)
1594 (if (stringp matcher) 1585 (if (stringp matcher)
1595 (re-search-forward matcher limit t) 1586 (re-search-forward matcher limit t)
2185 "Gaudy level highlighting for Lisp modes.") 2176 "Gaudy level highlighting for Lisp modes.")
2186 2177
2187 (defvar lisp-font-lock-keywords lisp-font-lock-keywords-1 2178 (defvar lisp-font-lock-keywords lisp-font-lock-keywords-1
2188 "Default expressions to highlight in Lisp modes.") 2179 "Default expressions to highlight in Lisp modes.")
2189 2180
2190 ;; TeX.
2191
2192 ;(defvar tex-font-lock-keywords
2193 ; ;; Regexps updated with help from Ulrik Dickow <dickow@nbi.dk>.
2194 ; '(("\\\\\\(begin\\|end\\|newcommand\\){\\([a-zA-Z0-9\\*]+\\)}"
2195 ; 2 font-lock-function-name-face)
2196 ; ("\\\\\\(cite\\|label\\|pageref\\|ref\\){\\([^} \t\n]+\\)}"
2197 ; 2 font-lock-constant-face)
2198 ; ;; It seems a bit dubious to use `bold' and `italic' faces since we might
2199 ; ;; not be able to display those fonts.
2200 ; ("{\\\\bf\\([^}]+\\)}" 1 'bold keep)
2201 ; ("{\\\\\\(em\\|it\\|sl\\)\\([^}]+\\)}" 2 'italic keep)
2202 ; ("\\\\\\([a-zA-Z@]+\\|.\\)" . font-lock-keyword-face)
2203 ; ("^[ \t\n]*\\\\def[\\\\@]\\(\\w+\\)" 1 font-lock-function-name-face keep))
2204 ; ;; Rewritten and extended for LaTeX2e by Ulrik Dickow <dickow@nbi.dk>.
2205 ; '(("\\\\\\(begin\\|end\\|newcommand\\){\\([a-zA-Z0-9\\*]+\\)}"
2206 ; 2 font-lock-function-name-face)
2207 ; ("\\\\\\(cite\\|label\\|pageref\\|ref\\){\\([^} \t\n]+\\)}"
2208 ; 2 font-lock-constant-face)
2209 ; ("^[ \t]*\\\\def\\\\\\(\\(\\w\\|@\\)+\\)" 1 font-lock-function-name-face)
2210 ; "\\\\\\([a-zA-Z@]+\\|.\\)"
2211 ; ;; It seems a bit dubious to use `bold' and `italic' faces since we might
2212 ; ;; not be able to display those fonts.
2213 ; ;; LaTeX2e: \emph{This is emphasized}.
2214 ; ("\\\\emph{\\([^}]+\\)}" 1 'italic keep)
2215 ; ;; LaTeX2e: \textbf{This is bold}, \textit{...}, \textsl{...}
2216 ; ("\\\\text\\(\\(bf\\)\\|it\\|sl\\){\\([^}]+\\)}"
2217 ; 3 (if (match-beginning 2) 'bold 'italic) keep)
2218 ; ;; Old-style bf/em/it/sl. Stop at `\\' and un-escaped `&', for tables.
2219 ; ("\\\\\\(\\(bf\\)\\|em\\|it\\|sl\\)\\>\\(\\([^}&\\]\\|\\\\[^\\]\\)+\\)"
2220 ; 3 (if (match-beginning 2) 'bold 'italic) keep))
2221
2222 ;; Rewritten with the help of Alexandra Bac <abac@welcome.disi.unige.it>.
2223 (defconst tex-font-lock-keywords-1
2224 (eval-when-compile
2225 (let* (;; Names of commands whose arg should be fontified as heading, etc.
2226 (headings (regexp-opt
2227 '("title" "begin" "end" "chapter" "part"
2228 "section" "subsection" "subsubsection"
2229 "paragraph" "subparagraph" "subsubparagraph"
2230 "newcommand" "renewcommand" "newenvironment"
2231 "newtheorem")
2232 t))
2233 (variables (regexp-opt
2234 '("newcounter" "newcounter*" "setcounter" "addtocounter"
2235 "setlength" "addtolength" "settowidth")
2236 t))
2237 (includes (regexp-opt
2238 '("input" "include" "includeonly" "bibliography"
2239 "epsfig" "psfig" "epsf" "nofiles" "usepackage"
2240 "includegraphics" "includegraphics*")
2241 t))
2242 ;; Miscellany.
2243 (slash "\\\\")
2244 (opt "\\(\\[[^]]*\\]\\)?")
2245 (arg "{\\(\\(?:[^{}]+\\(?:{[^}]*}\\)?\\)+\\)"))
2246 (list
2247 ;; Heading args.
2248 (list (concat slash headings "\\*?" opt arg)
2249 3 'font-lock-function-name-face 'prepend)
2250 ;; Variable args.
2251 (list (concat slash variables arg) 2 'font-lock-variable-name-face)
2252 ;; Include args.
2253 (list (concat slash includes opt arg) 3 'font-lock-builtin-face)
2254 ;; Definitions. I think.
2255 '("^[ \t]*\\\\def\\\\\\(\\(\\w\\|@\\)+\\)"
2256 1 font-lock-function-name-face)
2257 )))
2258 "Subdued expressions to highlight in TeX modes.")
2259
2260 (defconst tex-font-lock-keywords-2
2261 (append tex-font-lock-keywords-1
2262 (eval-when-compile
2263 (let* (;;
2264 ;; Names of commands whose arg should be fontified with fonts.
2265 (bold (regexp-opt '("bf" "textbf" "textsc" "textup"
2266 "boldsymbol" "pmb") t))
2267 (italic (regexp-opt '("it" "textit" "textsl" "emph") t))
2268 (type (regexp-opt '("texttt" "textmd" "textrm" "textsf") t))
2269 ;;
2270 ;; Names of commands whose arg should be fontified as a citation.
2271 (citations (regexp-opt
2272 '("label" "ref" "pageref" "vref" "eqref"
2273 "cite" "nocite" "caption" "index" "glossary"
2274 "footnote" "footnotemark" "footnotetext")
2275 t))
2276 ;;
2277 ;; Names of commands that should be fontified.
2278 (specials (regexp-opt
2279 '("\\"
2280 "linebreak" "nolinebreak" "pagebreak" "nopagebreak"
2281 "newline" "newpage" "clearpage" "cleardoublepage"
2282 "displaybreak" "allowdisplaybreaks" "enlargethispage")
2283 t))
2284 (general "\\([a-zA-Z@]+\\**\\|[^ \t\n]\\)")
2285 ;;
2286 ;; Miscellany.
2287 (slash "\\\\")
2288 (opt "\\(\\[[^]]*\\]\\)?")
2289 (arg "{\\(\\(?:[^{}]+\\(?:{[^}]*}\\)?\\)+\\)"))
2290 (list
2291 ;;
2292 ;; Citation args.
2293 (list (concat slash citations opt arg) 3 'font-lock-constant-face)
2294 ;;
2295 ;; Command names, special and general.
2296 (cons (concat slash specials) 'font-lock-warning-face)
2297 (concat slash general)
2298 ;;
2299 ;; Font environments. It seems a bit dubious to use `bold' etc. faces
2300 ;; since we might not be able to display those fonts.
2301 (list (concat slash bold arg) 2 '(quote bold) 'append)
2302 (list (concat slash italic arg) 2 '(quote italic) 'append)
2303 (list (concat slash type arg) 2 '(quote bold-italic) 'append)
2304 ;;
2305 ;; Old-style bf/em/it/sl. Stop at `\\' and un-escaped `&', for tables.
2306 (list (concat "\\\\\\(\\(bf\\)\\|em\\|it\\|sl\\)\\>"
2307 "\\(\\([^}&\\]\\|\\\\[^\\]\\)+\\)")
2308 3 '(if (match-beginning 2) 'bold 'italic) 'append)
2309 ))))
2310 "Gaudy expressions to highlight in TeX modes.")
2311
2312 (defvar tex-font-lock-keywords tex-font-lock-keywords-1
2313 "Default expressions to highlight in TeX modes.")
2314
2315 ;;; User choices. 2181 ;;; User choices.
2316 2182
2317 ;; These provide a means to fontify types not defined by the language. Those 2183 ;; These provide a means to fontify types not defined by the language. Those
2318 ;; types might be the user's own or they might be generally accepted and used. 2184 ;; types might be the user's own or they might be generally accepted and used.
2319 ;; Generally accepted types are used to provide default variable values. 2185 ;; Generally accepted types are used to provide default variable values.