| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | " Vim settings file | 
					
						
							| 
									
										
										
										
											2023-12-23 06:31:38 -04:00
										 |  |  | " Language:	Fortran 2023 (and Fortran 2018, 2008, 2003, 95, 90, 77, 66) | 
					
						
							|  |  |  | " Version:	(v55) 2023 December 22 | 
					
						
							| 
									
										
										
										
											2023-12-05 23:07:27 +01:00
										 |  |  | " Maintainers:	Ajit J. Thakkar <ajit@unb.ca>; <https://ajit.ext.unb.ca/> | 
					
						
							|  |  |  | " 	        Joshua Hollett <j.hollett@uwinnipeg.ca> | 
					
						
							| 
									
										
										
										
											2015-12-29 19:10:25 +01:00
										 |  |  | " Usage:	For instructions, do :help fortran-plugin from Vim | 
					
						
							| 
									
										
										
										
											2010-07-24 20:57:44 +02:00
										 |  |  | " Credits: | 
					
						
							| 
									
										
										
										
											2020-10-11 13:57:40 +02:00
										 |  |  | "  Version 0.1 was created in September 2000 by Ajit Thakkar. | 
					
						
							|  |  |  | "  Since then, useful suggestions and contributions have been made, in order, by: | 
					
						
							|  |  |  | "  Stefano Zacchiroli, Hendrik Merx, Ben Fritz, David Barnett, Eisuke Kawashima, | 
					
						
							| 
									
										
										
										
											2021-04-07 21:07:20 +02:00
										 |  |  | "  Doug Kearns, and Fritz Reese. | 
					
						
							| 
									
										
										
										
											2024-01-14 20:59:02 +01:00
										 |  |  | " Last Change:	2023 Dec 22 | 
					
						
							|  |  |  | "		2024 Jan 14 by Vim Project (browsefilter) | 
					
						
							| 
									
										
										
										
											2024-06-03 20:40:45 +02:00
										 |  |  | "		2024 May 23 by Riley Bruins <ribru17@gmail.com> ('commentstring') | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | " Only do these settings when not done yet for this buffer | 
					
						
							|  |  |  | if exists("b:did_ftplugin") | 
					
						
							|  |  |  |   finish | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-30 13:11:27 +01:00
										 |  |  | let s:cposet=&cpoptions | 
					
						
							|  |  |  | set cpoptions&vim | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | " Don't do other file type settings for this buffer | 
					
						
							|  |  |  | let b:did_ftplugin = 1 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | " Determine whether this is a fixed or free format source file | 
					
						
							| 
									
										
										
										
											2015-12-29 19:10:25 +01:00
										 |  |  | " if this hasn't been done yet using the priority: | 
					
						
							|  |  |  | " buffer-local value | 
					
						
							|  |  |  | " > global value | 
					
						
							|  |  |  | " > file extension as in Intel ifort, gcc (gfortran), NAG, Pathscale, and Cray compilers | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | if !exists("b:fortran_fixed_source") | 
					
						
							|  |  |  |   if exists("fortran_free_source") | 
					
						
							|  |  |  |     " User guarantees free source form | 
					
						
							|  |  |  |     let b:fortran_fixed_source = 0 | 
					
						
							|  |  |  |   elseif exists("fortran_fixed_source") | 
					
						
							|  |  |  |     " User guarantees fixed source form | 
					
						
							|  |  |  |     let b:fortran_fixed_source = 1 | 
					
						
							| 
									
										
										
										
											2020-04-20 19:52:53 +02:00
										 |  |  |   elseif expand("%:e") =~? '^f\%(90\|95\|03\|08\)$' | 
					
						
							| 
									
										
										
										
											2015-12-29 19:10:25 +01:00
										 |  |  |     " Free-form file extension defaults as in Intel ifort, gcc(gfortran), NAG, Pathscale, and Cray compilers | 
					
						
							|  |  |  |     let b:fortran_fixed_source = 0 | 
					
						
							| 
									
										
										
										
											2020-04-20 19:52:53 +02:00
										 |  |  |   elseif expand("%:e") =~? '^\%(f\|f77\|for\)$' | 
					
						
							| 
									
										
										
										
											2015-12-29 19:10:25 +01:00
										 |  |  |     " Fixed-form file extension defaults | 
					
						
							|  |  |  |     let b:fortran_fixed_source = 1 | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |   else | 
					
						
							| 
									
										
										
										
											2023-12-05 23:07:27 +01:00
										 |  |  |     " Modern fortran compilers still allow both fixed and free source form | 
					
						
							| 
									
										
										
										
											2015-12-29 19:10:25 +01:00
										 |  |  |     " Assume fixed source form unless signs of free source form | 
					
						
							|  |  |  |     " are detected in the first five columns of the first s:lmax lines. | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |     " Detection becomes more accurate and time-consuming if more lines | 
					
						
							|  |  |  |     " are checked. Increase the limit below if you keep lots of comments at | 
					
						
							| 
									
										
										
										
											2015-12-29 19:10:25 +01:00
										 |  |  |     " the very top of each file and you have a fast computer. | 
					
						
							| 
									
										
										
										
											2010-07-24 20:57:44 +02:00
										 |  |  |     let s:lmax = 500 | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |     if ( s:lmax > line("$") ) | 
					
						
							|  |  |  |       let s:lmax = line("$") | 
					
						
							|  |  |  |     endif | 
					
						
							|  |  |  |     let b:fortran_fixed_source = 1 | 
					
						
							|  |  |  |     let s:ln=1 | 
					
						
							|  |  |  |     while s:ln <= s:lmax | 
					
						
							|  |  |  |       let s:test = strpart(getline(s:ln),0,5) | 
					
						
							| 
									
										
										
										
											2010-07-24 20:57:44 +02:00
										 |  |  |       if s:test !~ '^[Cc*]' && s:test !~ '^ *[!#]' && s:test =~ '[^ 0-9\t]' && s:test !~ '^[ 0-9]*\t' | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 	let b:fortran_fixed_source = 0 | 
					
						
							|  |  |  | 	break | 
					
						
							|  |  |  |       endif | 
					
						
							|  |  |  |       let s:ln = s:ln + 1 | 
					
						
							|  |  |  |     endwhile | 
					
						
							| 
									
										
										
										
											2010-07-24 20:57:44 +02:00
										 |  |  |     unlet! s:lmax s:ln s:test | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |   endif | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | " Set comments and textwidth according to source type | 
					
						
							|  |  |  | if (b:fortran_fixed_source == 1) | 
					
						
							|  |  |  |   setlocal comments=:!,:*,:C | 
					
						
							| 
									
										
										
										
											2021-04-07 21:07:20 +02:00
										 |  |  |   " Fixed format requires a textwidth of 72 for code, | 
					
						
							|  |  |  |   " but some vendor extensions allow longer lines | 
					
						
							|  |  |  |   if exists("fortran_extended_line_length") | 
					
						
							|  |  |  |     setlocal tw=132 | 
					
						
							|  |  |  |   else | 
					
						
							| 
									
										
										
										
											2023-12-05 23:07:27 +01:00
										 |  |  |   " The use of columns 73-80 for sequence numbers is obsolete | 
					
						
							|  |  |  |   " so almost all compilers allow a textwidth of 80 | 
					
						
							|  |  |  |     setlocal tw=80 | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |   " If you need to add "&" on continued lines so that the code is | 
					
						
							|  |  |  |   " compatible with both free and fixed format, then you should do so | 
					
						
							| 
									
										
										
										
											2023-12-05 23:07:27 +01:00
										 |  |  |   " in column 81 and uncomment the next line | 
					
						
							|  |  |  |   " setlocal tw=81 | 
					
						
							| 
									
										
										
										
											2021-04-07 21:07:20 +02:00
										 |  |  |   endif | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | else | 
					
						
							|  |  |  |   setlocal comments=:! | 
					
						
							| 
									
										
										
										
											2013-10-06 14:22:40 +02:00
										 |  |  |   " Free format allows a textwidth of 132 | 
					
						
							|  |  |  |   setlocal tw=132 | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | " Set commentstring for foldmethod=marker | 
					
						
							| 
									
										
										
										
											2024-06-03 20:40:45 +02:00
										 |  |  | setlocal cms=!\ %s | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | " Tabs are not a good idea in Fortran so the default is to expand tabs | 
					
						
							|  |  |  | if !exists("fortran_have_tabs") | 
					
						
							|  |  |  |   setlocal expandtab | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-06 14:22:40 +02:00
										 |  |  | " Set 'formatoptions' to break text lines | 
					
						
							|  |  |  | setlocal fo+=t | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-05 20:41:53 +00:00
										 |  |  | setlocal include=^\\c#\\=\\s*include\\s\\+ | 
					
						
							| 
									
										
										
										
											2012-04-25 19:07:41 +02:00
										 |  |  | setlocal suffixesadd+=.f08,.f03,.f95,.f90,.for,.f,.F,.f77,.ftn,.fpp | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | " Define patterns for the matchit plugin | 
					
						
							|  |  |  | if !exists("b:match_words") | 
					
						
							|  |  |  |   let s:notend = '\%(\<end\s\+\)\@<!' | 
					
						
							|  |  |  |   let s:notselect = '\%(\<select\s\+\)\@<!' | 
					
						
							|  |  |  |   let s:notelse = '\%(\<end\s\+\|\<else\s\+\)\@<!' | 
					
						
							| 
									
										
										
										
											2006-04-05 20:41:53 +00:00
										 |  |  |   let s:notprocedure = '\%(\s\+procedure\>\)\@!' | 
					
						
							| 
									
										
										
										
											2022-06-03 21:59:47 +01:00
										 |  |  |   let s:nothash = '\%(^\s*#\s*\)\@<!' | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |   let b:match_ignorecase = 1 | 
					
						
							|  |  |  |   let b:match_words = | 
					
						
							| 
									
										
										
										
											2012-04-25 19:07:41 +02:00
										 |  |  |     \ '(:),' . | 
					
						
							| 
									
										
										
										
											2023-12-23 06:31:38 -04:00
										 |  |  |     \ s:notend .'\<select\s\+type\>:' . s:notselect. '\<type\|class\>:\<end\s*select\>,' . | 
					
						
							|  |  |  |     \ s:notend .'\<select\s\+rank\>:' . s:notselect. '\<rank\>:\<end\s*select\>,' . | 
					
						
							|  |  |  |     \ s:notend .'\<select\>:'         . s:notselect. '\<case\>:\<end\s*select\>,' . | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |     \ s:notelse . '\<if\s*(.\+)\s*then\>:' . | 
					
						
							| 
									
										
										
										
											2022-06-03 21:59:47 +01:00
										 |  |  |     \ s:nothash . '\<else\s*\%(if\s*(.\+)\s*then\)\=\>:' . s:nothash . '\<end\s*if\>,'. | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |     \ 'do\s\+\(\d\+\):\%(^\s*\)\@<=\1\s,'. | 
					
						
							|  |  |  |     \ s:notend . '\<do\>:\<end\s*do\>,'. | 
					
						
							|  |  |  |     \ s:notelse . '\<where\>:\<elsewhere\>:\<end\s*where\>,'. | 
					
						
							|  |  |  |     \ s:notend . '\<type\s*[^(]:\<end\s*type\>,'. | 
					
						
							| 
									
										
										
										
											2012-04-25 19:07:41 +02:00
										 |  |  |     \ s:notend . '\<forall\>:\<end\s*forall\>,'. | 
					
						
							|  |  |  |     \ s:notend . '\<associate\>:\<end\s*associate\>,'. | 
					
						
							| 
									
										
										
										
											2023-12-23 06:31:38 -04:00
										 |  |  |     \ s:notend . '\<change\s\+team\>:\<end\s*team\>,'. | 
					
						
							|  |  |  |     \ s:notend . '\<critical\>:\<end\s*critical\>,'. | 
					
						
							|  |  |  |     \ s:notend . '\<block\>:\<end\s*block\>,'. | 
					
						
							| 
									
										
										
										
											2012-04-25 19:07:41 +02:00
										 |  |  |     \ s:notend . '\<enum\>:\<end\s*enum\>,'. | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |     \ s:notend . '\<interface\>:\<end\s*interface\>,'. | 
					
						
							|  |  |  |     \ s:notend . '\<subroutine\>:\<end\s*subroutine\>,'. | 
					
						
							|  |  |  |     \ s:notend . '\<function\>:\<end\s*function\>,'. | 
					
						
							| 
									
										
										
										
											2006-04-05 20:41:53 +00:00
										 |  |  |     \ s:notend . '\<module\>' . s:notprocedure . ':\<end\s*module\>,'. | 
					
						
							| 
									
										
										
										
											2022-06-03 21:59:47 +01:00
										 |  |  |     \ s:notend . '\<program\>:\<end\s*program\>,'. | 
					
						
							|  |  |  |     \ '\%(^\s*\)\@<=#\s*if\%(def\|ndef\)\=\>:\%(^\s*\)\@<=#\s*\%(elif\|else\)\>:\%(^\s*\)\@<=#\s*endif\>' | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | " File filters for :browse e | 
					
						
							| 
									
										
										
										
											2020-10-11 13:57:40 +02:00
										 |  |  | if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter") | 
					
						
							| 
									
										
										
										
											2024-01-14 20:59:02 +01:00
										 |  |  |   let b:browsefilter = "Fortran Files (*.f, *.for, *.f77, *.f90, *.f95, *.f03, *.f08, *.fpp, *.ftn)\t*.f;*.for;*.f77;*.f90;*.f95;*.f03;*.f08;*.fpp;*.ftn\n" | 
					
						
							|  |  |  |   if has("win32") | 
					
						
							|  |  |  |     let b:browsefilter .= "All Files (*.*)\t*\n" | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     let b:browsefilter .= "All Files (*)\t*\n" | 
					
						
							|  |  |  |   endif | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-06 14:22:40 +02:00
										 |  |  | let b:undo_ftplugin = "setl fo< com< tw< cms< et< inc< sua<" | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 	\ . "| unlet! b:match_ignorecase b:match_words b:browsefilter" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | let &cpoptions=s:cposet | 
					
						
							|  |  |  | unlet s:cposet | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | " vim:sw=2 |