Mercurial > emacs
comparison lisp/font-lock.el @ 50594:09c07c654b23
(font-lock-multiline, font-lock-fontified)
(font-lock-set-defaults): Move back from font-core.el and merge
it back with font-lock-set-defaults-1.
(font-lock-mode-internal): New function (basically the body of
the old font-lock-mode minor mode).
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Mon, 14 Apr 2003 23:07:39 +0000 |
parents | 7bfe36160365 |
children | 9d8489f40d2c |
comparison
equal
deleted
inserted
replaced
50593:9ede3f237c05 | 50594:09c07c654b23 |
---|---|
563 (defvar font-lock-inhibit-thing-lock nil | 563 (defvar font-lock-inhibit-thing-lock nil |
564 "List of Font Lock mode related modes that should not be turned on. | 564 "List of Font Lock mode related modes that should not be turned on. |
565 Currently, valid mode names are `fast-lock-mode', `jit-lock-mode' and | 565 Currently, valid mode names are `fast-lock-mode', `jit-lock-mode' and |
566 `lazy-lock-mode'. This is normally set via `font-lock-defaults'.") | 566 `lazy-lock-mode'. This is normally set via `font-lock-defaults'.") |
567 | 567 |
568 (defvar font-lock-multiline nil | |
569 "Whether font-lock should cater to multiline keywords. | |
570 If nil, don't try to handle multiline patterns. | |
571 If t, always handle multiline patterns. | |
572 If `undecided', don't try to handle multiline patterns until you see one. | |
573 Major/minor modes can set this variable if they know which option applies.") | |
574 | |
575 (defvar font-lock-fontified nil) ; Whether we have fontified the buffer. | |
568 | 576 |
569 ;; Font Lock mode. | 577 ;; Font Lock mode. |
570 | 578 |
571 (eval-when-compile | 579 (eval-when-compile |
572 ;; | 580 ;; |
594 (put 'save-buffer-state 'lisp-indent-function 1) | 602 (put 'save-buffer-state 'lisp-indent-function 1) |
595 (def-edebug-spec save-buffer-state let) | 603 (def-edebug-spec save-buffer-state let) |
596 ;; | 604 ;; |
597 ;; Shut up the byte compiler. | 605 ;; Shut up the byte compiler. |
598 (defvar font-lock-face-attributes)) ; Obsolete but respected if set. | 606 (defvar font-lock-face-attributes)) ; Obsolete but respected if set. |
607 | |
608 ;;;###autoload | |
609 (defun font-lock-mode-internal (arg) | |
610 ;; Turn on Font Lock mode. | |
611 (when arg | |
612 (add-hook 'after-change-functions 'font-lock-after-change-function t t) | |
613 (font-lock-set-defaults) | |
614 (font-lock-turn-on-thing-lock) | |
615 ;; Fontify the buffer if we have to. | |
616 (let ((max-size (font-lock-value-in-major-mode font-lock-maximum-size))) | |
617 (cond (font-lock-fontified | |
618 nil) | |
619 ((or (null max-size) (> max-size (buffer-size))) | |
620 (font-lock-fontify-buffer)) | |
621 (font-lock-verbose | |
622 (message "Fontifying %s...buffer size greater than font-lock-maximum-size" | |
623 (buffer-name)))))) | |
624 ;; Turn off Font Lock mode. | |
625 (unless font-lock-mode | |
626 (remove-hook 'after-change-functions 'font-lock-after-change-function t) | |
627 (font-lock-unfontify-buffer) | |
628 (font-lock-turn-off-thing-lock))) | |
599 | 629 |
600 ;;;###autoload | 630 ;;;###autoload |
601 (defun font-lock-add-keywords (mode keywords &optional append) | 631 (defun font-lock-add-keywords (mode keywords &optional append) |
602 "Add highlighting KEYWORDS for MODE. | 632 "Add highlighting KEYWORDS for MODE. |
603 MODE should be a symbol, the major mode command name, such as `c-mode' | 633 MODE should be a symbol, the major mode command name, such as `c-mode' |
1444 ((eq level t) | 1474 ((eq level t) |
1445 (car (reverse keywords))) | 1475 (car (reverse keywords))) |
1446 (t | 1476 (t |
1447 (car keywords)))) | 1477 (car keywords)))) |
1448 | 1478 |
1449 (defun font-lock-set-defaults-1 () | 1479 (defvar font-lock-set-defaults nil) ; Whether we have set up defaults. |
1450 (let* ((defaults (or font-lock-defaults | 1480 |
1451 (cdr (assq major-mode font-lock-defaults-alist)))) | 1481 (defun font-lock-set-defaults () |
1452 (keywords | 1482 "Set fontification defaults appropriately for this mode. |
1453 (font-lock-choose-keywords (nth 0 defaults) | 1483 Sets various variables using `font-lock-defaults' (or, if nil, using |
1454 (font-lock-value-in-major-mode font-lock-maximum-decoration))) | 1484 `font-lock-defaults-alist') and `font-lock-maximum-decoration'." |
1455 (local (cdr (assq major-mode font-lock-keywords-alist))) | 1485 ;; Set fontification defaults iff not previously set. |
1456 (removed-keywords | 1486 (unless font-lock-set-defaults |
1457 (cdr-safe (assq major-mode font-lock-removed-keywords-alist)))) | 1487 (set (make-local-variable 'font-lock-set-defaults) t) |
1458 (set (make-local-variable 'font-lock-defaults) defaults) | 1488 (make-local-variable 'font-lock-fontified) |
1459 ;; Syntactic fontification? | 1489 (make-local-variable 'font-lock-multiline) |
1460 (when (nth 1 defaults) | 1490 (let* ((defaults (or font-lock-defaults |
1461 (set (make-local-variable 'font-lock-keywords-only) t)) | 1491 (cdr (assq major-mode font-lock-defaults-alist)))) |
1462 ;; Case fold during regexp fontification? | 1492 (keywords |
1463 (when (nth 2 defaults) | 1493 (font-lock-choose-keywords (nth 0 defaults) |
1464 (set (make-local-variable 'font-lock-keywords-case-fold-search) t)) | 1494 (font-lock-value-in-major-mode font-lock-maximum-decoration))) |
1465 ;; Syntax table for regexp and syntactic fontification? | 1495 (local (cdr (assq major-mode font-lock-keywords-alist))) |
1466 (when (nth 3 defaults) | 1496 (removed-keywords |
1467 (set (make-local-variable 'font-lock-syntax-table) | 1497 (cdr-safe (assq major-mode font-lock-removed-keywords-alist)))) |
1468 (copy-syntax-table (syntax-table))) | 1498 (set (make-local-variable 'font-lock-defaults) defaults) |
1469 (dolist (selem (nth 3 defaults)) | 1499 ;; Syntactic fontification? |
1470 ;; The character to modify may be a single CHAR or a STRING. | 1500 (when (nth 1 defaults) |
1471 (let ((syntax (cdr selem))) | 1501 (set (make-local-variable 'font-lock-keywords-only) t)) |
1472 (dolist (char (if (numberp (car selem)) | 1502 ;; Case fold during regexp fontification? |
1473 (list (car selem)) | 1503 (when (nth 2 defaults) |
1474 (mapcar 'identity (car selem)))) | 1504 (set (make-local-variable 'font-lock-keywords-case-fold-search) t)) |
1475 (modify-syntax-entry char syntax font-lock-syntax-table))))) | 1505 ;; Syntax table for regexp and syntactic fontification? |
1476 ;; Syntax function for syntactic fontification? | 1506 (when (nth 3 defaults) |
1477 (when (nth 4 defaults) | 1507 (set (make-local-variable 'font-lock-syntax-table) |
1478 (set (make-local-variable 'font-lock-beginning-of-syntax-function) | 1508 (copy-syntax-table (syntax-table))) |
1479 (nth 4 defaults))) | 1509 (dolist (selem (nth 3 defaults)) |
1480 ;; Variable alist? | 1510 ;; The character to modify may be a single CHAR or a STRING. |
1481 (dolist (x (nthcdr 5 defaults)) | 1511 (let ((syntax (cdr selem))) |
1482 (set (make-local-variable (car x)) (cdr x))) | 1512 (dolist (char (if (numberp (car selem)) |
1483 ;; Setup `font-lock-keywords' last because its value might depend | 1513 (list (car selem)) |
1484 ;; on other settings (e.g. font-lock-compile-keywords uses | 1514 (mapcar 'identity (car selem)))) |
1485 ;; font-lock-beginning-of-syntax-function). | 1515 (modify-syntax-entry char syntax font-lock-syntax-table))))) |
1486 (set (make-local-variable 'font-lock-keywords) | 1516 ;; Syntax function for syntactic fontification? |
1487 (font-lock-compile-keywords (font-lock-eval-keywords keywords) t)) | 1517 (when (nth 4 defaults) |
1488 ;; Local fontification? | 1518 (set (make-local-variable 'font-lock-beginning-of-syntax-function) |
1489 (while local | 1519 (nth 4 defaults))) |
1490 (font-lock-add-keywords nil (car (car local)) (cdr (car local))) | 1520 ;; Variable alist? |
1491 (setq local (cdr local))) | 1521 (dolist (x (nthcdr 5 defaults)) |
1492 (when removed-keywords | 1522 (set (make-local-variable (car x)) (cdr x))) |
1493 (font-lock-remove-keywords nil removed-keywords)))) | 1523 ;; Setup `font-lock-keywords' last because its value might depend |
1524 ;; on other settings (e.g. font-lock-compile-keywords uses | |
1525 ;; font-lock-beginning-of-syntax-function). | |
1526 (set (make-local-variable 'font-lock-keywords) | |
1527 (font-lock-compile-keywords (font-lock-eval-keywords keywords) t)) | |
1528 ;; Local fontification? | |
1529 (while local | |
1530 (font-lock-add-keywords nil (car (car local)) (cdr (car local))) | |
1531 (setq local (cdr local))) | |
1532 (when removed-keywords | |
1533 (font-lock-remove-keywords nil removed-keywords))))) | |
1494 | 1534 |
1495 ;;; Colour etc. support. | 1535 ;;; Colour etc. support. |
1496 | 1536 |
1497 ;; Originally face attributes were specified via `font-lock-face-attributes'. | 1537 ;; Originally face attributes were specified via `font-lock-face-attributes'. |
1498 ;; Users then changed the default face attributes by setting that variable. | 1538 ;; Users then changed the default face attributes by setting that variable. |