Macro Monday – a new macro to dig into every Monday!
It’s a common idiom to swap things around in your code, either swapping the position of two function arguments, or changing the assignment o variable around in a save and restore operation. This is not often done, bu when you need to do it, this macro will save you a lot of time… I end up using this macro around once per day.
Examples
Given this piece of JavaScript assignment code:
window.myvariable = window.somefield;
when you select this piece of code and invoke the macro, you’d get the code
assignment swapped into this:
window.somefield = window.myvariable;
Another use case is to swap the position of function arguments:
def myfunction(arg1, arg2):
print(arg1, arg2)
myfunction("one", "two")
If you select arg1, arg2, or select “one”, “two” and run the macro you’d
swap those arguments around:
def myfunction(arg2, arg1):
print(arg2, arg1)
myfunction("two", "one")
Installation
To install the macro simply hit the download button below, then drag the downloaded file into your Komodo toolbox.
To use the macro, make an editor selection and then invoke the macro – by double-clicking on the macro in the toolbox, using the Invoke Tool (Ctrl+Shift+K) to search/execute “swap assignment”, or assigning your own keybinding to the macro.
Related Materials
- Komodo Developer Extension
- play around with JavaScript or Python code in the context of the Komodo window
- Komodo Macro API
- to programatically interact with the Komodo editor – available to both
Python and Javascript
- to programatically interact with the Komodo editor – available to both
- Editor API
- the Komodo editor provides a wrapper around the Scintilla API