You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
115 lines
2.1 KiB
115 lines
2.1 KiB
#!/usr/bin/python |
|
#snippet plugin |
|
import juci_to_python_api as juci, inspect |
|
|
|
def initPlugin(): |
|
juci.addMenuElement("Snippet") |
|
juci.addSubMenuElement("SnippetMenu", #name of parent menu |
|
"Insert snippet", #menu description |
|
"insertSnippet()", #function to execute |
|
inspect.getfile(inspect.currentframe()), #plugin path |
|
"<control><alt>space") |
|
snippets = {} |
|
|
|
snippets["for"] = """\ |
|
for(int i=0; i<v.size(); i++) { |
|
// std::cout << v[i] << std::endl; |
|
// Write code here |
|
} |
|
""" |
|
|
|
snippets["if"] = """\ |
|
if(true) { |
|
// Write code here |
|
} |
|
""" |
|
|
|
snippets["ifelse"] = """\ |
|
if(false) { |
|
// Write code here |
|
} else { |
|
// Write code here |
|
} |
|
""" |
|
|
|
snippets["while"] = """\ |
|
while(condition) { |
|
// Write code here |
|
} |
|
""" |
|
|
|
snippets["main"] = """\ |
|
int main(int argc, char *argv[]) { |
|
//Do something |
|
} |
|
""" |
|
|
|
snippets["hello"] = """\ |
|
#include <iostream> |
|
|
|
int main(int argc, char *argv[]) { |
|
std::cout << "Hello, world!" << std::endl; |
|
} |
|
""" |
|
|
|
snippets["fore"] = """\ |
|
for (auto i : v) { |
|
//std::cout << i << std::endl; |
|
} |
|
""" |
|
|
|
snippets["funca"] = """\ |
|
auto functionName(arg) { |
|
// Write code here |
|
return n; |
|
} |
|
""" |
|
|
|
snippets["lambdaa"] = """\ |
|
auto lambda = []() { |
|
//code here |
|
}; |
|
""" |
|
|
|
snippets["jucifor"] = """\ |
|
#include <iostream> |
|
#include <vector> |
|
|
|
|
|
int main(int argc, char *argv[]) { |
|
//Example under from this line to +4 |
|
std::vector<std::string> v = {"Hello!", "This is juCi++"}; |
|
for (auto& i : v) { |
|
std::cout << i << std::endl; |
|
} |
|
return 0; |
|
} |
|
""" |
|
snippets["switch"] = """\ |
|
switch (arg) { |
|
case 1: //some code |
|
//recommended to use break or return on only one possible outcome |
|
default: //some code |
|
} |
|
""" |
|
snippets["cout"] = """\ |
|
std::cout << "example"; |
|
""" |
|
snippets["coute"] = """\ |
|
std::cout << "example" << std::endl; |
|
""" |
|
|
|
|
|
def getSnippet(word): |
|
try: |
|
output = snippets[word] |
|
except KeyError: |
|
output = word |
|
return output |
|
|
|
def insertSnippet(): |
|
theWord=juci.getWord() |
|
output=getSnippet(theWord) |
|
juci.replaceWord(output) |
|
|
|
|
|
|