comparison lisp/font-lock.el @ 47611:6bc56530304a

(fast-lock-mode, lazy-lock-mode, jit-lock-mode): Don't bind them variables. (font-lock-turn-off-thing-lock, font-lock-after-fontify-buffer) (font-lock-after-unfontify-buffer): Check that the vars are bound. (font-lock-dont-widen): New var. (font-lock-default-fontify-region): Use it.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Wed, 25 Sep 2002 19:34:07 +0000
parents ec5f8ce91ceb
children d7662618cd11
comparison
equal deleted inserted replaced
47610:8a24f7edde82 47611:6bc56530304a
786 (const :tag "JIT lock" jit-lock-mode))) 786 (const :tag "JIT lock" jit-lock-mode)))
787 )) 787 ))
788 :version "21.1" 788 :version "21.1"
789 :group 'font-lock) 789 :group 'font-lock)
790 790
791 (defvar fast-lock-mode nil) 791 (defvar fast-lock-mode)
792 (defvar lazy-lock-mode nil) 792 (defvar lazy-lock-mode)
793 (defvar jit-lock-mode nil) 793 (defvar jit-lock-mode)
794 794
795 (defun font-lock-turn-on-thing-lock () 795 (defun font-lock-turn-on-thing-lock ()
796 (let ((thing-mode (font-lock-value-in-major-mode font-lock-support-mode))) 796 (let ((thing-mode (font-lock-value-in-major-mode font-lock-support-mode)))
797 (cond ((eq thing-mode 'fast-lock-mode) 797 (cond ((eq thing-mode 'fast-lock-mode)
798 (fast-lock-mode t)) 798 (fast-lock-mode t))
809 ;; Use jit-lock. 809 ;; Use jit-lock.
810 (jit-lock-register 'font-lock-fontify-region 810 (jit-lock-register 'font-lock-fontify-region
811 (not font-lock-keywords-only)))))) 811 (not font-lock-keywords-only))))))
812 812
813 (defun font-lock-turn-off-thing-lock () 813 (defun font-lock-turn-off-thing-lock ()
814 (cond (fast-lock-mode 814 (cond ((and (boundp 'fast-lock-mode) fast-lock-mode)
815 (fast-lock-mode -1)) 815 (fast-lock-mode -1))
816 (jit-lock-mode 816 ((and (boundp 'jit-lock-mode) jit-lock-mode)
817 (jit-lock-unregister 'font-lock-fontify-region) 817 (jit-lock-unregister 'font-lock-fontify-region)
818 ;; Reset local vars to the non-jit-lock case. 818 ;; Reset local vars to the non-jit-lock case.
819 (kill-local-variable 'font-lock-fontify-buffer-function)) 819 (kill-local-variable 'font-lock-fontify-buffer-function))
820 (lazy-lock-mode 820 ((and (boundp 'lazy-lock-mode) lazy-lock-mode)
821 (lazy-lock-mode -1)))) 821 (lazy-lock-mode -1))))
822 822
823 (defun font-lock-after-fontify-buffer () 823 (defun font-lock-after-fontify-buffer ()
824 (cond (fast-lock-mode 824 (cond ((and (boundp 'fast-lock-mode) fast-lock-mode)
825 (fast-lock-after-fontify-buffer)) 825 (fast-lock-after-fontify-buffer))
826 ;; Useless now that jit-lock intercepts font-lock-fontify-buffer. -sm 826 ;; Useless now that jit-lock intercepts font-lock-fontify-buffer. -sm
827 ;; (jit-lock-mode 827 ;; (jit-lock-mode
828 ;; (jit-lock-after-fontify-buffer)) 828 ;; (jit-lock-after-fontify-buffer))
829 (lazy-lock-mode 829 ((and (boundp 'lazy-lock-mode) lazy-lock-mode)
830 (lazy-lock-after-fontify-buffer)))) 830 (lazy-lock-after-fontify-buffer))))
831 831
832 (defun font-lock-after-unfontify-buffer () 832 (defun font-lock-after-unfontify-buffer ()
833 (cond (fast-lock-mode 833 (cond ((and (boundp 'fast-lock-mode) fast-lock-mode)
834 (fast-lock-after-unfontify-buffer)) 834 (fast-lock-after-unfontify-buffer))
835 ;; Useless as well. It's only called when: 835 ;; Useless as well. It's only called when:
836 ;; - turning off font-lock: it does not matter if we leave spurious 836 ;; - turning off font-lock: it does not matter if we leave spurious
837 ;; `fontified' text props around since jit-lock-mode is also off. 837 ;; `fontified' text props around since jit-lock-mode is also off.
838 ;; - font-lock-default-fontify-buffer fails: this is not run 838 ;; - font-lock-default-fontify-buffer fails: this is not run
839 ;; any more anyway. -sm 839 ;; any more anyway. -sm
840 ;; 840 ;;
841 ;; (jit-lock-mode 841 ;; (jit-lock-mode
842 ;; (jit-lock-after-unfontify-buffer)) 842 ;; (jit-lock-after-unfontify-buffer))
843 (lazy-lock-mode 843 ((and (boundp 'lazy-lock-mode) lazy-lock-mode)
844 (lazy-lock-after-unfontify-buffer)))) 844 (lazy-lock-after-unfontify-buffer))))
845 845
846 ;;; End of Font Lock Support mode. 846 ;;; End of Font Lock Support mode.
847 847
848 ;;; Fontification functions. 848 ;;; Fontification functions.
930 (widen) 930 (widen)
931 (font-lock-unfontify-region (point-min) (point-max)) 931 (font-lock-unfontify-region (point-min) (point-max))
932 (font-lock-after-unfontify-buffer) 932 (font-lock-after-unfontify-buffer)
933 (setq font-lock-fontified nil))) 933 (setq font-lock-fontified nil)))
934 934
935 (defvar font-lock-dont-widen nil
936 "If non-nil, font-lock will work on the non-widened buffer.
937 Useful for things like RMAIL and Info where the whole buffer is not
938 a very meaningful entity to highlight.")
939
935 (defun font-lock-default-fontify-region (beg end loudly) 940 (defun font-lock-default-fontify-region (beg end loudly)
936 (save-buffer-state 941 (save-buffer-state
937 ((parse-sexp-lookup-properties font-lock-syntactic-keywords) 942 ((parse-sexp-lookup-properties font-lock-syntactic-keywords)
938 (old-syntax-table (syntax-table))) 943 (old-syntax-table (syntax-table)))
939 (unwind-protect 944 (unwind-protect
940 (save-restriction 945 (save-restriction
941 (widen) 946 (unless font-lock-dont-widen (widen))
942 ;; Use the fontification syntax table, if any. 947 ;; Use the fontification syntax table, if any.
943 (when font-lock-syntax-table 948 (when font-lock-syntax-table
944 (set-syntax-table font-lock-syntax-table)) 949 (set-syntax-table font-lock-syntax-table))
945 ;; check to see if we should expand the beg/end area for 950 ;; check to see if we should expand the beg/end area for
946 ;; proper multiline matches 951 ;; proper multiline matches
1023 (save-excursion (forward-line lines) (point)))) 1028 (save-excursion (forward-line lines) (point))))
1024 (funcall font-lock-mark-block-function) 1029 (funcall font-lock-mark-block-function)
1025 (font-lock-fontify-region (point) (mark))) 1030 (font-lock-fontify-region (point) (mark)))
1026 ((error quit) (message "Fontifying block...%s" error-data))))))) 1031 ((error quit) (message "Fontifying block...%s" error-data)))))))
1027 1032
1028 (define-key facemenu-keymap "\M-g" 'font-lock-fontify-block) 1033 (if (boundp 'facemenu-keymap)
1034 (define-key facemenu-keymap "\M-g" 'font-lock-fontify-block))
1029 1035
1030 ;;; End of Fontification functions. 1036 ;;; End of Fontification functions.
1031 1037
1032 ;;; Additional text property functions. 1038 ;;; Additional text property functions.
1033 1039
1310 ;; Evaluate POST-MATCH-FORM. 1316 ;; Evaluate POST-MATCH-FORM.
1311 (eval (nth 2 keywords)))) 1317 (eval (nth 2 keywords))))
1312 1318
1313 (defun font-lock-fontify-keywords-region (start end &optional loudly) 1319 (defun font-lock-fontify-keywords-region (start end &optional loudly)
1314 "Fontify according to `font-lock-keywords' between START and END. 1320 "Fontify according to `font-lock-keywords' between START and END.
1315 START should be at the beginning of a line." 1321 START should be at the beginning of a line.
1322 LOUDLY, if non-nil, allows progress-meter bar."
1316 (unless (eq (car font-lock-keywords) t) 1323 (unless (eq (car font-lock-keywords) t)
1317 (setq font-lock-keywords 1324 (setq font-lock-keywords
1318 (font-lock-compile-keywords font-lock-keywords t))) 1325 (font-lock-compile-keywords font-lock-keywords t)))
1319 (let ((case-fold-search font-lock-keywords-case-fold-search) 1326 (let ((case-fold-search font-lock-keywords-case-fold-search)
1320 (keywords (cdr font-lock-keywords)) 1327 (keywords (cdr font-lock-keywords))