robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
2f5b8a0092
master
1" Vim settings file 2" Language: Fortran 2023 (and Fortran 2018, 2008, 2003, 95, 90, 77, 66) 3" Version: (v55) 2023 December 22 4" Maintainers: Ajit J. Thakkar <ajit@unb.ca>; <https://ajit.ext.unb.ca/> 5" Joshua Hollett <j.hollett@uwinnipeg.ca> 6" Usage: For instructions, do :help fortran-plugin from Vim 7" Credits: 8" Version 0.1 was created in September 2000 by Ajit Thakkar. 9" Since then, useful suggestions and contributions have been made, in order, by: 10" Stefano Zacchiroli, Hendrik Merx, Ben Fritz, David Barnett, Eisuke Kawashima, 11" Doug Kearns, and Fritz Reese. 12" Last Change: 2023 Dec 22 13" 2024 Jan 14 by Vim Project (browsefilter) 14" 2024 May 23 by Riley Bruins <ribru17@gmail.com> ('commentstring') 15 16" Only do these settings when not done yet for this buffer 17if exists ( "b:did_ftplugin" ) 18finish 19endif 20 21let s: cposet =& cpoptions 22set cpoptions & vim 23 24" Don't do other file type settings for this buffer 25let b: did_ftplugin = 1 26 27" Determine whether this is a fixed or free format source file 28" if this hasn't been done yet using the priority: 29" buffer-local value 30" > global value 31" > file extension as in Intel ifort, gcc (gfortran), NAG, Pathscale, and Cray compilers 32if ! exists ( "b:fortran_fixed_source" ) 33if exists ( "fortran_free_source" ) 34" User guarantees free source form 35let b: fortran_fixed_source = 0 36elseif exists ( "fortran_fixed_source" ) 37" User guarantees fixed source form 38let b: fortran_fixed_source = 1 39elseif expand ( "%:e" ) =~? '^f\%(90\|95\|03\|08\)$' 40" Free-form file extension defaults as in Intel ifort, gcc(gfortran), NAG, Pathscale, and Cray compilers 41let b: fortran_fixed_source = 0 42elseif expand ( "%:e" ) =~? '^\%(f\|f77\|for\)$' 43" Fixed-form file extension defaults 44let b: fortran_fixed_source = 1 45else 46" Modern fortran compilers still allow both fixed and free source form 47" Assume fixed source form unless signs of free source form 48" are detected in the first five columns of the first s:lmax lines. 49" Detection becomes more accurate and time-consuming if more lines 50" are checked. Increase the limit below if you keep lots of comments at 51" the very top of each file and you have a fast computer. 52let s: lmax = 500 53if ( s: lmax > line ( "$" ) ) 54let s: lmax = line ( "$" ) 55endif 56let b: fortran_fixed_source = 1 57let s: ln = 1 58while s: ln <= s: lmax 59let s: test = strpart ( getline ( s: ln ), 0 , 5 ) 60if s: test !~ '^[Cc*]' && s: test !~ '^ *[!#]' && s: test =~ '[^ 0-9\t]' && s: test !~ '^[ 0-9]*\t' 61let b: fortran_fixed_source = 0 62break 63endif 64let s: ln = s: ln + 1 65endwhile 66unlet ! s: lmax s: ln s: test 67endif 68endif 69 70" Set comments and textwidth according to source type 71if ( b: fortran_fixed_source == 1 ) 72setlocal comments = :!,:*,:C 73" Fixed format requires a textwidth of 72 for code, 74" but some vendor extensions allow longer lines 75if exists ( "fortran_extended_line_length" ) 76setlocal tw = 132 77else 78" The use of columns 73-80 for sequence numbers is obsolete 79" so almost all compilers allow a textwidth of 80 80setlocal tw = 80 81" If you need to add "&" on continued lines so that the code is 82" compatible with both free and fixed format, then you should do so 83" in column 81 and uncomment the next line 84" setlocal tw=81 85endif 86else 87setlocal comments = :! 88" Free format allows a textwidth of 132 89setlocal tw = 132 90endif 91 92" Set commentstring for foldmethod=marker 93setlocal cms = !\ %s 94 95" Tabs are not a good idea in Fortran so the default is to expand tabs 96if ! exists ( "fortran_have_tabs" ) 97setlocal expandtab 98endif 99 100" Set 'formatoptions' to break text lines 101setlocal fo += t 102 103setlocal include = ^\\c#\\=\\s*include\\s\\+ 104setlocal suffixesadd += .f08,.f03,.f95,.f90,.for,.f,.F,.f77,.ftn,.fpp 105 106" Define patterns for the matchit plugin 107if ! exists ( "b:match_words" ) 108let s: notend = '\%(\<end\s\+\)\@<!' 109let s: notselect = '\%(\<select\s\+\)\@<!' 110let s: notelse = '\%(\<end\s\+\|\<else\s\+\)\@<!' 111let s: notprocedure = '\%(\s\+procedure\>\)\@!' 112let s: nothash = '\%(^\s*#\s*\)\@<!' 113let b: match_ignorecase = 1 114let b: match_words = 115 \'(:),' . 116 \s: notend . '\<select\s\+type\>:' . s: notselect . '\<type\|class\>:\<end\s*select\>,' . 117 \s: notend . '\<select\s\+rank\>:' . s: notselect . '\<rank\>:\<end\s*select\>,' . 118 \s: notend . '\<select\>:' . s: notselect . '\<case\>:\<end\s*select\>,' . 119 \s: notelse . '\<if\s*(.\+)\s*then\>:' . 120 \s: nothash . '\<else\s*\%(if\s*(.\+)\s*then\)\=\>:' . s: nothash . '\<end\s*if\>,' . 121 \'do\s\+\(\d\+\):\%(^\s*\)\@<=\1\s,' . 122 \s: notend . '\<do\>:\<end\s*do\>,' . 123 \s: notelse . '\<where\>:\<elsewhere\>:\<end\s*where\>,' . 124 \s: notend . '\<type\s*[^(]:\<end\s*type\>,' . 125 \s: notend . '\<forall\>:\<end\s*forall\>,' . 126 \s: notend . '\<associate\>:\<end\s*associate\>,' . 127 \s: notend . '\<change\s\+team\>:\<end\s*team\>,' . 128 \s: notend . '\<critical\>:\<end\s*critical\>,' . 129 \s: notend . '\<block\>:\<end\s*block\>,' . 130 \s: notend . '\<enum\>:\<end\s*enum\>,' . 131 \s: notend . '\<interface\>:\<end\s*interface\>,' . 132 \s: notend . '\<subroutine\>:\<end\s*subroutine\>,' . 133 \s: notend . '\<function\>:\<end\s*function\>,' . 134 \s: notend . '\<module\>' . s: notprocedure . ':\<end\s*module\>,' . 135 \s: notend . '\<program\>:\<end\s*program\>,' . 136 \'\%(^\s*\)\@<=#\s*if\%(def\|ndef\)\=\>:\%(^\s*\)\@<=#\s*\%(elif\|else\)\>:\%(^\s*\)\@<=#\s*endif\>' 137endif 138 139" File filters for :browse e 140if ( has ( "gui_win32" ) || has ( "gui_gtk" )) && ! exists ( "b:browsefilter" ) 141let b: browsefilter = "Fortran Files (*.f, *.for, *.f77, *.f90, *.f95, *.f03, *.f08, *.fpp, *.ftn)\t*.f;*.for;*.f77;*.f90;*.f95;*.f03;*.f08;*.fpp;*.ftn\n" 142if has ( "win32" ) 143let b: browsefilter .= "All Files (*.*)\t*\n" 144else 145let b: browsefilter .= "All Files (*)\t*\n" 146endif 147endif 148 149let b: undo_ftplugin = "setl fo< com< tw< cms< et< inc< sua<" 150 \. "| unlet! b:match_ignorecase b:match_words b:browsefilter" 151 152let & cpoptions = s: cposet 153unlet s: cposet 154 155" vim:sw=2