Here is what I started with:

- Code: Select all
`def convert_to_mid_line_tabs(view, edit, tab_size, pt, length):`

spaces_end = pt + length

spaces_start = spaces_end

while view.substr(spaces_start-1) == ' ':

spaces_start -= 1

spaces_len = spaces_end - spaces_start

normed_start = normed_rowcol(view, spaces_start)[1]

normed_mod = normed_start % tab_size

tabs_len = 0

diff = 0

if normed_mod != 0:

diff = tab_size - normed_mod

tabs_len += 1

tabs_len += int(math.ceil(float(spaces_len - diff)

/ float(tab_size)))

view.replace(edit, sublime.Region(spaces_start,

spaces_end), '\t' * tabs_len)

return tabs_len - spaces_len

And here is what I have after hitting alt-q with the cursor anywhere inside of that code block.

- Code: Select all
`def convert_to_mid_line_tabs(view, edit, tab_size, pt, length): spaces_end = pt + length`

spaces_start = spaces_end while view.substr(spaces_start-1) == ' ': spaces_start -= 1

spaces_len = spaces_end - spaces_start normed_start = normed_rowcol(view, spaces_start)[1]

normed_mod = normed_start % tab_size tabs_len = 0 diff = 0 if normed_mod != 0:

diff = tab_size - normed_mod tabs_len += 1 tabs_len += int(math.ceil(float(spaces_len -

diff) / float(tab_size))) view.replace(edit, sublime.Region(spaces_start,

spaces_end), '\t' * tabs_len) return tabs_len - spaces_len

I am just starting to learn python, so I could be wrong, but I think this would brake the file.