Scite 设置等宽字体 |
|
MakeMonospace
,用户不再需要按 Ctrl+F11。
通过添加一些代码,可以自动将某些文件类型以等宽字体打开。这将允许在混合等宽字体和比例字体环境中使用,而无需一直按 Ctrl+F11。
该脚本通过覆盖默认的样式属性,将缓冲区强制设置为等宽模式。它使用 extman
来挂钩到 OnSwitchFile
。
----------------------------------------------------------------------- -- makes a buffer monospace <[email protected]> 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)
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