Sublime Forum

ST3: Wrap at ruler oddity

#1

I honestly did not know that this keyboard shortcut existed until earlier, when I hit it by mistake, but alt-q seems to be messed up on my python file.

Here is what I started with:

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.

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.

0 Likes

#2

AFAIK manual word wrap (alt+q), which breaks each line with an EOL char, considers every line to be part of a “paragraph” until there is a blank line, and reformats all the text as though it’s a paragraph. It’s obviously designed for blocks of text or code comment blocks where hard EOL’s happen at a particular column as defined by the ruler position.

On the other hand “virtual wrap” (View…Word Wrap) wraps lines visually in Sublime but lines remain one long line in the text file; this is typically more useful when programming. It differs from the Edit…Wrap (alt+Q and related) options which behave as above - designed to add physical line breaks.

While it could be made more intelligent in various ways, I think the behaviour is by design. Remember that you can always hit Undo :smile:

0 Likes

#3

Gotcha! I was completely able to undo it, I just wanted to make sure that it was working the way it was supposed to! :smile:

0 Likes