dparkins / language-fortran

Syntax highlighting for FORTRAN for atom
MIT License
35 stars 16 forks source link

Highlight C preprocessor directives in .f90 files #51

Open marcosvanella opened 9 years ago

marcosvanella commented 9 years ago

Hi, this is more a question than an issue.. I'm new to atom. I have fortran code in files with .F90 and .f90 extension, which have some C preprocessor directives. These look like

define CVAR 1

ifdef CVAR

Some Fortran code...

endif

for example. I see that code between # symbols is left of color white in atom with the language-fortran package. So, my question is: can we highlight with a particular color (say red) all lines that start with the symbol # (i.e. preprocessor directives) and leave the fortran code inside preprocessor conditionals with its usual colors?

Thank you!

Marcos

tomedunn commented 9 years ago

Highlighting processor directives is certainly doable. I never did much with these because I don't have a lot of experience using processor directives and I didn't want to put something in place that wasn't going to be useful. Are there any resources you know of that have examples of good processor directive highlighting?

Also, the color will depend on what scope we give them, i.e., comment or keyword, and it will depend on the color scheme used as well.

marcosvanella commented 9 years ago

Hi Tom, thank you for your answer. I saw in the grammars dir of the package that there is a cson file

fortran - modern preprocessor.cson

Is this related to what we are trying to do?

I see what you mean about the scope.. I have some basic knowledge of preprocessor directives myself. I guess my idea of highlighting for these comes from vim (fortran syntax). In vim, the comment scope is used, like this:

screen shot 2015-08-19 at 3 58 01 pm

so the preprocessor keywords are not highlighted with a separate color (which would be pretty cool). As you see on the pic, the fortran code inside the # conditionals is still highlighted. I can look around for more examples on this. Regards, Marcos

tomedunn commented 9 years ago

@marcosvanella, yes the file fortran - modern preprocessor.cson is intended to work along those line. Those were preprocessor rules that were left over from the original Textmate grammar this grammar package was based on. I think I would prefer to have things like preprocessor directives handled in their own language package by extending off the base fortran language package, however from my recollection this isn't supported that well. I think the next release of Atom is suppose too include improvements to the grammar engine that is suppose to address this. So it might be worth revisiting over the next few weeks.

marcosvanella commented 9 years ago

Thank you Tom. Yes, I checked the installed language-fortran package in atom, and didn't see the settings tab, so I assumed I couldn't switch among these fortran - x .cson options. So, when this is developed, fortran - modern preprocessor.cson will sit on top of the standard language fortran package? Thank you, Marcos

tomedunn commented 9 years ago

@marcosvanella yes that's likely how it will work. The other option would be to remove all of the preprocess stuff and put it into it's own language grammar and inject rules into the Fortran rules. So you would have to install language-fortran along with, lets say, language-fortran-preprocessor. Then you wouldn't have to change the actual language being applied, you would just have to make sure both were installed. I plan on trying it both ways to see if one feels better. Hopefully I can get on these changes soon.

marcosvanella commented 9 years ago

Thank you Tom, and best regards.

janbernloehr commented 9 years ago

Any updates on this one? I would highly appreciate it!

tomedunn commented 9 years ago

Sorry for the delayed response guys. I'm currently working on a separate grammar package to include preprocessor stuff for Fortran. It shouldn't take too much work but I just need to find the time to do it. My current plan of attack is to start with Intel fpp and then move on to other compiler preprocessor directives.

At some point I'd like to include them all here but I need to figure out if it's possible to turn grammar packages on an off via this package's settings. Again if there are specific collections of preprocessor directives that you'd like to see please link them here. I don't use preprocessor directives often when I'm programming in Fortran so I'm working a little bit in the dark on this topic.

tomedunn commented 9 years ago

I submitted a pull request with some updates to the preprocessor rules. I'm sure there is more work to be done regarding this but hopefully this will serve as a good starting point. Let me if there are any preprocessor rules that I missed. Also, for the time being, I set the scope to the preprocessor stuff as keyword.

marcosvanella commented 9 years ago

Hi Tom, thank you for putting this together! I apologise for not getting back to you. Intel fpp is just fine for the directives in my case. I did download version 2.0.1 of fortran-language. I guess my question is, is preprocessor directives highlighting already included on this package or, should I download another package? Thank you!

Date: Sun, 18 Oct 2015 19:45:36 -0700 From: notifications@github.com To: language-fortran@noreply.github.com Subject: Re: [language-fortran] Highlight C preprocessor directives in .f90 files (#51)

I submitted a pull request with some updates to the preprocessor rules. I'm sure there is more work to be done regarding this but hopefully this will serve as a good starting point. Let me if there are any preprocessor rules that I missed. Also, for the time being, I set the scope to the preprocessor stuff as keyword.

— Reply to this email directly or view it on GitHub.

tomedunn commented 9 years ago

@marcosvanella there were some preprocessor rules in the package previously but these were left over from the original Textmate bundle. I updated these to follow fpp which is used by both Intel and GCC. You shouldn't have to do anything differently to include the new preprocessor rules so long as you're using the latest build. They should be added automatically to all four of the grammars available.

marcosvanella commented 9 years ago

Thanks Tom, I see.. Do I need to use caps for the directives?

With caps I get the highlighting behavior: sshot_caps while without them I get white text: sshot_lowcase Thank you.

tomedunn commented 9 years ago

@marcosvanella the Atom package doesn't appear to be updating to the latest version of this repository. So the preprocessor rules that you're working with are the old ones. You can try to update manually by cloning this repository to your package directory. I'm not sure why it's not updating correctly. Maybe it needs the version number to update? @dparkins do you know why this might be happening?

marcosvanella commented 9 years ago

I cloned the language-fortran repo and get the new behavior: new_behavior

Is this the expected behavior? Looks good. I had to restart Atom, after cloning the package, as I was getting some C language "intrusions" in the editing behavior (i.e. CMD + / was giving a C comment /* ...*/). I will test it further. Thank you Tom.

tomedunn commented 9 years ago

@marcosvanella, yes this is what it should look like. It should be highlighting the 1 in your first line but it looks like I forgot to include the numeric rules in the define statement. I'll make a note to update that for the next release. If you notice any other things that I missed list them here. I'll aim to do an update by the end of the week.

dparkins commented 9 years ago

@tomedunn @marcosvanella I have updated the main Atom package with this version. Sorry for the delay.