dparkins / language-fortran

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

Fixes Issue 108 - Autocomment not working for fixed fortran #122

Closed trihedral closed 4 years ago

trihedral commented 4 years ago

This adds two lines to settings/language-fortran.cson to make the '!' the default comment character. This is already the case for all fortran versions specified in settings/language-fortran.cson (free and "modern"). Another solution would be to add entries in that file for fixed and "punchcard" fortran.

trihedral commented 4 years ago

This seems to be because "fixed" fortran is not specified in the language settings file (only "free" and "modern" are). I don't know that my regex skills are up to creating such an entry, but there is an easier solution to apply the ! commenting to every fortran type. I made pull request #122 to achieve this, but until then:

This can be done by adding two lines to the file settings/language-fortran.cson. Under line 2, which reads "'editor':", add the following two lines:

'commentStart': '! '

'commentEnd': ''

tomedunn commented 4 years ago

Comments for fixed form Fortran source code are handled by 'lib/language-fortran.coffee'. This was to allow fixed form comments to be placed in the first character position rather than in front of the first non-space character in a line.

dparkins commented 4 years ago

Roll it back?

tomedunn commented 4 years ago

I'm honestly not sure what the change does. I'm able to use block commenting in both the latest version and previous versions.

trihedral commented 4 years ago

Ah, perhaps there's a better solution. But before this commit, using Ctrl+/ in a fixed Fortran program would apply c++ style mutli line comments / /. This commit prevents that (because those aren't Fortran comments) and instead uses the correct single line comment (!).

On Mon, Jun 8, 2020, 9:26 PM Tom Dunn notifications@github.com wrote:

I'm honestly not sure what the change does. I'm able to use block commenting in both the latest version and previous versions.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/dparkins/language-fortran/pull/122#issuecomment-640973315, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACBFM5BW2LJ2CMZBKR7T4NLRVWFUDANCNFSM4NYSQQDA .

trihedral commented 4 years ago

Again, this is for fixed length Fortran codes, such as ones with the uppercase ".F" file extension. I believe ".f" files were already behaving correctly before the commit.

On Mon, Jun 8, 2020, 9:40 PM Kyle Brownell kyledbrownell@gmail.com wrote:

Ah, perhaps there's a better solution. But before this commit, using Ctrl+/ in a fixed Fortran program would apply c++ style mutli line comments / /. This commit prevents that (because those aren't Fortran comments) and instead uses the correct single line comment (!).

On Mon, Jun 8, 2020, 9:26 PM Tom Dunn notifications@github.com wrote:

I'm honestly not sure what the change does. I'm able to use block commenting in both the latest version and previous versions.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/dparkins/language-fortran/pull/122#issuecomment-640973315, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACBFM5BW2LJ2CMZBKR7T4NLRVWFUDANCNFSM4NYSQQDA .

tomedunn commented 4 years ago

That's definitely odd. What scope does it show for the files you're seeing this in? If you don't know how to display the scope at your cursor you can search your keybindings for "scope" (on OS X it's alt-cmd-p).

trihedral commented 4 years ago

Okay, I went back to the unmodified version and here's the cursor scope from a random spot in my fixed fortran (".F"). It looks like ".f" actually has the same problem - that file extension may also refer to fixed fortran (not sure). But non-fixed fortran codes are indeed commenting correctly before my commit (I checked with a ".F95" file, and included it's scope as well)

Fixed ".F" file (Ctrl+/ comment issue)

Scopes at Cursor source.fortran.fixed meta.program.fortran meta.block.specification.fortran meta.statement.IO.fortran punctuation.parentheses.right.fortran

Free ".F95" file (Ctrl+/ commenting works)

Scopes at Cursor source.fortran.free meta.program.fortran meta.block.specification.fortran meta.block.do.unlabeled.fortran keyword.control.enddo.fortran

On Mon, Jun 8, 2020 at 11:31 PM Tom Dunn notifications@github.com wrote:

That's definitely odd. What scope does it show for the files you're seeing this in? If you don't know how to display the scope at your cursor you can search your keybindings for "scope" (on OS X it's alt-cmd-p).

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/dparkins/language-fortran/pull/122#issuecomment-641006811, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACBFM5E4NEIWYVS34GYQCJTRVWUJJANCNFSM4NYSQQDA .

-- Kyle Brownell kyledbrownell@gmail.com

tomedunn commented 4 years ago

Thanks, it looks like the scopes are being applied correctly. So the next thing to check would be the keybindings for commenting. There should be two entries as shown below, one for editor:toggle-line-comments a second one for language-fortran:toggleComment.

Atom comment keybindings

If both of those are there for you then I think I'm out of ideas.

trihedral commented 4 years ago

Alright, looks like we're onto something. I'm guessing you're on a mac, but on a PC I should be seeing ctrl wherever you have cmd. However, that is not the case for the language-fortran line - I also have: cmd-/ language-fortran:toggleComment Language Fortran .editor[data-grammar='source fortran fixed']:not([mini]) But that should be ctrl-/ for me. So one solution is to append the ctrl-/ version of the command to keymaps\language-fortran.cson. That way both cmd-/ and ctrl-/ will comment (using 'C' rather than '!' it seems, but that's okay). So the visible portion of keymaps\language-fortran.cson would be:

".editor[data-grammar='source fortran fixed']:not([mini])": 'cmd-/': 'language-fortran:toggleComment' 'ctrl-/': 'language-fortran:toggleComment'

Although maybe Atom has some other cross-platform syntax. But even with this, uncommenting still doesn't work with ctrl-/.

Keep in mind that the .f95 files are behaving perfectly (commenting and uncommenting). I believe this is due to the fact that settings\language-fortran.cson has the entry '.source.fortran.free', but it does not have a similar entry for fixed fortran. My earlier solution was to add the comment values to '.source.fortran', so it would be default for all fortran sub-types. I think the superior solution would be to create/implement an entry: '.source.fortran.fixed'

On Tue, Jun 9, 2020 at 3:57 PM Tom Dunn notifications@github.com wrote:

Thanks, it looks like the scopes are being applied correctly. So the next thing to check would be the keybindings for commenting. There should be two entries as shown below, one for editor:toggle-line-comments a second one for language-fortran:toggleComment.

[image: Atom comment keybindings] https://user-images.githubusercontent.com/5925666/84193571-45ee0d80-aa61-11ea-8bab-1436acebd111.png

If both of those are there for you then I think I'm out of ideas.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/dparkins/language-fortran/pull/122#issuecomment-641537234, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACBFM5BX45BNYUWNOBDQMR3RV2H4FANCNFSM4NYSQQDA .

-- Kyle Brownell kyledbrownell@gmail.com

tomedunn commented 4 years ago

That's really interesting. As far as I know the grammar package never sets the keybinding for toggling comments, it only aliases the toggleComment function to a different function when in the source.fortran.fixed scope. So I'm not sure why it would be applying the mac keybindings to a non-mac environment. I'll have to read up on this a bit to see if there's a way to specify it.

tomedunn commented 4 years ago

Well that didn't take long. I found the keybinding specified in keymaps/language-fortran.cson and it does list the keymapping as cmd-/. Now to see if there's a way to define it in a system agnostic way.