Fixed Format FORTRAN Highlighting
-
Is there a way to turn off column-based highlighting in F77 files? Or have N++ interpret an initial ‘tab’ the same way Visual Studio / Intel Fortran does? (i.e., an initial tab puts you in “column 7” regardless of your tab settings - for the purpose of highlighting anyway).
Most of my .for files are actually fixed format and tab-spaced. In N++ this means I can use free-format to properly highlight keywords, but not comments, or I can use fixed-format to properly highlight comments, but not keywords after an initial tab.
Any way to fix either (or both) modes?
-
I’m not familiar with Fortran, so I may have missed something obvious.
But the copied example from https://ourcodingclub.github.io/tutorials/fortran-intro/ seems to work for me.The left side is the fixed version and the right side is the free formatted version.
Regarding the tab and column 7, do you mean that a tab should be replaced by 6 spaces to insert the next input in column 7? If so, you can override the default behavior in the settings.
-
@Ekopalypse I guess the real problem is VisualStudio allows for a number of ‘non-standard’ things when it comes to F77, but that is the format I have become accustomed to and am trying to replicate. To do this involves (ideally):
- not replacing my tabs with spaces
- recognising comment lines by the ‘C’ in column one
- recognising inline comments as everything after ‘!’
- allowing the first tab character to move the highlighting along past column 6
- an option to switch between 80 and 132 character line lengths
In N++ at present with fixed format you get this:
You see the comments are correctly coloured, but you get the continuation column (column 6) highlighting and the initial keywords aren’t recognised / coloured.In free format you get this:
Now the keywords are highlighted, but the ‘C’ comments aren’t. It’s not shown here, but you also find that any keywords in the comments are highlighted as keywords which makes visual parsing much trickier.I think this would require some pretty specific tweaks to the syntax parser, so I wouldn’t be surprised if it’s not possible, but you never know…
-
That’s strange, yes, ! is recognized as a comment start in Freeform, but C is not. As for line 8, does Fortran have block comments? My recollection is that this is not the case.
And yes, these are topics for the lexer and this is provided by Scintilla and only if it would be updated there, Npp makes these changes.
One way to make the C comments more colorful today would be to use the EnhanceAnyLexer plugin, which you can install via PluginAdmin. Caveat: I am the author. -
I was thinking that maybe one or both of the FORTRAN lexers might have some options (“properties”) to allow changing how they interpret things… but using the current version of the script I originally published a couple years ago that lists all the advertised properties for a given lexer, I see that neither the FORTRAN (free form) nor the FORTRAN_77 (fixed form) have any properties.
In that case, my recommendation to @Daniel-Crosby , since freeform seems to match the desires except regarding comments, would be to use freeform for the lexer, and then EnhanceAnyLexer¹ to add a color for
^C.*
(for the C-at-beginning comments)[fortran free form] ; color each word, 0xBBGGRR (blue, green, and red: windows is backwards from RGB normal order) 0x33FF00 = ^C.* ; check in the respective styler xml if the following IDs are valid excluded_styles = 1,2,3,4,5,8,9,10,11,12,13,14,15,16,20,21,22,23 ; we need C---- to be an operator, but ; the C is lexed as an IDENTIFIER (7) ; and - as an OPERATOR (6), ; so need to _not_ have 6 and 7 in excluded_styles
If we had been given text to copy/paste in a code block, we could have tested for the “you also find that any keywords in the comments are highlighted as keywords” statement, but without it, all I can say is that maybe styles INSTRUCTION WORD (8), FUNCTION1 (9), and/or FUNCTION2 (10) need to be removed from
excluded_styles
as well.—
¹: Caveat: though I am not the author, I am “just” a satisfied user of that plugin, so take my recommendation for what you think it’s worth. ;-) -
@PeterJones Thanks, it looks like EnhanceAnyLexer with free-form is pretty close to what I want. Is there a way to remove styles from comments? I mean, I’ve added ‘bold’ for keywords, now keywords in comments are the correct colour, but emboldened? (I could just remove the bold for the keywords, but its helpful on a hires monitor!)
-
EnhanceAnyLexer does not change bold/italic/underline, so it cannot do the job. If you change the Style Configurator for the keywords to turn off bold, then the EnhanceAnyLexer color-change should be sufficient for you – though of course, that means that keywords in non-comment lines would just be colorful without any bolding.