Scite 编号书签 |
|
这是一个使用 Scintilla 创建带有字符的自定义书签的示例,以及如何使用 `OnOpen` 和 `OnSwitchFile` 在每个文件的基础上管理对象。
此脚本使用 SciteExtMan 加载器以方便起见,但我希望它应该清楚如何使用直接的 SciTE/Lua 脚本进行操作。
-- borland.lua -- Defines borland-style numbered bookmarks. -- Put this in your extman scite_lua directory. scite_Command { 'ctrl-k|do_ctrl_command k|Ctrl+K', 'ctrl-q|do_ctrl_command q|Ctrl+Q', } local gMarksMap = {} local gMarks scite_OnOpen(function(f) gMarksMap[f] = {} end) scite_OnSwitchFile(function(f) gMarks = gMarksMap[f] end) function current_line() return editor:LineFromPosition(editor.CurrentPos)+1 end local markers_defined = false local base = 9 function define_markers() local zero = string.byte('0') for i = 1,9 do editor:MarkerDefine(i+base,SC_MARK_CHARACTER + zero + i) end markers_defined = true end function do_ctrl_command(key) editor:BeginUndoAction() scite_OnChar('once',function (ch) editor:EndUndoAction() editor:Undo() local num = tonumber(ch) local mark = num and gMarks[num] local line = current_line() if key == 'k' and num then if not markers_defined then define_markers() end if mark then -- clear mark gMarks[num] = nil editor:MarkerDelete(line-1,num+base) else gMarks[num] = line editor:MarkerAdd(line-1,num+base) end elseif key == 'q' and mark then editor:GotoLine(mark-1) end return true end) end