Reply To: macro to toggle between c/cpp and h

Product Compare Forums Multi-Edit Support macro to toggle between c/cpp and h Reply To: macro to toggle between c/cpp and h

#4217
ReidSweatman
Participant

Yes, the rewrite I posted behaves as I said it did. You seemed concerned in your original post about only being able to open files that were already open, so I modified it to open the file whether it was already open or no; I would think that would be the behavior you’d prefer.

I did mention the assumption I’d made regarding the mapping of extensions, and indicated that whatever assumptions you preferred would be easy to implement; I was aware as I wrote it that the version I wrote did not behave as the original in this regard. I was concerned here more with simplifying the structure and eliminating extraneous state variables to make it easier to understand. There are several other extension naming conventions common in C/C++ coding; I didn’t choose to deal with them, either, just as you didn’t. The point of being able to write your own macros is that you can tailor them to your own situation and needs. My rewrite was for illustration, and is not up to my standards for production code; the extra options, tests, and debugging code would have obscured the points you were asking about.

Have a look at the comment header for the LdFiles() macro in MeSys.s to see what it’s capable of. The reason you might prefer being asked if you want to reload is to prevent accidental loss of unsaved changes. If you don’t want to be asked, merely add the /NC=1 flag as an argument. Likewise, leaving the /LC=1 argument off, or setting it to 0 instead will load the related file in place of the original. There are any number of possibilities.

The important thing here is that the version I presented was intended to illustrate solutions to the questions you asked, not to outguess your intentions.

You were likely having trouble assigning the macro to a key because you can’t assign a macro that hasn’t been compiled. Once it has been, to assign it, go to Tools | Customize… | General from the main menu bar, press the large Keys/Commands… button, pick a location in the Command Mapping dialog where you’d like to position the command (usually the area flagged for user assignments), and click the Insert button. Then fill in the Name: field with whatever name you want to give the mapping, and the Command line: field with module_name^FlipC2H, where module_name is the name you assigned the file the macro is located in using the macro_file command. Then click on the button with the ellipsis (three dots) to the right of the Primary Key: field, and press the keystroke combination you want to assign. Then just back out of the sequence of dialog boxes by accepting all changes, and your key mapping should be functional.

Incidentally, I suppose this is niggling, but the name you gave the macro doesn’t describe what it really does. Something like OpenPairedFile() would be more accurate.