Scite 客製化摺疊

lua-users home
wiki

遞迴摺疊或展開檔案。通常,按一下摺疊不會遞迴摺疊和展開。按住 Ctrl 再按一下摺疊才會遞迴摺疊和展開。不過,如果你想要限制摺疊深度,你需要使用下列 Lua 腳本作為替換。


-- toggle folds, with customizable fold range
-- khman 20060117, public domain
function FoldSome()
  local FOLDSTART = 1024        -- level to start folding (from 1024)
  local FOLDDEPTH = 3           -- fold depth; comment out if no limit
  --------------------------------------------------------------------
  local FOLDEND = FOLDSTART + (FOLDDEPTH or 9999)
  if FOLDEND <= FOLDSTART or FOLDEND > 4096 then FOLDEND = 4096 end
  local start, ending, hide
  editor:Colourise(0, -1)       -- update doc's folding info
  for ln = 0, editor.LineCount - 1 do
    local foldRaw = editor.FoldLevel[ln]
    local foldLvl = math.mod(foldRaw, 4096)
    local foldHdr = math.mod(math.floor(foldRaw / 8192), 2) == 1
    -- fold if within limits and is a fold header
    if foldHdr and foldLvl >= FOLDSTART and foldLvl < FOLDEND then
      local expanded = editor.FoldExpanded[ln]
      if foldLvl == FOLDSTART and not start then -- start fold block
        -- fix a hide/show setting for whole doc, for consistency
        if hide == nil then hide = expanded end
        start = ln + 1 -- remember range
        ending = editor:GetLastChild(ln, foldLvl)
      end
      editor.FoldExpanded[ln] = not hide
    end
    -- if end of block, perform hide or show operation
    if start and ln == ending then
      if hide then
        editor:HideLines(start, ending)
      else
        editor:ShowLines(start, ending)
      end
      start, ending = nil, nil
    end
  end--for
end


RecentChanges · 偏好設定
編輯 · 歷程
最近編輯時間:2006 年 8 月 31 日 下午 8:35 GMT (diff)