Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim settings file |
| 2 | " Language: Fortran90 (and Fortran95, Fortran77, F and elf90) |
Bram Moolenaar | b6b046b | 2011-12-30 13:11:27 +0100 | [diff] [blame] | 3 | " Version: 0.47 |
| 4 | " Last Change: 2011 December 28 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5 | " Maintainer: Ajit J. Thakkar <ajit@unb.ca>; <http://www.unb.ca/chem/ajit/> |
| 6 | " Usage: Do :help fortran-plugin from Vim |
Bram Moolenaar | 365bdf7 | 2010-07-24 20:57:44 +0200 | [diff] [blame] | 7 | " Credits: |
| 8 | " Useful suggestions were made by Stefano Zacchiroli and Hendrik Merx. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9 | |
| 10 | " Only do these settings when not done yet for this buffer |
| 11 | if exists("b:did_ftplugin") |
| 12 | finish |
| 13 | endif |
| 14 | |
Bram Moolenaar | b6b046b | 2011-12-30 13:11:27 +0100 | [diff] [blame] | 15 | let s:cposet=&cpoptions |
| 16 | set cpoptions&vim |
| 17 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 18 | " Don't do other file type settings for this buffer |
| 19 | let b:did_ftplugin = 1 |
| 20 | |
| 21 | " Determine whether this is a fixed or free format source file |
| 22 | " if this hasn't been done yet |
| 23 | if !exists("b:fortran_fixed_source") |
| 24 | if exists("fortran_free_source") |
| 25 | " User guarantees free source form |
| 26 | let b:fortran_fixed_source = 0 |
| 27 | elseif exists("fortran_fixed_source") |
| 28 | " User guarantees fixed source form |
| 29 | let b:fortran_fixed_source = 1 |
| 30 | else |
| 31 | " f90 and f95 allow both fixed and free source form |
| 32 | " assume fixed source form unless signs of free source form |
Bram Moolenaar | 365bdf7 | 2010-07-24 20:57:44 +0200 | [diff] [blame] | 33 | " are detected in the first five columns of the first s:lmax lines |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 34 | " Detection becomes more accurate and time-consuming if more lines |
| 35 | " are checked. Increase the limit below if you keep lots of comments at |
| 36 | " the very top of each file and you have a fast computer |
Bram Moolenaar | 365bdf7 | 2010-07-24 20:57:44 +0200 | [diff] [blame] | 37 | let s:lmax = 500 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 38 | if ( s:lmax > line("$") ) |
| 39 | let s:lmax = line("$") |
| 40 | endif |
| 41 | let b:fortran_fixed_source = 1 |
| 42 | let s:ln=1 |
| 43 | while s:ln <= s:lmax |
| 44 | let s:test = strpart(getline(s:ln),0,5) |
Bram Moolenaar | 365bdf7 | 2010-07-24 20:57:44 +0200 | [diff] [blame] | 45 | if s:test !~ '^[Cc*]' && s:test !~ '^ *[!#]' && s:test =~ '[^ 0-9\t]' && s:test !~ '^[ 0-9]*\t' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 46 | let b:fortran_fixed_source = 0 |
| 47 | break |
| 48 | endif |
| 49 | let s:ln = s:ln + 1 |
| 50 | endwhile |
Bram Moolenaar | 365bdf7 | 2010-07-24 20:57:44 +0200 | [diff] [blame] | 51 | unlet! s:lmax s:ln s:test |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 52 | endif |
| 53 | endif |
| 54 | |
| 55 | " Set comments and textwidth according to source type |
| 56 | if (b:fortran_fixed_source == 1) |
| 57 | setlocal comments=:!,:*,:C |
| 58 | " Fixed format requires a textwidth of 72 for code |
| 59 | setlocal tw=72 |
| 60 | " If you need to add "&" on continued lines so that the code is |
| 61 | " compatible with both free and fixed format, then you should do so |
| 62 | " in column 73 and uncomment the next line |
| 63 | " setlocal tw=73 |
| 64 | else |
| 65 | setlocal comments=:! |
| 66 | " Free format allows a textwidth of 132 for code but 80 is more usual |
| 67 | setlocal tw=80 |
| 68 | endif |
| 69 | |
| 70 | " Set commentstring for foldmethod=marker |
| 71 | setlocal cms=!%s |
| 72 | |
| 73 | " Tabs are not a good idea in Fortran so the default is to expand tabs |
| 74 | if !exists("fortran_have_tabs") |
| 75 | setlocal expandtab |
| 76 | endif |
| 77 | |
| 78 | " Set 'formatoptions' to break comment and text lines but allow long lines |
| 79 | setlocal fo+=tcql |
| 80 | |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 81 | setlocal include=^\\c#\\=\\s*include\\s\\+ |
| 82 | setlocal suffixesadd+=.f95,.f90,.for,.f,.F,.f77,.ftn,.fpp |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 83 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 84 | " Define patterns for the matchit plugin |
| 85 | if !exists("b:match_words") |
| 86 | let s:notend = '\%(\<end\s\+\)\@<!' |
| 87 | let s:notselect = '\%(\<select\s\+\)\@<!' |
| 88 | let s:notelse = '\%(\<end\s\+\|\<else\s\+\)\@<!' |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 89 | let s:notprocedure = '\%(\s\+procedure\>\)\@!' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 90 | let b:match_ignorecase = 1 |
| 91 | let b:match_words = |
| 92 | \ '\<select\s*case\>:' . s:notselect. '\<case\>:\<end\s*select\>,' . |
| 93 | \ s:notelse . '\<if\s*(.\+)\s*then\>:' . |
| 94 | \ '\<else\s*\%(if\s*(.\+)\s*then\)\=\>:\<end\s*if\>,'. |
| 95 | \ 'do\s\+\(\d\+\):\%(^\s*\)\@<=\1\s,'. |
| 96 | \ s:notend . '\<do\>:\<end\s*do\>,'. |
| 97 | \ s:notelse . '\<where\>:\<elsewhere\>:\<end\s*where\>,'. |
| 98 | \ s:notend . '\<type\s*[^(]:\<end\s*type\>,'. |
| 99 | \ s:notend . '\<interface\>:\<end\s*interface\>,'. |
| 100 | \ s:notend . '\<subroutine\>:\<end\s*subroutine\>,'. |
| 101 | \ s:notend . '\<function\>:\<end\s*function\>,'. |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 102 | \ s:notend . '\<module\>' . s:notprocedure . ':\<end\s*module\>,'. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 103 | \ s:notend . '\<program\>:\<end\s*program\>' |
| 104 | endif |
| 105 | |
| 106 | " File filters for :browse e |
| 107 | if has("gui_win32") && !exists("b:browsefilter") |
| 108 | let b:browsefilter = "Fortran Files (*.f;*.F;*.for;*.f77;*.f90;*.f95;*.fpp;*.ftn)\t*.f;*.F;*.for;*.f77;*.f90;*.f95;*.fpp;*.ftn\n" . |
| 109 | \ "All Files (*.*)\t*.*\n" |
| 110 | endif |
| 111 | |
| 112 | let b:undo_ftplugin = "setl fo< com< tw< cms< et< inc<" |
| 113 | \ . "| unlet! b:match_ignorecase b:match_words b:browsefilter" |
| 114 | |
| 115 | let &cpoptions=s:cposet |
| 116 | unlet s:cposet |
| 117 | |
| 118 | " vim:sw=2 |