• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.10/emacs-93/emacs/lisp/

Lines Matching +defs:jit +defs:lock +defs:fontify +defs:now

0 ;;; jit-lock.el --- just-in-time fontification
46 (defmacro with-buffer-prepared-for-jit-lock (&rest body)
65 (defgroup jit-lock nil
66 "Font Lock support mode to fontify just-in-time."
68 :group 'font-lock)
70 (defcustom jit-lock-chunk-size 500
71 "*Jit-lock fontifies chunks of at most this many characters at a time.
75 :group 'jit-lock)
78 (defcustom jit-lock-stealth-time nil
86 :group 'jit-lock)
89 (defcustom jit-lock-stealth-nice 0.5
95 taking longer to fontify, you could increase the value of this variable.
96 See also `jit-lock-stealth-load'."
99 :group 'jit-lock)
102 (defcustom jit-lock-stealth-load
110 taking longer to fontify, you could reduce the value of this variable.
111 See also `jit-lock-stealth-nice'."
116 :group 'jit-lock)
119 (defcustom jit-lock-stealth-verbose nil
122 :group 'jit-lock)
125 (defvaralias 'jit-lock-defer-contextually 'jit-lock-contextually)
126 (defcustom jit-lock-contextually 'syntax-driven
133 their new syntactic context, after `jit-lock-context-time' seconds.
136 buffer mode's syntax table, i.e., only if `font-lock-keywords-only' is nil.
142 :group 'jit-lock)
144 (defcustom jit-lock-context-time 0.5
147 :group 'jit-lock)
149 (defcustom jit-lock-defer-time nil ;; 0.25
152 :group 'jit-lock
159 (defvar jit-lock-mode nil
161 (make-variable-buffer-local 'jit-lock-mode)
163 (defvar jit-lock-functions nil
165 They are called with two arguments: the START and END of the region to fontify.")
166 (make-variable-buffer-local 'jit-lock-functions)
168 (defvar jit-lock-context-unfontify-pos nil
171 (make-variable-buffer-local 'jit-lock-context-unfontify-pos)
174 (defvar jit-lock-stealth-timer nil
176 (defvar jit-lock-stealth-repeat-timer nil
178 (defvar jit-lock-context-timer nil
180 (defvar jit-lock-defer-timer nil
183 (defvar jit-lock-defer-buffers nil
185 (defvar jit-lock-stealth-buffers nil
189 ;;; JIT lock mode
191 (defun jit-lock-mode (arg)
194 Enable it automatically by customizing group `font-lock'.
205 - Stealthy buffer fontification if `jit-lock-stealth-time' is non-nil.
207 been idle for `jit-lock-stealth-time' seconds, while Emacs remains idle.
210 - Deferred context fontification if `jit-lock-contextually' is
212 true syntactic context, after `jit-lock-context-time' seconds of Emacs
219 If the system load rises above `jit-lock-stealth-load' percent, stealth
221 the variable `jit-lock-stealth-nice'."
222 (setq jit-lock-mode arg)
224 jit-lock-mode
227 (jit-lock-refontify)
230 (when (and jit-lock-stealth-time (null jit-lock-stealth-timer))
231 (setq jit-lock-stealth-timer
232 (run-with-idle-timer jit-lock-stealth-time t
233 'jit-lock-stealth-fontify)))
237 (when (and jit-lock-stealth-time (null jit-lock-stealth-repeat-timer))
238 (setq jit-lock-stealth-repeat-timer (timer-create))
239 (timer-set-function jit-lock-stealth-repeat-timer
240 'jit-lock-stealth-fontify '(t)))
243 (when (and jit-lock-defer-time (null jit-lock-defer-timer))
244 (setq jit-lock-defer-timer
245 (run-with-idle-timer jit-lock-defer-time t
246 'jit-lock-deferred-fontify)))
249 (when (eq jit-lock-contextually t)
250 (unless jit-lock-context-timer
251 (setq jit-lock-context-timer
252 (run-with-idle-timer jit-lock-context-time t
253 'jit-lock-context-fontify)))
254 (setq jit-lock-context-unfontify-pos
255 (or jit-lock-context-unfontify-pos (point-max))))
258 (add-hook 'after-change-functions 'jit-lock-after-change nil t)
259 (add-hook 'fontification-functions 'jit-lock-function))
264 (when (and (or jit-lock-stealth-timer jit-lock-defer-timer
265 jit-lock-context-timer)
270 (when jit-lock-mode (throw 'found t)))))))
271 (when jit-lock-stealth-timer
272 (cancel-timer jit-lock-stealth-timer)
273 (setq jit-lock-stealth-timer nil))
274 (when jit-lock-context-timer
275 (cancel-timer jit-lock-context-timer)
276 (setq jit-lock-context-timer nil))
277 (when jit-lock-defer-timer
278 (cancel-timer jit-lock-defer-timer)
279 (setq jit-lock-defer-timer nil)))
282 (remove-hook 'after-change-functions 'jit-lock-after-change t)
283 (remove-hook 'fontification-functions 'jit-lock-function))))
285 (defun jit-lock-register (fun &optional contextual)
290 (add-hook 'jit-lock-functions fun nil t)
291 (when (and contextual jit-lock-contextually)
292 (set (make-local-variable 'jit-lock-contextually) t))
293 (jit-lock-mode t))
295 (defun jit-lock-unregister (fun)
298 (remove-hook 'jit-lock-functions fun t)
299 (unless jit-lock-functions (jit-lock-mode nil)))
301 ;; This function is used to prevent font-lock-fontify-buffer from
305 (defun jit-lock-refontify (&optional beg end)
307 (with-buffer-prepared-for-jit-lock
316 (defun jit-lock-function (start)
318 This function is added to `fontification-functions' when `jit-lock-mode'
320 (when (and jit-lock-mode (not memory-full))
321 (if (null jit-lock-defer-timer)
323 (jit-lock-fontify-now start (+ start jit-lock-chunk-size))
325 (unless (memq (current-buffer) jit-lock-defer-buffers)
326 (push (current-buffer) jit-lock-defer-buffers))
328 ;; is happy and so that the idle timer can find the places to fontify.
329 (with-buffer-prepared-for-jit-lock
333 (min (point-max) (+ start jit-lock-chunk-size)))
336 (defun jit-lock-fontify-now (&optional start end)
339 (with-buffer-prepared-for-jit-lock
343 ;; This did bind `font-lock-beginning-of-syntax-function' to
347 ;; `font-lock-fontify-syntactically-region'. Example: paging
363 ;; middle of something matched by a font-lock regexp.
372 (when (and jit-lock-context-unfontify-pos
373 (< jit-lock-context-unfontify-pos next)
374 (>= jit-lock-context-unfontify-pos start)
379 (not (get-text-property start 'jit-lock-defer-multiline)))
380 (setq jit-lock-context-unfontify-pos next))
387 (run-hook-with-args 'jit-lock-functions start next)
389 ;; jit-locking), make sure the fontification will be performed
395 ;; `orig-start' and won't notice if the above jit-lock-functions
402 ;; jit-lock-after-change-extend-region-functions.
404 (run-with-timer 0 nil 'jit-lock-force-redisplay
410 (defun jit-lock-force-redisplay (buf start end)
413 (with-buffer-prepared-for-jit-lock
423 (defsubst jit-lock-stealth-chunk-start (around)
424 "Return the start of the next chunk to fontify around position AROUND..
425 Value is nil if there is nothing more to fontify."
443 (- around (/ jit-lock-chunk-size 2)))))
451 (- prev jit-lock-chunk-size)))
457 (max prev (- around jit-lock-chunk-size)))))
464 (defun jit-lock-stealth-fontify (&optional repeat)
467 `jit-lock-stealth-time' seconds. Optional argument REPEAT is expected
471 (cancel-timer jit-lock-stealth-repeat-timer))
475 ;; For first invocation set up `jit-lock-stealth-buffers'.
478 jit-lock-stealth-buffers
479 (setq jit-lock-stealth-buffers (buffer-list)))))
480 (let ((buffer (car jit-lock-stealth-buffers))
485 (if (and jit-lock-stealth-load
486 (> (car (load-average)) jit-lock-stealth-load))
488 (setq delay jit-lock-stealth-time)
491 (if (and jit-lock-mode
492 (setq start (jit-lock-stealth-chunk-start (point))))
493 ;; Fontify one block of at most `jit-lock-chunk-size'
495 (with-temp-message (if jit-lock-stealth-verbose
496 (concat "JIT stealth lock "
498 (jit-lock-fontify-now start
499 (+ start jit-lock-chunk-size))
500 ;; Run again after `jit-lock-stealth-nice' seconds.
501 (setq delay (or jit-lock-stealth-nice 0)))
502 ;; Nothing to fontify here. Remove this buffer from
503 ;; `jit-lock-stealth-buffers' and run again immediately.
504 (setq jit-lock-stealth-buffers (cdr jit-lock-stealth-buffers))))
506 ;; `jit-lock-stealth-buffers' and run again immediately.
507 (setq jit-lock-stealth-buffers (cdr jit-lock-stealth-buffers))))
509 (when jit-lock-stealth-buffers
510 (timer-set-idle-time jit-lock-stealth-repeat-timer (current-idle-time))
511 (timer-inc-time jit-lock-stealth-repeat-timer delay)
512 (timer-activate-when-idle jit-lock-stealth-repeat-timer t)))))
518 (defun jit-lock-deferred-fontify ()
520 (when (and jit-lock-defer-buffers (not memory-full))
522 (dolist (buffer jit-lock-defer-buffers)
526 (with-buffer-prepared-for-jit-lock
536 (setq jit-lock-defer-buffers nil)
538 (let ((jit-lock-defer-timer nil))
545 (defun jit-lock-context-fontify ()
550 (when jit-lock-context-unfontify-pos
554 (when (and (>= jit-lock-context-unfontify-pos (point-min))
555 (< jit-lock-context-unfontify-pos (point-max)))
557 ;; font-lock pattern, make sure the whole text will be
559 ;; Despite its name, we treat jit-lock-defer-multiline here
560 ;; rather than in jit-lock-defer since it has to do with multiple
562 (when (get-text-property jit-lock-context-unfontify-pos
563 'jit-lock-defer-multiline)
564 (setq jit-lock-context-unfontify-pos
566 jit-lock-context-unfontify-pos
567 'jit-lock-defer-multiline)
569 (with-buffer-prepared-for-jit-lock
572 jit-lock-context-unfontify-pos (point-max)
573 '(fontified nil jit-lock-defer-multiline nil)))
574 (setq jit-lock-context-unfontify-pos (point-max)))))))))
576 (defvar jit-lock-start) (defvar jit-lock-end) ; Dynamically scoped variables.
577 (defvar jit-lock-after-change-extend-region-functions nil
582 the variables `jit-lock-start' and `jit-lock-end'.
587 redisplay (see comment about repeated redisplay in `jit-lock-fontify-now').")
589 (defun jit-lock-after-change (start end old-len)
597 (when (and jit-lock-mode (not memory-full))
598 (let ((jit-lock-start start)
599 (jit-lock-end end))
600 (with-buffer-prepared-for-jit-lock
601 (run-hook-with-args 'jit-lock-after-change-extend-region-functions
604 (setq jit-lock-end (min (max jit-lock-end (1+ start)) (point-max)))
606 (put-text-property jit-lock-start jit-lock-end 'fontified nil))
608 (when jit-lock-context-unfontify-pos
609 (setq jit-lock-context-unfontify-pos
614 ;; buffer, only jit-lock-context-* will re-fontify it.
615 (min jit-lock-context-unfontify-pos jit-lock-start))))))
617 (provide 'jit-lock)
620 ;;; jit-lock.el ends here