• Login
Community
  • Login

Fixed Format FORTRAN Highlighting

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
7 Posts 3 Posters 981 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D
    Daniel Crosby
    last edited by May 18, 2023, 2:00 AM

    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?

    E 1 Reply Last reply May 18, 2023, 5:46 AM Reply Quote 0
    • E
      Ekopalypse @Daniel Crosby
      last edited by May 18, 2023, 5:46 AM

      @Daniel-Crosby

      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.

      2be86894-5048-49dc-b56c-acf35fb131c7-image.png

      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.

      8018417f-0e30-45cc-b1d3-6da3ff9993be-image.png

      D 1 Reply Last reply May 18, 2023, 9:30 PM Reply Quote 0
      • D
        Daniel Crosby @Ekopalypse
        last edited by May 18, 2023, 9:30 PM

        @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:
        For_Fixed.png
        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:
        For_Free.png
        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…

        E 1 Reply Last reply May 19, 2023, 6:47 AM Reply Quote 0
        • E
          Ekopalypse @Daniel Crosby
          last edited by May 19, 2023, 6:47 AM

          @Daniel-Crosby

          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.

          P 1 Reply Last reply May 19, 2023, 1:28 PM Reply Quote 1
          • P
            PeterJones @Ekopalypse
            last edited by PeterJones May 19, 2023, 1:30 PM May 19, 2023, 1:28 PM

            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. ;-)

            D 1 Reply Last reply May 21, 2023, 9:48 PM Reply Quote 2
            • D
              Daniel Crosby @PeterJones
              last edited by May 21, 2023, 9:48 PM

              @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!)

              P 1 Reply Last reply May 21, 2023, 10:23 PM Reply Quote 0
              • P
                PeterJones @Daniel Crosby
                last edited by May 21, 2023, 10:23 PM

                @Daniel-Crosby ,

                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.

                1 Reply Last reply Reply Quote 1
                1 out of 7
                • First post
                  1/7
                  Last post
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors