Sublime Forum

Hard line breaks in Sublime Text

#1

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? :smile: )

0 Likes

#2

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]
import sublime_plugin

class EventListener(sublime_plugin.EventListener):
def on_modified(self, view):
view.run_command(“wrap_lines_plus”)[/code]

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.

0 Likes

#3

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.

0 Likes

#4

You could use soft breaks and make it trigger run wrap_line_plus command on pre-save.

0 Likes

#5

Good idea Veedrac, I forgot about that listener.

0 Likes

#6

Excellent idea [slaps forehead]. Many thanks.

0 Likes