Mercurial > emacs
comparison lisp/font-lock.el @ 72308:c49cd0ee6018
(font-lock-extend-after-change-region-function,
font-lock-extend-region-functions,
font-lock-extend-jit-lock-region-after-change): Better comments.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Mon, 07 Aug 2006 17:42:36 +0000 |
parents | 0933613f837b |
children | e5f74bc78986 |
comparison
equal
deleted
inserted
replaced
72307:725af3953ee0 | 72308:c49cd0ee6018 |
---|---|
974 ;; example, TeX modes could fontify {\foo ...} and \bar{...} etc. multi-line | 974 ;; example, TeX modes could fontify {\foo ...} and \bar{...} etc. multi-line |
975 ;; directives correctly and cleanly. (It is the same problem as fontifying | 975 ;; directives correctly and cleanly. (It is the same problem as fontifying |
976 ;; multi-line strings and comments; regexps are not appropriate for the job.) | 976 ;; multi-line strings and comments; regexps are not appropriate for the job.) |
977 | 977 |
978 (defvar font-lock-extend-after-change-region-function nil | 978 (defvar font-lock-extend-after-change-region-function nil |
979 "A function that determines the region to fontify after a change. | 979 "A function that determines the region to refontify after a change. |
980 | 980 |
981 This variable is either nil, or is a function that determines the | 981 This variable is either nil, or is a function that determines the |
982 region to refontify after a change. | 982 region to refontify after a change. |
983 It is usually set by the major mode via `font-lock-defaults'. | 983 It is usually set by the major mode via `font-lock-defaults'. |
984 Font-lock calls this function after each buffer change. | 984 Font-lock calls this function after each buffer change. |
985 | 985 |
986 The function is given three parameters, the standard BEG, END, and OLD-LEN | 986 The function is given three parameters, the standard BEG, END, and OLD-LEN |
987 from `after-change-functions'. It should return either a cons of the beginning | 987 from `after-change-functions'. It should return either a cons of the beginning |
988 and end buffer positions \(in that order) of the region to fontify, or nil | 988 and end buffer positions \(in that order) of the region to refontify, or nil |
989 \(which directs the caller to fontify a default region). | 989 \(which directs the caller to fontify a default region). |
990 This function should preserve the match-data. | 990 This function should preserve the match-data. |
991 The region it returns may start or end in the middle of a line.") | 991 The region it returns may start or end in the middle of a line.") |
992 | 992 |
993 (defun font-lock-fontify-buffer () | 993 (defun font-lock-fontify-buffer () |
1042 | 1042 |
1043 | 1043 |
1044 (defvar font-lock-beg) (defvar font-lock-end) | 1044 (defvar font-lock-beg) (defvar font-lock-end) |
1045 (defvar font-lock-extend-region-functions | 1045 (defvar font-lock-extend-region-functions |
1046 '(font-lock-extend-region-wholelines | 1046 '(font-lock-extend-region-wholelines |
1047 ;; This use of font-lock-multiline property is unreliable but is just | |
1048 ;; a handy heuristic: in case you don't have a function that does | |
1049 ;; /identification/ of multiline elements, you may still occasionally | |
1050 ;; discover them by accident (or you may /identify/ them but not in all | |
1051 ;; cases), in which case the font-lock-multiline property can help make | |
1052 ;; sure you will properly *re*identify them during refontification. | |
1047 font-lock-extend-region-multiline) | 1053 font-lock-extend-region-multiline) |
1048 "Special hook run just before proceeding to fontify a region. | 1054 "Special hook run just before proceeding to fontify a region. |
1049 This is used to allow major modes to help font-lock find safe buffer positions | 1055 This is used to allow major modes to help font-lock find safe buffer positions |
1050 as beginning and end of the fontified region. Its most common use is to solve | 1056 as beginning and end of the fontified region. Its most common use is to solve |
1051 the problem of /identification/ of multiline elements by providing a function | 1057 the problem of /identification/ of multiline elements by providing a function |
1175 (if region | 1181 (if region |
1176 (setq beg (min jit-lock-start (car region)) | 1182 (setq beg (min jit-lock-start (car region)) |
1177 end (max jit-lock-end (cdr region)))) | 1183 end (max jit-lock-end (cdr region)))) |
1178 ;; Then extend the region obeying font-lock-multiline properties, | 1184 ;; Then extend the region obeying font-lock-multiline properties, |
1179 ;; indicating which part of the buffer needs to be refontified. | 1185 ;; indicating which part of the buffer needs to be refontified. |
1186 ;; !!! This is the *main* user of font-lock-multiline property !!! | |
1187 ;; font-lock-after-change-function could/should also do that, but it | |
1188 ;; doesn't need to because font-lock-default-fontify-region does | |
1189 ;; it anyway. Here OTOH we have no guarantee that | |
1190 ;; font-lock-default-fontify-region will be executed on this region | |
1191 ;; any time soon. | |
1180 (when (and (> beg (point-min)) | 1192 (when (and (> beg (point-min)) |
1181 (get-text-property (1- beg) 'font-lock-multiline)) | 1193 (get-text-property (1- beg) 'font-lock-multiline)) |
1182 (setq beg (or (previous-single-property-change | 1194 (setq beg (or (previous-single-property-change |
1183 beg 'font-lock-multiline) | 1195 beg 'font-lock-multiline) |
1184 (point-min)))) | 1196 (point-min)))) |