chrisbra / matchit

The matchit plugin from Vim
61 stars 9 forks source link

problems with pragma when matching keywords in Fortran #21

Closed aitzkora closed 4 years ago

aitzkora commented 4 years ago

Hi, I have a problem with matching fortran keywords when I used pragma compilation directives. If we mixing fortran and pagma compilation directive, matching is lost... for example, going on the first if an pressing '%'

program simple
   integer :: a,c

   read(*,*) a
   if (a==2 ) then
#if DEBUG
      print *,a
#endif
     c=a+2
   else 
#if DEBUG
      print *, a
#endif
      c = a -2
   end if
   print *,c
end program simple

makes the cursor go on the first '#endif'. Do you know how to correct that. Could I use a regexp to take that case into account. If you have any ideas... Bests regards marc

chrisbra commented 4 years ago

not sure I understand. Where is your cursor, when you hit %? And where would you like the cursor to be?

k-takata commented 4 years ago

I'm not familiar with fortran, but ftplugin/fortran.vim doesn't seem to define #if-#endif pair in b:match_words. Maybe you need to update b:match_words by yourself. (See :help b:match_words.)

aitzkora commented 4 years ago

@chrisbra : it would be nice that the cursor goes to the 'else' keywords. #if and #endif creates some interferences to navigate into control structures @k-takata : it was the sort of information I were looking for.... It hope defining b:match_words enrich the keywords not cancelling the previous definition

aitzkora commented 4 years ago

@k-takata : I tried let b:match_words = '\<#if>:\<#endif>,'. b:match_words on command line but it seems not to do the job. Have you a example for another langage, how to append some keywords ? And another question, where I can put these modifications not to modify the system configuration ? thanks by advance if you know the answers

chrisbra commented 4 years ago

So where was your cursor? Can you try the example from the b:match_words from the C ftplugin. It looks similar enough to give this a try. Also, are you sure, that matchit is actually run?

chrisbra commented 4 years ago

@aitzkora if we figure this out correctly, we can add those examples to the official vim fortran ftplugin.

aitzkora commented 4 years ago

@chrisba : yes the problem is clearly not matchit but fortran ftplugin. You can close this issue, i will post an issue on ftplugin fortran thanks

aitzkora commented 4 years ago

doing manually a

:let b:match_words = b:match_words .'^\s*#\s*if(\|def\|ndef\)\>:^\s*#\s*elif\>:^\s*#\s*else\>:^\s*#\s*endif\>'

in my fortran file window solve the problem

andymass commented 4 years ago

Match-up includes something similar for fortran

https://github.com/andymass/vim-matchup/blob/acf3fca1a0a644bbe3d1478d3be1861c73614d9b/after/ftplugin/fortran_matchup.vim#L17

aitzkora commented 4 years ago

thanks, I dit not know this package, I will give a try!