dparkins / language-fortran

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

Toggle comment in fixed-form grammar #78

Closed dpo closed 8 years ago

dpo commented 8 years ago

What's the way to indicate how toggle comment should work (Command-/) in fixed-form source files? Currently, Command-/ inserts C-style comments. I tried adding this to my config.cson:

".fixed.fortran.source":
  editor:
    commentStart: "^C "
    commentEnd: ""

but clearly, that's not the way to insert a C in column 1... Any ideas?

tomedunn commented 8 years ago

Naively, I would expect it to be this

'.source.fortran.fixed':
  'editor':
    'commentStart': 'C '

However this always inserts the comment character before the first non-whitespace character. I don't know how to make it insert the comment character in the first column of a line. I'll look into it and see if I can find anything.

dpo commented 8 years ago

Thanks! A cursory search didn't reveal anything for me. It might need some JavaScript to the rescue, but that's uncharted territory for me.

tomedunn commented 8 years ago

It appears as though this isn't currently possible in Atom at the moment (see this post), or at least without doing some serious hacking. I've opened an issue at https://github.com/atom/atom. Hopefully they get around to introducing this feature soon.

dpo commented 8 years ago

Thanks. Maybe this calls for a specialized extension in the vein of comment. For example, https://github.com/havber/comment/blob/master/lib/comment.js#L70 seems relevant.

tomedunn commented 8 years ago

Thanks for the link @dpo, I'm not too familiar with how to write non-syntax highlighting packages for Atom but I'll definitely give that a look to see if it can help.

tomedunn commented 8 years ago

@dpo I looked into this issue and it looks like I can add some coffee-script or javascript to make this work. I can't give you an ETA as I'm this will require me diving into entirely new territory as far as Atom is concerned and I'm going to be exceedingly busy over the next few months. However, I can say that this is next on my todo list for this package.

dpo commented 8 years ago

@tomedunn I think that would be excellent. I can try to help, but my javascript is just about nil.

tomedunn commented 8 years ago

So I was able to make some progress on this. It's still not resolved completely but it should be a good first step. This adds a function that can be assigned to a keybinding that will add comments to the start of a line in Fortran - Fixed Form files.

The next step that is needed is to figure out how to create a keybinding that is scope specific. For instance, set things up so cmd+/ calls the regular comment toggling function in Atom when not in Fortran - Fixed Form files and calls the custom function I just added when inside Fortran - Fixed Form files.

dpo commented 8 years ago

Many thanks for this! I just upgraded to 2.0.11. Calling "Language-Fortran ToggleComment" from the command palette doesn't seem to do anything though. What am I missing?

tomedunn commented 8 years ago

The command will only work in files that are using the Fortran - Fixed Form grammar. I set a keybinding to work with cmd-/. Are you trying this on windows or OS X? If you check out the keybinding file here you can see how to change the keybinding. Let me know if you aren't able to get it to work.

dpo commented 8 years ago

I'm not having any luck. I tried changing the keymap in my keymap.cson with no luck. I experimented with the syntax

"atom-text-editor[data-grammar='source fortran']":
  'cmd-/': 'language-fortran:toggleComment'

(found here). Still no luck.

If anything, calling the function Language Fortran: ToggleComment explicitly from the command palette should always work, shouldn't it?

tomedunn commented 8 years ago

Did you check the keybinding resolve window with cmd-. to see if the keybinding is being set properly? Also, if you haven't, check the scope with cmd-alt-p to make sure the scope is source.fortran.fixed.

dpo commented 8 years ago

Well I closed the Atom window and opened a fresh one, and now it's working. I guess it needed refreshing. It works nicely now. Many thanks for that!!!

tomedunn commented 8 years ago

Awesome. If you run into any issues with it let me know! :smile: