/[emacs]/emacs/lisp/progmodes/f90.el
ViewVC logotype

Diff of /emacs/lisp/progmodes/f90.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.67 by gm, Sat Apr 12 20:43:41 2003 UTC revision 1.68 by gm, Tue Apr 15 19:18:23 2003 UTC
# Line 65  Line 65 
65  ;; The function f90-comment-region toggles insertion of  ;; The function f90-comment-region toggles insertion of
66  ;; the variable f90-comment-region in every line of the region.  ;; the variable f90-comment-region in every line of the region.
67    
68  ;; One common convention for free vs. fixed format is that free-format files  ;; One common convention for free vs. fixed format is that free format files
69  ;; have the ending .f90 or .f95 while fixed format files have the ending .f.  ;; have the ending .f90 or .f95 while fixed format files have the ending .f.
70  ;; Emacs automatically loads Fortran files in the appropriate mode based  ;; Emacs automatically loads Fortran files in the appropriate mode based
71  ;; on extension. You can modify this by adjusting the variable auto-mode-alist.  ;; on extension. You can modify this by adjusting the variable auto-mode-alist.
# Line 150  Line 150 
150  ;; Also thanks to the authors of the fortran and pascal modes, on which some  ;; Also thanks to the authors of the fortran and pascal modes, on which some
151  ;; of this code is built.  ;; of this code is built.
152    
153    ;;; Code:
154    
155  ;; TODO  ;; TODO
156  ;; Support for hideshow, align.  ;; Support for hideshow, align.
157  ;; OpenMP, preprocessor highlighting.  ;; OpenMP, preprocessor highlighting.
158    
 ;;; Code:  
   
159  (defvar comment-auto-fill-only-comments)  (defvar comment-auto-fill-only-comments)
160  (defvar font-lock-keywords)  (defvar font-lock-keywords)
161    
162  ;; User options  ;; User options
163    
164  (defgroup f90 nil  (defgroup f90 nil
165    "Major mode for editing Fortran 90,95 code."    "Major mode for editing free format Fortran 90,95 code."
166    :group 'languages)    :group 'languages)
167    
168  (defgroup f90-indent nil  (defgroup f90-indent nil
169    "Indentation in free-format Fortran."    "Indentation in free format Fortran."
170    :prefix "f90-"    :prefix "f90-"
171    :group 'f90)    :group  'f90)
172    
173    
174  (defcustom f90-do-indent 3  (defcustom f90-do-indent 3
175    "*Extra indentation applied to DO blocks."    "*Extra indentation applied to DO blocks."
176    :type 'integer    :type  'integer
177    :group 'f90-indent)    :group 'f90-indent)
178    
179  (defcustom f90-if-indent 3  (defcustom f90-if-indent 3
180    "*Extra indentation applied to IF, SELECT CASE, WHERE and FORALL blocks."    "*Extra indentation applied to IF, SELECT CASE, WHERE and FORALL blocks."
181    :type 'integer    :type  'integer
182    :group 'f90-indent)    :group 'f90-indent)
183    
184  (defcustom f90-type-indent 3  (defcustom f90-type-indent 3
185    "*Extra indentation applied to TYPE, INTERFACE and BLOCK DATA blocks."    "*Extra indentation applied to TYPE, INTERFACE and BLOCK DATA blocks."
186    :type 'integer    :type  'integer
187    :group 'f90-indent)    :group 'f90-indent)
188    
189  (defcustom f90-program-indent 2  (defcustom f90-program-indent 2
190    "*Extra indentation applied to PROGRAM/MODULE/SUBROUTINE/FUNCTION blocks."    "*Extra indentation applied to PROGRAM, MODULE, SUBROUTINE, FUNCTION blocks."
191    :type 'integer    :type  'integer
192    :group 'f90-indent)    :group 'f90-indent)
193    
194  (defcustom f90-continuation-indent 5  (defcustom f90-continuation-indent 5
195    "*Extra indentation applied to F90 continuation lines."    "*Extra indentation applied to continuation lines."
196    :type 'integer    :type  'integer
197    :group 'f90-indent)    :group 'f90-indent)
198    
199  (defcustom f90-comment-region "!!$"  (defcustom f90-comment-region "!!$"
200    "*String inserted by \\[f90-comment-region] at start of each line in region."    "*String inserted by \\[f90-comment-region] at start of each line in region."
201    :type 'string    :type  'string
202    :group 'f90-indent)    :group 'f90-indent)
203    
204  (defcustom f90-indented-comment-re "!"  (defcustom f90-indented-comment-re "!"
205    "*Regexp saying which comments to indent like code."    "*Regexp matching comments to indent as code."
206    :type 'regexp    :type  'regexp
207    :group 'f90-indent)    :group 'f90-indent)
208    
209  (defcustom f90-directive-comment-re "!hpf\\$"  (defcustom f90-directive-comment-re "!hpf\\$"
210    "*Regexp of comment-like directive like \"!HPF\\\\$\", not to be indented."    "*Regexp of comment-like directive like \"!HPF\\\\$\", not to be indented."
211    :type 'regexp    :type  'regexp
212    :group 'f90-indent)    :group 'f90-indent)
213    
214  (defcustom f90-beginning-ampersand t  (defcustom f90-beginning-ampersand t
215    "*Non-nil gives automatic insertion of \& at start of continuation line."    "*Non-nil gives automatic insertion of \& at start of continuation line."
216    :type 'boolean    :type  'boolean
217    :group 'f90)    :group 'f90)
218    
219  (defcustom f90-smart-end 'blink  (defcustom f90-smart-end 'blink
220    "*From an END statement, check and fill the end using matching block start.    "*From an END statement, check and fill the end using matching block start.
221  Allowed values are 'blink, 'no-blink, and nil, which determine  Allowed values are 'blink, 'no-blink, and nil, which determine
222  whether to blink the matching beginning."  whether to blink the matching beginning."
223    :type '(choice (const blink) (const no-blink) (const nil))    :type  '(choice (const blink) (const no-blink) (const nil))
224    :group 'f90)    :group 'f90)
225    
226  (defcustom f90-break-delimiters "[-+\\*/><=,% \t]"  (defcustom f90-break-delimiters "[-+\\*/><=,% \t]"
227    "*Regexp holding list of delimiters at which lines may be broken."    "*Regexp holding list of delimiters at which lines may be broken."
228    :type 'regexp    :type  'regexp
229    :group 'f90)    :group 'f90)
230    
231  (defcustom f90-break-before-delimiters t  (defcustom f90-break-before-delimiters t
232    "*Non-nil causes `f90-do-auto-fill' to break lines before delimiters."    "*Non-nil causes `f90-do-auto-fill' to break lines before delimiters."
233    :type 'boolean    :type  'boolean
234    :group 'f90)    :group 'f90)
235    
236  (defcustom f90-auto-keyword-case nil  (defcustom f90-auto-keyword-case nil
237    "*Automatic case conversion of keywords.    "*Automatic case conversion of keywords.
238  The options are 'downcase-word, 'upcase-word, 'capitalize-word and nil."  The options are 'downcase-word, 'upcase-word, 'capitalize-word and nil."
239    :type '(choice (const downcase-word) (const upcase-word)    :type  '(choice (const downcase-word) (const upcase-word)
240                   (const capitalize-word) (const nil))                    (const capitalize-word) (const nil))
241    :group 'f90)    :group 'f90)
242    
243  (defcustom f90-leave-line-no nil  (defcustom f90-leave-line-no nil
244    "*If non-nil, line numbers are not left justified."    "*If non-nil, line numbers are not left justified."
245    :type 'boolean    :type  'boolean
246    :group 'f90)    :group 'f90)
247    
248  (defcustom f90-mode-hook nil  (defcustom f90-mode-hook nil
249    "Hook run when entering F90 mode."    "Hook run when entering F90 mode."
250    :type 'hook    :type    'hook
251    :options '(f90-add-imenu-menu)    :options '(f90-add-imenu-menu)
252    :group 'f90)    :group   'f90)
253    
254  ;; User options end here.  ;; User options end here.
255    
# Line 455  Can be overridden by the value of `font- Line 455  Can be overridden by the value of `font-
455      (define-key map "-"        'f90-electric-insert)      (define-key map "-"        'f90-electric-insert)
456      (define-key map "*"        'f90-electric-insert)      (define-key map "*"        'f90-electric-insert)
457      (define-key map "/"        'f90-electric-insert)      (define-key map "/"        'f90-electric-insert)
458    
459        (easy-menu-define f90-menu map "Menu for F90 mode."
460          `("F90"
461            ("Customization"
462             ,(custom-menu-create 'f90)
463             ["Set"  Custom-set t]
464             ["Save" Custom-save t]
465             ["Reset to Current" Custom-reset-current t]
466             ["Reset to Saved"   Custom-reset-saved t]
467             ["Reset to Standard Settings" Custom-reset-standard t]
468             )
469            "--"
470            ["Indent Subprogram"       f90-indent-subprogram       t]
471            ["Mark Subprogram"         f90-mark-subprogram         t]
472            ["Beginning of Subprogram" f90-beginning-of-subprogram t]
473            ["End of Subprogram"       f90-end-of-subprogram       t]
474            "--"
475            ["(Un)Comment Region" f90-comment-region mark-active]
476            ["Indent Region"      f90-indent-region  mark-active]
477            ["Fill Region"        f90-fill-region    mark-active]
478            "--"
479            ["Break Line at Point"     f90-break-line t]
480            ["Join with Previous Line" f90-join-lines t]
481            ["Insert Block End"        f90-insert-end t]
482            "--"
483            ("Highlighting"
484             ["Toggle font-lock-mode" font-lock-mode :selected font-lock-mode
485              :style toggle]
486             "--"
487             ["Light highlighting (level 1)"    f90-font-lock-1 t]
488             ["Moderate highlighting (level 2)" f90-font-lock-2 t]
489             ["Heavy highlighting (level 3)"    f90-font-lock-3 t]
490             ["Maximum highlighting (level 4)"  f90-font-lock-4 t]
491             )
492            ("Change Keyword Case"
493             ["Upcase Keywords (buffer)"     f90-upcase-keywords     t]
494             ["Capitalize Keywords (buffer)" f90-capitalize-keywords t]
495             ["Downcase Keywords (buffer)"   f90-downcase-keywords   t]
496             "--"
497             ["Upcase Keywords (region)"     f90-upcase-region-keywords
498              mark-active]
499             ["Capitalize Keywords (region)" f90-capitalize-region-keywords
500              mark-active]
501             ["Downcase Keywords (region)"   f90-downcase-region-keywords
502              mark-active]
503             )
504            "--"
505            ["Toggle auto-fill"   auto-fill-mode :selected auto-fill-function
506             :style toggle]
507            ["Toggle abbrev-mode" abbrev-mode    :selected abbrev-mode
508             :style toggle]
509            ["Add imenu Menu" f90-add-imenu-menu
510             :active   (not (lookup-key (current-local-map) [menu-bar index]))
511             :included (fboundp 'imenu-add-to-menubar)]))
512      map)      map)
513    "Keymap used in F90 mode.")    "Keymap used in F90 mode.")
514    
515    
 (easy-menu-define f90-menu f90-mode-map "Menu for F90 mode."  
   '("F90"  
     ["Indent Subprogram"       f90-indent-subprogram       t]  
     ["Mark Subprogram"         f90-mark-subprogram         t]  
     ["Beginning of Subprogram" f90-beginning-of-subprogram t]  
     ["End of Subprogram"       f90-end-of-subprogram       t]  
     "--"  
     ["(Un)Comment Region" f90-comment-region mark-active]  
     ["Indent Region"      f90-indent-region  mark-active]  
     ["Fill Region"        f90-fill-region    mark-active]  
     "--"  
     ["Break Line at Point"     f90-break-line t]  
     ["Join with Previous Line" f90-join-lines t]  
     ["Insert Block End"        f90-insert-end t]  
     "--"  
     ("Highlighting"  
      ["Toggle font-lock-mode" font-lock-mode :selected font-lock-mode  
       :style toggle]  
      "--"  
      ["Light highlighting (level 1)"    f90-font-lock-1 t]  
      ["Moderate highlighting (level 2)" f90-font-lock-2 t]  
      ["Heavy highlighting (level 3)"    f90-font-lock-3 t]  
      ["Maximum highlighting (level 4)"  f90-font-lock-4 t]  
      )  
     ("Change Keyword Case"  
      ["Upcase Keywords (buffer)"     f90-upcase-keywords     t]  
      ["Capitalize Keywords (buffer)" f90-capitalize-keywords t]  
      ["Downcase Keywords (buffer)"   f90-downcase-keywords   t]  
      "--"  
      ["Upcase Keywords (region)"     f90-upcase-region-keywords mark-active]  
      ["Capitalize Keywords (region)" f90-capitalize-region-keywords  
       mark-active]  
      ["Downcase Keywords (region)"   f90-downcase-region-keywords mark-active]  
      )  
     "--"  
     ["Toggle auto-fill"   auto-fill-mode :selected auto-fill-function  
      :style toggle]  
     ["Toggle abbrev-mode" abbrev-mode    :selected abbrev-mode :style toggle]  
     ["Add imenu Menu" f90-add-imenu-menu  
      :active (not (lookup-key (current-local-map) [menu-bar index]))  
      :included (fboundp 'imenu-add-to-menubar)]  
     ))  
   
516  (defun f90-font-lock-1 ()  (defun f90-font-lock-1 ()
517    "Set `font-lock-keywords' to `f90-font-lock-keywords-1'."    "Set `font-lock-keywords' to `f90-font-lock-keywords-1'."
518    (interactive)    (interactive)
# Line 595  Can be overridden by the value of `font- Line 606  Can be overridden by the value of `font-
606         "\\)"         "\\)"
607         "[ \t]*\\(function\\|subroutine\\)[ \t]+\\(\\sw+\\)")         "[ \t]*\\(function\\|subroutine\\)[ \t]+\\(\\sw+\\)")
608        4)))        4)))
609    "Generic imenu expression for F90 mode.")    "Value for `imenu-generic-expression' in F90 mode.")
610    
611  (defun f90-add-imenu-menu ()  (defun f90-add-imenu-menu ()
612    "Add an imenu menu to the menubar."    "Add an imenu menu to the menubar."
# Line 680  Can be overridden by the value of `font- Line 691  Can be overridden by the value of `font-
691  ;;;###autoload  ;;;###autoload
692  (defun f90-mode ()  (defun f90-mode ()
693    "Major mode for editing Fortran 90,95 code in free format.    "Major mode for editing Fortran 90,95 code in free format.
694    For fixed format code, use `fortran-mode'.
695    
696    \\[f90-indent-line] indents the current line.
697  \\[f90-indent-new-line] indents current line and creates a new\  \\[f90-indent-new-line] indents current line and creates a new\
698   indented line.   indented line.
 \\[f90-indent-line] indents the current line.  
699  \\[f90-indent-subprogram] indents the current subprogram.  \\[f90-indent-subprogram] indents the current subprogram.
700    
701  Type `? or `\\[help-command] to display a list of built-in\  Type `? or `\\[help-command] to display a list of built-in\
# Line 752  with no args, if that value is non-nil." Line 764  with no args, if that value is non-nil."
764    (set (make-local-variable 'abbrev-all-caps) t)    (set (make-local-variable 'abbrev-all-caps) t)
765    (set (make-local-variable 'normal-auto-fill-function) 'f90-do-auto-fill)    (set (make-local-variable 'normal-auto-fill-function) 'f90-do-auto-fill)
766    (setq indent-tabs-mode nil)           ; auto buffer local    (setq indent-tabs-mode nil)           ; auto buffer local
   (easy-menu-add f90-menu)  
   ;; Setting up things for font-lock.  
767    (set (make-local-variable 'font-lock-defaults)    (set (make-local-variable 'font-lock-defaults)
768         '((f90-font-lock-keywords f90-font-lock-keywords-1         '((f90-font-lock-keywords f90-font-lock-keywords-1
769                                   f90-font-lock-keywords-2                                   f90-font-lock-keywords-2
# Line 763  with no args, if that value is non-nil." Line 773  with no args, if that value is non-nil."
773    ;; Tell imenu how to handle f90.    ;; Tell imenu how to handle f90.
774    (set (make-local-variable 'imenu-case-fold-search) t)    (set (make-local-variable 'imenu-case-fold-search) t)
775    (set (make-local-variable 'imenu-generic-expression)    (set (make-local-variable 'imenu-generic-expression)
776          f90-imenu-generic-expression)         f90-imenu-generic-expression)
777      (set (make-local-variable 'beginning-of-defun-function)
778           'f90-beginning-of-subprogram)
779      (set (make-local-variable 'end-of-defun-function) 'f90-end-of-subprogram)
780    (set (make-local-variable 'add-log-current-defun-function)    (set (make-local-variable 'add-log-current-defun-function)
781         #'f90-current-defun)         #'f90-current-defun)
782    (run-hooks 'f90-mode-hook))    (run-hooks 'f90-mode-hook))
# Line 1282  A block is a subroutine, if-endif, etc." Line 1295  A block is a subroutine, if-endif, etc."
1295    
1296    
1297  (defun f90-mark-subprogram ()  (defun f90-mark-subprogram ()
1298    "Put mark at end of F90 subprogram, point at beginning, push marks."    "Put mark at end of F90 subprogram, point at beginning, push mark."
1299    (interactive)    (interactive)
1300    (let ((pos (point)) program)    (let ((pos (point)) program)
1301      (f90-end-of-subprogram)      (f90-end-of-subprogram)
# Line 1318  in the region, or, if already present, r Line 1331  in the region, or, if already present, r
1331    "Indent current line as F90 code.    "Indent current line as F90 code.
1332  Unless optional argument NO-UPDATE is non-nil, call `f90-update-line'  Unless optional argument NO-UPDATE is non-nil, call `f90-update-line'
1333  after indenting."  after indenting."
1334    (interactive)    (interactive "*P")
1335    (let (indent no-line-number (pos (make-marker)) (case-fold-search t))    (let (indent no-line-number (pos (make-marker)) (case-fold-search t))
1336      (set-marker pos (point))      (set-marker pos (point))
1337      (beginning-of-line)                ; digits after & \n are not line-nos      (beginning-of-line)                ; digits after & \n are not line-nos
# Line 1342  after indenting." Line 1355  after indenting."
1355      (set-marker pos nil)))      (set-marker pos nil)))
1356    
1357  (defun f90-indent-new-line ()  (defun f90-indent-new-line ()
1358    "Reindent current line, insert a newline and indent the newline.    "Re-indent current line, insert a newline and indent the newline.
1359  An abbrev before point is expanded if the variable `abbrev-mode' is non-nil.  An abbrev before point is expanded if the variable `abbrev-mode' is non-nil.
1360  If run in the middle of a line, the line is not broken."  If run in the middle of a line, the line is not broken."
1361    (interactive)    (interactive "*")
1362    (let (string cont (case-fold-search t))    (let (string cont (case-fold-search t))
1363      (if abbrev-mode (expand-abbrev))      (if abbrev-mode (expand-abbrev))
1364      (beginning-of-line)                ; reindent where likely to be needed      (beginning-of-line)                ; reindent where likely to be needed
# Line 1473  If run in the middle of a line, the line Line 1486  If run in the middle of a line, the line
1486    
1487  (defun f90-indent-subprogram ()  (defun f90-indent-subprogram ()
1488    "Properly indent the subprogram containing point."    "Properly indent the subprogram containing point."
1489    (interactive)    (interactive "*")
1490    (save-excursion    (save-excursion
1491      (let ((program (f90-mark-subprogram)))      (let ((program (f90-mark-subprogram)))
1492        (if program        (if program
# Line 1491  If run in the middle of a line, the line Line 1504  If run in the middle of a line, the line
1504    "Break line at point, insert continuation marker(s) and indent.    "Break line at point, insert continuation marker(s) and indent.
1505  Unless in a string or comment, or if the optional argument NO-UPDATE  Unless in a string or comment, or if the optional argument NO-UPDATE
1506  is non-nil, call `f90-update-line' after inserting the continuation marker."  is non-nil, call `f90-update-line' after inserting the continuation marker."
1507    (interactive)    (interactive "*P")
1508    (cond ((f90-in-string)    (cond ((f90-in-string)
1509           (insert "&\n&"))           (insert "&\n&"))
1510          ((f90-in-comment)          ((f90-in-comment)
# Line 1517  is non-nil, call `f90-update-line' after Line 1530  is non-nil, call `f90-update-line' after
1530  (defun f90-do-auto-fill ()  (defun f90-do-auto-fill ()
1531    "Break line if non-white characters beyond `fill-column'.    "Break line if non-white characters beyond `fill-column'.
1532  Update keyword case first."  Update keyword case first."
1533    (interactive)    (interactive "*")
1534    ;; Break line before or after last delimiter (non-word char) if    ;; Break line before or after last delimiter (non-word char) if
1535    ;; position is beyond fill-column.    ;; position is beyond fill-column.
1536    ;; Will not break **, //, or => (as specified by f90-no-break-re).    ;; Will not break **, //, or => (as specified by f90-no-break-re).
# Line 1536  Update keyword case first." Line 1549  Update keyword case first."
1549    
1550  (defun f90-join-lines (&optional arg)  (defun f90-join-lines (&optional arg)
1551    "Join current line to previous, fix whitespace, continuation, comments.    "Join current line to previous, fix whitespace, continuation, comments.
1552  With an argument, join current line to following line.  With optional argument ARG, join current line to following line.
1553  Like `join-line', but handles F90 syntax."  Like `join-line', but handles F90 syntax."
1554    (interactive "*P")    (interactive "*P")
1555    (beginning-of-line)    (beginning-of-line)
# Line 1564  Like `join-line', but handles F90 syntax Line 1577  Like `join-line', but handles F90 syntax
1577      (goto-char beg-region)      (goto-char beg-region)
1578      (while go-on      (while go-on
1579        ;; Join as much as possible.        ;; Join as much as possible.
1580        (while (progn        (while (progn
1581                 (end-of-line)                 (end-of-line)
1582                 (skip-chars-backward " \t")                 (skip-chars-backward " \t")
1583                 (eq (preceding-char) ?&))                 (eq (preceding-char) ?&))
# Line 1662  Leave point at the end of line." Line 1675  Leave point at the end of line."
1675    
1676  (defun f90-insert-end ()  (defun f90-insert-end ()
1677    "Insert a complete end statement matching beginning of present block."    "Insert a complete end statement matching beginning of present block."
1678    (interactive)    (interactive "*")
1679    (let ((f90-smart-end (or f90-smart-end 'blink)))    (let ((f90-smart-end (or f90-smart-end 'blink)))
1680      (insert "end")      (insert "end")
1681      (f90-indent-new-line)))      (f90-indent-new-line)))
# Line 1703  Any other key combination is executed no Line 1716  Any other key combination is executed no
1716    
1717  (defun f90-upcase-keywords ()  (defun f90-upcase-keywords ()
1718    "Upcase all F90 keywords in the buffer."    "Upcase all F90 keywords in the buffer."
1719    (interactive)    (interactive "*")
1720    (f90-change-keywords 'upcase-word))    (f90-change-keywords 'upcase-word))
1721    
1722  (defun f90-capitalize-keywords ()  (defun f90-capitalize-keywords ()
1723    "Capitalize all F90 keywords in the buffer."    "Capitalize all F90 keywords in the buffer."
1724    (interactive)    (interactive "*")
1725    (f90-change-keywords 'capitalize-word))    (f90-change-keywords 'capitalize-word))
1726    
1727  (defun f90-downcase-keywords ()  (defun f90-downcase-keywords ()
1728    "Downcase all F90 keywords in the buffer."    "Downcase all F90 keywords in the buffer."
1729    (interactive)    (interactive "*")
1730    (f90-change-keywords 'downcase-word))    (f90-change-keywords 'downcase-word))
1731    
1732  (defun f90-upcase-region-keywords (beg end)  (defun f90-upcase-region-keywords (beg end)

Legend:
Removed from v.1.67  
changed lines
  Added in v.1.68

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26