diff options
| author | Alan Mackenzie | 2006-03-14 18:23:47 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2006-03-14 18:23:47 +0000 |
| commit | ef0083218d1bb912de6e7a156e5b56607ac4997b (patch) | |
| tree | a87580096d1e70512b158ff12472e3c30312c874 | |
| parent | 8a34117e23756a7e6e5f3f1a00d46774e6f35975 (diff) | |
| download | emacs-ef0083218d1bb912de6e7a156e5b56607ac4997b.tar.gz emacs-ef0083218d1bb912de6e7a156e5b56607ac4997b.zip | |
* font-core.el: New function/variable
font-lock-extend-region\(-function\)?.
* font-lock.el (font-lock-after-change-function): Call
font-lock-extend-region. Obey font-lock-lines-before.
(font-lock-default-fontify-region): Remove reference to
font-lock-lines-before.
* jit-lock.el (jit-lock-after-change): Call
font-lock-extend-region. Obey font-lock-lines-before.
| -rw-r--r-- | lisp/font-core.el | 28 | ||||
| -rw-r--r-- | lisp/font-lock.el | 17 | ||||
| -rw-r--r-- | lisp/jit-lock.el | 68 |
3 files changed, 77 insertions, 36 deletions
diff --git a/lisp/font-core.el b/lisp/font-core.el index 85bbf60f0d9..d2cb8dccd10 100644 --- a/lisp/font-core.el +++ b/lisp/font-core.el | |||
| @@ -83,6 +83,34 @@ where MAJOR-MODE is a symbol and FONT-LOCK-DEFAULTS is a list of default | |||
| 83 | settings. See the variable `font-lock-defaults', which takes precedence.") | 83 | settings. See the variable `font-lock-defaults', which takes precedence.") |
| 84 | (make-obsolete-variable 'font-lock-defaults-alist 'font-lock-defaults) | 84 | (make-obsolete-variable 'font-lock-defaults-alist 'font-lock-defaults) |
| 85 | 85 | ||
| 86 | (defvar font-lock-extend-region-function nil | ||
| 87 | "A function that determines the region to fontify after a change. | ||
| 88 | |||
| 89 | This buffer-local variable is either nil, or is a function that determines the | ||
| 90 | region to fontify. It is usually set by the major mode. The currently active | ||
| 91 | font-lock after-change function calls this function after each buffer change. | ||
| 92 | |||
| 93 | The function is given three parameters, the standard BEG, END, and OLD-LEN | ||
| 94 | from after-change-functions. It should return either a cons of the beginning | ||
| 95 | and end buffer positions \(in that order) of the region to fontify, or nil | ||
| 96 | \(which directs the caller to fontify a default region). This function need | ||
| 97 | not preserve point or the match-data, but must preserve the current | ||
| 98 | restriction. The region it returns may start or end in the middle of a | ||
| 99 | line.") | ||
| 100 | (make-variable-buffer-local 'font-lock-extend-region-function) | ||
| 101 | |||
| 102 | (defun font-lock-extend-region (beg end old-len) | ||
| 103 | "Determine the region to fontify after a buffer change. | ||
| 104 | |||
| 105 | BEG END and OLD-LEN are the standard parameters from after-change-functions. | ||
| 106 | The return value is either nil \(which directs the caller to chose the region | ||
| 107 | itself), or a cons of the beginning and end \(in that order) of the region. | ||
| 108 | The region returned may start or end in the middle of a line." | ||
| 109 | (if font-lock-extend-region-function | ||
| 110 | (save-match-data | ||
| 111 | (save-excursion | ||
| 112 | (funcall font-lock-extend-region-function beg end old-len))))) | ||
| 113 | |||
| 86 | (defvar font-lock-function 'font-lock-default-function | 114 | (defvar font-lock-function 'font-lock-default-function |
| 87 | "A function which is called when `font-lock-mode' is toggled. | 115 | "A function which is called when `font-lock-mode' is toggled. |
| 88 | It will be passed one argument, which is the current value of | 116 | It will be passed one argument, which is the current value of |
diff --git a/lisp/font-lock.el b/lisp/font-lock.el index 47d2267dbea..bae492509ec 100644 --- a/lisp/font-lock.el +++ b/lisp/font-lock.el | |||
| @@ -1039,7 +1039,7 @@ a very meaningful entity to highlight.") | |||
| 1039 | (when font-lock-syntax-table | 1039 | (when font-lock-syntax-table |
| 1040 | (set-syntax-table font-lock-syntax-table)) | 1040 | (set-syntax-table font-lock-syntax-table)) |
| 1041 | (goto-char beg) | 1041 | (goto-char beg) |
| 1042 | (setq beg (line-beginning-position (- 1 font-lock-lines-before))) | 1042 | (setq beg (line-beginning-position)) |
| 1043 | ;; check to see if we should expand the beg/end area for | 1043 | ;; check to see if we should expand the beg/end area for |
| 1044 | ;; proper multiline matches | 1044 | ;; proper multiline matches |
| 1045 | (when (and (> beg (point-min)) | 1045 | (when (and (> beg (point-min)) |
| @@ -1090,13 +1090,18 @@ what properties to clear before refontifying a region.") | |||
| 1090 | ;; Called when any modification is made to buffer text. | 1090 | ;; Called when any modification is made to buffer text. |
| 1091 | (defun font-lock-after-change-function (beg end old-len) | 1091 | (defun font-lock-after-change-function (beg end old-len) |
| 1092 | (let ((inhibit-point-motion-hooks t) | 1092 | (let ((inhibit-point-motion-hooks t) |
| 1093 | (inhibit-quit t)) | 1093 | (inhibit-quit t) |
| 1094 | (region (font-lock-extend-region beg end old-len))) | ||
| 1094 | (save-excursion | 1095 | (save-excursion |
| 1095 | (save-match-data | 1096 | (save-match-data |
| 1096 | ;; Rescan between start of lines enclosing the region. | 1097 | (if region |
| 1097 | (font-lock-fontify-region | 1098 | ;; Fontify the region the major mode has specified. |
| 1098 | (progn (goto-char beg) (forward-line 0) (point)) | 1099 | (setq beg (car region) end (cdr region)) |
| 1099 | (progn (goto-char end) (forward-line 1) (point))))))) | 1100 | ;; Fontify the whole lines which enclose the region. |
| 1101 | (setq beg (progn (goto-char beg) | ||
| 1102 | (forward-line (- font-lock-lines-before))) | ||
| 1103 | end (progn (goto-char end) (forward-line 1) (point)))) | ||
| 1104 | (font-lock-fontify-region beg end))))) | ||
| 1100 | 1105 | ||
| 1101 | (defun font-lock-fontify-block (&optional arg) | 1106 | (defun font-lock-fontify-block (&optional arg) |
| 1102 | "Fontify some lines the way `font-lock-fontify-buffer' would. | 1107 | "Fontify some lines the way `font-lock-fontify-buffer' would. |
diff --git a/lisp/jit-lock.el b/lisp/jit-lock.el index 09870310584..f82ead462f0 100644 --- a/lisp/jit-lock.el +++ b/lisp/jit-lock.el | |||
| @@ -557,36 +557,44 @@ This function ensures that lines following the change will be refontified | |||
| 557 | in case the syntax of those lines has changed. Refontification | 557 | in case the syntax of those lines has changed. Refontification |
| 558 | will take place when text is fontified stealthily." | 558 | will take place when text is fontified stealthily." |
| 559 | (when (and jit-lock-mode (not memory-full)) | 559 | (when (and jit-lock-mode (not memory-full)) |
| 560 | (save-excursion | 560 | (let ((region (font-lock-extend-region start end old-len))) |
| 561 | (with-buffer-prepared-for-jit-lock | 561 | (save-excursion |
| 562 | ;; It's important that the `fontified' property be set from the | 562 | (with-buffer-prepared-for-jit-lock |
| 563 | ;; beginning of the line, else font-lock will properly change the | 563 | ;; It's important that the `fontified' property be set from the |
| 564 | ;; text's face, but the display will have been done already and will | 564 | ;; beginning of the line, else font-lock will properly change the |
| 565 | ;; be inconsistent with the buffer's content. | 565 | ;; text's face, but the display will have been done already and will |
| 566 | (goto-char start) | 566 | ;; be inconsistent with the buffer's content. |
| 567 | (setq start (line-beginning-position)) | 567 | ;; |
| 568 | 568 | ;; FIXME!!! (Alan Mackenzie, 2006-03-14): If start isn't at a BOL, | |
| 569 | ;; If we're in text that matches a multi-line font-lock pattern, | 569 | ;; expanding the region to BOL might mis-fontify, should the BOL not |
| 570 | ;; make sure the whole text will be redisplayed. | 570 | ;; be at a "safe" position. |
| 571 | ;; I'm not sure this is ever necessary and/or sufficient. -stef | 571 | (setq start (if region |
| 572 | (when (get-text-property start 'font-lock-multiline) | 572 | (car region) |
| 573 | (setq start (or (previous-single-property-change | 573 | (goto-char start) |
| 574 | start 'font-lock-multiline) | 574 | (line-beginning-position (- 1 font-lock-lines-before)))) |
| 575 | (point-min)))) | 575 | |
| 576 | 576 | ;; If we're in text that matches a multi-line font-lock pattern, | |
| 577 | ;; Make sure we change at least one char (in case of deletions). | 577 | ;; make sure the whole text will be redisplayed. |
| 578 | (setq end (min (max end (1+ start)) (point-max))) | 578 | ;; I'm not sure this is ever necessary and/or sufficient. -stef |
| 579 | ;; Request refontification. | 579 | (when (get-text-property start 'font-lock-multiline) |
| 580 | (put-text-property start end 'fontified nil)) | 580 | (setq start (or (previous-single-property-change |
| 581 | ;; Mark the change for deferred contextual refontification. | 581 | start 'font-lock-multiline) |
| 582 | (when jit-lock-context-unfontify-pos | 582 | (point-min)))) |
| 583 | (setq jit-lock-context-unfontify-pos | 583 | |
| 584 | ;; Here we use `start' because nothing guarantees that the | 584 | (if region (setq end (cdr region))) |
| 585 | ;; text between start and end will be otherwise refontified: | 585 | ;; Make sure we change at least one char (in case of deletions). |
| 586 | ;; usually it will be refontified by virtue of being | 586 | (setq end (min (max end (1+ start)) (point-max))) |
| 587 | ;; displayed, but if it's outside of any displayed area in the | 587 | ;; Request refontification. |
| 588 | ;; buffer, only jit-lock-context-* will re-fontify it. | 588 | (put-text-property start end 'fontified nil)) |
| 589 | (min jit-lock-context-unfontify-pos start)))))) | 589 | ;; Mark the change for deferred contextual refontification. |
| 590 | (when jit-lock-context-unfontify-pos | ||
| 591 | (setq jit-lock-context-unfontify-pos | ||
| 592 | ;; Here we use `start' because nothing guarantees that the | ||
| 593 | ;; text between start and end will be otherwise refontified: | ||
| 594 | ;; usually it will be refontified by virtue of being | ||
| 595 | ;; displayed, but if it's outside of any displayed area in the | ||
| 596 | ;; buffer, only jit-lock-context-* will re-fontify it. | ||
| 597 | (min jit-lock-context-unfontify-pos start))))))) | ||
| 590 | 598 | ||
| 591 | (provide 'jit-lock) | 599 | (provide 'jit-lock) |
| 592 | 600 | ||