How Can I Make Kate Properly Indent Snippets with Multiple Lines

88 views Asked by At

I enjoy using Kate snippets for quick Python scripts, but I'm having a hard time getting them to properly inherit or detect indentation levels after the first line. Consider the following snippet:

print("line1")
print("line2")

I want to insert this in 3 places in my code, at the global level, at the definition level, and at the class level. When I insert, it looks like this:

print("line1")
print("line2")

def test():
    print("line1")
print("line2")#<- not what I intend
    return

class MyClass():
    def mydef():
        print("line1")
print("line2")#<- not what I intend
    return
return

Each time, the snippet's second line is inserted at the 0th indentation level.

If I create a new snippet with static indentation like:

print("line3")
    print("line4")

the print("line3") obeys the current indentation level, but print("line4") always reverts to the 1st indentation level verbatim. This causes problems for deeper indentation. See:

print("line3")
    print("line4")#<- not what I intend

def test():
    print("line3")
    print("line4")#<- correct only by luck

class MyClass():
    def mydef():
        print("line3")
    print("line4")#<- not what I intend
    return
return

I want subsequent lines in my code to automatically detect the current indentation level, but I can't figure out how. It seems like there should be some method in the JavaScript backend, but I can't find anything which is available to the snippets user without modifying a .js file, something which is not extensible between computers. E.g., I should be able to create a snippet that looks like:

class MySnippetClass():
${cur_indent()}    def my_snippet_def(${arg1}):
${cur_indent()}        return
${cur_indent()}    return

How do I fix this and make large, automagically indented snippets?

0

There are 0 answers