Scite 比较文件

lua-users home
wiki

此脚本允许您使用 Meld 等外部工具比较选定的文件。您需要通过菜单命令 Tools > Add File to Comparison 来选择 2 个文件。在选择第二个文件后,外部比较程序会自动打开。

将以下代码放入文件 compare_files.lua

-- -*- coding: utf-8 -*-

local f1, f2
local diffTool
local cmdNum = 48       -- menu commands occupy the last 2 slots

if props["PLAT_WIN"] == "1" then
    diffTool = 'start /b C:\\"Program Files (x86)"\\Meld\\Meld.exe -n %q %q'
else
    diffTool = "meld -n %q %q &"
end

local function setMenuCommands()
    local which

    which = "."..cmdNum..".*"
    props["command.name"..which] = f1 and "Add File to Comparison (1)"
                                      or "Add File to Comparison (0)"
    props["command.subsystem"..which] = 3
    props["command"..which] = "addFileToComparison"
    props["command.mode"..which] = "savebefore:no"
    props["command.shortcut"..which] = ""

    which = "."..(cmdNum+1)..".*"
    props["command.name"..which] = f1 and "Reset File Comparison" or ""
    props["command.subsystem"..which] = 3
    props["command"..which] = "resetFileComparison"
    props["command.mode"..which] = "savebefore:no"
    props["command.shortcut"..which] = ""
end

function addFileToComparison()
    if props["FileNameExt"] ~= "" then
        if f1 then
            f2 = props["FilePath"]
            if f2 ~= f1 then
                local exec = diffTool:format(f1, f2)
                resetFileComparison()
                os.execute(exec)
            else
                f2 = nil
                print("Error: Same file selected")
            end
        else
            f1 = props["FilePath"]
            setMenuCommands()
        end
    else
        print("Error: File not saved")
    end
end

function resetFileComparison()
    f1 = nil
    f2 = nil
    setMenuCommands()
end

setMenuCommands()

之后,使用 dofile 命令在您的 Lua 启动脚本中包含 compare_files.lua

-- Andrey Moskalev --


RecentChanges · preferences
编辑 · 历史
最后编辑于 2021 年 2 月 11 日 下午 3:38 GMT (差异)