Sublime Forum

Sublime Writer

#1

I’ve been using the excellent distraction free mode in Sublime and I love it. I also created some user prefs for Markdown mode that attempts to mimic Writer on the iPad. I can get pretty close. It’s really nice. BUT, I can’t get the current line to stay centered on the screen like writer does. Is this something that is possible via the API or some hidden setting. Also, the way lines fade out above and below the current line in Writer is nice. Again, possible in Sublime somehow? I thought a species syntax might do it…?

0 Likes

#2

I’m not familiar with Writer, but this may approximate what you’re after regarding the cursor.

Bind this to “enter” in your user keybindings.

Note that it only keeps the cursor centered in the screen; you have to place it there first.

[code]import sublime_plugin

class SublimeWriter(sublime_plugin.TextCommand):
def run(self, edit):
self.view.insert(edit, self.view.sel()[0].begin(), “\n”)
self.view.run_command(“scroll_lines”, {“amount”: -1.0})[/code]

And this will give you the middle point:

v = view.visible_region() a = view.rowcol(v.begin())[0] b = view.rowcol(v.end())[0] middle = (b + a)/2

HTH,
G

0 Likes

#3

In v1 it used to be possible to issue a sequence of commands in a single key binding. That would eliminate the need for the plugin, but I haven’t figured out yet how to do this in v2…

0 Likes

#4

When I implement distraction free mode in Sublime Text 2, I’ll see what I can do to get some of these incorporated.

0 Likes

#5

I thought that there was something important missing :blush:

0 Likes

#6

Hi all,

I, too, am hoping to get Sublime Text 2 to behave more like WriterRoom or iA’s Writer.

I failed to use the code snippets provided by guillermooo. (I use ST for CSS, HTML and regular text; I haven’t programmed in a decade.) I’d be grateful for any help implementing them.

Since ST’s API has a show_at_center(point) function, it seems fairly straightforward (for someone who can write Python) to implement the centering effect. The code would be the python equivalent of: after each keypress, show_at_center(where there cursor is). This might break ST’s more advanced features, but if all you’re doing is writing text, I think it should work okay.

The fade out effect is more complicated, because iA’s Writer doesn’t just highlight the line, it highlights the sentence. (See http://www.geekosity.org/wp-content/uploads/2011/06/iA-Writer.png) Implementing this would break compatibility with TextMate’s themes, which presumably is undesirable.

A rather complicated plugin might be able to grab the text between the two punctuation points (. ? ! for English) before and after the cursor’s position and call that regular text, while making everything else styled as a comment (which tend to be themed so that they fade into the background). Of course, this would stumble on a text like “Did you know? St. Jerome was a saint.” (It would think that “St.” was a complete sentence.)

I hope that the above is not too muddled. I also was not sure whether I should reply here or post a new topic under the Ideas & Feature Requests section. (I’m not activate on forums that much, except when I love the app!)

0 Likes