diff options
| author | Colin Walters | 2002-05-21 21:01:35 +0000 |
|---|---|---|
| committer | Colin Walters | 2002-05-21 21:01:35 +0000 |
| commit | 53785d2b31c3dcaf4c7537ee7a8f0f2f9db27eca (patch) | |
| tree | 19119b43b1b65b9908480312965efdb622a3e6de | |
| parent | daae70bf8c6c8926c5cce8c966aeffe8dbb9c3d9 (diff) | |
| download | emacs-53785d2b31c3dcaf4c7537ee7a8f0f2f9db27eca.tar.gz emacs-53785d2b31c3dcaf4c7537ee7a8f0f2f9db27eca.zip | |
(font-lock-defaults, font-lock-defaults-alist)
(font-lock-multiline, font-lock-fontified, font-lock-mode)
(turn-on-font-lock, font-lock-add-keywords, global-font-lock-mode)
(font-lock-global-modes): Moved to font-core.el.
(font-lock-set-defaults-1): Partially moved to font-core.el.
| -rw-r--r-- | lisp/font-lock.el | 385 |
1 files changed, 46 insertions, 339 deletions
diff --git a/lisp/font-lock.el b/lisp/font-lock.el index 3ebe23ba872..ba8b25f0980 100644 --- a/lisp/font-lock.el +++ b/lisp/font-lock.el | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | ;;; font-lock.el --- Electric font lock mode | 1 | ;;; font-lock.el --- Electric font lock mode |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1992, 93, 94, 95, 96, 97, 98, 1999, 2000, 2001 | 3 | ;; Copyright (C) 1992, 93, 94, 95, 96, 97, 98, 1999, 2000, 2001, 2002 |
| 4 | ;; Free Software Foundation, Inc. | 4 | ;; Free Software Foundation, Inc. |
| 5 | 5 | ||
| 6 | ;; Author: jwz, then rms, then sm | 6 | ;; Author: jwz, then rms, then sm |
| @@ -446,106 +446,6 @@ This variable is set by major modes via the variable `font-lock-defaults'. | |||
| 446 | Be careful when composing regexps for this list; a poorly written pattern can | 446 | Be careful when composing regexps for this list; a poorly written pattern can |
| 447 | dramatically slow things down!") | 447 | dramatically slow things down!") |
| 448 | 448 | ||
| 449 | ;; This variable is used by mode packages that support Font Lock mode by | ||
| 450 | ;; defining their own keywords to use for `font-lock-keywords'. (The mode | ||
| 451 | ;; command should make it buffer-local and set it to provide the set up.) | ||
| 452 | (defvar font-lock-defaults nil | ||
| 453 | "Defaults for Font Lock mode specified by the major mode. | ||
| 454 | Defaults should be of the form: | ||
| 455 | |||
| 456 | (KEYWORDS KEYWORDS-ONLY CASE-FOLD SYNTAX-ALIST SYNTAX-BEGIN ...) | ||
| 457 | |||
| 458 | KEYWORDS may be a symbol (a variable or function whose value is the keywords to | ||
| 459 | use for fontification) or a list of symbols. If KEYWORDS-ONLY is non-nil, | ||
| 460 | syntactic fontification (strings and comments) is not performed. | ||
| 461 | If CASE-FOLD is non-nil, the case of the keywords is ignored when fontifying. | ||
| 462 | If SYNTAX-ALIST is non-nil, it should be a list of cons pairs of the form | ||
| 463 | \(CHAR-OR-STRING . STRING) used to set the local Font Lock syntax table, for | ||
| 464 | keyword and syntactic fontification (see `modify-syntax-entry'). | ||
| 465 | |||
| 466 | If SYNTAX-BEGIN is non-nil, it should be a function with no args used to move | ||
| 467 | backwards outside any enclosing syntactic block, for syntactic fontification. | ||
| 468 | Typical values are `beginning-of-line' (i.e., the start of the line is known to | ||
| 469 | be outside a syntactic block), or `beginning-of-defun' for programming modes or | ||
| 470 | `backward-paragraph' for textual modes (i.e., the mode-dependent function is | ||
| 471 | known to move outside a syntactic block). If nil, the beginning of the buffer | ||
| 472 | is used as a position outside of a syntactic block, in the worst case. | ||
| 473 | |||
| 474 | These item elements are used by Font Lock mode to set the variables | ||
| 475 | `font-lock-keywords', `font-lock-keywords-only', | ||
| 476 | `font-lock-keywords-case-fold-search', `font-lock-syntax-table' and | ||
| 477 | `font-lock-beginning-of-syntax-function', respectively. | ||
| 478 | |||
| 479 | Further item elements are alists of the form (VARIABLE . VALUE) and are in no | ||
| 480 | particular order. Each VARIABLE is made buffer-local before set to VALUE. | ||
| 481 | |||
| 482 | Currently, appropriate variables include `font-lock-mark-block-function'. | ||
| 483 | If this is non-nil, it should be a function with no args used to mark any | ||
| 484 | enclosing block of text, for fontification via \\[font-lock-fontify-block]. | ||
| 485 | Typical values are `mark-defun' for programming modes or `mark-paragraph' for | ||
| 486 | textual modes (i.e., the mode-dependent function is known to put point and mark | ||
| 487 | around a text block relevant to that mode). | ||
| 488 | |||
| 489 | Other variables include that for syntactic keyword fontification, | ||
| 490 | `font-lock-syntactic-keywords' | ||
| 491 | and those for buffer-specialised fontification functions, | ||
| 492 | `font-lock-fontify-buffer-function', `font-lock-unfontify-buffer-function', | ||
| 493 | `font-lock-fontify-region-function', `font-lock-unfontify-region-function', | ||
| 494 | `font-lock-inhibit-thing-lock' and `font-lock-maximum-size'.") | ||
| 495 | ;;;###autoload | ||
| 496 | (make-variable-buffer-local 'font-lock-defaults) | ||
| 497 | |||
| 498 | ;; This variable is used where font-lock.el itself supplies the keywords. | ||
| 499 | (defvar font-lock-defaults-alist | ||
| 500 | (let (;; We use `beginning-of-defun', rather than nil, for SYNTAX-BEGIN. | ||
| 501 | ;; Thus the calculation of the cache is usually faster but not | ||
| 502 | ;; infallible, so we risk mis-fontification. sm. | ||
| 503 | (c-mode-defaults | ||
| 504 | '((c-font-lock-keywords c-font-lock-keywords-1 | ||
| 505 | c-font-lock-keywords-2 c-font-lock-keywords-3) | ||
| 506 | nil nil ((?_ . "w")) beginning-of-defun | ||
| 507 | (font-lock-syntactic-face-function | ||
| 508 | . c-font-lock-syntactic-face-function) | ||
| 509 | (font-lock-mark-block-function . mark-defun))) | ||
| 510 | (c++-mode-defaults | ||
| 511 | '((c++-font-lock-keywords c++-font-lock-keywords-1 | ||
| 512 | c++-font-lock-keywords-2 c++-font-lock-keywords-3) | ||
| 513 | nil nil ((?_ . "w")) beginning-of-defun | ||
| 514 | (font-lock-syntactic-face-function | ||
| 515 | . c-font-lock-syntactic-face-function) | ||
| 516 | (font-lock-mark-block-function . mark-defun))) | ||
| 517 | (objc-mode-defaults | ||
| 518 | '((objc-font-lock-keywords objc-font-lock-keywords-1 | ||
| 519 | objc-font-lock-keywords-2 objc-font-lock-keywords-3) | ||
| 520 | nil nil ((?_ . "w") (?$ . "w")) nil | ||
| 521 | (font-lock-syntactic-face-function | ||
| 522 | . c-font-lock-syntactic-face-function) | ||
| 523 | (font-lock-mark-block-function . mark-defun))) | ||
| 524 | (java-mode-defaults | ||
| 525 | '((java-font-lock-keywords java-font-lock-keywords-1 | ||
| 526 | java-font-lock-keywords-2 java-font-lock-keywords-3) | ||
| 527 | nil nil ((?_ . "w") (?$ . "w")) nil | ||
| 528 | (font-lock-syntactic-face-function | ||
| 529 | . java-font-lock-syntactic-face-function) | ||
| 530 | (font-lock-mark-block-function . mark-defun)))) | ||
| 531 | (list | ||
| 532 | (cons 'c-mode c-mode-defaults) | ||
| 533 | (cons 'c++-mode c++-mode-defaults) | ||
| 534 | (cons 'objc-mode objc-mode-defaults) | ||
| 535 | (cons 'java-mode java-mode-defaults))) | ||
| 536 | "Alist of fall-back Font Lock defaults for major modes. | ||
| 537 | |||
| 538 | This variable should not be used any more. | ||
| 539 | Set the buffer-local `font-lock-keywords' in the major mode instead. | ||
| 540 | |||
| 541 | Each item should be a list of the form: | ||
| 542 | |||
| 543 | (MAJOR-MODE . FONT-LOCK-DEFAULTS) | ||
| 544 | |||
| 545 | where MAJOR-MODE is a symbol and FONT-LOCK-DEFAULTS is a list of default | ||
| 546 | settings. See the variable `font-lock-defaults', which takes precedence.") | ||
| 547 | (make-obsolete-variable 'font-lock-defaults-alist 'font-lock-defaults) | ||
| 548 | |||
| 549 | (defvar font-lock-keywords-alist nil | 449 | (defvar font-lock-keywords-alist nil |
| 550 | "*Alist of `font-lock-keywords' local to a `major-mode'. | 450 | "*Alist of `font-lock-keywords' local to a `major-mode'. |
| 551 | This is normally set via `font-lock-add-keywords' and | 451 | This is normally set via `font-lock-add-keywords' and |
| @@ -657,14 +557,6 @@ This is normally set via `font-lock-defaults'.") | |||
| 657 | Currently, valid mode names are `fast-lock-mode', `jit-lock-mode' and | 557 | Currently, valid mode names are `fast-lock-mode', `jit-lock-mode' and |
| 658 | `lazy-lock-mode'. This is normally set via `font-lock-defaults'.") | 558 | `lazy-lock-mode'. This is normally set via `font-lock-defaults'.") |
| 659 | 559 | ||
| 660 | (defvar font-lock-multiline nil | ||
| 661 | "Whether font-lock should cater to multiline keywords. | ||
| 662 | If nil, don't try to handle multiline patterns. | ||
| 663 | If t, always handle multiline patterns. | ||
| 664 | If `undecided', don't try to handle multiline patterns until you see one. | ||
| 665 | Major/minor modes can set this variable if they know which option applies.") | ||
| 666 | |||
| 667 | (defvar font-lock-fontified nil) ; Whether we have fontified the buffer. | ||
| 668 | 560 | ||
| 669 | ;; Font Lock mode. | 561 | ;; Font Lock mode. |
| 670 | 562 | ||
| @@ -698,94 +590,6 @@ Major/minor modes can set this variable if they know which option applies.") | |||
| 698 | (defvar font-lock-face-attributes)) ; Obsolete but respected if set. | 590 | (defvar font-lock-face-attributes)) ; Obsolete but respected if set. |
| 699 | 591 | ||
| 700 | ;;;###autoload | 592 | ;;;###autoload |
| 701 | (define-minor-mode font-lock-mode | ||
| 702 | "Toggle Font Lock mode. | ||
| 703 | With arg, turn Font Lock mode off if and only if arg is a non-positive | ||
| 704 | number; if arg is nil, toggle Font Lock mode; anything else turns Font | ||
| 705 | Lock on. | ||
| 706 | \(Font Lock is also known as \"syntax highlighting\".) | ||
| 707 | |||
| 708 | When Font Lock mode is enabled, text is fontified as you type it: | ||
| 709 | |||
| 710 | - Comments are displayed in `font-lock-comment-face'; | ||
| 711 | - Strings are displayed in `font-lock-string-face'; | ||
| 712 | - Certain other expressions are displayed in other faces according to the | ||
| 713 | value of the variable `font-lock-keywords'. | ||
| 714 | |||
| 715 | To customize the faces (colors, fonts, etc.) used by Font Lock for | ||
| 716 | fontifying different parts of buffer text, use \\[customize-face]. | ||
| 717 | |||
| 718 | You can enable Font Lock mode in any major mode automatically by turning on in | ||
| 719 | the major mode's hook. For example, put in your ~/.emacs: | ||
| 720 | |||
| 721 | (add-hook 'c-mode-hook 'turn-on-font-lock) | ||
| 722 | |||
| 723 | Alternatively, you can use Global Font Lock mode to automagically turn on Font | ||
| 724 | Lock mode in buffers whose major mode supports it and whose major mode is one | ||
| 725 | of `font-lock-global-modes'. For example, put in your ~/.emacs: | ||
| 726 | |||
| 727 | (global-font-lock-mode t) | ||
| 728 | |||
| 729 | There are a number of support modes that may be used to speed up Font Lock mode | ||
| 730 | in various ways, specified via the variable `font-lock-support-mode'. Where | ||
| 731 | major modes support different levels of fontification, you can use the variable | ||
| 732 | `font-lock-maximum-decoration' to specify which level you generally prefer. | ||
| 733 | When you turn Font Lock mode on/off the buffer is fontified/defontified, though | ||
| 734 | fontification occurs only if the buffer is less than `font-lock-maximum-size'. | ||
| 735 | |||
| 736 | For example, to specify that Font Lock mode use use Lazy Lock mode as a support | ||
| 737 | mode and use maximum levels of fontification, put in your ~/.emacs: | ||
| 738 | |||
| 739 | (setq font-lock-support-mode 'lazy-lock-mode) | ||
| 740 | (setq font-lock-maximum-decoration t) | ||
| 741 | |||
| 742 | To add your own highlighting for some major mode, and modify the highlighting | ||
| 743 | selected automatically via the variable `font-lock-maximum-decoration', you can | ||
| 744 | use `font-lock-add-keywords'. | ||
| 745 | |||
| 746 | To fontify a buffer, without turning on Font Lock mode and regardless of buffer | ||
| 747 | size, you can use \\[font-lock-fontify-buffer]. | ||
| 748 | |||
| 749 | To fontify a block (the function or paragraph containing point, or a number of | ||
| 750 | lines around point), perhaps because modification on the current line caused | ||
| 751 | syntactic change on other lines, you can use \\[font-lock-fontify-block]. | ||
| 752 | |||
| 753 | See the variable `font-lock-defaults-alist' for the Font Lock mode default | ||
| 754 | settings. You can set your own default settings for some mode, by setting a | ||
| 755 | buffer local value for `font-lock-defaults', via its mode hook." | ||
| 756 | nil nil nil | ||
| 757 | ;; Don't turn on Font Lock mode if we don't have a display (we're running a | ||
| 758 | ;; batch job) or if the buffer is invisible (the name starts with a space). | ||
| 759 | (when (or noninteractive (eq (aref (buffer-name) 0) ?\ )) | ||
| 760 | (setq font-lock-mode nil)) | ||
| 761 | |||
| 762 | ;; Turn on Font Lock mode. | ||
| 763 | (when font-lock-mode | ||
| 764 | (add-hook 'after-change-functions 'font-lock-after-change-function t t) | ||
| 765 | (font-lock-set-defaults) | ||
| 766 | (font-lock-turn-on-thing-lock) | ||
| 767 | ;; Fontify the buffer if we have to. | ||
| 768 | (let ((max-size (font-lock-value-in-major-mode font-lock-maximum-size))) | ||
| 769 | (cond (font-lock-fontified | ||
| 770 | nil) | ||
| 771 | ((or (null max-size) (> max-size (buffer-size))) | ||
| 772 | (font-lock-fontify-buffer)) | ||
| 773 | (font-lock-verbose | ||
| 774 | (message "Fontifying %s...buffer size greater than font-lock-maximum-size" | ||
| 775 | (buffer-name)))))) | ||
| 776 | ;; Turn off Font Lock mode. | ||
| 777 | (unless font-lock-mode | ||
| 778 | (remove-hook 'after-change-functions 'font-lock-after-change-function t) | ||
| 779 | (font-lock-unfontify-buffer) | ||
| 780 | (font-lock-turn-off-thing-lock))) | ||
| 781 | |||
| 782 | ;;;###autoload | ||
| 783 | (defun turn-on-font-lock () | ||
| 784 | "Turn on Font Lock mode (only if the terminal can display it)." | ||
| 785 | (unless font-lock-mode | ||
| 786 | (font-lock-mode))) | ||
| 787 | |||
| 788 | ;;;###autoload | ||
| 789 | (defun font-lock-add-keywords (mode keywords &optional append) | 593 | (defun font-lock-add-keywords (mode keywords &optional append) |
| 790 | "Add highlighting KEYWORDS for MODE. | 594 | "Add highlighting KEYWORDS for MODE. |
| 791 | MODE should be a symbol, the major mode command name, such as `c-mode' | 595 | MODE should be a symbol, the major mode command name, such as `c-mode' |
| @@ -937,94 +741,6 @@ subtle problems due to details of the implementation." | |||
| 937 | (delete (font-lock-compile-keyword keyword) | 741 | (delete (font-lock-compile-keyword keyword) |
| 938 | font-lock-keywords))))))) | 742 | font-lock-keywords))))))) |
| 939 | 743 | ||
| 940 | ;;; Global Font Lock mode. | ||
| 941 | |||
| 942 | ;; A few people have hassled in the past for a way to make it easier to turn on | ||
| 943 | ;; Font Lock mode, without the user needing to know for which modes s/he has to | ||
| 944 | ;; turn it on, perhaps the same way hilit19.el/hl319.el does. I've always | ||
| 945 | ;; balked at that way, as I see it as just re-moulding the same problem in | ||
| 946 | ;; another form. That is; some person would still have to keep track of which | ||
| 947 | ;; modes (which may not even be distributed with Emacs) support Font Lock mode. | ||
| 948 | ;; The list would always be out of date. And that person might have to be me. | ||
| 949 | |||
| 950 | ;; Implementation. | ||
| 951 | ;; | ||
| 952 | ;; In a previous discussion the following hack came to mind. It is a gross | ||
| 953 | ;; hack, but it generally works. We use the convention that major modes start | ||
| 954 | ;; by calling the function `kill-all-local-variables', which in turn runs | ||
| 955 | ;; functions on the hook variable `change-major-mode-hook'. We attach our | ||
| 956 | ;; function `font-lock-change-major-mode' to that hook. Of course, when this | ||
| 957 | ;; hook is run, the major mode is in the process of being changed and we do not | ||
| 958 | ;; know what the final major mode will be. So, `font-lock-change-major-mode' | ||
| 959 | ;; only (a) notes the name of the current buffer, and (b) adds our function | ||
| 960 | ;; `turn-on-font-lock-if-enabled' to the hook variables `find-file-hooks' and | ||
| 961 | ;; `post-command-hook' (for buffers that are not visiting files). By the time | ||
| 962 | ;; the functions on the first of these hooks to be run are run, the new major | ||
| 963 | ;; mode is assumed to be in place. This way we get a Font Lock function run | ||
| 964 | ;; when a major mode is turned on, without knowing major modes or their hooks. | ||
| 965 | ;; | ||
| 966 | ;; Naturally this requires that (a) major modes run `kill-all-local-variables', | ||
| 967 | ;; as they are supposed to do, and (b) the major mode is in place after the | ||
| 968 | ;; file is visited or the command that ran `kill-all-local-variables' has | ||
| 969 | ;; finished, whichever the sooner. Arguably, any major mode that does not | ||
| 970 | ;; follow the convension (a) is broken, and I can't think of any reason why (b) | ||
| 971 | ;; would not be met (except `gnudoit' on non-files). However, it is not clean. | ||
| 972 | ;; | ||
| 973 | ;; Probably the cleanest solution is to have each major mode function run some | ||
| 974 | ;; hook, e.g., `major-mode-hook', but maybe implementing that change is | ||
| 975 | ;; impractical. I am personally against making `setq' a macro or be advised, | ||
| 976 | ;; or have a special function such as `set-major-mode', but maybe someone can | ||
| 977 | ;; come up with another solution? | ||
| 978 | |||
| 979 | ;; User interface. | ||
| 980 | ;; | ||
| 981 | ;; Although Global Font Lock mode is a pseudo-mode, I think that the user | ||
| 982 | ;; interface should conform to the usual Emacs convention for modes, i.e., a | ||
| 983 | ;; command to toggle the feature (`global-font-lock-mode') with a variable for | ||
| 984 | ;; finer control of the mode's behaviour (`font-lock-global-modes'). | ||
| 985 | ;; | ||
| 986 | ;; The feature should not be enabled by loading font-lock.el, since other | ||
| 987 | ;; mechanisms for turning on Font Lock mode, such as M-x font-lock-mode RET or | ||
| 988 | ;; (add-hook 'c-mode-hook 'turn-on-font-lock), would cause Font Lock mode to be | ||
| 989 | ;; turned on everywhere. That would not be intuitive or informative because | ||
| 990 | ;; loading a file tells you nothing about the feature or how to control it. It | ||
| 991 | ;; would also be contrary to the Principle of Least Surprise. sm. | ||
| 992 | |||
| 993 | (defcustom font-lock-global-modes t | ||
| 994 | "*Modes for which Font Lock mode is automagically turned on. | ||
| 995 | Global Font Lock mode is controlled by the command `global-font-lock-mode'. | ||
| 996 | If nil, means no modes have Font Lock mode automatically turned on. | ||
| 997 | If t, all modes that support Font Lock mode have it automatically turned on. | ||
| 998 | If a list, it should be a list of `major-mode' symbol names for which Font Lock | ||
| 999 | mode should be automatically turned on. The sense of the list is negated if it | ||
| 1000 | begins with `not'. For example: | ||
| 1001 | (c-mode c++-mode) | ||
| 1002 | means that Font Lock mode is turned on for buffers in C and C++ modes only." | ||
| 1003 | :type '(choice (const :tag "none" nil) | ||
| 1004 | (const :tag "all" t) | ||
| 1005 | (set :menu-tag "mode specific" :tag "modes" | ||
| 1006 | :value (not) | ||
| 1007 | (const :tag "Except" not) | ||
| 1008 | (repeat :inline t (symbol :tag "mode")))) | ||
| 1009 | :group 'font-lock) | ||
| 1010 | |||
| 1011 | (defun turn-on-font-lock-if-enabled () | ||
| 1012 | (when (and (or font-lock-defaults | ||
| 1013 | (assq major-mode font-lock-defaults-alist)) | ||
| 1014 | (or (eq font-lock-global-modes t) | ||
| 1015 | (if (eq (car-safe font-lock-global-modes) 'not) | ||
| 1016 | (not (memq major-mode (cdr font-lock-global-modes))) | ||
| 1017 | (memq major-mode font-lock-global-modes)))) | ||
| 1018 | (let (inhibit-quit) | ||
| 1019 | (turn-on-font-lock)))) | ||
| 1020 | |||
| 1021 | ;;;###autoload | ||
| 1022 | (easy-mmode-define-global-mode | ||
| 1023 | global-font-lock-mode font-lock-mode turn-on-font-lock-if-enabled | ||
| 1024 | :extra-args (dummy)) | ||
| 1025 | |||
| 1026 | ;;; End of Global Font Lock mode. | ||
| 1027 | |||
| 1028 | ;;; Font Lock Support mode. | 744 | ;;; Font Lock Support mode. |
| 1029 | 745 | ||
| 1030 | ;; This is the code used to interface font-lock.el with any of its add-on | 746 | ;; This is the code used to interface font-lock.el with any of its add-on |
| @@ -1718,60 +1434,51 @@ A LEVEL of nil is equal to a LEVEL of 0, a LEVEL of t is equal to | |||
| 1718 | (t | 1434 | (t |
| 1719 | (car keywords)))) | 1435 | (car keywords)))) |
| 1720 | 1436 | ||
| 1721 | (defvar font-lock-set-defaults nil) ; Whether we have set up defaults. | 1437 | (defun font-lock-set-defaults-1 () |
| 1722 | 1438 | (let* ((defaults (or font-lock-defaults | |
| 1723 | (defun font-lock-set-defaults () | 1439 | (cdr (assq major-mode font-lock-defaults-alist)))) |
| 1724 | "Set fontification defaults appropriately for this mode. | 1440 | (keywords |
| 1725 | Sets various variables using `font-lock-defaults' (or, if nil, using | 1441 | (font-lock-choose-keywords (nth 0 defaults) |
| 1726 | `font-lock-defaults-alist') and `font-lock-maximum-decoration'." | 1442 | (font-lock-value-in-major-mode font-lock-maximum-decoration))) |
| 1727 | ;; Set fontification defaults iff not previously set. | 1443 | (local (cdr (assq major-mode font-lock-keywords-alist))) |
| 1728 | (unless font-lock-set-defaults | 1444 | (removed-keywords |
| 1729 | (set (make-local-variable 'font-lock-set-defaults) t) | 1445 | (cdr-safe (assq major-mode font-lock-removed-keywords-alist)))) |
| 1730 | (make-local-variable 'font-lock-fontified) | 1446 | (set (make-local-variable 'font-lock-defaults) defaults) |
| 1731 | (make-local-variable 'font-lock-multiline) | 1447 | ;; Syntactic fontification? |
| 1732 | (let* ((defaults (or font-lock-defaults | 1448 | (when (nth 1 defaults) |
| 1733 | (cdr (assq major-mode font-lock-defaults-alist)))) | 1449 | (set (make-local-variable 'font-lock-keywords-only) t)) |
| 1734 | (keywords | 1450 | ;; Case fold during regexp fontification? |
| 1735 | (font-lock-choose-keywords (nth 0 defaults) | 1451 | (when (nth 2 defaults) |
| 1736 | (font-lock-value-in-major-mode font-lock-maximum-decoration))) | 1452 | (set (make-local-variable 'font-lock-keywords-case-fold-search) t)) |
| 1737 | (local (cdr (assq major-mode font-lock-keywords-alist))) | 1453 | ;; Syntax table for regexp and syntactic fontification? |
| 1738 | (removed-keywords | 1454 | (when (nth 3 defaults) |
| 1739 | (cdr-safe (assq major-mode font-lock-removed-keywords-alist)))) | 1455 | (set (make-local-variable 'font-lock-syntax-table) |
| 1740 | ;; Syntactic fontification? | 1456 | (copy-syntax-table (syntax-table))) |
| 1741 | (when (nth 1 defaults) | 1457 | (dolist (selem (nth 3 defaults)) |
| 1742 | (set (make-local-variable 'font-lock-keywords-only) t)) | 1458 | ;; The character to modify may be a single CHAR or a STRING. |
| 1743 | ;; Case fold during regexp fontification? | 1459 | (let ((syntax (cdr selem))) |
| 1744 | (when (nth 2 defaults) | 1460 | (dolist (char (if (numberp (car selem)) |
| 1745 | (set (make-local-variable 'font-lock-keywords-case-fold-search) t)) | 1461 | (list (car selem)) |
| 1746 | ;; Syntax table for regexp and syntactic fontification? | 1462 | (mapcar 'identity (car selem)))) |
| 1747 | (when (nth 3 defaults) | 1463 | (modify-syntax-entry char syntax font-lock-syntax-table))))) |
| 1748 | (set (make-local-variable 'font-lock-syntax-table) | 1464 | ;; Syntax function for syntactic fontification? |
| 1749 | (copy-syntax-table (syntax-table))) | 1465 | (when (nth 4 defaults) |
| 1750 | (dolist (selem (nth 3 defaults)) | 1466 | (set (make-local-variable 'font-lock-beginning-of-syntax-function) |
| 1751 | ;; The character to modify may be a single CHAR or a STRING. | 1467 | (nth 4 defaults))) |
| 1752 | (let ((syntax (cdr selem))) | 1468 | ;; Variable alist? |
| 1753 | (dolist (char (if (numberp (car selem)) | 1469 | (dolist (x (nthcdr 5 defaults)) |
| 1754 | (list (car selem)) | 1470 | (set (make-local-variable (car x)) (cdr x))) |
| 1755 | (mapcar 'identity (car selem)))) | 1471 | ;; Setup `font-lock-keywords' last because its value might depend |
| 1756 | (modify-syntax-entry char syntax font-lock-syntax-table))))) | 1472 | ;; on other settings (e.g. font-lock-compile-keywords uses |
| 1757 | ;; Syntax function for syntactic fontification? | 1473 | ;; font-lock-beginning-of-syntax-function). |
| 1758 | (when (nth 4 defaults) | 1474 | (set (make-local-variable 'font-lock-keywords) |
| 1759 | (set (make-local-variable 'font-lock-beginning-of-syntax-function) | 1475 | (font-lock-compile-keywords (font-lock-eval-keywords keywords) t)) |
| 1760 | (nth 4 defaults))) | 1476 | ;; Local fontification? |
| 1761 | ;; Variable alist? | 1477 | (while local |
| 1762 | (dolist (x (nthcdr 5 defaults)) | 1478 | (font-lock-add-keywords nil (car (car local)) (cdr (car local))) |
| 1763 | (set (make-local-variable (car x)) (cdr x))) | 1479 | (setq local (cdr local))) |
| 1764 | ;; Setup `font-lock-keywords' last because its value might depend | 1480 | (when removed-keywords |
| 1765 | ;; on other settings (e.g. font-lock-compile-keywords uses | 1481 | (font-lock-remove-keywords nil removed-keywords)))) |
| 1766 | ;; font-lock-beginning-of-syntax-function). | ||
| 1767 | (set (make-local-variable 'font-lock-keywords) | ||
| 1768 | (font-lock-compile-keywords (font-lock-eval-keywords keywords) t)) | ||
| 1769 | ;; Local fontification? | ||
| 1770 | (while local | ||
| 1771 | (font-lock-add-keywords nil (car (car local)) (cdr (car local))) | ||
| 1772 | (setq local (cdr local))) | ||
| 1773 | (when removed-keywords | ||
| 1774 | (font-lock-remove-keywords nil removed-keywords))))) | ||
| 1775 | 1482 | ||
| 1776 | ;;; Colour etc. support. | 1483 | ;;; Colour etc. support. |
| 1777 | 1484 | ||