;; This file is part of GNU Emacs.
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; To facilitate typing, a fairly complete list of abbreviations is provided.
;; All abbreviations begin with the backquote character "`"
-;; (this requires modification of the syntax-table).
;; For example, `i expands to integer (if abbrev-mode is on).
;; There are two separate features for altering the appearance of code:
Set the match data so that subexpression 1,2 are the TYPE, and
type-name parts, respectively."
(let (found l)
- (while (and (re-search-forward "\\<\\(\\(?:end[ \t]*\\)?type\\)[ \t]*"
+ (while (and (re-search-forward "\\<\\(\\(?:end[ \t]*\\)?type\\)\\>[ \t]*"
limit t)
(not (setq found
(progn
(list
f90-keywords-level-3-re
f90-operators-re
+ ;; FIXME why isn't this font-lock-builtin-face, which
+ ;; otherwise we hardly use, as in fortran.el?
(list f90-procedures-re '(1 font-lock-keyword-face keep))
"\\<real\\>" ; avoid overwriting real defs
;; As an attribute, but not as an optional argument.
(let ((table (make-syntax-table)))
(modify-syntax-entry ?\! "<" table) ; begin comment
(modify-syntax-entry ?\n ">" table) ; end comment
+ ;; FIXME: This goes against the convention: it should be "_".
(modify-syntax-entry ?_ "w" table) ; underscore in names
(modify-syntax-entry ?\' "\"" table) ; string quote
(modify-syntax-entry ?\" "\"" table) ; string quote
- (modify-syntax-entry ?\` "w" table) ; for abbrevs
+ ;; FIXME: We used to set ` to word syntax for the benefit of abbrevs, but
+ ;; we do not need it any more. Not sure if it should be "_" or "." now.
+ (modify-syntax-entry ?\` "_" table)
(modify-syntax-entry ?\r " " table) ; return is whitespace
(modify-syntax-entry ?+ "." table) ; punctuation
(modify-syntax-entry ?- "." table)
(modify-syntax-entry ?= "." table)
(modify-syntax-entry ?* "." table)
(modify-syntax-entry ?/ "." table)
- ;; I think that the f95 standard leaves the behaviour of \
+ ;; I think that the f95 standard leaves the behavior of \
;; unspecified, but that f2k will require it to be non-special.
;; Use `f90-backslash-not-special' to change.
(modify-syntax-entry ?\\ "\\" table) ; escape chars
(define-key map "\C-\M-p" 'f90-beginning-of-block)
(define-key map "\C-\M-q" 'f90-indent-subprogram)
(define-key map "\C-j" 'f90-indent-new-line) ; LFD equals C-j
- (define-key map "\r" 'newline)
+;;; (define-key map "\r" 'newline)
(define-key map "\C-c\r" 'f90-break-line)
;;; (define-key map [M-return] 'f90-break-line)
(define-key map "\C-c\C-a" 'f90-previous-block)
(define-key map "\C-c\C-p" 'f90-previous-statement)
(define-key map "\C-c\C-n" 'f90-next-statement)
(define-key map "\C-c\C-w" 'f90-insert-end)
- (define-key map "\t" 'f90-indent-line)
+ ;; Standard tab binding will call this, and also handle regions.
+;;; (define-key map "\t" 'f90-indent-line)
(define-key map "," 'f90-electric-insert)
(define-key map "+" 'f90-electric-insert)
(define-key map "-" 'f90-electric-insert)
(defun f90-imenu-type-matcher ()
"Search backward for the start of a derived type.
Set subexpression 1 in the match-data to the name of the type."
- (let (found l)
+ (let (found)
(while (and (re-search-backward "^[ \t0-9]*type[ \t]*" nil t)
(not (setq found
(save-excursion
(defvar f90-imenu-generic-expression
(let ((good-char "[^!\"\&\n \t]") (not-e "[^e!\n\"\& \t]")
(not-n "[^n!\n\"\& \t]") (not-d "[^d!\n\"\& \t]")
- (not-ib "[^i(!\n\"\& \t]") (not-s "[^s!\n\"\& \t]"))
+ ;; (not-ib "[^i(!\n\"\& \t]") (not-s "[^s!\n\"\& \t]")
+ )
(list
'(nil "^[ \t0-9]*program[ \t]+\\(\\sw+\\)" 1)
'("Modules" "^[ \t0-9]*module[ \t]+\\(\\sw+\\)[ \t]*\\(!\\|$\\)" 1)
\f
;; Abbrevs have generally two letters, except standard types `c, `i, `r, `t.
-(defvar f90-mode-abbrev-table
- (progn
- (define-abbrev-table 'f90-mode-abbrev-table nil)
- f90-mode-abbrev-table)
- "Abbrev table for F90 mode.")
-
-;; Not in defvar because user abbrevs may be restored before this file loads.
-(mapc
- (lambda (e)
- (condition-case nil
- (define-abbrev f90-mode-abbrev-table (car e) (cdr e) nil :count 0
- :system t)
- (wrong-number-of-arguments ; Emacs 22
- (define-abbrev f90-mode-abbrev-table (car e) (cdr e) nil 0 t))))
- '(("`al" . "allocate" )
- ("`ab" . "allocatable" )
- ("`ai" . "abstract interface")
- ("`as" . "assignment" )
- ("`asy" . "asynchronous" )
- ("`ba" . "backspace" )
- ("`bd" . "block data" )
- ("`c" . "character" )
- ("`cl" . "close" )
- ("`cm" . "common" )
- ("`cx" . "complex" )
- ("`cn" . "contains" )
- ("`cy" . "cycle" )
- ("`de" . "deallocate" )
- ("`df" . "define" )
- ("`di" . "dimension" )
- ("`dp" . "double precision")
- ("`dw" . "do while" )
- ("`el" . "else" )
- ("`eli" . "else if" )
- ("`elw" . "elsewhere" )
- ("`em" . "elemental" )
- ("`e" . "enumerator" )
- ("`eq" . "equivalence" )
- ("`ex" . "external" )
- ("`ey" . "entry" )
- ("`fl" . "forall" )
- ("`fo" . "format" )
- ("`fu" . "function" )
- ("`fa" . ".false." )
- ("`im" . "implicit none")
- ("`in" . "include" )
- ("`i" . "integer" )
- ("`it" . "intent" )
- ("`if" . "interface" )
- ("`lo" . "logical" )
- ("`mo" . "module" )
- ("`na" . "namelist" )
- ("`nu" . "nullify" )
- ("`op" . "optional" )
- ("`pa" . "parameter" )
- ("`po" . "pointer" )
- ("`pr" . "print" )
- ("`pi" . "private" )
- ("`pm" . "program" )
- ("`pr" . "protected" )
- ("`pu" . "public" )
- ("`r" . "real" )
- ("`rc" . "recursive" )
- ("`rt" . "return" )
- ("`rw" . "rewind" )
- ("`se" . "select" )
- ("`sq" . "sequence" )
- ("`su" . "subroutine" )
- ("`ta" . "target" )
- ("`tr" . ".true." )
- ("`t" . "type" )
- ("`vo" . "volatile" )
- ("`wh" . "where" )
- ("`wr" . "write" )))
-
+(define-abbrev-table 'f90-mode-abbrev-table
+ (mapcar (lambda (e) (list (car e) (cdr e) nil :system t))
+ '(("`al" . "allocate" )
+ ("`ab" . "allocatable" )
+ ("`ai" . "abstract interface")
+ ("`as" . "assignment" )
+ ("`asy" . "asynchronous" )
+ ("`ba" . "backspace" )
+ ("`bd" . "block data" )
+ ("`c" . "character" )
+ ("`cl" . "close" )
+ ("`cm" . "common" )
+ ("`cx" . "complex" )
+ ("`cn" . "contains" )
+ ("`cy" . "cycle" )
+ ("`de" . "deallocate" )
+ ("`df" . "define" )
+ ("`di" . "dimension" )
+ ("`dp" . "double precision")
+ ("`dw" . "do while" )
+ ("`el" . "else" )
+ ("`eli" . "else if" )
+ ("`elw" . "elsewhere" )
+ ("`em" . "elemental" )
+ ("`e" . "enumerator" )
+ ("`eq" . "equivalence" )
+ ("`ex" . "external" )
+ ("`ey" . "entry" )
+ ("`fl" . "forall" )
+ ("`fo" . "format" )
+ ("`fu" . "function" )
+ ("`fa" . ".false." )
+ ("`im" . "implicit none")
+ ("`in" . "include" )
+ ("`i" . "integer" )
+ ("`it" . "intent" )
+ ("`if" . "interface" )
+ ("`lo" . "logical" )
+ ("`mo" . "module" )
+ ("`na" . "namelist" )
+ ("`nu" . "nullify" )
+ ("`op" . "optional" )
+ ("`pa" . "parameter" )
+ ("`po" . "pointer" )
+ ("`pr" . "print" )
+ ("`pi" . "private" )
+ ("`pm" . "program" )
+ ("`pr" . "protected" )
+ ("`pu" . "public" )
+ ("`r" . "real" )
+ ("`rc" . "recursive" )
+ ("`rt" . "return" )
+ ("`rw" . "rewind" )
+ ("`se" . "select" )
+ ("`sq" . "sequence" )
+ ("`su" . "subroutine" )
+ ("`ta" . "target" )
+ ("`tr" . ".true." )
+ ("`t" . "type" )
+ ("`vo" . "volatile" )
+ ("`wh" . "where" )
+ ("`wr" . "write" )))
+ "Abbrev table for F90 mode."
+ ;; Accept ` as the first char of an abbrev. Also allow _ in abbrevs.
+ :regexp "\\(?:[^[:word:]_`]\\|^\\)\\(`?[[:word:]_]+\\)[^[:word:]_]*")
\f
;;;###autoload
(defun f90-mode ()
NAME is non-nil only for type."
(cond
((save-excursion
- (and (looking-at "\\<type[ \t]*")
+ (and (looking-at "\\<type\\>[ \t]*")
(goto-char (match-end 0))
(not (looking-at "\\(is\\>\\|(\\)"))
(or (looking-at "\\(\\sw+\\)")
matching-beg
;; Note this includes the case of an un-named main program,
;; in which case we go to (point-min).
- (message "No beginning found.")
+ (if (interactive-p) (message "No beginning found"))
nil)))
(defun f90-end-of-subprogram ()
Return (TYPE NAME), or nil if not found."
(interactive)
(let ((case-fold-search t)
- (count 1)
+ (count 1)
matching-end)
(end-of-line)
(while (and (> count 0)
;;; (forward-line 1)
(if (zerop count)
matching-end
- (message "No end found.")
+ (if (interactive-p) (message "No end found"))
nil)))
(defun f90-prepare-abbrev-list-buffer ()
"Create a buffer listing the F90 mode abbreviations."
- (save-excursion
- (set-buffer (get-buffer-create "*Abbrevs*"))
+ (with-current-buffer (get-buffer-create "*Abbrevs*")
(erase-buffer)
(insert-abbrev-table-description 'f90-mode-abbrev-table t)
(goto-char (point-min))
(funcall change-word -1)
(or (string= saveword (buffer-substring back-point ref-point))
(setq modified t))))
- (or modified (set-buffer-modified-p nil))))))
+ (or modified (restore-buffer-modified-p nil))))))
(defun f90-current-defun ()