Sublime Forum

Converting text file to old school NNTP-like reply?

#1

I find myself in the need for a plugin/pretty-fier that would take a pasted in text blob (imagine a copy paste from Gmail with variable line lengths) to a 80 length max with a > prepended to each line.

Before I start to write it myself, I thought I’d see if anyone knows of one already so I don’t reinvent the wheel.

0 Likes

#2

no need for a plugin:

  1. Edit menu -> Wrap -> Wrap paragraph at 80 characters
  2. Select all (relevant text)
  3. Selection menu -> Split into lines
  4. Home
  5. >
1 Like

#3
    1. CtrlA
    1. CtrlShiftL
    1. >Space
0 Likes

#5

The only reason I’d want a plug in is I have the feeling I’m going to need to do it daily and I don’t want the wrap to always be at 80. But, on the plus side, that works for now.

@rppn Um, don’t your steps delete the whole text?

0 Likes

#6

I posted the keyboard shortcuts for steps 2, 3 and 5 which @kingkeith provided in his post. Not sure what you were doing instead…

0 Likes

#7

Actually I think that the menu command as provided always wraps at 80 regardless of what your wrap is currently set to.

In any case, if you’re going to do the same thing on a regular basis, you can perhaps get away with a macro. For example, if you save the following as Packages\User\RewrapAndQuote.sublime-macro:

[
	{ "command": "select_all"},
	{ "command": "wrap_lines", "args": {"width": 78 } },
	{ "command": "select_all"},
	{ "command": "split_selection_into_lines"},
	{ "command": "move_to", "args": {"extend": false, "to": "bol"} },
	{ "command": "insert",  "args": {"characters": "> "} },
	{ "command": "single_selection"}
]

You can execute it from the menu via Tools > Macros > User > RewrapAndQuote or make a key binding that will do it for you:

    {
        "keys": ["ctrl+enter"],
        "command": "run_macro_file", "args": {"file": "res://Packages/User/RewrapAndQuote.sublime-macro"}
    },

Note that since I am a purist, this wraps at 78 instead of 80 because the quote characters inserted takes up 2 characters and I am a grumpy old man; that may or may not be something you need/require. :wink:

As defined, this selects all of the text in the view and operates on it. If that’s not desirable, you can replace the two instances of select_all with expand_selection_to_paragraph instead, and then the menu item or key binding will operate on the current paragraph, allowing you to use it inside of any document.

4 Likes

#8

Ah, okay, that makes more sense then.

0 Likes