diff options
| author | Karl Heuer | 1994-02-26 00:14:42 +0000 |
|---|---|---|
| committer | Karl Heuer | 1994-02-26 00:14:42 +0000 |
| commit | f60f18ae0cc034e52673507bfde539cec0f4b46b (patch) | |
| tree | be49306a6d4de9782dba8b8deacf71340d45c805 | |
| parent | 7ea9c0209a19c13dcbe0088585155550d1605bc9 (diff) | |
| download | emacs-f60f18ae0cc034e52673507bfde539cec0f4b46b.tar.gz emacs-f60f18ae0cc034e52673507bfde539cec0f4b46b.zip | |
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
declarations.
| -rw-r--r-- | lisp/font-lock.el | 162 |
1 files changed, 85 insertions, 77 deletions
diff --git a/lisp/font-lock.el b/lisp/font-lock.el index b16fa85bcc6..4dee589a7c4 100644 --- a/lisp/font-lock.el +++ b/lisp/font-lock.el | |||
| @@ -496,89 +496,97 @@ This does fairly subdued highlighting.") | |||
| 496 | "For consideration as a value of `c-font-lock-keywords'. | 496 | "For consideration as a value of `c-font-lock-keywords'. |
| 497 | This does a lot more highlighting.") | 497 | This does a lot more highlighting.") |
| 498 | 498 | ||
| 499 | (let ((storage "auto\\|extern\\|register\\|static\\|volatile") | 499 | (let* ((storage "auto\\|extern\\|register\\|static\\|typedef") |
| 500 | (prefixes "unsigned\\|short\\|long") | 500 | (struct "struct\\|union\\|enum") |
| 501 | (types (concat "int\\|char\\|float\\|double\\|void\\|struct\\|" | 501 | (prefixes "signed\\|unsigned\\|short\\|long") |
| 502 | "union\\|enum\\|typedef")) | 502 | (types (concat prefixes "\\|int\\|char\\|float\\|double\\|void")) |
| 503 | (ctoken "[a-zA-Z0-9_:~*]+") | 503 | (ctoken "[a-zA-Z0-9_:~*]+")) |
| 504 | ) | 504 | (setq c-font-lock-keywords-1 |
| 505 | (setq c-font-lock-keywords-1 | 505 | (list |
| 506 | ;; fontify preprocessor directives as comments. | ||
| 507 | '("^#[ \t]*[a-z]+" . font-lock-comment-face) | ||
| 508 | ;; | ||
| 509 | ;; fontify names being defined. | ||
| 510 | '("^#[ \t]*\\(define\\|undef\\)[ \t]+\\(\\(\\sw\\|\\s_\\)+\\)" 2 | ||
| 511 | font-lock-function-name-face) | ||
| 512 | ;; | ||
| 513 | ;; fontify other preprocessor lines. | ||
| 514 | '("^#[ \t]*\\(if\\|elif\\|else\\|endif\\)[ \t]+\\([^\n]+\\)" | ||
| 515 | 2 font-lock-function-name-face keep) | ||
| 516 | '("^#[ \t]*\\(ifn?def\\)[ \t]+\\([^ \t\n]+\\)" | ||
| 517 | 2 font-lock-function-name-face t) | ||
| 518 | ;; | ||
| 519 | ;; fontify the filename in #include <...> | ||
| 520 | ;; don't need to do this for #include "..." because those were | ||
| 521 | ;; already fontified as strings by the syntactic pass. | ||
| 522 | '("^#[ \t]*include[ \t]+\\(<[^>\"\n]+>\\)" 1 font-lock-string-face) | ||
| 523 | ;; | ||
| 524 | ;; fontify the names of functions being defined. | ||
| 525 | (list (concat | ||
| 526 | "^\\(" ctoken "[ \t]+\\)?" ; type specs; there can be no | ||
| 527 | "\\(" ctoken "[ \t]+\\)?" ; more than 3 tokens, right? | ||
| 528 | "\\(" ctoken "[ \t]+\\)?" | ||
| 529 | "\\([*&]+[ \t]*\\)?" ; pointer | ||
| 530 | "\\(" ctoken "\\)[ \t]*(") ; name | ||
| 531 | 5 'font-lock-function-name-face) | ||
| 532 | ;; | ||
| 533 | ;; | ||
| 534 | ;; Fontify structure names (in structure definition form). | ||
| 535 | (list (concat "^\\(" storage "\\)?[ \t]*\\<\\(" struct "\\)" | ||
| 536 | "[ \t]+\\(" ctoken "\\)[ \t]*\\(\{\\|$\\)") | ||
| 537 | 3 'font-lock-function-name-face) | ||
| 538 | ;; | ||
| 539 | ;; Fontify declarations of simple identifiers (including typedefs). | ||
| 540 | ;; (Should this be in c-font-lock-keywords-2 instead?) | ||
| 541 | (list (concat "^[ \t]*\\(\\(" storage "\\)[ \t]+\\)?\\(\\(\\(" prefixes | ||
| 542 | "\\)\\>[ \t]*\\)*\\(" types "\\)\\)[ \t]+\\(" ctoken | ||
| 543 | "\\)[ \t]*[=;]") | ||
| 544 | 7 'font-lock-function-name-face 'keep) | ||
| 545 | ;; | ||
| 546 | ;; And likewise for structs | ||
| 547 | (list (concat "^[ \t]*\\(\\(" storage "\\)[ \t]+\\)?\\(" struct | ||
| 548 | "\\)[ \t]+" ctoken "[ \t]+\\(" ctoken "\\);") | ||
| 549 | 4 'font-lock-function-name-face 'keep) | ||
| 550 | ;; | ||
| 551 | ;; Fontify case clauses. This is fast because its anchored on the left. | ||
| 552 | '("case[ \t]+\\(\\(\\sw\\|\\s_\\)+\\):". 1) | ||
| 553 | '("\\<\\(default\\):". 1) | ||
| 554 | )) | ||
| 555 | |||
| 556 | (setq c-font-lock-keywords-2 | ||
| 557 | (append c-font-lock-keywords-1 | ||
| 506 | (list | 558 | (list |
| 507 | ;; fontify preprocessor directives as comments. | ||
| 508 | '("^#[ \t]*[a-z]+" . font-lock-comment-face) | ||
| 509 | ;; | ||
| 510 | ;; fontify names being defined. | ||
| 511 | '("^#[ \t]*\\(define\\|undef\\)[ \t]+\\(\\(\\sw\\|\\s_\\)+\\)" 2 | ||
| 512 | font-lock-function-name-face) | ||
| 513 | ;; | ||
| 514 | ;; fontify other preprocessor lines. | ||
| 515 | '("^#[ \t]*\\(if\\)[ \t]+\\([^\n]+\\)" | ||
| 516 | 2 font-lock-function-name-face keep) | ||
| 517 | '("^#[ \t]*\\(endif\\|else\\)[ \t]+\\([^\n]+\\)" | ||
| 518 | 2 font-lock-function-name-face keep) | ||
| 519 | '("^#[ \t]*\\(ifn?def\\)[ \t]+\\([^ \t\n]+\\)" | ||
| 520 | 2 font-lock-function-name-face t) | ||
| 521 | ;; | 559 | ;; |
| 522 | ;; fontify the filename in #include <...> | 560 | ;; fontify all storage classes and type specifiers |
| 523 | ;; don't need to do this for #include "..." because those were | 561 | (cons (concat "\\<\\(" storage "\\)\\>") 'font-lock-type-face) |
| 524 | ;; already fontified as strings by the syntactic pass. | 562 | (cons (concat "\\<\\(\\(\\(" prefixes "\\)\\>[ \t]*\\)*\\(" types |
| 525 | '("^#[ \t]*include[ \t]+\\(<[^>\"\n]+>\\)" 1 font-lock-string-face) | 563 | "\\)\\)\\>") |
| 564 | 'font-lock-type-face) | ||
| 565 | (list (concat "\\<\\(" struct "\\)[ \t]+" ctoken) | ||
| 566 | 0 'font-lock-type-face 'keep) | ||
| 526 | ;; | 567 | ;; |
| 527 | ;; fontify the names of functions being defined. | 568 | ;; fontify all builtin tokens |
| 528 | (list (concat | 569 | (cons (concat |
| 529 | "^\\(" ctoken "[ \t]+\\)?" ; type specs; there can be no | 570 | "[ \t]\\(" |
| 530 | "\\(" ctoken "[ \t]+\\)?" ; more than 3 tokens, right? | 571 | (mapconcat 'identity |
| 531 | "\\(" ctoken "[ \t]+\\)?" | 572 | '("for" "while" "do" "return" "goto" "case" "break" "switch" |
| 532 | "\\([*&]+[ \t]*\\)?" ; pointer | 573 | "if" "else" "default" "continue" "default") |
| 533 | "\\(" ctoken "\\)[ \t]*(") ; name | 574 | "\\|") |
| 534 | 5 'font-lock-function-name-face) | 575 | "\\)[ \t\n(){};,]") |
| 576 | 1) | ||
| 535 | ;; | 577 | ;; |
| 578 | ;; fontify case targets and goto-tags. This is slow because the | ||
| 579 | ;; expression is anchored on the right. | ||
| 580 | "\\(\\(\\sw\\|\\s_\\)+\\):" | ||
| 536 | ;; | 581 | ;; |
| 537 | ;; Fontify structure names (in structure definition form). | 582 | ;; Fontify variables declared with structures, or typedef names. |
| 538 | (list (concat "^\\(typedef[ \t]+struct\\|struct\\|static[ \t]+struct\\)" | 583 | '("}[ \t*]*\\(\\(\\sw\\|\\s_\\)+\\)[ \t]*[,;]" |
| 539 | "[ \t]+\\(" ctoken "\\)[ \t]*\\(\{\\|$\\)") | 584 | 1 font-lock-function-name-face) |
| 540 | 2 'font-lock-function-name-face) | ||
| 541 | ;; | 585 | ;; |
| 542 | ;; Fontify case clauses. This is fast because its anchored on the left. | 586 | ;; Fontify global variables without a type. |
| 543 | '("case[ \t]+\\(\\(\\sw\\|\\s_\\)+\\):". 1) | 587 | ; '("^\\([_a-zA-Z0-9:~*]+\\)[ \t]*[[;={]" 1 font-lock-function-name-face) |
| 544 | '("\\<\\(default\\):". 1) | 588 | ))) |
| 545 | )) | 589 | ) |
| 546 | |||
| 547 | (setq c-font-lock-keywords-2 | ||
| 548 | (append c-font-lock-keywords-1 | ||
| 549 | (list | ||
| 550 | ;; | ||
| 551 | ;; fontify all storage classes and type specifiers | ||
| 552 | (cons (concat "\\<\\(" storage "\\)\\>") 'font-lock-type-face) | ||
| 553 | (cons (concat "\\<\\(" types "\\)\\>") 'font-lock-type-face) | ||
| 554 | (cons (concat "\\<\\(" prefixes "[ \t]+" types "\\)\\>") | ||
| 555 | 'font-lock-type-face) | ||
| 556 | ;; | ||
| 557 | ;; fontify all builtin tokens | ||
| 558 | (cons (concat | ||
| 559 | "[ \t]\\(" | ||
| 560 | (mapconcat 'identity | ||
| 561 | '("for" "while" "do" "return" "goto" "case" "break" "switch" | ||
| 562 | "if" "then" "else if" "else" "return" "default" "continue" | ||
| 563 | "default" | ||
| 564 | ) | ||
| 565 | "\\|") | ||
| 566 | "\\)[ \t\n(){};,]") | ||
| 567 | 1) | ||
| 568 | ;; | ||
| 569 | ;; fontify case targets and goto-tags. This is slow because the | ||
| 570 | ;; expression is anchored on the right. | ||
| 571 | "\\(\\(\\sw\\|\\s_\\)+\\):" | ||
| 572 | ;; | ||
| 573 | ;; Fontify variables declared with structures, or typedef names. | ||
| 574 | '("}[ \t*]*\\(\\(\\sw\\|\\s_\\)+\\)[ \t]*[,;]" | ||
| 575 | 1 font-lock-function-name-face) | ||
| 576 | ;; | ||
| 577 | ;; Fontify global variables without a type. | ||
| 578 | ; '("^\\([_a-zA-Z0-9:~*]+\\)[ \t]*[[;={]" 1 font-lock-function-name-face) | ||
| 579 | |||
| 580 | ))) | ||
| 581 | ) | ||
| 582 | 590 | ||
| 583 | ; default to the gaudier variety? | 591 | ; default to the gaudier variety? |
| 584 | ;(defvar c-font-lock-keywords c-font-lock-keywords-2 | 592 | ;(defvar c-font-lock-keywords c-font-lock-keywords-2 |