aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2015-03-30 21:33:20 -0400
committerStefan Monnier2015-03-30 21:33:20 -0400
commitbc9a6fcd29cd2e35a34e42f6e8b9492c98c1560f (patch)
treee44d050c05b9104e1259aa73d7acf9dde443f19a
parent2e4b0c98a77657e787e04ae680403b187b271c21 (diff)
downloademacs-bc9a6fcd29cd2e35a34e42f6e8b9492c98c1560f.tar.gz
emacs-bc9a6fcd29cd2e35a34e42f6e8b9492c98c1560f.zip
Let jit-lock know the result of font-lock-extend-region-functions.
* lisp/jit-lock.el (jit-lock--run-functions): New function. (jit-lock-fontify-now): Use it. Handle fontification bounds more precisely in case the backend functions fontify more than requested. Don't round up to whole lines since that shouldn't be needed any more. * lisp/font-lock.el (font-lock-fontify-region-function): Adjust docstring. (font-lock-inhibit-thing-lock): Make obsolete. (font-lock-default-fontify-region): Return the bounds actually used. * lisp/emacs-lisp/eieio-base.el (eieio-persistent-validate/fix-slot-value): Fix compilation error.
-rw-r--r--lisp/ChangeLog15
-rw-r--r--lisp/emacs-lisp/eieio-base.el3
-rw-r--r--lisp/font-lock.el13
-rw-r--r--lisp/jit-lock.el109
4 files changed, 91 insertions, 49 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index cad239d7dee..e50c69b8af4 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,18 @@
12015-03-31 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 Let jit-lock know the result of font-lock-extend-region-functions.
4 * jit-lock.el (jit-lock--run-functions): New function.
5 (jit-lock-fontify-now): Use it. Handle fontification bounds more
6 precisely in case the backend functions fontify more than requested.
7 Don't round up to whole lines since that shouldn't be needed
8 any more.
9 * font-lock.el (font-lock-fontify-region-function): Adjust docstring.
10 (font-lock-inhibit-thing-lock): Make obsolete.
11 (font-lock-default-fontify-region): Return the bounds actually used.
12
13 * emacs-lisp/eieio-base.el (eieio-persistent-validate/fix-slot-value):
14 Fix compilation error.
15
12015-03-30 Artur Malabarba <bruce.connor.am@gmail.com> 162015-03-30 Artur Malabarba <bruce.connor.am@gmail.com>
2 17
3 * emacs-lisp/package.el: Reorganize package.el and divide it with 18 * emacs-lisp/package.el: Reorganize package.el and divide it with
diff --git a/lisp/emacs-lisp/eieio-base.el b/lisp/emacs-lisp/eieio-base.el
index c2eab202881..2e280365a7a 100644
--- a/lisp/emacs-lisp/eieio-base.el
+++ b/lisp/emacs-lisp/eieio-base.el
@@ -294,7 +294,8 @@ Second, any text properties will be stripped from strings."
294 (cond ((consp proposed-value) 294 (cond ((consp proposed-value)
295 ;; Lists with something in them need special treatment. 295 ;; Lists with something in them need special treatment.
296 (let* ((slot-idx (- (eieio--slot-name-index class slot) 296 (let* ((slot-idx (- (eieio--slot-name-index class slot)
297 (eval-when-compile eieio--object-num-slots))) 297 (eval-when-compile
298 (length (cl-struct-slot-info 'eieio--object)))))
298 (type (cl--slot-descriptor-type (aref (eieio--class-slots class) 299 (type (cl--slot-descriptor-type (aref (eieio--class-slots class)
299 slot-idx))) 300 slot-idx)))
300 (classtype (eieio-persistent-slot-type-is-class-p type))) 301 (classtype (eieio-persistent-slot-type-is-class-p type)))
diff --git a/lisp/font-lock.el b/lisp/font-lock.el
index 6c8392bc090..96b290e34f4 100644
--- a/lisp/font-lock.el
+++ b/lisp/font-lock.el
@@ -585,11 +585,14 @@ This is normally set via `font-lock-defaults'.")
585This is used when turning off Font Lock mode. 585This is used when turning off Font Lock mode.
586This is normally set via `font-lock-defaults'.") 586This is normally set via `font-lock-defaults'.")
587 587
588(defvar font-lock-fontify-region-function 'font-lock-default-fontify-region 588(defvar font-lock-fontify-region-function #'font-lock-default-fontify-region
589 "Function to use for fontifying a region. 589 "Function to use for fontifying a region.
590It should take two args, the beginning and end of the region, and an optional 590It should take two args, the beginning and end of the region, and an optional
591third arg VERBOSE. If VERBOSE is non-nil, the function should print status 591third arg VERBOSE. If VERBOSE is non-nil, the function should print status
592messages. This is normally set via `font-lock-defaults'.") 592messages. This is normally set via `font-lock-defaults'.
593If it fontifies a larger region, it should ideally return a list of the form
594\(jit-lock-bounds BEG . END) indicating the bounds of the region actually
595fontified.")
593 596
594(defvar font-lock-unfontify-region-function 'font-lock-default-unfontify-region 597(defvar font-lock-unfontify-region-function 'font-lock-default-unfontify-region
595 "Function to use for unfontifying a region. 598 "Function to use for unfontifying a region.
@@ -600,6 +603,7 @@ This is normally set via `font-lock-defaults'.")
600 "List of Font Lock mode related modes that should not be turned on. 603 "List of Font Lock mode related modes that should not be turned on.
601Currently, valid mode names are `fast-lock-mode', `jit-lock-mode' and 604Currently, valid mode names are `fast-lock-mode', `jit-lock-mode' and
602`lazy-lock-mode'. This is normally set via `font-lock-defaults'.") 605`lazy-lock-mode'. This is normally set via `font-lock-defaults'.")
606(make-obsolete-variable 'font-lock-inhibit-thing-lock nil "25.1")
603 607
604(defvar-local font-lock-multiline nil 608(defvar-local font-lock-multiline nil
605 "Whether font-lock should cater to multiline keywords. 609 "Whether font-lock should cater to multiline keywords.
@@ -935,7 +939,7 @@ The value of this variable is used when Font Lock mode is turned on."
935 ;; Don't fontify eagerly (and don't abort if the buffer is large). 939 ;; Don't fontify eagerly (and don't abort if the buffer is large).
936 (set (make-local-variable 'font-lock-fontified) t) 940 (set (make-local-variable 'font-lock-fontified) t)
937 ;; Use jit-lock. 941 ;; Use jit-lock.
938 (jit-lock-register 'font-lock-fontify-region 942 (jit-lock-register #'font-lock-fontify-region
939 (not font-lock-keywords-only)) 943 (not font-lock-keywords-only))
940 ;; Tell jit-lock how we extend the region to refontify. 944 ;; Tell jit-lock how we extend the region to refontify.
941 (add-hook 'jit-lock-after-change-extend-region-functions 945 (add-hook 'jit-lock-after-change-extend-region-functions
@@ -1220,7 +1224,8 @@ This function is the default `font-lock-fontify-region-function'."
1220 (font-lock-fontify-syntactic-keywords-region start end))) 1224 (font-lock-fontify-syntactic-keywords-region start end)))
1221 (unless font-lock-keywords-only 1225 (unless font-lock-keywords-only
1222 (font-lock-fontify-syntactically-region beg end loudly)) 1226 (font-lock-fontify-syntactically-region beg end loudly))
1223 (font-lock-fontify-keywords-region beg end loudly))))) 1227 (font-lock-fontify-keywords-region beg end loudly)
1228 `(jit-lock-bounds ,beg . ,end)))))
1224 1229
1225;; The following must be rethought, since keywords can override fontification. 1230;; The following must be rethought, since keywords can override fontification.
1226;; ;; Now scan for keywords, but not if we are inside a comment now. 1231;; ;; Now scan for keywords, but not if we are inside a comment now.
diff --git a/lisp/jit-lock.el b/lisp/jit-lock.el
index 788646c97be..d271a447756 100644
--- a/lisp/jit-lock.el
+++ b/lisp/jit-lock.el
@@ -351,6 +351,24 @@ is active."
351 (min (point-max) (+ start jit-lock-chunk-size))) 351 (min (point-max) (+ start jit-lock-chunk-size)))
352 'fontified 'defer))))) 352 'fontified 'defer)))))
353 353
354(defun jit-lock--run-functions (beg end)
355 (let ((tight-beg nil) (tight-end nil)
356 (loose-beg beg) (loose-end end))
357 (run-hook-wrapped
358 'jit-lock-functions
359 (lambda (fun)
360 (pcase-let*
361 ((res (funcall fun beg end))
362 (`(,this-beg . ,this-end)
363 (if (eq (car-safe res) 'jit-lock-bounds)
364 (cdr res) (cons beg end))))
365 (setq tight-beg (max tight-beg (or this-beg (point-min))))
366 (setq tight-end (max tight-end (or this-end (point-max))))
367 (setq loose-beg (max loose-beg this-beg))
368 (setq loose-end (max loose-end this-end))
369 nil)))
370 `(,(min tight-beg beg) ,(max tight-end end) ,loose-beg ,loose-end)))
371
354(defun jit-lock-fontify-now (&optional start end) 372(defun jit-lock-fontify-now (&optional start end)
355 "Fontify current buffer from START to END. 373 "Fontify current buffer from START to END.
356Defaults to the whole buffer. END can be out of bounds." 374Defaults to the whole buffer. END can be out of bounds."
@@ -376,54 +394,57 @@ Defaults to the whole buffer. END can be out of bounds."
376 (setq next (or (text-property-any start end 'fontified t) 394 (setq next (or (text-property-any start end 'fontified t)
377 end)) 395 end))
378 396
379 ;; Decide which range of text should be fontified.
380 ;; The problem is that START and NEXT may be in the
381 ;; middle of something matched by a font-lock regexp.
382 ;; Until someone has a better idea, let's start
383 ;; at the start of the line containing START and
384 ;; stop at the start of the line following NEXT.
385 (goto-char next) (setq next (line-beginning-position 2))
386 (goto-char start) (setq start (line-beginning-position))
387
388 ;; Make sure the contextual refontification doesn't re-refontify
389 ;; what's already been refontified.
390 (when (and jit-lock-context-unfontify-pos
391 (< jit-lock-context-unfontify-pos next)
392 (>= jit-lock-context-unfontify-pos start)
393 ;; Don't move boundary forward if we have to
394 ;; refontify previous text. Otherwise, we risk moving
395 ;; it past the end of the multiline property and thus
396 ;; forget about this multiline region altogether.
397 (not (get-text-property start 'jit-lock-defer-multiline)))
398 (setq jit-lock-context-unfontify-pos next))
399
400 ;; Fontify the chunk, and mark it as fontified. 397 ;; Fontify the chunk, and mark it as fontified.
401 ;; We mark it first, to make sure that we don't indefinitely 398 ;; We mark it first, to make sure that we don't indefinitely
402 ;; re-execute this fontification if an error occurs. 399 ;; re-execute this fontification if an error occurs.
403 (put-text-property start next 'fontified t) 400 (put-text-property start next 'fontified t)
404 (condition-case err 401 (pcase-let
405 (run-hook-with-args 'jit-lock-functions start next) 402 ;; `tight' is the part we've fully refontified, and `loose'
406 ;; If the user quits (which shouldn't happen in normal on-the-fly 403 ;; is the part we've partly refontified (some of the
407 ;; jit-locking), make sure the fontification will be performed 404 ;; functions have refontified it but maybe not all).
408 ;; before displaying the block again. 405 ((`(,tight-beg ,tight-end ,loose-beg ,loose-end)
409 (quit (put-text-property start next 'fontified nil) 406 (condition-case err
410 (funcall 'signal (car err) (cdr err)))) 407 (jit-lock--run-functions start next)
411 408 ;; If the user quits (which shouldn't happen in normal
412 ;; The redisplay engine has already rendered the buffer up-to 409 ;; on-the-fly jit-locking), make sure the fontification
413 ;; `orig-start' and won't notice if the above jit-lock-functions 410 ;; will be performed before displaying the block again.
414 ;; changed the appearance of any part of the buffer prior 411 (quit (put-text-property start next 'fontified nil)
415 ;; to that. So if `start' is before `orig-start', we need to 412 (signal (car err) (cdr err))))))
416 ;; cause a new redisplay cycle after this one so that any changes 413
417 ;; are properly reflected on screen. 414 ;; In case we fontified more than requested, take note.
418 ;; To make such repeated redisplay happen less often, we can 415 (when (or (< tight-beg start) (> tight-end next))
419 ;; eagerly extend the refontified region with 416 (put-text-property tight-beg tight-end 'fontified t))
420 ;; jit-lock-after-change-extend-region-functions. 417
421 (when (< start orig-start) 418 ;; Make sure the contextual refontification doesn't re-refontify
422 (run-with-timer 0 nil #'jit-lock-force-redisplay 419 ;; what's already been refontified.
423 (copy-marker start) (copy-marker orig-start))) 420 (when (and jit-lock-context-unfontify-pos
424 421 (< jit-lock-context-unfontify-pos tight-end)
425 ;; Find the start of the next chunk, if any. 422 (>= jit-lock-context-unfontify-pos tight-beg)
426 (setq start (text-property-any next end 'fontified nil)))))))) 423 ;; Don't move boundary forward if we have to
424 ;; refontify previous text. Otherwise, we risk moving
425 ;; it past the end of the multiline property and thus
426 ;; forget about this multiline region altogether.
427 (not (get-text-property tight-beg
428 'jit-lock-defer-multiline)))
429 (setq jit-lock-context-unfontify-pos tight-end))
430
431 ;; The redisplay engine has already rendered the buffer up-to
432 ;; `orig-start' and won't notice if the above jit-lock-functions
433 ;; changed the appearance of any part of the buffer prior
434 ;; to that. So if `loose-beg' is before `orig-start', we need to
435 ;; cause a new redisplay cycle after this one so that the changes
436 ;; are properly reflected on screen.
437 ;; To make such repeated redisplay happen less often, we can
438 ;; eagerly extend the refontified region with
439 ;; jit-lock-after-change-extend-region-functions.
440 (when (< loose-beg orig-start)
441 (run-with-timer 0 nil #'jit-lock-force-redisplay
442 (copy-marker loose-beg)
443 (copy-marker orig-start)))
444
445 ;; Find the start of the next chunk, if any.
446 (setq start
447 (text-property-any tight-end end 'fontified nil)))))))))
427 448
428(defun jit-lock-force-redisplay (start end) 449(defun jit-lock-force-redisplay (start end)
429 "Force the display engine to re-render START's buffer from START to END. 450 "Force the display engine to re-render START's buffer from START to END.