comparison lisp/font-lock.el @ 62362:ebcb47e6b3f3

(font-lock-comment-start-skip): New variable. (font-lock-comment-end-skip): New variable. (font-lock-fontify-syntactically-region): Use them if non-nil.
author Richard M. Stallman <rms@gnu.org>
date Sun, 15 May 2005 14:28:55 +0000
parents f1e03f4e94d2
children f0e96503b7e0 8b66fddd72c5
comparison
equal deleted inserted replaced
62361:b50e483e582a 62362:ebcb47e6b3f3
1309 1309
1310 ;;; End of Syntactic regexp fontification functions. 1310 ;;; End of Syntactic regexp fontification functions.
1311 1311
1312 ;;; Syntactic fontification functions. 1312 ;;; Syntactic fontification functions.
1313 1313
1314 (defvar font-lock-comment-start-skip nil
1315 "If non-nil, Font Lock mode uses this instead of `comment-start-skip'.")
1316
1317 (defvar font-lock-comment-end-skip nil
1318 "If non-nil, Font Lock mode uses this instead of `comment-end'.")
1319
1314 (defun font-lock-fontify-syntactically-region (start end &optional loudly ppss) 1320 (defun font-lock-fontify-syntactically-region (start end &optional loudly ppss)
1315 "Put proper face on each string and comment between START and END. 1321 "Put proper face on each string and comment between START and END.
1316 START should be at the beginning of a line." 1322 START should be at the beginning of a line."
1317 (let ((comment-end-regexp 1323 (let ((comment-end-regexp
1318 (regexp-quote 1324 (or font-lock-comment-end-skip
1319 (replace-regexp-in-string "^ *" "" comment-end))) 1325 (regexp-quote
1326 (replace-regexp-in-string "^ *" "" comment-end))))
1320 state face beg) 1327 state face beg)
1321 (if loudly (message "Fontifying %s... (syntactically...)" (buffer-name))) 1328 (if loudly (message "Fontifying %s... (syntactically...)" (buffer-name)))
1322 (goto-char start) 1329 (goto-char start)
1323 ;; 1330 ;;
1324 ;; Find the `start' state. 1331 ;; Find the `start' state.
1332 (setq beg (max (nth 8 state) start)) 1339 (setq beg (max (nth 8 state) start))
1333 (setq state (parse-partial-sexp (point) end nil nil state 1340 (setq state (parse-partial-sexp (point) end nil nil state
1334 'syntax-table)) 1341 'syntax-table))
1335 (when face (put-text-property beg (point) 'face face)) 1342 (when face (put-text-property beg (point) 'face face))
1336 (when (and (eq face 'font-lock-comment-face) 1343 (when (and (eq face 'font-lock-comment-face)
1337 comment-start-skip) 1344 (or font-lock-comment-start-skip
1345 comment-start-skip))
1338 ;; Find the comment delimiters 1346 ;; Find the comment delimiters
1339 ;; and use font-lock-comment-delimiter-face for them. 1347 ;; and use font-lock-comment-delimiter-face for them.
1340 (save-excursion 1348 (save-excursion
1341 (goto-char beg) 1349 (goto-char beg)
1342 (if (looking-at comment-start-skip) 1350 (if (looking-at (or font-lock-comment-start-skip
1351 comment-start-skip))
1343 (put-text-property beg (match-end 0) 'face 1352 (put-text-property beg (match-end 0) 'face
1344 font-lock-comment-delimiter-face))) 1353 font-lock-comment-delimiter-face)))
1345 (if (looking-back comment-end-regexp (point-at-bol)) 1354 (if (looking-back comment-end-regexp (point-at-bol))
1346 (put-text-property (match-beginning 0) (point) 'face 1355 (put-text-property (match-beginning 0) (point) 'face
1347 font-lock-comment-delimiter-face)))) 1356 font-lock-comment-delimiter-face))))