Home Download Buy Blog Forum Support

ST3: Wrap at ruler oddity

ST3: Wrap at ruler oddity

Postby zchrykng on Tue Feb 12, 2013 2:25 pm

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:

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.
zchrykng
 
Posts: 14
Joined: Wed Jan 04, 2012 9:25 pm

Re: ST3: Wrap at ruler oddity

Postby qgates on Wed Feb 13, 2013 12:58 am

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 :)
qgates
 
Posts: 230
Joined: Mon Nov 05, 2012 4:33 pm

Re: ST3: Wrap at ruler oddity

Postby zchrykng on Wed Feb 13, 2013 9:47 pm

Gotcha! I was completely able to undo it, I just wanted to make sure that it was working the way it was supposed to! :)
zchrykng
 
Posts: 14
Joined: Wed Jan 04, 2012 9:25 pm


Return to Technical Support

Who is online

Users browsing this forum: No registered users and 17 guests