Fortran Syntax Highlighting User Defined
-
Is it possible to handle both “force at beginning of the line” and “allow anywhere” comment highlighting? I can’t seem to get Notepad++ to high both styles of commenting in FORTRAN but the code that I am using has both styles.
Style 1
C The beginning of the line in fortran.
x = y + 1 ! Or a comment following a standard lineI would like both of these comments in green but I have to choose one or the other or just use Visual Studio Code’s custom highlighting that handles both. Any help would be appreciated. Thanks
Notepad++ Version v7.3.3)
-
When I pick
Language > Fortran (free form)
, it only comments the!...
comment. But if I chooseLanguage > Fortran (fixed form)
, it highlights both theC
-line and the! ...
comments.According to
Settings > Style Configurator
, the languageFortran (free form)
has most of the file extensions associated with it, butFortran (fixed form)
is associated with the.f77
file extension.I just ran a quick experiment: if you add
for
to theUser ext. :
list of theFortran (fixed form)
, then when you load a.for
file, it will pick the fixed form rather than the default free-form for syntax highlighting.Hope this helps.
-
I’ve tried that but for some reason fixed form highlighting is not working for me. Not sure if its my VS2015-Dark Theme applied. Only the free-form is working but only provides the “!” as comments and not the C in the first character as the comments.
-
I don’t have the VS2015-Dark theme. But with manually overriding to “Language > Fortran (fixed form)”, when I go through any of the dozen themes that have found their way into my
%AppData%\Notepad++
theme list over the years, all of them highlight both types of comments the same. Originally, I was thinking that there was a problem with your theme… but after doing that loop, I realized that the “Fortran (fixed form)” lexer is what will set the style to COMMENT, and the theme just assigns specific colors/formatting to the COMMENT style.I’m going to step back to your comment “fixed form highlighting is not working for me”. Does that mean it doesn’t provide any highlighting, or just that it’s the same highlighting as “free form”?
For example, when I take a plain file
Style 1 C The beginning of the line in fortran. x = y + 1 ! Or a comment following a standard line <html> </html>
… and then manually change the Language from
Normal Text
toHTML
toFortran (free form)
toFortran (fixed form)
, I see the following (using the default styler):
(captured using ScreenToGif, which is free/open-source)You can see that the formatting changes each time. Similar transitions happens, but with different colors, if I switch to another theme.
You can also see the selected Language name change in the lower left-hand corner of the status bar, which is a way you can confirm that you are really changing languages when you think you do.
I believe the Fortran lexers are built into the SciLexer.dll. If your Fortran lexers behave differently than mine, maybe there’s a difference. I am using Notepad++ (pasting in
? > Debug Info
):Notepad++ v7.5.6 (32-bit) Build time : Mar 19 2018 - 00:26:59 Path : C:\Program Files (x86)\Notepad++\notepad++.exe Admin mode : OFF Local Conf mode : OFF OS : Windows 10 (64-bit) Plugins : ComparePlugin.dll dbgpPlugin.dll DSpellCheck.dll MarkdownViewerPlusPlus.dll mimeTools.dll NppConverter.dll NppExec.dll NppExport.dll NppFTP.dll PluginManager.dll PreviewHTML.dll PythonScript.dll XMLTools.dll
And per Windows Explorer >
c:\program files (x86)\notepad++\SciLexer.dll
, RightClick, Properties, Details, I see that my Scintilla Lexer isFile Version = 3.5.6.0
. I don’t think the version of Scintilla changed between your NPP 7.3.3 and my 7.5.6, but my memory is not perfect, and I haven’t gone back to study all the release notes between there.I get the same results when I run
notepad++.exe -noPlugin
->? > Debug Info
Notepad++ v7.5.6 (32-bit) Build time : Mar 19 2018 - 00:26:59 Path : C:\Program Files (x86)\Notepad++\notepad++.exe Admin mode : OFF Local Conf mode : OFF OS : Windows 10 (64-bit) Plugins : none
-
I also have the same version of SciLexer.dll 3.5.6.0. Thanks for all the information I’d show you screenshots but I’m confined within our secure work environment. I have also tried notepad++ on two other computers to see if it was any of my tweaks to notepad++ but all (3) installations of notepad yield the same result. When I stated “fixed form highlighting is not working for me”. What I mean is that it doesn’t provide any highlighting at all (zippo nota nothing). Yes I confirmed that it even states what highlighting is active which is Fortran fixed form from source file. Highlighting does in fact work for both fortran free form and user defined.
-
I tried one last thing: since you said you were on 7.3.3, I downloaded the minimalist 7.3.3 32-bit and ran it standalone: it still gave me the same results I showed in the screenshots.
Notepad++ v7.3.3 (32-bit) Build time : Mar 8 2017 - 03:37:37 Path : C:\usr\local\apps\npp32_733\notepad++.exe Admin mode : OFF Local Conf mode : ON OS : Windows 10 (64-bit) Plugins : none
I also tried 64-bit, since you didn’t mention which, but it also properly highlights the fixed-form comment.
Notepad++ v7.3.3 (64-bit) Build time : Mar 8 2017 - 03:39:58 Path : C:\usr\local\apps\npp64_733\notepad++.exe Admin mode : OFF Local Conf mode : ON OS : Windows 10 (64-bit) Plugins : none
The only three things I can think of at this point:
- Some plugin is interfering. You might want to close any open instance of NPP, then run
notepad++.exe -noPlugin
from the command line or theWin+R
run menu (or temporarily change your shortcut to include the-noPlugin
argument), and see if you still have the problem. (You can verify no plugins are loaded because the Plugin menu will have disappeared, and? > Debug Info
will list “Plugins : none”.) - Somehow your VS2015-Dark Theme is getting in the way. I don’t know how. Can you try changing to default styler, and see if the problem persists? Do you know where you got the VS2015-Dark Theme? If so, could you provide a link, so that we can try to replicate the problem?
- Your installation of NPP (on all three machines?!) is corrupt. I find this highly unlikely, but I’m grasping at straws here. If you have the ability to download the standalone / minimalist and unzip it into a temporary directory, and see if it has the same results, that would be one of my next steps if I were having the issue. (But I understand that IT departs like locking down machines nowadays, so you might not be able to.)
If anyone else has any ideas, or can jump in with confirmation that they can reproduce the issue…
- Some plugin is interfering. You might want to close any open instance of NPP, then run
-
Apparently VS2015-Dark Theme is causing the problem. I remove it and the fortran fixed highlighting works. It must be something in the xml file.
-
Glad you found the culprit.
When I looked at my default
%AppData%\Notepad++\stylers.xml
, or a random one of the theme stylers in%AppData%\Notepad++\themes\____.xml
, I see that there are twoLexerType
’s, one for each… both have identical content, but differentname
anddesc
attributes. So, you could probably look in your%AppData%\Notepad++\themes\VS2015-Dark.xml
(or whatever it’s called), and check to make sure that both exist, and that the name and desc fields are similar to what I have (quoted here). If you have thename="fortran" desc="Fortran (free form)"
, but not thename="fortran77" desc="Fortran (fixed form)"
, you might want to just duplicate the free-form settings, and rename the duplicate to fortran77/fixed (and save and reload NPP).My example from
stylers.xml
:<LexerType name="fortran" desc="Fortran (free form)" ext=""> <WordsStyle name="DEFAULT" styleID="0" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="COMMENT" styleID="1" fgColor="008000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="NUMBER" styleID="2" fgColor="FF8000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="STRING" styleID="3" fgColor="808080" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="STRING2" styleID="4" fgColor="808080" bgColor="FFFFFF" fontName="" fontStyle="1" fontSize="" /> <WordsStyle name="OPERATOR" styleID="6" fgColor="000080" bgColor="FFFFFF" fontName="" fontStyle="1" fontSize="" /> <WordsStyle name="IDENTIFIER" styleID="7" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="INSTRUCTION WORD" styleID="8" fgColor="0000FF" bgColor="FFFFFF" fontName="" fontStyle="1" fontSize="" keywordClass="instre1" /> <WordsStyle name="FUNCTION1" styleID="9" fgColor="8000FF" bgColor="FFFFFF" fontName="" fontStyle="1" fontSize="" keywordClass="instre2" /> <WordsStyle name="FUNCTION2" styleID="10" fgColor="0080C0" bgColor="FFFFFF" fontName="" fontStyle="1" fontSize="" keywordClass="type1" /> <WordsStyle name="PREPROCESSOR" styleID="11" fgColor="800000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="OPERATOR2" styleID="12" fgColor="808080" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="LABEL" styleID="13" fgColor="FFFFFF" bgColor="FF80FF" fontName="" fontStyle="1" fontSize="" /> <WordsStyle name="CONTINUATION" styleID="14" fgColor="008000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" /> </LexerType> <LexerType name="fortran77" desc="Fortran (fixed form)" ext=""> <WordsStyle name="DEFAULT" styleID="0" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="COMMENT" styleID="1" fgColor="008000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="NUMBER" styleID="2" fgColor="FF8000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="STRING" styleID="3" fgColor="808080" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="STRING2" styleID="4" fgColor="808080" bgColor="FFFFFF" fontName="" fontStyle="1" fontSize="" /> <WordsStyle name="OPERATOR" styleID="6" fgColor="000080" bgColor="FFFFFF" fontName="" fontStyle="1" fontSize="" /> <WordsStyle name="IDENTIFIER" styleID="7" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="INSTRUCTION WORD" styleID="8" fgColor="0000FF" bgColor="FFFFFF" fontName="" fontStyle="1" fontSize="" keywordClass="instre1" /> <WordsStyle name="FUNCTION1" styleID="9" fgColor="8000FF" bgColor="FFFFFF" fontName="" fontStyle="1" fontSize="" keywordClass="instre2" /> <WordsStyle name="FUNCTION2" styleID="10" fgColor="0080C0" bgColor="FFFFFF" fontName="" fontStyle="1" fontSize="" keywordClass="type1" /> <WordsStyle name="PREPROCESSOR" styleID="11" fgColor="800000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="OPERATOR2" styleID="12" fgColor="808080" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="LABEL" styleID="13" fgColor="FFFFFF" bgColor="FF80FF" fontName="" fontStyle="1" fontSize="" /> <WordsStyle name="CONTINUATION" styleID="14" fgColor="008000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" /> </LexerType>
-
Thank you. Thank you! Yep that did the trick. It was a simple fix that I actually found 1/2 way into my research on this subject but overlooked it because I didn’t understand why the user posted that LexerType had to be duplicated. Now I know and it works. Now I need to figure why NppExec is not saving my scripts when I upgraded to 7.4.2:)