927 |
|
|
928 |
(defface font-latex-superscript-face |
(defface font-latex-superscript-face |
929 |
'((t (:height 0.8))) |
'((t (:height 0.8))) |
930 |
"Face used for superscripts.") |
"Face used for superscripts." |
931 |
|
:group 'font-latex-highlighting-faces) |
932 |
|
|
933 |
(defface font-latex-subscript-face |
(defface font-latex-subscript-face |
934 |
'((t (:height 0.8))) |
'((t (:height 0.8))) |
935 |
"Face used for subscripts.") |
"Face used for subscripts." |
936 |
|
:group 'font-latex-highlighting-faces) |
937 |
|
|
938 |
|
|
939 |
;;; Setup |
;;; Setup |
1266 |
;; 'font-latex-match-command-cache keywords limit))) |
;; 'font-latex-match-command-cache keywords limit))) |
1267 |
(when font-latex-use-cache |
(when font-latex-use-cache |
1268 |
(font-latex-check-cache 'font-latex-match-command-cache keywords limit)) |
(font-latex-check-cache 'font-latex-match-command-cache keywords limit)) |
1269 |
(when (re-search-forward keywords limit t) |
(catch 'match |
1270 |
(cond |
(while (re-search-forward keywords limit t) |
1271 |
((or (font-latex-faces-present-p '(font-lock-comment-face |
(catch 'irrelevant |
1272 |
font-latex-verbatim-face) |
(when (or (font-latex-faces-present-p '(font-lock-comment-face |
1273 |
(match-beginning 0)) |
font-latex-verbatim-face) |
1274 |
(font-latex-commented-outp)) |
(match-beginning 0)) |
1275 |
;; Return a dummy match such that we skip over this pattern. |
(font-latex-commented-outp)) |
1276 |
;; (Would be better to skip over internally to this function) |
(throw 'irrelevant nil)) |
1277 |
;; We used to return a (nil nil) pattern match along with the |
(let ((kbeg (match-beginning 0)) |
1278 |
;; status of `t' to keep looking. font-lock was happy with that. |
kend sbeg send cbeg cend |
1279 |
;; But when font-lock-multiline is `t', the match really needs to |
cache-reset opt-arg |
1280 |
;; exists otherwise there is a elisp error at line 1625 of |
(parse-sexp-ignore-comments t)) ; scan-sexps ignores comments |
1281 |
;; font-lock.el in function font-lock-fontify-keywords-region. |
(save-restriction |
1282 |
(store-match-data (list (match-end 0)(match-end 0))) |
;; Restrict to LIMIT. |
1283 |
t) |
(narrow-to-region (point-min) limit) |
1284 |
(t |
(goto-char (match-end 0)) |
1285 |
(let ((kbeg (match-beginning 0)) |
(if (and asterisk (eq (following-char) ?\*)) |
1286 |
kend sbeg send cbeg cend |
(forward-char 1)) |
1287 |
cache-reset opt-arg |
(setq kend (point)) |
1288 |
(parse-sexp-ignore-comments t)) ; scan-sexps ignores comments |
(while (and (not (eobp)) (font-latex-forward-comment))) |
1289 |
(save-restriction |
;; Optional arguments [...] |
1290 |
;; Restrict to LIMIT. |
(while (eq (following-char) ?\[) |
1291 |
(narrow-to-region (point-min) limit) |
(unless opt-arg (setq sbeg (point)) (setq opt-arg t)) |
1292 |
(goto-char (match-end 0)) |
(if (font-latex-find-matching-close ?\[ ?\]) |
1293 |
(if (and asterisk (eq (following-char) ?\*)) |
(progn |
1294 |
(forward-char 1)) |
(setq send (point)) |
1295 |
(setq kend (point)) |
(while (and (not (eobp)) (font-latex-forward-comment)))) |
1296 |
(while (and (not (eobp)) (font-latex-forward-comment))) |
(setq cache-reset t) |
1297 |
;; Optional arguments [...] |
(setq send (point-max)) |
1298 |
(while (eq (following-char) ?\[) |
(goto-char send))) |
1299 |
(unless opt-arg (setq sbeg (point)) (setq opt-arg t)) |
;; Mandatory arguments {...} |
1300 |
(if (font-latex-find-matching-close ?\[ ?\]) |
(catch 'runaway |
1301 |
(progn |
(dotimes (i arg-count) |
1302 |
(setq send (point)) |
(when (eq (following-char) ?\{) |
1303 |
(while (and (not (eobp)) (font-latex-forward-comment)))) |
(when (= i 0) (setq cbeg (point))) |
1304 |
(setq cache-reset t) |
(if (font-latex-find-matching-close ?\{ ?\}) |
1305 |
(setq send (point-max)) |
(progn |
1306 |
(goto-char send))) |
(setq cend (point)) |
1307 |
;; Mandatory arguments {...} |
(while (and (not (eobp)) (font-latex-forward-comment)))) |
1308 |
(catch 'runaway |
(setq cache-reset t) |
1309 |
(dotimes (i arg-count) |
(setq cend (point-max)) |
1310 |
(when (eq (following-char) ?\{) |
(goto-char cend) |
1311 |
(when (= i 0) (setq cbeg (point))) |
(throw 'runaway nil)))))) |
1312 |
(if (font-latex-find-matching-close ?\{ ?\}) |
(store-match-data (list kbeg kend sbeg send cbeg cend)) |
|
(progn |
|
|
(setq cend (point)) |
|
|
(while (and (not (eobp)) (font-latex-forward-comment)))) |
|
|
(setq cache-reset t) |
|
|
(setq cend (point-max)) |
|
|
(goto-char cend) |
|
|
(throw 'runaway nil)))))) |
|
|
(store-match-data (list kbeg kend sbeg send cbeg cend)) |
|
1313 |
|
|
1314 |
;; Handle cache |
;; Handle cache |
1315 |
; (if (and we-moved |
; (if (and we-moved |
1320 |
; (message "pattern cancelled... twice in a row") |
; (message "pattern cancelled... twice in a row") |
1321 |
; nil) ;; Return a nul search (cancel this fontification) |
; nil) ;; Return a nul search (cancel this fontification) |
1322 |
|
|
1323 |
(when (and font-latex-use-cache cache-reset) |
(when (and font-latex-use-cache cache-reset) |
1324 |
(font-latex-set-cache |
(font-latex-set-cache |
1325 |
'font-latex-match-command-cache |
'font-latex-match-command-cache |
1326 |
kbeg kend limit keywords (list kbeg kend sbeg send cbeg cend))) |
kbeg kend limit keywords (list kbeg kend sbeg send cbeg cend))) |
1327 |
t))))) |
(throw 'match t)))))) |
1328 |
|
|
1329 |
(defvar font-latex-match-in-braces-cache nil |
(defvar font-latex-match-in-braces-cache nil |
1330 |
"Cache start of unterminated LaTeX commands to fontify.") |
"Cache start of unterminated LaTeX commands to fontify.") |
1338 |
Returns nil if no command is found." |
Returns nil if no command is found." |
1339 |
(when font-latex-use-cache |
(when font-latex-use-cache |
1340 |
(font-latex-check-cache 'font-latex-match-in-braces-cache 'in-braces limit)) |
(font-latex-check-cache 'font-latex-match-in-braces-cache 'in-braces limit)) |
1341 |
(when (re-search-forward keywords limit t) |
(catch 'match |
1342 |
(cond |
(while (re-search-forward keywords limit t) |
1343 |
((or (font-latex-faces-present-p '(font-lock-comment-face |
(catch 'irrelevant |
1344 |
font-latex-verbatim-face) |
(when (or (font-latex-faces-present-p '(font-lock-comment-face |
1345 |
(match-beginning 0)) |
font-latex-verbatim-face) |
1346 |
(font-latex-commented-outp)) |
(match-beginning 0)) |
1347 |
(store-match-data (list (match-end 0)(match-end 0))) |
(font-latex-commented-outp)) |
1348 |
t) |
(throw 'irrelevant nil)) |
1349 |
(t |
(let ((kbeg (match-beginning 0)) (kend (match-end 1)) |
1350 |
(let ((kbeg (match-beginning 0)) (kend (match-end 1)) |
(beg (match-end 0)) |
1351 |
(beg (match-end 0)) |
end cbeg cend |
1352 |
end cbeg cend |
cache-reset |
1353 |
cache-reset |
(parse-sexp-ignore-comments t)) ; scan-sexps ignores comments |
1354 |
(parse-sexp-ignore-comments t)) ; scan-sexps ignores comments |
(goto-char kbeg) |
1355 |
(goto-char kbeg) |
(cond |
1356 |
(cond |
((not (eq (preceding-char) ?\{)) |
1357 |
((not (eq (preceding-char) ?\{)) |
;; Fontify only the keyword (no argument found). |
1358 |
;; Fontify only the keyword (no argument found). |
(setq cbeg kbeg cend kend) |
1359 |
(setq cbeg kbeg cend kend) |
(goto-char (match-end 0)) |
1360 |
(goto-char (match-end 0)) |
(store-match-data (list (point) (point) cbeg cend)) |
1361 |
(store-match-data (list (point) (point) cbeg cend)) |
(throw 'match t)) |
1362 |
t) |
(t |
1363 |
(t |
;; There's an opening bracket |
1364 |
;; There's an opening bracket |
(save-restriction |
1365 |
(save-restriction |
;; Restrict to LIMIT. |
1366 |
;; Restrict to LIMIT. |
(narrow-to-region (point-min) limit) |
1367 |
(narrow-to-region (point-min) limit) |
(forward-char -1) ;Move on the opening bracket |
1368 |
(forward-char -1) ;Move on the opening bracket |
(if (font-latex-find-matching-close ?\{ ?\}) |
1369 |
(if (font-latex-find-matching-close ?\{ ?\}) |
(setq end (1- (point))) |
1370 |
(setq end (1- (point))) |
(setq cache-reset t) |
1371 |
(setq cache-reset t) |
(setq end (point-max)) |
1372 |
(setq end (point-max)) |
(goto-char end)) |
1373 |
(goto-char end)) |
(setq cbeg beg cend end) |
1374 |
(setq cbeg beg cend end) |
(store-match-data (list kbeg kend cbeg cend)) |
1375 |
(store-match-data (list kbeg kend cbeg cend)) |
;; Cache |
1376 |
|
(when (and font-latex-use-cache cache-reset) |
1377 |
(when (and font-latex-use-cache cache-reset) |
(goto-char limit) ;Avoid infinite loops? |
1378 |
(goto-char limit) ;Avoid infinite loops? |
(font-latex-set-cache |
1379 |
(font-latex-set-cache |
'font-latex-match-in-braces-cache |
1380 |
'font-latex-match-in-braces-cache |
kbeg kend limit 'in-braces |
1381 |
kbeg kend limit 'in-braces |
(list kbeg kend cbeg cend))) |
1382 |
(list kbeg kend cbeg cend))) |
(throw 'match t))))))))) |
|
|
|
|
t)))))))) |
|
1383 |
|
|
1384 |
(defun font-latex-match-simple-command (limit) |
(defun font-latex-match-simple-command (limit) |
1385 |
"Search for command like \\foo before LIMIT." |
"Search for command like \\foo before LIMIT." |
1391 |
Used for patterns like: |
Used for patterns like: |
1392 |
\\( F = ma \\) |
\\( F = ma \\) |
1393 |
\\ [ F = ma \\] but not \\\\ [len]" |
\\ [ F = ma \\] but not \\\\ [len]" |
1394 |
(when (re-search-forward "\\(\\\\(\\)\\|\\(\\\\\\[\\)" limit t) |
(catch 'match |
1395 |
(goto-char (match-beginning 0)) |
(while (re-search-forward "\\(\\\\(\\)\\|\\(\\\\\\[\\)" limit t) |
1396 |
(if (eq (preceding-char) ?\\) ; \\[ is not a math environment |
(catch 'irrelevant |
1397 |
(progn |
(goto-char (match-beginning 0)) |
1398 |
(goto-char (match-end 0)) |
(when (eq (preceding-char) ?\\) ; \\[ is not a math environment |
1399 |
(store-match-data (list (match-end 0)(match-end 0))) |
(goto-char (match-end 0)) |
1400 |
t) |
(throw 'irrelevant nil)) |
1401 |
(let ((b1start (point))) |
(let ((beg (point))) |
1402 |
(search-forward (cond ((match-beginning 1) "\\)") |
(search-forward (cond ((match-beginning 1) "\\)") |
1403 |
(t "\\]")) |
(t "\\]")) |
1404 |
limit 'move) |
limit 'move) |
1405 |
(let ((b2end (or (match-end 0) (point)))) |
(store-match-data (list beg (or (match-end 0) (point)))) |
1406 |
(store-match-data (list b1start b2end)) |
(throw 'match t)))))) |
|
t))))) |
|
1407 |
|
|
1408 |
(defun font-latex-match-math-envII (limit) |
(defun font-latex-match-math-envII (limit) |
1409 |
"Match math patterns up to LIMIT. |
"Match math patterns up to LIMIT. |