As an happy user of the SciTE editor I was missing this feature in Komodo Edit which by the way is an excellent product.
Comment/uncomment means that a "special" comment string is used, i.e. #~ for Python. If this string is present at beginning of line the macro removes it (uncomment); if not it is inserted (comment). Python and PHP only for now, and poor code for sure. Any help is welcome.
import logging
logger = logging.getLogger('macro')
h = logging.FileHandler("/tmp/somefile", "w")
logger.addHandler(h)
ke = komodo.editor
kd = komodo.document
kv = komodo.view
commentMap = {
u'python': '#~ ',
u'php': '//~ ',
u'javascript': '//~ ',
u'c++': '//~ ',
}
commentTxt = commentMap[kd.language.lower()]
def EVAL(stmt):
res = eval(stmt)
logger.error("%s --> %s" % (stmt, res))
def getLineNo(position=None):
pos = position or ke.currentPos
return ke.lineFromPosition(pos)
def getLine(lineNo=None):
line = lineNo or getLineNo()
eol = ke.getLineEndPosition(line)
return ke.getTextRange(ke.currentPos, eol)
def vCHome(lineNo=None):
if (lineNo is not None):
ke.gotoLine(lineNo)
ke.vCHome()
if (getLine().strip() == ''):
return
if (ke.getTextRange(ke.currentPos, ke.currentPos+1).isspace()):
ke.vCHome()
def doLine(lineNo=None):
vCHome(lineNo)
pos = ke.currentPos
s = ke.getTextRange(pos, pos+len(commentTxt))
if (s == commentTxt):
ke.setSel(pos, pos+len(commentTxt))
ke.replaceSel('')
else:
ke.insertText(pos, commentTxt)
komodo.view.setFocus()
try:
pStart = ke.anchor
pEnd = ke.currentPos
lStart = ke.lineFromPosition(pStart)
lEnd = ke.lineFromPosition(pEnd)
if (lEnd < lStart):
tmp = lStart
lStart = lEnd
lEnd = tmp
for line in range(lStart, lEnd+1):
doLine(line)
except:
logger.error("Error", exc_info=True)
return