From a642b4d35c86b871a97a4d5f150ed17303603413 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Wed, 11 Dec 2019 20:21:17 -0500 Subject: [PATCH] * lisp/font-lock.el (font-lock-fontify-region): Widen here (bug#38049) (font-lock-default-fontify-region): Instead of here. --- lisp/font-lock.el | 68 +++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/lisp/font-lock.el b/lisp/font-lock.el index c20b410a687..c44041da073 100644 --- a/lisp/font-lock.el +++ b/lisp/font-lock.el @@ -1071,7 +1071,9 @@ The region it returns may start or end in the middle of a line.") If LOUDLY is non-nil, print status messages while fontifying. This works by calling `font-lock-fontify-region-function'." (font-lock-set-defaults) - (funcall font-lock-fontify-region-function beg end loudly)) + (save-restriction + (unless font-lock-dont-widen (widen)) + (funcall font-lock-fontify-region-function beg end loudly))) (defun font-lock-unfontify-region (beg end) "Unfontify the text between BEG and END. @@ -1219,39 +1221,37 @@ Put first the functions more likely to cause a change and cheaper to compute.") If LOUDLY is non-nil, print status messages while fontifying. This function is the default `font-lock-fontify-region-function'." (save-buffer-state - ;; Use the fontification syntax table, if any. - (with-syntax-table (or font-lock-syntax-table (syntax-table)) - (save-restriction - (unless font-lock-dont-widen (widen)) - ;; Extend the region to fontify so that it starts and ends at - ;; safe places. - (let ((funs font-lock-extend-region-functions) - (font-lock-beg beg) - (font-lock-end end)) - (while funs - (setq funs (if (or (not (funcall (car funs))) - (eq funs font-lock-extend-region-functions)) - (cdr funs) - ;; If there's been a change, we should go through - ;; the list again since this new position may - ;; warrant a different answer from one of the fun - ;; we've already seen. - font-lock-extend-region-functions))) - (setq beg font-lock-beg end font-lock-end)) - ;; Now do the fontification. - (font-lock-unfontify-region beg end) - (when (and font-lock-syntactic-keywords - (null syntax-propertize-function)) - ;; Ensure the beginning of the file is properly syntactic-fontified. - (let ((start beg)) - (when (< font-lock-syntactically-fontified start) - (setq start (max font-lock-syntactically-fontified (point-min))) - (setq font-lock-syntactically-fontified end)) - (font-lock-fontify-syntactic-keywords-region start end))) - (unless font-lock-keywords-only - (font-lock-fontify-syntactically-region beg end loudly)) - (font-lock-fontify-keywords-region beg end loudly) - `(jit-lock-bounds ,beg . ,end))))) + ;; Use the fontification syntax table, if any. + (with-syntax-table (or font-lock-syntax-table (syntax-table)) + ;; Extend the region to fontify so that it starts and ends at + ;; safe places. + (let ((funs font-lock-extend-region-functions) + (font-lock-beg beg) + (font-lock-end end)) + (while funs + (setq funs (if (or (not (funcall (car funs))) + (eq funs font-lock-extend-region-functions)) + (cdr funs) + ;; If there's been a change, we should go through + ;; the list again since this new position may + ;; warrant a different answer from one of the fun + ;; we've already seen. + font-lock-extend-region-functions))) + (setq beg font-lock-beg end font-lock-end)) + ;; Now do the fontification. + (font-lock-unfontify-region beg end) + (when (and font-lock-syntactic-keywords + (null syntax-propertize-function)) + ;; Ensure the beginning of the file is properly syntactic-fontified. + (let ((start beg)) + (when (< font-lock-syntactically-fontified start) + (setq start (max font-lock-syntactically-fontified (point-min))) + (setq font-lock-syntactically-fontified end)) + (font-lock-fontify-syntactic-keywords-region start end))) + (unless font-lock-keywords-only + (font-lock-fontify-syntactically-region beg end loudly)) + (font-lock-fontify-keywords-region beg end loudly) + `(jit-lock-bounds ,beg . ,end)))) ;; The following must be rethought, since keywords can override fontification. ;; ;; Now scan for keywords, but not if we are inside a comment now. -- 2.39.2