Home Download Buy Blog Forum Support

Jump Along Indent

Jump Along Indent

Postby mwean on Fri Nov 08, 2013 2:42 am

One thing I missed a lot coming from TextMate was the ability to jump up and down the page to lines at the same indent level:

ImageImage

I made a small plugin that reproduces this functionality, including extending your selection while jumping. You can find the source on github and install it using Package Control.

Feedback and suggestions are welcome!
mwean
 
Posts: 9
Joined: Wed Aug 01, 2012 9:48 pm

Re: Jump Along Indent

Postby quodlibet on Fri Nov 08, 2013 11:49 am

Cool! This is _very_ useful for prose writing, as it allows me to skip from paragraph to paragraph. (In prose writing a paragraph is a indistinguishable from a line of code, except that they occupy several "lines" due to soft wrapping, which your plugin disregards.)

Would it be possible to add a setting for taking whitespace into account along with indenting? That is, to provide an option to stop the cursor stop on the first "line" (with soft-wrap) after and before a line of whitespace. (In the same way that Ctrl+Left/Right moves from word to word, but also allows you to move to the beginning and end of the current word).

Does this make sense?

Alex

Edit: Is that font Anonymous Pro?
quodlibet
 
Posts: 542
Joined: Sat Jun 18, 2011 5:53 pm

Re: Jump Along Indent

Postby mwean on Sun Nov 10, 2013 4:29 am

I'm glad you like it! I really like your suggestion, and I've implemented it for several lines at the same indent level. Unfortunately, I couldn't find a good way to take soft-wrapped lines into account. I could probably do it if you use a monospace font by checking the width of the window and dividing by the width of the characters, but that's pretty hacky. Does anyone know of a better way of finding the beginnings of soft-wrapped lines?

The font is Source Code Pro Light by Adobe.
mwean
 
Posts: 9
Joined: Wed Aug 01, 2012 9:48 pm

Re: Jump Along Indent

Postby quodlibet on Sun Nov 10, 2013 6:17 am

I thought I was confusing . . . I actually _like_ that your plugin disregards soft-wrapped lines. The addition I was asking for was some consideration for whitespace. The closest thing I can come up with is to look at how Ctrl+Left/Right works. When you are within a word, moving to the right takes you to the end of the word before (on the next press) you are taken to the end of the next word and so on.

Let me try and explain at the level of the "paragraph" (i.e., loads of soft-wrapped text):

Code: Select all
Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
Suspendisse malesuada semper
lectus, quis adipiscing metus aliquam vitae.

Morbi commodo, scelerisque laoreet,
magna elit | vestibulum ligula,
vitae eleifend risus erat vel lorem.

Dignissim ullamcorper nulla pharetra non.
Mauris arcu vel eros hendrerit vitae semper
tortor sodales. Vestibulum vel tincidunt metus.


If the cursor is between elit and vestibulum, I would like Alt+Up to move me to `commodo` and then to `ipsum`. If I then press Alt+Down, it would move me to `quis` and then `eleifend` (approximately).

Does this make sense? (And is it possible?)

Alex
quodlibet
 
Posts: 542
Joined: Sat Jun 18, 2011 5:53 pm

Re: Jump Along Indent

Postby mwean on Sun Nov 10, 2013 8:46 pm

So it actually does work that way now with separate lines. The problem is that it sees the paragraphs as one long line, so there's no way to jump to the last "line" of the paragraph. If there's a good way of identifying soft-wrapped lines, then I could definitely implement it. In the meantime, I'll try implementing it by dividing the window width by the character width.
mwean
 
Posts: 9
Joined: Wed Aug 01, 2012 9:48 pm

Re: Jump Along Indent

Postby Shin6745 on Mon Nov 25, 2013 6:50 am

Thanks for sharing.
Shin6745
 
Posts: 1
Joined: Mon Nov 25, 2013 6:45 am

Re: Jump Along Indent

Postby angusyeh on Thu Jan 16, 2014 1:11 pm

Thanks for developing this plugin!

It was *almost* what I wanted, so I had a go and made two commands that do something similar. They are not as smart as Jump Along Indent. They only "jump to top/bottom" of the current level of indentation. The indent region is determined by using the build-in command "expand_selection to indentation".

Here is the plugin code:
Code: Select all
class JumpToIndentTopCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        self.view.run_command("expand_selection",{"to": "indentation"})
        pos = self.view.sel()[0].a
        self.view.sel().clear()
        self.view.sel().add(sublime.Region(pos,pos))

class JumpToIndentBottomCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        self.view.run_command("expand_selection",{"to": "indentation"})
        pos = self.view.line(self.view.sel()[0].b-1).a
        self.view.sel().clear()
        self.view.sel().add(sublime.Region(pos,pos))


Like Jump Along Indent, I then bind these two commands to alt+up and alt+down .

I actually use a slightly different version of this to move one line further up. So it jumps "up" a level, which helps in language like Python: with a couple of jumps, you can easily land on the current code scope's def or class. This is close to the operation achieved by using goto symbol (ctrl+r) then jump to the current def or next def.

This is probably not perfect, I haven't used it long enough to know all the quirks in various situation. Who knows, maybe one day I will switch back and use Jump Along Indent. But maybe someone will find this useful. Or maybe someone can point out how I can improve this. :)
angusyeh
 
Posts: 13
Joined: Thu Jan 09, 2014 10:49 pm


Return to Plugin Announcements

Who is online

Users browsing this forum: Exabot [Bot] and 7 guests