Off switch for active code by "//" in procedure file

I have a procedure with multiple isolated functions. But I don't want all the functions being loaded and I don't want to create multiple file for small procedure.

I usually put "//" to disable a function, and i have to put multiple "//" in front of each line depend on how long the code is.
It would be better if I could disable a/the function(s) by
1. Select multiple lines of the code
2. "right click"
3. Insert "//" in front of each line.

This would be also useful for making note contains multiple lines.
just a thought
For multiline comments I usually use
#ifdef NOT_DEFINED

function myfunction()

End

#endif

Requires Igor 6.20 though.

I also have defined some keyboard shortcuts for commenting/decommenting. Save the following snippet as keyboard-shortcuts.ipf in "Igor Procedures" and restart Igor.
#pragma rtGlobals=1     // Use modern global access method.
#pragma IndependentModule=keyboardShortCuts

Menu "Procedure", dynamic, hideable
     "-"
     "Commentize/8",/Q, Execute/P/Q/Z "DoIgorMenu \"Edit\", \"Commentize\""
     "Decommentize/9",/Q, Execute/P/Q/Z "DoIgorMenu \"Edit\",\"Decommentize\""
     "Adjust Indentation/7",/Q, Execute/P/Q/Z "DoIgorMenu \"Edit\",\"Adjust Indentation\""
 
 End


Now you can comment/decomment any selection with CTRL+8 and CTRl+9.
thomas_braun wrote:
For multiline comments I usually use
#ifdef NOT_DEFINED

function myfunction()

End

#endif

Requires Igor 6.20 though.

I also have defined some keyboard shortcuts for commenting/decommenting. Save the following snippet as keyboard-shortcuts.ipf in "Igor Procedures" and restart Igor.
#pragma rtGlobals=1     // Use modern global access method.
#pragma IndependentModule=keyboardShortCuts

Menu "Procedure", dynamic, hideable
     "-"
     "Commentize/8",/Q, Execute/P/Q/Z "DoIgorMenu \"Edit\", \"Commentize\""
     "Decommentize/9",/Q, Execute/P/Q/Z "DoIgorMenu \"Edit\",\"Decommentize\""
     "Adjust Indentation/7",/Q, Execute/P/Q/Z "DoIgorMenu \"Edit\",\"Adjust Indentation\""
 
 End


Now you can comment/decomment any selection with CTRL+8 and CTRl+9.


Beautiful! Thanks!
In case it's not already clear from Thomas's post, Igor has built in menu items for commentizing and decommentizing code. With code in a procedure window selected, choose Edit->Commentize or Edit->Decommentize. You would only need to use a snippet like the one he suggested if you want to have keyboard shortcuts for these commands.

To temporarily disable a user-defined function, you can also put an x before the first keyword in the declaration. For example:
xFunction test()
    print 123
End

xThreadsafe Function test2()
    print 456
End


I don't believe that this is documented so I wouldn't rely on the current behavior continuing on until the end of time. For code that you ship you should use #if...#endif statements to disable your code. But this saves you some typing when you're developing code and want to quickly disable a function.
aclight wrote:
To temporarily disable a user-defined function, you can also put an x before the first keyword in the declaration.

Nice hack!
I don't know if it's documented, but any text that's not part of a function or macro body is simply ignored. That's why putting an X in from of the function declaration makes the function disappear. If it's not documented, it's still not likely to go away because Larry, the compiler writer, uses that trick all the time :)

What I said above is almost but not quite correct. If you save an experiment with lines above the first macro or function in the main procedure window, Igor will try to execute them when you open the experiment. That's intended- it allows you to write experiment initialization commands:
DisplayHelpTopic "Experiment Initialization Procedures"

I will also divulge that Igor 7 will have cmd-/ and cmd-\ shortcuts for Commentize and Decommentize (read "Ctrl" for "cmd" if you're on Windows). Now don't go asking when Igor 7 will be available...

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
johnweeks wrote:
I don't know if it's documented, but any text that's not part of a function or macro body is simply ignored. That's why putting an X in from of the function declaration makes the function disappear. If it's not documented, it's still not likely to go away because Larry, the compiler writer, uses that trick all the time :)

What I said above is almost but not quite correct. If you save an experiment with lines above the first macro or function in the main procedure window, Igor will try to execute them when you open the experiment. That's intended- it allows you to write experiment initialization commands:
DisplayHelpTopic "Experiment Initialization Procedures"

I will also divulge that Igor 7 will have cmd-/ and cmd-\ shortcuts for Commentize and Decommentize (read "Ctrl" for "cmd" if you're on Windows). Now don't go asking when Igor 7 will be available...

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com


I am not going to ask the release date of Igor 7.
But I have another request for Igor 7.
I use Ctrl +M ; Ctrl + J and data browser very often.
Please add a shortcut for "data browser"
Forgive me if I had overlooked.

Thanks in advance.
Quote:
I use Ctrl +M ; Ctrl + J and data browser very often.
Please add a shortcut for "data browser"
Forgive me if I had overlooked.

You didn't overlook it, and it looks like there will be a shortcut for it in 7.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com