comparison lisp/progmodes/f90.el @ 11501:a56d6a86fa85

(f90-keywords): "only" added to keyword list. (f90-font-lock-keywords-1): Type may now have attributes private and public. (f90-font-lock-keywords-2): Fixed difference between type and type(). (hilit-set-mode-patterns): Type may now have attributes private. and public, fixed difference between type and type(). (f90-p-type-re): New regular-expression constant for type commands. (f90-mode): indent-tabs-mode put to nil by default. (f90-looking-at-type-like): Now uses f90-p-type-re. (f90-no-block-limit): Now uses f90-p-type-re. (f90-change-keywords): Don't change preprocessor lines.
author Karl Heuer <kwzh@gnu.org>
date Thu, 20 Apr 1995 17:23:29 +0000
parents bb8df7aad5ef
children 33f97b477bad
comparison
equal deleted inserted replaced
11500:1bae87dcd653 11501:a56d6a86fa85
1 ;; f90.el --- Fortran-90 mode (free format) for GNU Emacs. 1 ;; f90.el --- Fortran-90 mode (free format) for GNU Emacs and GNU XEmacs.
2 ;; Copyright (C) 1995 Free Software Foundation, Inc. 2 ;; Copyright (C) 1995 Free Software Foundation, Inc.
3 3
4 ;; Author: Torbj\"orn Einarsson <tfkte@fy.chalmers.se> 4 ;; Author: Torbj\"orn Einarsson <tfkte@fy.chalmers.se>
5 ;; Created: Jan 21, 1995 5 ;; Created: Apr. 13, 1995
6 ;; Keywords: fortran, f90, languages 6 ;; Keywords: fortran, f90, languages
7 7
8 ;; This program is free software; you can redistribute it and/or modify 8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by 9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2 of the License, or 10 ;; the Free Software Foundation; either version 2 of the License, or
84 ;; f90-beginning-ampersand t 84 ;; f90-beginning-ampersand t
85 ;; f90-smart-end 'blink 85 ;; f90-smart-end 'blink
86 ;; f90-auto-keyword-case nil 86 ;; f90-auto-keyword-case nil
87 ;; f90-auto-hilit19 t 87 ;; f90-auto-hilit19 t
88 ;; f90-leave-line-no nil 88 ;; f90-leave-line-no nil
89 ;; f90-startup-message t) 89 ;; f90-startup-message t
90 ;; indent-tabs-mode nil
91 ;; )
90 ;; ;;The rest is not default. 92 ;; ;;The rest is not default.
91 ;; (abbrev-mode 1) ; turn on abbreviation mode 93 ;; (abbrev-mode 1) ; turn on abbreviation mode
92 ;; (f90-auto-fill-mode 1) ; turn on auto-filling 94 ;; (f90-auto-fill-mode 1) ; turn on auto-filling
93 ;; (if f90-auto-keyword-case ; change case of all keywords on startup 95 ;; (if f90-auto-keyword-case ; change case of all keywords on startup
94 ;; (f90-change-keywords f90-auto-keyword-case)) 96 ;; (f90-change-keywords f90-auto-keyword-case))
106 ;; 3) You can use either hilit19 or font-lock-mode for your highlighting 108 ;; 3) You can use either hilit19 or font-lock-mode for your highlighting
107 ;; a) To use hilit19, be sure that hilit19 is loaded before this file 109 ;; a) To use hilit19, be sure that hilit19 is loaded before this file
108 ;; b) To use font-lock-mode, nothing special is needed. 110 ;; b) To use font-lock-mode, nothing special is needed.
109 ;; 4) For FIXED FORMAT code, use the ordinary fortran mode. 111 ;; 4) For FIXED FORMAT code, use the ordinary fortran mode.
110 ;; 5) This mode does not work under emacs-18.x. 112 ;; 5) This mode does not work under emacs-18.x.
113 ;; 6) Preprocessor directives, i.e., lines starting with # are left-justified
114 ;; and are untouched by all case-changing commands. There is, at present, no
115 ;; mechanism for treating multi-line directives (continued by \ ).
111 116
112 ;; List of user commands 117 ;; List of user commands
113 ;; f90-previous-statement f90-next-statement 118 ;; f90-previous-statement f90-next-statement
114 ;; f90-beginning-of-subprogram f90-end-of-subprogram f90-mark-subprogram 119 ;; f90-beginning-of-subprogram f90-end-of-subprogram f90-mark-subprogram
115 ;; f90-comment-region 120 ;; f90-comment-region
192 "call" "case" "character" "close" "common" "complex" "contains" 197 "call" "case" "character" "close" "common" "complex" "contains"
193 "continue" "cycle" "data" "deallocate" "dimension" "do" "double" "else" 198 "continue" "cycle" "data" "deallocate" "dimension" "do" "double" "else"
194 "elseif" "elsewhere" "end" "enddo" "endfile" "endif" "entry" "equivalence" 199 "elseif" "elsewhere" "end" "enddo" "endfile" "endif" "entry" "equivalence"
195 "exit" "external" "forall" "format" "function" "goto" "if" "implicit" 200 "exit" "external" "forall" "format" "function" "goto" "if" "implicit"
196 "include" "inquire" "integer" "intent" "interface" "intrinsic" "logical" 201 "include" "inquire" "integer" "intent" "interface" "intrinsic" "logical"
197 "module" "namelist" "none" "nullify" "open" "optional" "parameter" 202 "module" "namelist" "none" "nullify" "only" "open" "optional" "parameter"
198 "pause" "pointer" "precision" "print" "private" "procedure" "program" 203 "pause" "pointer" "precision" "print" "private" "procedure" "program"
199 "public" "read" "real" "recursive" "return" "rewind" "save" "select" 204 "public" "read" "real" "recursive" "return" "rewind" "save" "select"
200 "sequence" "stop" "subroutine" "target" "then" "type" "use" "where" 205 "sequence" "stop" "subroutine" "target" "then" "type" "use" "where"
201 "while" "write") 206 "while" "write")
202 "*List of f90-keywords.") 207 "*List of f90-keywords.")
260 (list (concat "^[ \t]*end[ \t]*\\(program\\|module\\|function\\|" 265 (list (concat "^[ \t]*end[ \t]*\\(program\\|module\\|function\\|"
261 "subroutine\\|type\\)[ \t]+\\(\\sw+\\)") 2 266 "subroutine\\|type\\)[ \t]+\\(\\sw+\\)") 2
262 'font-lock-function-name-face) 267 'font-lock-function-name-face)
263 '("^[ \t]*\\(type\\)[ \t]+\\sw+" 1 font-lock-keyword-face) 268 '("^[ \t]*\\(type\\)[ \t]+\\sw+" 1 font-lock-keyword-face)
264 '("^[ \t]*type[ \t]+\\(\\sw+\\)" 1 font-lock-function-name-face) 269 '("^[ \t]*type[ \t]+\\(\\sw+\\)" 1 font-lock-function-name-face)
270 '("^[ \t]*\\(type[ \t]*,[ \t]*\\(private\\|public\\)\\)[ \t]*::\
271 [ \t]*\\(\\sw+\\)" 1 font-lock-keyword-face)
272 '("^[ \t]*\\(type[ \t]*,[ \t]*\\(private\\|public\\)\\)[ \t]*::\
273 [ \t]*\\(\\sw+\\)" 3 font-lock-function-name-face)
265 '("^[ \t]*\\(end[ \t]*\\)?interface\\>" . font-lock-keyword-face) 274 '("^[ \t]*\\(end[ \t]*\\)?interface\\>" . font-lock-keyword-face)
266 '("^[ \t]*contains\\>" . font-lock-keyword-face))) 275 '("^[ \t]*contains\\>" . font-lock-keyword-face)))
267 "For consideration as a value of `f90-font-lock-keywords-1'. 276 "For consideration as a value of `f90-font-lock-keywords-1'.
268 This does fairly subdued highlighting of comments and function names.") 277 This does fairly subdued highlighting of comments and function names.")
269 278
270 (defconst f90-font-lock-keywords-2 279 (defconst f90-font-lock-keywords-2
271 (purecopy 280 (purecopy
272 (append f90-font-lock-keywords-1 281 (append f90-font-lock-keywords-1
273 (list 282 (list
274 ;; Variable declarations 283 ;; Variable declarations
275 '("\\(\\(real\\|integer\\|character\\|complex\\|logical\\|type\\).*\\)::" 284 '("\\(\\(real\\|integer\\|character\\|complex\\|logical\\|\
276 1 font-lock-type-face) 285 type[ \t]*(\\sw+)\\).*\\)::" 1 font-lock-type-face)
277 '("implicit[ \t]*none" . font-lock-keyword-face) 286 '("implicit[ \t]*none" . font-lock-keyword-face)
278 '("^[ \t]*\\(\\sw+[ \t]*:[ \t]*\\)?\\(do\\([ \t]*while\\)?\\)\\>" 287 '("^[ \t]*\\(\\sw+[ \t]*:[ \t]*\\)?\\(do\\([ \t]*while\\)?\\)\\>"
279 2 font-lock-keyword-face) 288 2 font-lock-keyword-face)
280 '("^[ \t]*\\(\\sw+\\)[ \t]*:[ \t]*\\(do\\([ \t]*while\\)?\\)\\>" 1 289 '("^[ \t]*\\(\\sw+\\)[ \t]*:[ \t]*\\(do\\([ \t]*while\\)?\\)\\>" 1
281 font-lock-function-name-face) 290 font-lock-function-name-face)
350 "\\(\"[^\"\n]*\\(&[ \t]*\\(![^\n]*\\)?\n[ \t]*&[^\"\n]*\\)*\"" 359 "\\(\"[^\"\n]*\\(&[ \t]*\\(![^\n]*\\)?\n[ \t]*&[^\"\n]*\\)*\""
351 "\\|'[^'\n]*\\(&[ \t]*\\(![^\n]*\\)?\n[ \t]*&[^'\n]*\\)*'\\)") 360 "\\|'[^'\n]*\\(&[ \t]*\\(![^\n]*\\)?\n[ \t]*&[^'\n]*\\)*'\\)")
352 nil f90-face-string) 361 nil f90-face-string)
353 (list "!" "$" f90-face-comment) 362 (list "!" "$" f90-face-comment)
354 (list "\\(\\(real\\|integer\\|character\\|complex\\|logical\ 363 (list "\\(\\(real\\|integer\\|character\\|complex\\|logical\
355 \\|type\\).*\\)::" 1 f90-face-decl) 364 \\|type[ \t]*(\\sw+)\\).*\\)::" 1 f90-face-decl)
356 (list "implicit[ \t]*none" nil f90-face-decl) 365 (list "implicit[ \t]*none" nil f90-face-decl)
357 (list "^[ \t]*\\(program\\|module\\)[ \t]+\\sw+" 1 f90-face-prog) 366 (list "^[ \t]*\\(program\\|module\\)[ \t]+\\sw+" 1 f90-face-prog)
358 (list "^[ \t]*\\(program\\|module\\)[ \t]+\\(\\sw+\\)" 2 f90-face-label) 367 (list "^[ \t]*\\(program\\|module\\)[ \t]+\\(\\sw+\\)" 2 f90-face-label)
359 (list "\\(^.*\\(function\\|subroutine\\)\\)[ \t]+\\sw+" 1 368 (list "\\(^.*\\(function\\|subroutine\\)\\)[ \t]+\\sw+" 1
360 f90-face-prog) 369 f90-face-prog)
364 \\|subroutine\\|type\\)" nil f90-face-prog) 373 \\|subroutine\\|type\\)" nil f90-face-prog)
365 (list (concat "^[ \t]*end[ \t]*\\(program\\|module\\|function\\|" 374 (list (concat "^[ \t]*end[ \t]*\\(program\\|module\\|function\\|"
366 "subroutine\\|type\\)[ \t]+\\(\\sw+\\)") 2 f90-face-label) 375 "subroutine\\|type\\)[ \t]+\\(\\sw+\\)") 2 f90-face-label)
367 (list "^[ \t]*\\(type\\)[ \t]+\\sw+" 1 f90-face-type) 376 (list "^[ \t]*\\(type\\)[ \t]+\\sw+" 1 f90-face-type)
368 (list "^[ \t]*type[ \t]+\\(\\sw+\\)" 1 f90-face-label) 377 (list "^[ \t]*type[ \t]+\\(\\sw+\\)" 1 f90-face-label)
378 (list "^[ \t]*\\(type[ \t]*,[ \t]*\\(private\\|public\\)\\)[ \t]*::[ \t]*\\(\\sw+\\)" 1 f90-face-type)
379 (list "^[ \t]*\\(type[ \t]*,[ \t]*\\(private\\|public\\)\\)[ \t]*::[ \t]*\\(\\sw+\\)" 3 f90-face-label)
369 (list "^[ \t]*\\(end[ \t]*\\)?interface\\>" nil f90-face-interface) 380 (list "^[ \t]*\\(end[ \t]*\\)?interface\\>" nil f90-face-interface)
370 (list "^[ \t]*contains\\>" nil f90-face-contains) 381 (list "^[ \t]*contains\\>" nil f90-face-contains)
371 (list "^[ \t]*\\(\\sw+[ \t]*:[ \t]*\\)?\\(do\\([ \t]*while\\)?\\)\\>" 382 (list "^[ \t]*\\(\\sw+[ \t]*:[ \t]*\\)?\\(do\\([ \t]*while\\)?\\)\\>"
372 2 f90-face-do) 383 2 f90-face-do)
373 (list "^[ \t]*\\(\\sw+\\)[ \t]*:[ \t]*\\(do\\([ \t]*while\\)?\\)\\>" 1 384 (list "^[ \t]*\\(\\sw+\\)[ \t]*:[ \t]*\\(do\\([ \t]*while\\)?\\)\\>" 1
531 (defconst f90-end-if-re 542 (defconst f90-end-if-re
532 "end[ \t]*\\(if\\|select\\|where\\|forall\\)\\>") 543 "end[ \t]*\\(if\\|select\\|where\\|forall\\)\\>")
533 (defconst f90-end-type-re 544 (defconst f90-end-type-re
534 "end[ \t]*\\(type\\|interface\\|block[ \t]*data\\)\\>") 545 "end[ \t]*\\(type\\|interface\\|block[ \t]*data\\)\\>")
535 (defconst f90-no-break-re "\\(\\*\\*\\|//\\|=>\\)") 546 (defconst f90-no-break-re "\\(\\*\\*\\|//\\|=>\\)")
547 (defconst f90-p-type-re
548 (concat "\\(type\\)[ \t]*,[ \t]*\\(public\\|private\\)"
549 "[ \t]*::[ \t]*\\(" f90-symbol-re "\\)\\>"))
536 ;; A temporary position to make region operators faster 550 ;; A temporary position to make region operators faster
537 (defvar f90-cache-position nil) 551 (defvar f90-cache-position nil)
538 (make-variable-buffer-local 'f90-cache-position) 552 (make-variable-buffer-local 'f90-cache-position)
539 553
540 ;; abbrevs have generally two letters, except standard types `c, `i, `r, `t 554 ;; abbrevs have generally two letters, except standard types `c, `i, `r, `t
680 (setq comment-start-skip "!+ *") 694 (setq comment-start-skip "!+ *")
681 (make-local-variable 'comment-indent-function) 695 (make-local-variable 'comment-indent-function)
682 (setq comment-indent-function 'f90-comment-indent) 696 (setq comment-indent-function 'f90-comment-indent)
683 (make-local-variable 'abbrev-all-caps) 697 (make-local-variable 'abbrev-all-caps)
684 (setq abbrev-all-caps t) 698 (setq abbrev-all-caps t)
699 (setq indent-tabs-mode nil)
685 ;; Setting up things for font-lock 700 ;; Setting up things for font-lock
686 (if (string-match "Lucid" emacs-version) 701 (if (string-match "Lucid" emacs-version)
687 (put 'f90-mode 'font-lock-keywords-case-fold-search t) 702 (put 'f90-mode 'font-lock-keywords-case-fold-search t)
688 ;; (make-local-variable 'font-lock-keywords) ; for version <= 19.28 703 ;; (make-local-variable 'font-lock-keywords) ; for Emacs version <= 19.28
689 ;; (setq font-lock-keywords f90-font-lock-keywords) 704 ;; (setq font-lock-keywords f90-font-lock-keywords)
690 (make-local-variable 'font-lock-defaults) ; for version > 19.28 705 (make-local-variable 'font-lock-defaults) ; for Emacs version > 19.28
691 (setq font-lock-defaults '(f90-font-lock-keywords t)) 706 (setq font-lock-defaults '(f90-font-lock-keywords t))
692 ) 707 )
693 (make-local-variable 'font-lock-keywords-case-fold-search) 708 (make-local-variable 'font-lock-keywords-case-fold-search)
694 (setq font-lock-keywords-case-fold-search t) 709 (setq font-lock-keywords-case-fold-search t)
695 (run-hooks 'f90-mode-hook) 710 (run-hooks 'f90-mode-hook)
833 "Return (kind name) at the start of a type/interface/block-data block. 848 "Return (kind name) at the start of a type/interface/block-data block.
834 Name is non-nil only for type." 849 Name is non-nil only for type."
835 (cond 850 (cond
836 ((looking-at (concat "\\(type\\)[ \t]+\\(" f90-symbol-re "\\)\\>")) 851 ((looking-at (concat "\\(type\\)[ \t]+\\(" f90-symbol-re "\\)\\>"))
837 (list (f90-match-piece 1) (f90-match-piece 2))) 852 (list (f90-match-piece 1) (f90-match-piece 2)))
853 ((looking-at f90-p-type-re)
854 (list (f90-match-piece 1) (f90-match-piece 3)))
838 ((looking-at "\\(interface\\)\\>") 855 ((looking-at "\\(interface\\)\\>")
839 (list (f90-match-piece 1) nil)) 856 (list (f90-match-piece 1) nil))
840 ((looking-at "\\(block[ \t]*data\\)\\>") 857 ((looking-at "\\(block[ \t]*data\\)\\>")
841 (list (f90-match-piece 1) nil)))) 858 (list (f90-match-piece 1) nil))))
842 859
900 case\\|where\\|forall\\)\\>") 917 case\\|where\\|forall\\)\\>")
901 (looking-at "\\(program\\|module\\|interface\\|\ 918 (looking-at "\\(program\\|module\\|interface\\|\
902 block[ \t]*data\\)\\>") 919 block[ \t]*data\\)\\>")
903 (looking-at "\\(contains\\|continue\\|\\sw+[ \t]*:\\)") 920 (looking-at "\\(contains\\|continue\\|\\sw+[ \t]*:\\)")
904 (looking-at "type[ \t]+\\sw+") 921 (looking-at "type[ \t]+\\sw+")
922 (looking-at f90-p-type-re)
905 (re-search-forward "\\(function\\|subroutine\\)" eol t)))))) 923 (re-search-forward "\\(function\\|subroutine\\)" eol t))))))
906 924
907 (defsubst f90-update-line () 925 (defsubst f90-update-line ()
908 (let (bol eol) 926 (let (bol eol)
909 (if (or f90-auto-keyword-case f90-auto-hilit19) 927 (if (or f90-auto-keyword-case f90-auto-hilit19)
1551 "\\)\\>")) (ref-point (point-min)) state) 1569 "\\)\\>")) (ref-point (point-min)) state)
1552 (goto-char beg) 1570 (goto-char beg)
1553 (while (re-search-forward keyword-re end t) 1571 (while (re-search-forward keyword-re end t)
1554 (if (progn 1572 (if (progn
1555 (setq state (parse-partial-sexp ref-point (point))) 1573 (setq state (parse-partial-sexp ref-point (point)))
1556 (and (not (nth 3 state)) (not (nth 4 state)))) 1574 (or (nth 3 state) (nth 4 state)
1557 (progn 1575 (save-excursion ; Check for cpp directive.
1558 (setq ref-point (point)) 1576 (beginning-of-line)
1559 (funcall change-word -1))))))) 1577 (skip-chars-forward " \t0-9")
1578 (looking-at "#"))))
1579 ()
1580 (setq ref-point (point))
1581 (funcall change-word -1))))))
1560 1582
1561 (provide 'f90) 1583 (provide 'f90)
1562 1584
1563 ;;; f90.el ends here 1585 ;;; f90.el ends here