home *** CD-ROM | disk | FTP | other *** search
/ Java 1996 August / Java - Summer 1996.iso / sundist / java / contrib / emacs / java-f-lck.el.jpayne next >
Encoding:
Text File  |  1995-09-10  |  4.3 KB  |  129 lines

  1. ;; Version:  @(#)java-f-lck.el    1.1 28 Mar 1995
  2. ;; Font Lock Keywords for java-mode
  3. ;; Copyright (C) 1994 Mitch Chapman
  4.  
  5. ;; Author: Mitch Chapman
  6. ;;         This module was derived from the c-mode font-lock
  7. ;;         keywords provided with GNU emacs 19.22.  As font-lock.el
  8. ;;         is distributed under the terms of the GNU General Public
  9. ;;         License, so is this code.  (See below.)
  10.  
  11. ;; Maintainer: none
  12. ;; Keywords: languages, faces
  13.  
  14. ;; This file is *NOT* part of GNU Emacs.
  15.  
  16. ;; java-f-lck.el is free software; you can redistribute it and/or modify
  17. ;; it under the terms of the GNU General Public License as published by
  18. ;; the Free Software Foundation; either version 2, or (at your option)
  19. ;; any later version.
  20.  
  21. ;; java-f-lck.el is distributed in the hope that it will be useful,
  22. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  24. ;; GNU General Public License for more details.
  25.  
  26. ;; You should have received a copy of the GNU General Public License
  27. ;; along with java-f-lck.el; see the file COPYING.  If not, write to
  28. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  29.  
  30.  
  31. ;;; Commentary:
  32.  
  33. ;; This module defines font-lock keywords and regular expressions for
  34. ;; java-mode buffers.  You can use these definitions in
  35. ;; conjunction with font-lock.el to "fontify" Java buffers.
  36.  
  37. ;; To automatically use the definitions in this module you need to
  38. ;; "plug in" the java font-lock keywords when entering
  39. ;; font-lock mode in an java-mode buffer.  Here's how:
  40. ;;       (add-hook 'font-lock-mode-hook
  41. ;;                 (function
  42. ;;                  (lambda ()
  43. ;;                    (if (eq major-mode 'java-mode)
  44. ;;                        (setq font-lock-keywords java-font-lock-keywords)))))
  45.  
  46. ;; This is done for you at the end of this module.  If you don't
  47. ;; want this behavior, just comment out the relevant code.
  48.  
  49. (defconst java-font-lock-keywords-1 nil
  50.  "For consideration as a value of `java-font-lock-keywords'.
  51. This does fairly subdued highlighting.")
  52.  
  53. (defconst java-font-lock-keywords-2 nil
  54.  "For consideration as a value of `java-font-lock-keywords'.
  55. This does a lot more highlighting.")
  56.  
  57. (let ((storage (concat "static\\|abstract\\|const\\|final\\|"
  58.                "synchronized\\|threadsafe\\|transient\\|native"))
  59.       (types (concat
  60.           "boolean\\|int\\|char\\|byte\\|float\\|double\\|void"))
  61.       (reserved-words
  62.        '("private" "protected" "public" "break" "byvalue"
  63.      "case" "catch" "class"
  64.      "continue" "default" "do" "else if"
  65.      "else" "extends" "false" "finally"
  66.      "for" "if" "implements" "import"
  67.      "instanceof" "interface"
  68.      "new" "null" "package" "return"
  69.      "super" "switch"
  70.      "this" "throw"
  71.      "true" "try" "synchronize" "while"))
  72.  
  73.       (java-token "\\w+"))
  74.   (setq java-font-lock-keywords-1
  75.    (list
  76.     ;;
  77.     ;; fontify C++-style comments as comments.
  78.     '("//.*" . font-lock-comment-face)
  79.     ;;
  80.     ;; fontify the (first word of) names of methods being defined.
  81.     (list (concat
  82.        "^[ \t]+"            ;; indent of line
  83.        "\\(" java-token "[ \t]+\\)"
  84.        "\\(" java-token "[ \t]+\\)?"
  85.        "\\(" java-token "[ \t]+\\)?"
  86.        "\\(" java-token "[ \t]+\\)?"
  87.        "\\(" java-token "[ \t]+\\)?"
  88.        "\\(" java-token "[ \t]+\\)?"
  89.        "\\(" java-token "\\)[ \t]*(")
  90.       7 'font-lock-function-name-face)
  91.     ;;
  92.     ;; Fontify case clauses.  This is fast because its anchored on the left.
  93.     '("case[ \t]+\\(\\(\\sw\\|\\s_\\)+\\):". 1)
  94.     '("\\<\\(default\\):". 1)
  95.     ))
  96.  
  97.   (setq java-font-lock-keywords-2
  98.    (append java-font-lock-keywords-1
  99.     (list
  100.      ;;
  101.      ;; fontify all storage classes and type specifiers
  102.      (cons (concat "\\<\\(" storage "\\)\\>") 'font-lock-type-face)
  103.      (cons (concat "\\<\\(" types "\\)\\>") 'font-lock-type-face)
  104.      
  105.      ;;
  106.      ;; fontify all builtin tokens
  107.         (cons (concat
  108.            "\\<\\("
  109.            (mapconcat 'identity reserved-words "\\|")
  110.            "\\)\\>")
  111.           1)))))
  112.  
  113. ; default to the gaudier variety:
  114. (defvar java-font-lock-keywords java-font-lock-keywords-2
  115.   "Additional expressions to highlight in Java mode.")
  116.  
  117.  
  118. ;; Plug in the Java font-lock keywords, so they'll be used
  119. ;; automatically when you're in java-mode.
  120. (add-hook 'font-lock-mode-hook
  121.       (function
  122.        (lambda ()
  123.          (if (eq major-mode 'java-mode)
  124.          (setq font-lock-keywords java-font-lock-keywords)))))
  125.  
  126.  
  127. (provide 'java-f-lck)
  128.  
  129.