在 SciTE 中重新格式化 80 列文本(或者更好的是 LaTeX)

发布于 2024-09-10 23:02:19 字数 447 浏览 4 评论 0原文

我最近在 Lix 这样的所见即所得编辑器的帮助下开始研究 LaTeX。现在我开始在 Sci-TE 中编写 tex 文件,它已经具有语法高亮显示,并且我调整了 tex.properties 文件以在 Windows 中工作,显示 Go 上的预览 [F5]

Lyx 做了一件漂亮的事情,但很难用它来实现一个常见的文本编辑器,是将文本格式化为 80 列:我可以写一个段落,每次到达边缘列附近时都按回车键,但如果在初稿之后,我想在这里或那里添加或删除一些单词,我就会结束打破布局并必须重新排列换行符。

在 Sci-TE 中拥有一个工具会很有用,这样我就可以选择添加或删除了一些单词的文本段落,并将其重新排列为 80 列。可能不适用于整个文档,因为它可能会破坏一些预期的换行符。

也许我可以轻松地为 geany 编写一个 Python 插件,我看到 vim 有类似的东西,但我想知道它是否' 在 Sci-TE 中也是可能的。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

仲春光 2024-09-17 23:02:19

当我在寻找相同的答案时没有找到答案,我感到有点失望。 Google 也没有帮助程序,所以我搜索了 Lua 示例和语法,希望自己制作它。我不了解 Lua,所以这也许可以以不同的方式或有效地进行,但它比我希望的没有更好 - 这是需要放入 SciTE 启动 Lua 脚本中的 Lua 函数:

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

用法与启动时的任何其他函数一样脚本,但为了完整性,我将从 SciTE 属性文件中粘贴我的工具定义:

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

它确实尊重段落,因此它可以用于更广泛的选择,而不仅仅是一个段落。

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.

神也荒唐 2024-09-17 23:02:19

这是在 scite 中执行此操作的一种方法:首先,将其添加到您的 .SciTEUser.properties (选项/打开用户选项文件):

# 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

...并保存,这样您就可以在 80 处看到一行人物。

然后缩放 scite 窗口,以便您看到的文本自动换行。

最后,选择要分成行的长行文本,然后执行编辑/段落/拆分(对我来说,快捷键 Ctrl-K 也适用于此)。

不幸的是,scite 中似乎没有“break-lines-as-you-type”功能,如 geany 中的“换行”功能。< /s> 不再是了,现在有一个插件 - 请参阅这个答案

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

假面具 2024-09-17 23:02:19

好吧,我相当失望 scite 中似乎没有“break-lines-as-you-type”设施< /代码>;我最终成功地为此编写了一个小型 Lua 插件/附加组件/扩展,并将其发布在这里:

安装和使用说明在脚本本身中。以下是正确安装扩展并在启动后激活切换后 SciTE 的外观:

SciteLineBreak.png

请注意,它几乎是这样与 geany 中的功能相同 - 它在键入文本时插入换行符 - 但不在按退格键或复制/粘贴时插入换行符。

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.

三五鸿雁 2024-09-17 23:02:19

相同但更容易,我认为......

将其放入用户属性中:

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

Ciao
彼得罗

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文