changeset 13300:73b7a6396cbe

Fix to fortran-font-lock-keywords-* for new font-lock-keywords structure.
author Simon Marshall <simon@gnu.org>
date Thu, 26 Oct 1995 13:31:26 +0000
parents d6bfe124472c
children 0cbf58edd87f
files lisp/progmodes/fortran.el
diffstat 1 files changed, 87 insertions(+), 55 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/progmodes/fortran.el	Thu Oct 26 13:27:36 1995 +0000
+++ b/lisp/progmodes/fortran.el	Thu Oct 26 13:31:26 1995 +0000
@@ -188,27 +188,17 @@
 ;; Regexps done by simon@gnu with help from Ulrik Dickow <dickow@nbi.dk> and
 ;; probably others Si's forgotten about (sorry).
 
-(defconst fortran-font-lock-keywords-1
-  (let ((comment-chars "c!*"))
-    (list
-     ;;
-     ;; Fontify comments and strings.  We assume that strings cannot be quoted.
-     (cons (concat "^[" comment-chars "].*") 'font-lock-comment-face)
-     '(fortran-match-!-comment . font-lock-comment-face)
-     (list (concat "^[^" comment-chars "\t\n]" (make-string 71 ?.) "\\(.*\\)")
-           '(1 font-lock-comment-face))
-     '("'[^'\n]*'?" . font-lock-string-face)
-     ;;
-     ;; Program, subroutine and function declarations, plus calls.
-     (list (concat "\\<\\(block[ \t]*data\\|call\\|entry\\|function\\|"
-                   "program\\|subroutine\\)\\>[ \t]*\\(\\sw+\\)?")
-           '(1 font-lock-keyword-face)
-           '(2 font-lock-function-name-face nil t))))
+(defconst fortran-font-lock-keywords-1 nil
   "Subdued level highlighting for Fortran mode.")
 
-(defconst fortran-font-lock-keywords-2
-  (append fortran-font-lock-keywords-1
-   (let ((type-types
+(defconst fortran-font-lock-keywords-2 nil
+  "Medium level highlighting for Fortran mode.")
+
+(defconst fortran-font-lock-keywords-3 nil
+  "Gaudy level highlighting for Fortran mode.")
+
+(let ((comment-chars "c!*")
+      (fortran-type-types
 ;     (make-regexp
 ;      (let ((simple-types '("character" "byte" "integer" "logical"
 ;			    "none" "real" "complex"
@@ -234,7 +224,7 @@
                   "nt\\(eger\\|rinsic\\)\\)\\|"
                   "logical\\|map\\|none\\|parameter\\|re\\(al\\|cord\\)\\|"
                   "s\\(ave\\|tructure\\)\\|union"))
-	 (fkeywords
+	 (fortran-keywords
 ;	  ("continue" "format" "end" "enddo" "if" "then" "else" "endif"
 ;	   "elseif" "while" "inquire" "stop" "return" "include" "open"
 ;	   "close" "read" "write" "format" "print")
@@ -242,46 +232,85 @@
 		  "e\\(lse\\(\\|if\\)\\|nd\\(\\|do\\|if\\)\\)\\|format\\|"
 		  "i\\(f\\|n\\(clude\\|quire\\)\\)\\|open\\|print\\|"
 		  "re\\(ad\\|turn\\)\\|stop\\|then\\|w\\(hile\\|rite\\)"))
-	 (flogicals
-;	  ("and" "or" "not" "lt" "le" "eq" "ge" "gt" "ne" "true" "false")
-	  "and\\|eq\\|false\\|g[et]\\|l[et]\\|n\\(e\\|ot\\)\\|or\\|true"))
-     (list
-      ;;
-      ;; Fontify types and variable names (but not length specs or `/'s).
-      (list (concat "\\<\\(" type-types "\\)\\>[0-9 \t/*]*\\(\\sw+\\)?")
-	    '(1 font-lock-type-face)
-	    '(15 font-lock-variable-name-face nil t))
-      ;;
-      ;; Fontify all builtin keywords (except logical, do and goto; see below).
-      (concat "\\<\\(" fkeywords "\\)\\>")
-      ;;
-      ;; Fontify all builtin operators.
-      (concat "\\.\\(" flogicals "\\)\\.")
-      ;;
-      ;; Fontify do/goto keywords and targets, and goto tags.
-      (list "\\<\\(do\\|go *to\\)\\>[ \t]*\\([0-9]+\\)?"
-	    '(1 font-lock-keyword-face)
-	    '(2 font-lock-reference-face nil t))
-      (cons "^ *\\([0-9]+\\)" 'font-lock-reference-face))))
-  "Medium level highlighting for Fortran mode.")
+        (fortran-logicals
+;       ("and" "or" "not" "lt" "le" "eq" "ge" "gt" "ne" "true" "false")
+         "and\\|eq\\|false\\|g[et]\\|l[et]\\|n\\(e\\|ot\\)\\|or\\|true"))
 
-(defconst fortran-font-lock-keywords-3
-  (append fortran-font-lock-keywords-2
+  (setq fortran-font-lock-keywords-1
    (list
     ;;
-    ;; Fontify goto-like `err=label'/`end=label' in read/write statements.
-    (list ", *\\(e\\(nd\\|rr\\)\\)\\> *\\(= *\\([0-9]+\\)\\)?"
-          '(1 font-lock-keyword-face)
-          '(4 font-lock-reference-face nil t))
+    ;; Fontify syntactically (assuming strings cannot be quoted or span lines).
+    (cons (concat "^[" comment-chars "].*") 'font-lock-comment-face)
+    '(fortran-match-!-comment . font-lock-comment-face)
+    (list (concat "^[^" comment-chars "\t\n]" (make-string 71 ?.) "\\(.*\\)")
+	  '(1 font-lock-comment-face))
+    '("'[^'\n]*'?" . font-lock-string-face)
     ;;
-    ;; Highlight a standard continuation character and in a TAB-formatted line.
-    '("^     \\([^ 0]\\)" 1 font-lock-string-face)
-    '("^\t\\([1-9]\\)" 1 font-lock-string-face)))
-  "Gaudy level highlighting for Fortran mode.")
+    ;; Program, subroutine and function declarations, plus calls.
+    (list (concat "\\<\\(block[ \t]*data\\|call\\|entry\\|function\\|"
+		  "program\\|subroutine\\)\\>[ \t]*\\(\\sw+\\)?")
+	  '(1 font-lock-keyword-face)
+	  '(2 font-lock-function-name-face nil t))))
+
+  (setq fortran-font-lock-keywords-2
+   (append fortran-font-lock-keywords-1
+    (list
+     ;;
+     ;; Fontify all type specifiers (must be first; see below).
+     (cons (concat "\\<\\(" fortran-type-types "\\)\\>") 'font-lock-type-face)
+     ;;
+     ;; Fontify all builtin keywords (except logical, do and goto; see below).
+     (concat "\\<\\(" fortran-keywords "\\)\\>")
+     ;;
+     ;; Fontify all builtin operators.
+     (concat "\\.\\(" fortran-logicals "\\)\\.")
+     ;;
+     ;; Fontify do/goto keywords and targets, and goto tags.
+     (list "\\<\\(do\\|go *to\\)\\>[ \t]*\\([0-9]+\\)?"
+	   '(1 font-lock-keyword-face)
+	   '(2 font-lock-reference-face nil t))
+     (cons "^ *\\([0-9]+\\)" 'font-lock-reference-face))))
+
+  (setq fortran-font-lock-keywords-3
+   (append
+    ;;
+    ;; The list `fortran-font-lock-keywords-1'.
+    fortran-font-lock-keywords-1
+    ;;
+    ;; Fontify all type specifiers plus their declared items.
+    (list
+     (list (concat "\\<\\(" fortran-type-types "\\)\\>[ \t(/]*\\(*\\)?")
+	   ;; Fontify the type specifier.
+	   '(1 font-lock-type-face)
+	   ;; Fontify each declaration item (or just the /.../ block name).
+	   '(font-lock-match-c++-style-declaration-item-and-skip-to-next
+	     ;; Start after any *(...) expression.
+	     (and (match-beginning 15) (forward-sexp 1))
+	     ;; No need to clean up.
+	     nil
+	     ;; Fontify as a variable name, functions are fontified elsewhere.
+	     (1 font-lock-variable-name-face nil t))))
+    ;;
+    ;; Things extra to `fortran-font-lock-keywords-3' (must be done first).
+    (list
+     ;;
+     ;; Fontify goto-like `err=label'/`end=label' in read/write statements.
+     '(", *\\(e\\(nd\\|rr\\)\\)\\> *\\(= *\\([0-9]+\\)\\)?"
+       (1 font-lock-keyword-face) (4 font-lock-reference-face nil t))
+     ;;
+     ;; Highlight standard continuation character and in a TAB-formatted line.
+     '("^     \\([^ 0]\\)" 1 font-lock-string-face)
+     '("^\t\\([1-9]\\)" 1 font-lock-string-face))
+    ;;
+    ;; The list `fortran-font-lock-keywords-2' less that for types (see above).
+    (cdr (nthcdr (length fortran-font-lock-keywords-1)
+		 fortran-font-lock-keywords-2))))
+  )
 
 (defvar fortran-font-lock-keywords fortran-font-lock-keywords-1
   "Default expressions to highlight in Fortran mode.")
 
+
 (defvar fortran-mode-map () 
   "Keymap used in Fortran mode.")
 (if fortran-mode-map
@@ -458,9 +487,12 @@
   (setq local-abbrev-table fortran-mode-abbrev-table)
   (set-syntax-table fortran-mode-syntax-table)
   ;; Font Lock mode support.
-  (set (make-local-variable 'font-lock-defaults)
-       '((fortran-font-lock-keywords fortran-font-lock-keywords-1
-	  fortran-font-lock-keywords-2 fortran-font-lock-keywords-3) t t))
+  (make-local-variable 'font-lock-defaults)
+  (setq font-lock-defaults '((fortran-font-lock-keywords
+			      fortran-font-lock-keywords-1
+			      fortran-font-lock-keywords-2
+			      fortran-font-lock-keywords-3)
+			     t t ((?/ . "$/"))))
   (make-local-variable 'fortran-break-before-delimiters)
   (setq fortran-break-before-delimiters t)
   (make-local-variable 'indent-line-function)