Mercurial > hg > xemacs-beta
comparison lisp/font-lock.el @ 398:74fd4e045ea6 r21-2-29
Import from CVS: tag r21-2-29
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:13:30 +0200 |
parents | 7d59cb494b73 |
children | a86b2b5e0111 |
comparison
equal
deleted
inserted
replaced
397:f4aeb21a5bad | 398:74fd4e045ea6 |
---|---|
2 | 2 |
3 ;; Copyright (C) 1992-1995, 1997 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1992-1995, 1997 Free Software Foundation, Inc. |
4 ;; Copyright (C) 1995 Amdahl Corporation. | 4 ;; Copyright (C) 1995 Amdahl Corporation. |
5 ;; Copyright (C) 1996 Ben Wing. | 5 ;; Copyright (C) 1996 Ben Wing. |
6 | 6 |
7 ;; Author: Jamie Zawinski <jwz@netscape.com>, for the LISPM Preservation Society. | 7 ;; Author: Jamie Zawinski <jwz@jwz.org>, for the LISPM Preservation Society. |
8 ;; Minimally merged with FSF 19.34 by Barry Warsaw <bwarsaw@python.org> | 8 ;; Minimally merged with FSF 19.34 by Barry Warsaw <bwarsaw@python.org> |
9 ;; Then (partially) synched with FSF 19.30, leading to: | 9 ;; Then (partially) synched with FSF 19.30, leading to: |
10 ;; Next Author: RMS | 10 ;; Next Author: RMS |
11 ;; Next Author: Simon Marshall <simon@gnu.ai.mit.edu> | 11 ;; Next Author: Simon Marshall <simon@gnu.ai.mit.edu> |
12 ;; Latest XEmacs Author: Ben Wing | 12 ;; Latest XEmacs Author: Ben Wing |
609 | 609 |
610 (defface font-lock-doc-string-face | 610 (defface font-lock-doc-string-face |
611 '((((class color) (background dark)) (:foreground "light coral")) | 611 '((((class color) (background dark)) (:foreground "light coral")) |
612 (((class color) (background light)) (:foreground "green4")) | 612 (((class color) (background light)) (:foreground "green4")) |
613 (t (:bold t))) | 613 (t (:bold t))) |
614 "Font Lock mode face used to highlight documentation strings." | 614 "Font Lock mode face used to highlight documentation strings. |
615 This is currently supported only in Lisp-like modes, which are those | |
616 with \"lisp\" or \"scheme\" in their name. You can explicitly make | |
617 a mode Lisp-like by putting a non-nil `font-lock-lisp-like' property | |
618 on the major mode's symbol." | |
615 :group 'font-lock-faces) | 619 :group 'font-lock-faces) |
616 | 620 |
617 (defface font-lock-keyword-face | 621 (defface font-lock-keyword-face |
618 '((((class color) (background dark)) (:foreground "cyan")) | 622 '((((class color) (background dark)) (:foreground "cyan")) |
619 (((class color) (background light)) (:foreground "red4")) | 623 (((class color) (background light)) (:foreground "red4")) |
1282 ; (setq prev nil))) | 1286 ; (setq prev nil))) |
1283 ; ;; | 1287 ; ;; |
1284 ; ;; Clean up. | 1288 ; ;; Clean up. |
1285 ; (and prev (remove-text-properties prev end '(face nil))))) | 1289 ; (and prev (remove-text-properties prev end '(face nil))))) |
1286 | 1290 |
1291 (defun font-lock-lisp-like (mode) | |
1292 ;; Note: (or (get mode 'font-lock-lisp-like) (string-match ...)) is | |
1293 ;; not enough because the property needs to be able to specify a nil | |
1294 ;; value. | |
1295 (if (plist-member (symbol-plist mode) 'font-lock-lisp-like) | |
1296 (get mode 'font-lock-lisp-like) | |
1297 ;; If the property is not specified, guess. Similar logic exists | |
1298 ;; in add-log, but I think this encompasses more modes. | |
1299 (string-match "lisp\\|scheme" (symbol-name mode)))) | |
1300 | |
1287 (defun font-lock-fontify-syntactically-region (start end &optional loudly) | 1301 (defun font-lock-fontify-syntactically-region (start end &optional loudly) |
1288 "Put proper face on each string and comment between START and END. | 1302 "Put proper face on each string and comment between START and END. |
1289 START should be at the beginning of a line." | 1303 START should be at the beginning of a line." |
1290 (if font-lock-keywords-only | 1304 (if font-lock-keywords-only |
1291 nil | 1305 nil |
1294 (lmessage 'progress "Fontifying %s... (syntactically...)" | 1308 (lmessage 'progress "Fontifying %s... (syntactically...)" |
1295 (buffer-name))) | 1309 (buffer-name))) |
1296 (font-lock-unfontify-region start end loudly) | 1310 (font-lock-unfontify-region start end loudly) |
1297 (goto-char start) | 1311 (goto-char start) |
1298 (if (> end (point-max)) (setq end (point-max))) | 1312 (if (> end (point-max)) (setq end (point-max))) |
1299 (syntactically-sectionize | 1313 (let ((lisp-like (font-lock-lisp-like major-mode))) |
1300 #'(lambda (s e context depth) | 1314 (syntactically-sectionize |
1301 (let (face) | 1315 #'(lambda (s e context depth) |
1302 (cond ((eq context 'string) | 1316 (let (face) |
1303 ;;#### Should only do this is Lisp-like modes! | 1317 (cond ((eq context 'string) |
1304 (setq face | 1318 (setq face |
1305 (if (= depth 1) | 1319 ;; #### It would be nice if we handled |
1306 ;; really we should only use this if | 1320 ;; Python and other non-Lisp languages with |
1307 ;; in position 3 depth 1, but that's | 1321 ;; docstrings correctly. |
1308 ;; too expensive to compute. | 1322 (if (and lisp-like (= depth 1)) |
1309 'font-lock-doc-string-face | 1323 ;; really we should only use this if |
1310 'font-lock-string-face))) | 1324 ;; in position 3 depth 1, but that's |
1311 ((or (eq context 'comment) | 1325 ;; too expensive to compute. |
1312 (eq context 'block-comment)) | 1326 'font-lock-doc-string-face |
1313 (setq face 'font-lock-comment-face) | 1327 'font-lock-string-face))) |
1328 ((or (eq context 'comment) | |
1329 (eq context 'block-comment)) | |
1330 (setq face 'font-lock-comment-face) | |
1314 ; ;; Don't fontify whitespace at the beginning of lines; | 1331 ; ;; Don't fontify whitespace at the beginning of lines; |
1315 ; ;; otherwise comment blocks may not line up with code. | 1332 ; ;; otherwise comment blocks may not line up with code. |
1316 ; ;; (This is sometimes a good idea, sometimes not; in any | 1333 ; ;; (This is sometimes a good idea, sometimes not; in any |
1317 ; ;; event it should be in C for speed --jwz) | 1334 ; ;; event it should be in C for speed --jwz) |
1318 ; (save-excursion | 1335 ; (save-excursion |
1321 ; (setq face 'font-lock-comment-face) | 1338 ; (setq face 'font-lock-comment-face) |
1322 ; (setq e (point))) | 1339 ; (setq e (point))) |
1323 ; (skip-chars-forward " \t\n") | 1340 ; (skip-chars-forward " \t\n") |
1324 ; (setq s (point))) | 1341 ; (setq s (point))) |
1325 )) | 1342 )) |
1326 (font-lock-set-face s e face))) | 1343 (font-lock-set-face s e face))) |
1327 start end) | 1344 start end) |
1328 )) | 1345 ))) |
1329 | 1346 |
1330 ;;; Additional text property functions. | 1347 ;;; Additional text property functions. |
1331 | 1348 |
1332 ;; The following three text property functions are not generally available (and | 1349 ;; The following three text property functions are not generally available (and |
1333 ;; it's not certain that they should be) so they are inlined for speed. | 1350 ;; it's not certain that they should be) so they are inlined for speed. |
2442 '(0 nil)) ; Workaround for bug in XEmacs. | 2459 '(0 nil)) ; Workaround for bug in XEmacs. |
2443 '(font-lock-match-java-declarations | 2460 '(font-lock-match-java-declarations |
2444 (goto-char (match-end 1)) | 2461 (goto-char (match-end 1)) |
2445 (goto-char (match-end 0)) | 2462 (goto-char (match-end 0)) |
2446 (1 font-lock-variable-name-face)))))) | 2463 (1 font-lock-variable-name-face)))))) |
2447 | 2464 |
2448 ;; Modifier keywords and Java doc tags | 2465 ;; Modifier keywords and Java doc tags |
2449 (setq java-font-lock-keywords-3 | 2466 (setq java-font-lock-keywords-3 |
2450 (append | 2467 (append |
2451 | 2468 |
2452 '( | 2469 '( |
2453 ;; Feature scoping: | 2470 ;; Feature scoping: |
2454 ;; These must come first or the Modifiers from keywords-1 will | 2471 ;; These must come first or the Modifiers from keywords-1 will |
2455 ;; catch them. We don't want to use override fontification here | 2472 ;; catch them. We don't want to use override fontification here |
2456 ;; because then these terms will be fontified within comments. | 2473 ;; because then these terms will be fontified within comments. |
2457 ("\\<private\\>" 0 font-lock-string-face) | 2474 ("\\<private\\>" 0 font-lock-string-face) |
2458 ("\\<protected\\>" 0 font-lock-preprocessor-face) | 2475 ("\\<protected\\>" 0 font-lock-preprocessor-face) |
2459 ("\\<public\\>" 0 font-lock-reference-face)) | 2476 ("\\<public\\>" 0 font-lock-reference-face)) |
2460 java-font-lock-keywords-2 | 2477 java-font-lock-keywords-2 |
2461 | 2478 |
2462 (list | 2479 (list |
2463 | 2480 |
2464 ;; Java doc tags | 2481 ;; Java doc tags |
2465 '("@\\(author\\|exception\\|param\\|return\\|see\\|version\\)\\s " | 2482 '("@\\(author\\|exception\\|throws\\|deprecated\\|param\\|return\\|see\\|since\\|version\\)\\s " |
2466 0 font-lock-keyword-face t) | 2483 0 font-lock-keyword-face t) |
2467 | 2484 |
2468 ;; Doc tag - Parameter identifiers | 2485 ;; Doc tag - Parameter identifiers |
2469 (list (concat "@param\\s +" java-font-lock-identifier-regexp) | 2486 (list (concat "@param\\s +" java-font-lock-identifier-regexp) |
2470 1 'font-lock-variable-name-face t) | 2487 1 'font-lock-variable-name-face t) |
2471 | 2488 |
2472 ;; Doc tag - Exception types | 2489 ;; Doc tag - Exception types |
2473 (list (concat "@exception\\ s*" | 2490 (list (concat "@exception\\s +" |
2474 java-font-lock-identifier-regexp) | 2491 java-font-lock-identifier-regexp) |
2475 '(1 (if (equal (char-after (match-end 0)) ?.) | 2492 '(1 (if (equal (char-after (match-end 0)) ?.) |
2476 font-lock-reference-face font-lock-type-face) t) | 2493 font-lock-reference-face font-lock-type-face) t) |
2477 (list (concat "\\=\\." java-font-lock-identifier-regexp) | 2494 (list (concat "\\=\\." java-font-lock-identifier-regexp) |
2478 '(goto-char (match-end 0)) nil | 2495 '(goto-char (match-end 0)) nil |
2479 '(1 (if (equal (char-after (match-end 0)) ?.) | 2496 '(1 (if (equal (char-after (match-end 0)) ?.) |
2480 'font-lock-reference-face 'font-lock-type-face) t))) | 2497 'font-lock-reference-face 'font-lock-type-face) t))) |
2498 | |
2499 ;; Doc tag - Exception types | |
2500 (list (concat "@exception\\s +" | |
2501 java-font-lock-identifier-regexp) | |
2502 '(1 (if (equal (char-after (match-end 0)) ?.) | |
2503 font-lock-reference-face font-lock-type-face) t) | |
2504 (list (concat "\\=\\." java-font-lock-identifier-regexp) | |
2505 '(goto-char (match-end 0)) nil | |
2506 '(1 (if (equal (char-after (match-end 0)) ?.) | |
2507 'font-lock-reference-face 'font-lock-type-face) t))) | |
2481 | 2508 |
2482 ;; Doc tag - Cross-references, usually to methods | 2509 ;; Doc tag - Cross-references, usually to methods |
2483 '("@see\\s +\\(\\S *[^][ \t\n\r\f(){},.;:]\\)" | 2510 '("@see\\s +\\(\\S *[^][ \t\n\r\f(){},.;:]\\)" |
2484 1 font-lock-function-name-face t) | 2511 1 font-lock-function-name-face t) |
2485 | 2512 |
2513 ;; Doc tag - Links | |
2514 '("{@link\\s +\\([^}]*\\)}" | |
2515 0 font-lock-keyword-face t) | |
2516 ;; Doc tag - Links | |
2517 '("{@link\\s +\\(\\S +\\s +\\S +\\)}" | |
2518 1 font-lock-function-name-face t) | |
2519 | |
2486 ))) | 2520 ))) |
2487 ) | 2521 ) |
2488 | 2522 |
2489 (defvar java-font-lock-keywords java-font-lock-keywords-1 | 2523 (defvar java-font-lock-keywords java-font-lock-keywords-1 |
2490 "Additional expressions to highlight in Java mode.") | 2524 "Additional expressions to highlight in Java mode.") |