1

Strange issue here with getting indentexpr=FortranGetFreeIndent() to be set correctly.

The first time I open a file (free form, of course), say new.f90, :set gives

:set
--- Options ---
  autoindent          filetype=fortran    incsearch           smartcase
  autowrite           helplang=en         mouse=a             syntax=fortran
  background=dark     hidden              ruler               textwidth=72
  backup              history=500         shiftwidth=3        ttyfast
  comments=:!,:*,:C   hlsearch            showcmd             ttymouse=xterm2
  commentstring=!%s   ignorecase          showmatch
  backspace=indent,eol,start
  fileencodings=ucs-bom,utf-8,default,latin1
  formatoptions=tcql
  include=^\c#\=\s*include\s\+
  indentexpr=FortranGetFixedIndent()
  indentkeys=0{,0},:,0#,!^F,o,O,e,=~end,=~case,=~if,=~else,=~do,=~where,=~elsewh
ere,=~select,=~endif,=~enddo,=~endwhere,=~endselect,=~elseif,=~type,=~interface,
=~forall,=~associate,=~block,=~enum,=~endforall,=~endassociate,=~endblock,=~ende
num
  printoptions=paper:letter
  runtimepath=~/.vim,/var/lib/vim/addons,/usr/share/vim/vimfiles,/usr/share/vim/
vim73,/usr/share/vim/vimfiles/after,/var/lib/vim/addons/after,~/.vim/after
  suffixes=.bak,~,.swp,.o,.info,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.ilg
,.inx,.out,.toc
  suffixesadd=.f95,.f90,.for,.f,.F,.f77,.ftn,.fpp
Press ENTER or type command to continue

Now, if I manually :set indentexpr=FortranGetFreeIndent() and then write some code

program testfree
   print *,"Test free format"
end program testfree

then the next time I open the file, :set indentexpr gives indentexpr=FortranGetFreeIndent.

So it appears that "signs are detected in the first five columns of the first 25 lines" (comment quoted from 'fortran.vim') but that the file extension isn't being recognized as .f90 implying free form.

Thanks for your help.

jnovack
  • 1,486
MarkWayne
  • 111

1 Answers1

0

Do this (or that portion of it that you need):

cd
mkdir .vim
cd .vim
mkdir ftplugin
cd ftplugin
vi fortran.vim

Then, in fortran.vim:

let s:extfname = expand("%:e")
if s:extfname ==? "f90"
   let fortran_free_source=1
   unlet! fortran_fixed_source
else
   let fortran_fixed_source=1
   unlet! fortran_free_source
endif

Works -- every time.

MarkWayne
  • 111