Scite Make Monospace

lua-users home
wiki

這個腳本的運作方式就像 Ctrl+F11(使用等寬字型),但可以由 Lua 腳本呼叫。需要 SciteExtMan。如果使用者要使用需要等寬模式的腳本(例如 SciteTicTacToe),但在其他時候使用比例字型,這個腳本就很方便。只要在初始化需要等寬字型的腳本後立即執行 MakeMonospace,使用者就不用再按 Ctrl+F11 了。

只要再寫一點程式碼,就能自動讓某些類型的檔案以等寬字型開啟。這樣就能建立一個混和等寬字型和比例字型的環境,而不用一直按 Ctrl+F11。

這個腳本會覆寫一般的樣式屬性,強制一個緩衝區採用等寬模式。它使用 extman 掛勾到 OnSwitchFile


-----------------------------------------------------------------------
-- makes a buffer monospace <khman@users.sf.net> public domain 20060906
-----------------------------------------------------------------------
-- [[
scite_Command('Make Monospace|MakeMonospace|Ctrl+8')

function MakeMonospace()
  local MonoFont, MonoSize = "Courier New", 9
  local SIG = "MakeMonospace"
  local function AllMono()
    for i = 0, 127 do
      editor.StyleFont[i] = MonoFont
      editor.StyleSize[i] = MonoSize
    end
    editor:Colourise(0, -1)
  end
  scite_OnSwitchFile(function() if buffer[SIG] then AllMono() return true end end)
  buffer[SIG] = true
  AllMono()
end
--]]


如果你要從目前編輯器屬性取得等寬字型名稱和大小,可以新增下列內容

  -- retrieve monospace font information
  local StyleMono = {}
  local monoprop = props["font.monospace"]
  for style, value in string.gfind(monoprop, "([^,:]+):([^,]+)") do
    StyleMono[style] = value
  end
  -- grab styles, assuming they are defined
  MonoFont = StyleMono.font
  MonoSize = tonumber(StyleMono.size)


如果你只是要 Scite 讓所有新緩衝區都以等寬模式開始,試著這樣做(需要 SciteExtMan

function ToggleMonospace()
    scite.MenuCommand(450)
    return false
end

scite_OnOpen(ToggleMonospace)

若要確保新建立的檔案以等寬模式開始,試著這樣做

function ToggleMonospace()
  -- the buffer table is provided for user data
  if buffer and not buffer["MadeMonospace"] then
    scite.MenuCommand(IDM_MONOFONT)
    buffer["MadeMonospace"] = true
  end
end

function OpenMonospace(filename) 
  if filename ~= "" then 
    ToggleMonospace()
  end
end

-- OnOpen event (with empty filename) is generated when SciTE starts
--  with new file, but not when File->New creates another new file tab.
scite_OnOpen(OpenMonospace)  -- for opening existing file
scite_OnSavePointLeft(ToggleMonospace) -- first character typed in new file

最近變更 · 偏好設定
編輯 · 歷程
上次編輯:2010 年 3 月 9 日,上午 6 點 49 分(格林威治標準時間)(diff)