mirror of https://gitlab.com/cppit/jucipp
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.
68 lines
1.3 KiB
68 lines
1.3 KiB
|
11 years ago
|
#!/usr/bin/python
|
||
|
|
#snippet plugin
|
||
|
11 years ago
|
import juci_to_python_api as juci, inspect
|
||
|
11 years ago
|
|
||
|
|
def initPlugin():
|
||
|
|
juci.addMenuElement("Snippet")
|
||
|
|
juci.addSubMenuElement("SnippetMenu", #name of parent menu
|
||
|
|
"Insert snippet", #menu description
|
||
|
|
"insertSnippet()", #function to execute
|
||
|
11 years ago
|
inspect.getfile(inspect.currentframe()), #plugin path
|
||
|
11 years ago
|
"<control><alt>space")
|
||
|
11 years ago
|
snippets = {}
|
||
|
11 years ago
|
|
||
|
11 years ago
|
snippets["for"] = """\
|
||
|
11 years ago
|
for(int i=0; i<v.size(); i++) {
|
||
|
|
// std::cout << v[i] << std::endl;
|
||
|
|
// Write code here
|
||
|
11 years ago
|
}
|
||
|
|
"""
|
||
|
11 years ago
|
|
||
|
11 years ago
|
snippets["if"] = """\
|
||
|
11 years ago
|
if(true) {
|
||
|
|
// Write code here
|
||
|
11 years ago
|
}
|
||
|
|
"""
|
||
|
11 years ago
|
|
||
|
11 years ago
|
snippets["ifelse"] = """\
|
||
|
11 years ago
|
if(false) {
|
||
|
|
// Write code here
|
||
|
11 years ago
|
} else {
|
||
|
11 years ago
|
// Write code here
|
||
|
11 years ago
|
}
|
||
|
|
"""
|
||
|
11 years ago
|
|
||
|
11 years ago
|
snippets["while"] = """\
|
||
|
11 years ago
|
while(condition) {
|
||
|
|
// Write code here
|
||
|
11 years ago
|
}
|
||
|
|
"""
|
||
|
11 years ago
|
|
||
|
11 years ago
|
snippets["main"] = """\
|
||
|
|
int main(int argc, char *argv[]) {
|
||
|
|
//Do something
|
||
|
|
}
|
||
|
|
"""
|
||
|
11 years ago
|
|
||
|
11 years ago
|
snippets["hello"] = """\
|
||
|
|
#include <iostream>
|
||
|
|
|
||
|
|
int main(int argc, char *argv[]) {
|
||
|
|
std::cout << "Hello, world! << std::endl;
|
||
|
|
}
|
||
|
|
"""
|
||
|
11 years ago
|
|
||
|
11 years ago
|
def getSnippet(word):
|
||
|
|
try:
|
||
|
|
output = snippets[word]
|
||
|
|
except KeyError:
|
||
|
|
output = word
|
||
|
|
return output
|
||
|
|
|
||
|
11 years ago
|
def insertSnippet():
|
||
|
|
theWord=juci.getWord()
|
||
|
|
output=getSnippet(theWord)
|
||
|
|
juci.replaceWord(output)
|
||
|
|
|
||
|
11 years ago
|
|