;; f90-comment-region (C-c;) toggles insertion of f90-comment-region in region.
;; One common convention for free vs. fixed format is that free-format files
-;; have the ending .f90 while the fixed format files have the ending .f.
+;; have the ending .f90 while the fixed format files have the ending .f.
;; To make f90-mode work, put this file in, for example, your directory
;; ~/lisp, and be sure that you have the following in your .emacs-file
;; (setq load-path (append load-path '("~/lisp")))
;; (autoload 'f90-mode "f90"
;; "Major mode for editing Fortran 90 code in free format." t)
-;; (setq auto-mode-alist (append auto-mode-alist
+;; (setq auto-mode-alist (append auto-mode-alist
;; (list '("\\.f90$" . f90-mode))))
;; Once you have entered f90-mode, you may get more info by using
;; the command describe-mode (C-h m). For online help describing various
'("\\<\\(namelist\\|common\\)[ \t]*\/\\(\\sw+\\)?\/" (1 font-lock-keyword-face) (2 font-lock-constant-face nil t))
"\\<else\\([ \t]*if\\|where\\)?\\>"
"\\<\\(then\\|continue\\|format\\|include\\|stop\\|return\\)\\>"
- '("\\<\\(exit\\|cycle\\)[ \t]*\\(\\sw+\\)?\\>"
+ '("\\<\\(exit\\|cycle\\)[ \t]*\\(\\sw+\\)?\\>"
(1 font-lock-keyword-face) (2 font-lock-constant-face nil t))
'("\\<\\(case\\)[ \t]*\\(default\\|(\\)" . 1)
'("\\<\\(do\\|go *to\\)\\>[ \t]*\\([0-9]+\\)"
(modify-syntax-entry ?\" "\"" f90-mode-syntax-table) ; string quote
(modify-syntax-entry ?\` "w" f90-mode-syntax-table) ; for abbrevs
(modify-syntax-entry ?\r " " f90-mode-syntax-table) ; return is whitespace
- (modify-syntax-entry ?+ "." f90-mode-syntax-table)
+ (modify-syntax-entry ?+ "." f90-mode-syntax-table)
(modify-syntax-entry ?- "." f90-mode-syntax-table)
(modify-syntax-entry ?= "." f90-mode-syntax-table)
(modify-syntax-entry ?* "." f90-mode-syntax-table)
(define-key f90-mode-map "*" 'f90-electric-insert)
(define-key f90-mode-map "/" 'f90-electric-insert))
-
+
;; menus
(if (string-match "XEmacs" emacs-version)
(defvar f90-xemacs-menu
["Upcase Keywords (region)" f90-upcase-region-keywords
t]
["Capitalize Keywords (buffer)" f90-capitalize-keywords t]
- ["Capitalize Keywords (region)"
+ ["Capitalize Keywords (region)"
f90-capitalize-region-keywords t]
["Downcase Keywords (buffer)" f90-downcase-keywords t]
- ["Downcase Keywords (region)"
+ ["Downcase Keywords (region)"
f90-downcase-region-keywords t]
"-----"
["Toggle abbrev-mode" abbrev-mode t]
(defvar f90-change-case-menu
(let ((map (make-sparse-keymap "Change Keyword Case")))
-
+
(define-key map [dkr] (cons "Downcase Keywords (region)"
'f90-downcase-region-keywords))
(put 'f90-downcase-region-keywords 'menu-enable 'mark-active)
-
+
(define-key map [ckr] (cons "Capitalize Keywords (region)"
'f90-capitalize-region-keywords))
(put 'f90-capitalize-region-keywords 'menu-enable 'mark-active)
-
+
(define-key map [ukr] (cons "Upcase Keywords (region)"
'f90-upcase-region-keywords))
(put 'f90-upcase-region-keywords 'menu-enable 'mark-active)
-
+
(define-key map [line] (list "-----------------"))
-
+
(define-key map [dkb] (cons "Downcase Keywords (buffer)"
'f90-downcase-keywords))
-
+
(define-key map [ckb] (cons "Capitalize Keywords (buffer)"
'f90-capitalize-keywords))
-
+
(define-key map [ukb] (cons "Upcase Keywords (buffer)"
'f90-upcase-keywords))
map)
(defalias 'f90-font-lock-off 'font-lock-mode)
(put 'f90-font-lock-on 'menu-enable 'font-lock-mode)
(put 'f90-font-lock-off 'menu-enable '(not font-lock-mode))
-
+
(defun f90-font-lock-1 ()
(interactive)
"Set font-lock-keywords to f90-font-lock-keywords-1."
(font-lock-mode 1)
(setq font-lock-keywords f90-font-lock-keywords-1)
(font-lock-fontify-buffer))
-
+
(defun f90-font-lock-2 ()
(interactive)
"Set font-lock-keywords to f90-font-lock-keywords-2."
(font-lock-mode 1)
(setq font-lock-keywords f90-font-lock-keywords-2)
(font-lock-fontify-buffer))
-
+
(defun f90-font-lock-3 ()
(interactive)
"Set font-lock-keywords to f90-font-lock-keywords-3."
(font-lock-mode 1)
(setq font-lock-keywords f90-font-lock-keywords-3)
(font-lock-fontify-buffer))
-
+
(defun f90-font-lock-4 ()
(interactive)
"Set font-lock-keywords to f90-font-lock-keywords-4."
(font-lock-mode 1)
(setq font-lock-keywords f90-font-lock-keywords-4)
(font-lock-fontify-buffer))
-
+
(defvar f90-font-lock-menu
(let ((map (make-sparse-keymap "f90-font-lock-menu")))
(define-key map [h4] (cons "Maximum highlighting (level 4)"
(defalias 'f90-font-lock-menu f90-font-lock-menu)
(define-key f90-mode-map [menu-bar] (make-sparse-keymap))
- (define-key f90-mode-map [menu-bar f90]
- (cons "F90" (make-sparse-keymap "f90")))
+ (define-key f90-mode-map [menu-bar f90]
+ (cons "F90" (make-sparse-keymap "f90")))
(define-key f90-mode-map [menu-bar f90 f90-imenu-menu]
'("Add imenu Menu" . f90-add-imenu-menu))
'("Join with Next Line" . f90-join-lines))
(define-key f90-mode-map [menu-bar f90 f90-break-line]
'("Break Line at Point" . f90-break-line))
-
+
(define-key f90-mode-map [menu-bar f90 line3]
'("----"))
-
+
(define-key f90-mode-map [menu-bar f90 f90-fill-region]
'("Fill Region" . f90-fill-region))
(put 'f90-fill-region 'menu-enable 'mark-active)
-
+
(define-key f90-mode-map [menu-bar f90 indent-region]
'("Indent Region" . indent-region))
-
+
(define-key f90-mode-map [menu-bar f90 f90-comment-region]
'("(Un)Comment Region" . f90-comment-region))
(put 'f90-comment-region 'menu-enable 'mark-active)
-
+
(define-key f90-mode-map [menu-bar f90 line4]
'("----"))
-
+
(define-key f90-mode-map [menu-bar f90 f90-end-of-subprogram]
'("End of Subprogram" . f90-end-of-subprogram))
(define-key f90-mode-map [menu-bar f90 f90-beginning-of-subprogram]
)
;; Regexps for finding program structures.
-(defconst f90-blocks-re
+(defconst f90-blocks-re
"\\(block[ \t]*data\\|do\\|if\\|interface\\|function\\|module\\|\
program\\|select\\|subroutine\\|type\\|where\\|forall\\)\\>")
-(defconst f90-program-block-re
+(defconst f90-program-block-re
"\\(program\\|module\\|subroutine\\|function\\)")
-(defconst f90-else-like-re
+(defconst f90-else-like-re
"\\(else\\([ \t]*if\\|where\\)?\\|case[ \t]*\\(default\\|(\\)\\)")
-(defconst f90-end-if-re
+(defconst f90-end-if-re
"end[ \t]*\\(if\\|select\\|where\\|forall\\)\\>")
-(defconst f90-end-type-re
+(defconst f90-end-type-re
"end[ \t]*\\(type\\|interface\\|block[ \t]*data\\)")
(defconst f90-type-def-re
"\\<\\(type\\)\\>\\([^(\n]*::\\)?[ \t]*\\(\\sw+\\)")
'("Modules" "^[ \t0-9]*module[ \t]+\\(\\sw+\\)[ \t]*\\(!\\|$\\)" 1)
'("Types" "^[ \t0-9]*type[ \t]+\\(\\sw+\\)" 1)
(list
- "Procedures"
+ "Procedures"
(concat
"^[ \t0-9]*"
"\\("
\\[f90-indent-new-line] corrects current indentation and creates new\
indented line.
-\\[f90-indent-line] indents the current line correctly.
-\\[f90-indent-subprogram] indents the current subprogram.
+\\[f90-indent-line] indents the current line correctly.
+\\[f90-indent-subprogram] indents the current subprogram.
Type `? or `\\[help-command] to display a list of built-in\
abbrevs for F90 keywords.
f90-continuation-indent
Extra indentation applied to continuation lines. (default 5)
f90-comment-region
- String inserted by \\[f90-comment-region] at start of each line in
+ String inserted by \\[f90-comment-region] at start of each line in
region. (default \"!!!$\")
f90-indented-comment-re
Regexp determining the type of comment to be intended like code.
f90-break-before-delimiters
Non-nil causes `f90-do-auto-fill' to break lines before delimiters.
(default t)
- f90-beginning-ampersand
+ f90-beginning-ampersand
Automatic insertion of \& at beginning of continuation lines. (default t)
- f90-smart-end
+ f90-smart-end
From an END statement, check and fill the end using matching block start.
Allowed values are 'blink, 'no-blink, and nil, which determine
whether to blink the matching beginning.) (default 'blink)
(add-submenu nil f90-xemacs-menu)))))
;; XEmacs: (Don't need a special case, since both emacsen work alike -sb)
(make-local-variable 'font-lock-defaults)
- (setq font-lock-defaults
+ (setq font-lock-defaults
'((f90-font-lock-keywords f90-font-lock-keywords-1
f90-font-lock-keywords-2
f90-font-lock-keywords-3
f90-cache-position
(point-min))))
(nth 3 (parse-partial-sexp beg-pnt (point)))))
-
+
(defsubst f90-in-comment ()
(let ((beg-pnt
(if (and f90-cache-position (> (point) f90-cache-position))
(defsubst f90-looking-at-type-like ()
"Return (kind name) at the start of a type/interface/block-data block.
Name is non-nil only for type."
- (cond
+ (cond
((looking-at f90-type-def-re)
(list (f90-match-piece 1) (f90-match-piece 3)))
((looking-at "\\(interface\\|block[\t]*data\\)\\>")
(defsubst f90-looking-at-program-block-end ()
"Return list of type and name of end of block."
- (if (looking-at (concat "end[ \t]*" f90-blocks-re
+ (if (looking-at (concat "end[ \t]*" f90-blocks-re
"?\\([ \t]+\\(\\sw+\\)\\)?\\>"))
(list (f90-match-piece 1) (f90-match-piece 3))))
(setq icol (- icol f90-do-indent))))
(end-of-line))
icol)))
-
-
+
+
(defun f90-calculate-indent ()
"Calculate the indent column based on previous statements."
(interactive)
(cond ((or (f90-looking-at-if-then)
(f90-looking-at-where-or-forall)
(f90-looking-at-select-case)
- (looking-at f90-else-like-re))
+ (looking-at f90-else-like-re))
(setq icol (+ icol f90-if-indent)))
((f90-looking-at-do)
(setq icol (+ icol f90-do-indent)))
(interactive)
(let ((count 1) (case-fold-search t) matching-beg)
(beginning-of-line) (skip-chars-forward " \t0-9")
- (if (setq matching-beg (f90-looking-at-program-block-start))
+ (if (setq matching-beg (f90-looking-at-program-block-start))
(setq count (- count 1)))
(while (and (not (zerop count))
(re-search-backward f90-program-block-re nil 'move))
(beginning-of-line) (skip-chars-forward " \t0-9")
- (cond
+ (cond
((setq matching-beg (f90-looking-at-program-block-start))
(setq count (- count 1)))
((f90-looking-at-program-block-end)
(< (point) end-region-mark))
(if (looking-at "[ \t]*!")
(f90-indent-to (f90-comment-indent))
- (if (not (zerop (- (current-indentation)
+ (if (not (zerop (- (current-indentation)
(+ ind-curr f90-continuation-indent))))
(f90-indent-to (+ ind-curr f90-continuation-indent) 'no-line-no))))
;; process all following lines
((setq end-struct (f90-looking-at-program-block-end))
(setq beg-struct (car block-list)
block-list (cdr block-list))
- (if f90-smart-end
+ (if f90-smart-end
(save-excursion
(f90-block-match (car beg-struct)(car (cdr beg-struct))
(car end-struct)(car (cdr end-struct)))))
(< (point) end-region-mark))
(if (looking-at "[ \t]*!")
(f90-indent-to (f90-comment-indent))
- (if (not (zerop (- (current-indentation)
+ (if (not (zerop (- (current-indentation)
(+ ind-curr f90-continuation-indent))))
(f90-indent-to
(+ ind-curr f90-continuation-indent) 'no-line-no)))))
(newline 1)
(if f90-beginning-ampersand (insert "&")))))
(f90-indent-line))
-
+
(defun f90-find-breakpoint ()
"From fill-column, search backward for break-delimiter."
(let ((bol (f90-get-beg-of-line)))
(if end-block
(progn
(message "END %s does not match %s." end-block beg-block)
- (end-of-line)
+ (end-of-line)
(throw 'no-match nil))
(message "Inserting %s." beg-block)
(insert (concat " " beg-block)))
(search-forward end-block))
(if (not (f90-equal-symbols beg-name end-name))
- (cond ((and beg-name (not end-name))
+ (cond ((and beg-name (not end-name))
(message "Inserting %s." beg-name)
(insert (concat " " beg-name)))
- ((and beg-name end-name)
+ ((and beg-name end-name)
(message "Replacing %s with %s." end-name beg-name)
(search-forward end-name)
(replace-match beg-name))
- ((and (not beg-name) end-name)
+ ((and (not beg-name) end-name)
(message "Deleting %s." end-name)
(search-forward end-name)
(replace-match "")))
(setq end-name (car (cdr end-struct)))
(save-excursion
(beginning-of-line)
- (while
+ (while
(and (not (zerop count))
(let ((stop nil) notexist)
(while (not stop)
(setq notexist
- (not (re-search-backward
+ (not (re-search-backward
(concat "\\(" f90-blocks-re "\\)") nil t)))
(if notexist
(setq stop t)
(f90-block-match beg-block beg-name end-block end-name)))))))
(defun f90-insert-end ()
- "Inserts an complete end statement matching beginning of present block."
+ "Inserts a complete end statement matching beginning of present block."
(interactive)
(let ((f90-smart-end (if f90-smart-end f90-smart-end 'blink)))
(insert "end")
;; abbrevs and keywords
(defun f90-abbrev-start ()
- "Typing `\\[help-command] or `? lists all the F90 abbrevs.
+ "Typing `\\[help-command] or `? lists all the F90 abbrevs.
Any other key combination is executed normally."
(interactive)
(let (e c)
(save-excursion
(setq beg (if beg beg (point-min)))
(setq end (if end end (point-max)))
- (let ((keyword-re
+ (let ((keyword-re
(concat "\\("
f90-keywords-re "\\|" f90-procedures-re "\\|"
f90-hpf-keywords-re "\\|" f90-operators-re "\\)"))