Home Download Buy Blog Forum Support

Hard line breaks in Sublime Text

Hard line breaks in Sublime Text

Postby yrammos on Sun Sep 08, 2013 3:22 pm

I use ST2/3 as my primary LaTeX editor and push all my git commits onto GitHub. For several reasons, I need to use hard line breaks—"word wrap" doesn't do the trick. I have installed the WrapPlus package via Package Control, and while very helpful, and so far reliable, it needs to be triggered manually using a shortcut.

Is there a way to have this done automatically, e.g. by triggering the WrapPlus command every time I type a whitespace? It seems that sublime_plugin.EventListener does not provide a method for tracking the last character entered into the buffer, so some major (and possible inefficient) intervention might be needed to obtain that information.

(Incidentally, it would be nice to have a "meta-package" of sorts that would parametrically run any command whenever a given event is triggered. Any volunteers? :) )
yrammos
 
Posts: 18
Joined: Fri Jun 22, 2012 3:26 am

Re: Hard line breaks in Sublime Text

Postby skuroda on Sun Sep 08, 2013 10:47 pm

You could probably use the "on_modified" event listener to run the command. Though to get it to run after a space was inserted would take a little bit more work. Untested, but something like the following would run the command after every modification. Again, you would have to do some work to see what the last character entered was.

Code: Select all
import sublime_plugin

class EventListener(sublime_plugin.EventListener):
    def on_modified(self, view):
        view.run_command("wrap_lines_plus")


Another option is to create a text command that will insert the space, the run the command. Though this could cause issues if you don't set up you context entries correctly.
skuroda
 
Posts: 674
Joined: Fri Oct 05, 2012 8:11 am

Re: Hard line breaks in Sublime Text

Postby yrammos on Mon Sep 09, 2013 2:14 pm

Many thanks, Skuroda, I tried something along the lines of what you described (in your code snippet) and the result was a total mess—garbled text and noticeable latency between text entry and display. I would indeed need to have it run only when whitespace is entered (probably by diff-ing the buffer in the vicinity of the cursor before and after the keystroke, right?). This seems like too much work given my tight schedule unfortunately… But an idea for the future, certainly.
yrammos
 
Posts: 18
Joined: Fri Jun 22, 2012 3:26 am

Re: Hard line breaks in Sublime Text

Postby Veedrac on Tue Sep 10, 2013 12:45 am

You could use soft breaks and make it trigger run wrap_line_plus command on pre-save.
Veedrac
 
Posts: 19
Joined: Sun Aug 18, 2013 4:16 pm

Re: Hard line breaks in Sublime Text

Postby skuroda on Tue Sep 10, 2013 2:28 am

Good idea Veedrac, I forgot about that listener.
skuroda
 
Posts: 674
Joined: Fri Oct 05, 2012 8:11 am

Re: Hard line breaks in Sublime Text

Postby yrammos on Tue Sep 10, 2013 12:16 pm

Excellent idea [slaps forehead]. Many thanks.
yrammos
 
Posts: 18
Joined: Fri Jun 22, 2012 3:26 am


Return to Ideas and Feature Requests

Who is online

Users browsing this forum: No registered users and 8 guests

cron