Scite 比較檔案

lua-users home
wiki

此指令碼允許您使用外部工具(例如 Meld)來比較選定的檔案。您需要使用功能表命令選取 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 指令將 compare_files.lua 含到您的 Lua 啟動指令碼中。

--Andrey Moskalev--


最近異動 · 偏好設定
編輯 · 歷程記錄
上次編輯時間:2021 年 2 月 11 日下午 9:38 GMT (diff)