4

I recently dived into LaTeX, starting with the help of a WYSIWYM editor like Lix. Now I'm staring writing tex files in Sci-TE, It already has syntax higlighting and I adapted the tex.properties file to work in Windows showing a preview on Go [F5]

One pretty thing Lyx does, and it's hard to acheive with a common text editor, is to format text in 80 columns: I can write a paragraph and hit Return each time I reach near the edge column but if, after the first draft, I want to add or cut some words here and there I end up breaking the layout and having to rearrange newlines.

It would be useful to have a tool in Sci-TE so I can select a paragraph of text I added or deleted some words in and have it rearranged in 80 columns. Probably not something working on the whole document since it could probably break some intended anticipated line break.

Probably I could easily write a Python plugin for geany, I saw vim has something similar, but I'd like to know if its' possible in Sci-TE too.

neurino
  • 11,500
  • 2
  • 40
  • 63

4 Answers4

5

I was a bit disappointed when I found no answer as I was searching for same. No helpers by Google either, so I searched for Lua examples and syntax in a hope to craft it myself. I don't know Lua so this can perhaps be made differently or efficiently but its better then nothing I hope - here is Lua function which needs to be put in SciTE start-up Lua script:

function wrap_text()

    local border = 80
    local t = {}

    local pos = editor.SelectionStart
    local sel = editor:GetSelText()
    if #sel == 0 then return end

    local para = {}
    local function helper(line) table.insert(para, line) return "" end
    helper((sel:gsub("(.-)\r?\n", helper)))

    for k, v in pairs(para) do
        line = ""
        for token in string.gmatch(v, "[^%s]+") do
            if string.len(token .. line) >= border then
                t[#t + 1] = line
                line = token .. " "
            else
                line = line .. token .. " "
            end
        end
        t[#t + 1] = line:gsub("%s$", "")
    end

    editor:ReplaceSel(table.concat(t, "\n"))
    editor:GotoPos(pos)

end

Usage is like any other function from start-up script, but for completness I'll paste my tool definition from SciTE properties file:

command.name.8.*=Wrap Text
command.mode.8.*=subsystem:lua,savebefore:no,groupundo
command.8.*=wrap_text
command.replace.selection.8.*=2

It does respect paragraphs, so it can be used on broader selection, not just one paragraph.

theta
  • 24,593
  • 37
  • 119
  • 159
  • Thanks, I accept the answer but have no way to test it now since I switched to Linux and Geany editor has a nice shortcut for that, preserving indentation and paragraphs. It will be helpful if I need to switch back to Windows in the future. Cheers. – neurino Jan 14 '12 at 20:39
  • Indentation (space between beginning of line and paragraph start) is not preserved. It just reformats in plain way based on looping over words length. BTW, I'm using latest SciTE 3.02 on Linux. Geany is nice too, but I use SciTE both on Windows and Linux – theta Jan 15 '12 at 06:47
3

This is one way to do it in scite: first, add this to your .SciTEUser.properties (Options/Open User Options file):

# Column guide, indicates long lines (https://wiki.archlinux.org/index.php/SciTE)
# this is what they call "margin line" in gedit (at right),
# in scite, "margin" is the area on left for line numbers
edge.mode=1
edge.column=80

... and save, so you can see a line at 80 characters.

Then scale the scite window, so the text you see is wrapped at the line.

Finally, select the long line text which is to be broken into lines, and do Edit / Paragraph / Split (for me the shortcut Ctrl-K also works for that).

Unfortunately, there seems to be no "break-lines-as-you-type" facility in scite, like the "Line Breaking" facility in geany. not anymore, now there's a plugin - see this answer

Community
  • 1
  • 1
sdaau
  • 36,975
  • 46
  • 198
  • 278
2

Well, I was rather disappointed that there seems to be no "break-lines-as-you-type" facility in scite; and I finally managed to code a small Lua plugin/add-on/extension for that, and released it here:

Installation and usage instructions are in the script itself. Here is how SciTE may look when the extension properly installed, and toggle activated after startup:

SciteLineBreak.png

Note that it's pretty much the same functionality as in geany - it inserts linebreaks upon typing text - but not on pressing backspace, nor upon copy/pasting.

Community
  • 1
  • 1
sdaau
  • 36,975
  • 46
  • 198
  • 278
  • 3
    In `geany` it's quite less automatic: you have a menu option (and a kyb shortcut) that reformats selected text o paragraph, nothing more. Anyway it's quite enough as you don't have to care how the text is inserted: when you're done with editing the block you `Ctrl-J` it and that's all. – neurino Apr 08 '13 at 07:24
  • 1
    Note site linked in the answer contains a (dead) link to the script on Soruceforge. Sourceforge has changed their site quite a bit since this was posted, so the URL for the script has changed. It now lives here: https://sourceforge.net/p/sdaaubckp/code/HEAD/tree/extensions/scite/SciTELineBreak.lua – Kevin Horn Jul 28 '22 at 16:01
1

the same but more easy, I think...

put this in the user properties:

command.name.0.*=swrap
command.0.*=fold -s $(FileNameExt) > /tmp/scite_temp ; cat /tmp/scite_temp >$(FileNameExt)
command.is.filter.0.*=1

Ciao Pietro

Pietro
  • 11
  • 1
  • 1
    Ciao Pietro, as far as I know fold, cat and file redirection will not work in Windows... Nice for linux anyway :) – neurino Jan 15 '12 at 22:28