load header file with same name as the current c file
-
Hi
I often edit .c files and then at some point need to open the header file of same name.
Is there a macro or short-cut to switch from editing main.c to main.h and back?
-
I don’t believe so. But this is something that can easily be scripted if you use or are willing to use the Pythonscript plugin…
-
I whipped up a quick script for this, for “associated” C/C++/H files. It would go nicely as a right-click context menu entry. :)
import os temp_list = notepad.getCurrentFilename().rsplit('.', 1) if len(temp_list) == 2: ext = temp_list[1].lower() if ext in [ 'cpp', 'c', 'h' ]: all_except_ext = temp_list[0] if 'c' in ext: assoc_file = all_except_ext + '.h' else: assoc_file = all_except_ext + '.c' if not os.path.exists(assoc_file): assoc_file = all_except_ext + '.cpp' if os.path.exists(assoc_file): notepad.open(assoc_file)
-
Thanks Alan! You make it sound easy.
I know how to make changes to the contextMenu.xml file, to add or delete menu entries. But that is it.
Is it possible to add your code to the contextMenu.xml ? Can you show an example?
-
I can certainly show an example of how to add a script to the right-click context menu. But the script isn’t embedded there, it’s just “pointed-to” there. Have you installed the Pythonscript plugin and tried to get the script running manually?
-
I am sorry, but I don’t know anything about Pytonscript or running scripts “manually”. That sounds weird to me.
I am not a super user of Notepad++, and my “programming skills” (if I can call it that) is limited to C and Matlab.
I totally understand, if you consider me a “lost cause”, at this point. Anyway, thanks for trying. Have a nice weekend. :-)
-
There are various plugins that have been written to solve your issue. Here is a presumeably uncomplete list (all untested):
QuickOpenPlugin
SourceSwitch
Switcher
Open Selection -
@Ion-Marqvardsen said:
if you consider me a “lost cause”
Well… I’m not 100% sure (yet) but you are starting to sound like someone that wants to be spoon-fed, yes. I’m not so much into that, but if you show some amount of effort, I and others here are definitely “in your corner” and will help you.
-
Hi Alan,
I would need to be “spoon-fed”. And I don’t like that. When I made the request, I was hoping there would be a solution ready.
Once again, thanks for your help.
I will give the plugins on the list a try. They might be exactly what I was looking for.
-
hoping there would be a solution ready
Hmmmmmm…Pythonscript is just another plugin on the list…
-
Hi Alan,
For me there is nothing easy about pythonscripts. It is a question of knowing my limitations and balance between how much benefit there is with loading the associated header/source file versus the time to learn about and write the python code. Starting from where I am today, it does not give any meaning. I will have to progress on my own terms.
-
LOL
-
Yes, I know. I understand you reaction.
-
@Ion-Marqvardsen
You might want to install the Solution Tools plug-in. I use it and the <Ctrl>~ hotkey to cycle among files having the same name and various different file extensions.See here: http://npp.incrediblejunior.com/