diff --git a/scripts/LuaSpell/LuaSpell.lua b/scripts/LuaSpell/LuaSpell.lua
index 83e8856..21c08da 100644
--- a/scripts/LuaSpell/LuaSpell.lua
+++ b/scripts/LuaSpell/LuaSpell.lua
@@ -1,4 +1,5 @@
---[[ LuaSpell ]]--
+-- Based on http:// forum.farmanager.com/viewtopic.php?p=118520#p118520
+--[[ LuaSpell ]]--
----------------------------------------
--[[ description:
@@ -33,11 +34,11 @@
По умолчанию макрос настроен на словари
ru_RU_yo и en_US (нужны файлы aff и dic).
3. Конфигурация:
- файл конфигурации макроса — ~%FARPROFILE%\data\macros\LuaSpell.cfg~.
+ файл конфигурации макроса — ~%FARPROFILE%\data\macros\LuaSpell.cfg.lua~.
--]]
--------------------------------------------------------------------------------
-----------------------------------------
+--[[--------------------------------------
local useprofiler = false
--local useprofiler = true
@@ -46,12 +47,7 @@ if useprofiler then
require "profiler" -- Lua Profiler
actprofiler = false
end
-
-----------------------------------------
-local tostring = tostring
-
-----------------------------------------
-local regex = regex
+]]----------------------------------------
local F = far.Flags
local Flag4BIT = bit64.bor(F.FCF_FG_4BIT, F.FCF_BG_4BIT)
@@ -78,7 +74,7 @@ local function ExpandEnv (s)
end
---------------------------------------- config
-local CfgNameFmt = [[%%FARPROFILE%%\%s\%s\%s.cfg]]
+local CfgNameFmt = [[%%FARPROFILE%%\%s\%s\%s.cfg.lua]]
local CfgName = CfgNameFmt:format(win.GetEnv("FARUSERDATADIR") or "data",
"macros", unit.ScriptName)
local DictionaryPath = [[%FARPROFILE%\Dictionaries\]]
@@ -99,17 +95,19 @@ local DefCfgData = {
CharsSet = CharsSet, -- Множество допустимых символов
-- для проверки на наличие слова:
- InnerSet = CharsSet.."$", -- - в конце строке
- StartSet = "^"..CharsSet, -- - в начале строке
+ InnerSet = CharsSet.."$", -- - в конце строки
+ StartSet = "^"..CharsSet, -- - в начале строки
CheckSet = "/\\b"..CharsSet.."\\b/", -- - в середине строки
BoundSet = "\\S*", -- - с граничными символами
ColorPrio = 199, -- Приоритет раскрашивания
+ ShowEmptyList = false, -- Показывать ли пустой список предположений
MacroKeys = { -- Клавиши для макросов:
CheckSpell = "CtrlF12", -- - проверка текущего слова
- Misspelling = "ShiftF12", -- - переход на следующее ошибочное слово
- SwitchCheck = "CtrlShiftF12", -- - переключение подсветки ошибочных слов
+ NextMisspelling = "ShiftF12", -- - переход на следующее ошибочное слово
+ PrevMisspelling = "LCtrlShiftF12", -- - переход на предыдущее ошибочное слово
+ SwitchCheck = "LCtrlLAltF12", -- - переключение подсветки ошибочных слов
UnloadSpell = "LCtrlLAltShiftF12", -- - завершение проверки (выгрузка)
},
@@ -138,7 +136,7 @@ local DefCfgData = {
-- при обнаружении слова в словаре
},
{ -- Word list
- Type = "WordList", -- Тип
+ Type = "WordList", -- Тип
WordType = "disabled", -- Тип слов: запрещённый
StrToPath = false,
path = UserDictPath,
@@ -212,6 +210,8 @@ local function CreateMain (ArgData)
end
if not config then config = {} end
+ local _,_ = ArgData,serror
+
setmetatable(config, { __index = DefCfgData })
local n = #config
@@ -261,24 +261,17 @@ function unit.StrToStr (s)
return s
end ---- StrToStr
-do
- local AnsiCP
- local WCtoMB = win.WideCharToMultiByte
- local U8toU16 = win.Utf8ToUtf16
-
function unit.StrToAnsi (s)
- if not AnsiCP then AnsiCP = win.GetACP() end
- return WCtoMB(U8toU16(s), AnsiCP)
+ return win.WideCharToMultiByte(win.Utf8ToUtf16(s), win.GetACP())
end ---- StrToAnsi
-end -- do
---------------------------------------- Hunspell
local hunspell = require "hunspell"
-local function NewHunspell (k, v)
+local function NewHunspell (k_, v_)
if not hunspell then return false end
-
- local v = v
+
+ local _,v = k_,v_
--local handle, text = hunspell.new(v.affpath, v.dicpath, nil)
local handle, text = hunspell.new(v.StrToPath(v.affpath),
v.StrToPath(v.dicpath), nil)
@@ -290,8 +283,8 @@ local function NewHunspell (k, v)
return false
end -- NewHunspell
-function unit.InitHunspell (k)
- local k = k
+function unit.InitHunspell (k_)
+ local k = k_
local v = config[k]
local Path = v.path or config.Path
@@ -323,10 +316,10 @@ end ---- InitHunspell
---------------------------------------- UserDict
local userdict = require "userdict"
-local function NewUserDict (k, v)
+local function NewUserDict (k_, v_)
if not userdict then return false end
-
- local v = v
+
+ local _,v = k_,v_
--local handle, text = hunspell.new(v.affpath, v.dicpath, nil)
local handle, text = userdict.new(v)
if handle then return handle end
@@ -337,8 +330,8 @@ local function NewUserDict (k, v)
return false
end -- NewUserDict
-function unit.InitUserDict (k)
- local k = k
+function unit.InitUserDict (k_)
+ local k = k_
local v = config[k]
local Path = v.path or config.Path
@@ -373,8 +366,6 @@ end ---- InitUserDict
---------------------------------------- Dictionary
-local tostring = tostring
-
function unit.InitDictionary (k)
local v = config[k]
--local Path = config.Path
@@ -430,8 +421,8 @@ function unit.FreeDictionary (k)
end
end ---- FreeDictionary
-function unit.Add_Dics (k)
- local k = k
+function unit.Add_Dics (k_)
+ local k = k_
local v = config[k]
local h = v.handle
@@ -459,12 +450,12 @@ function unit.Add_Dics (k)
end
end -- Add_Dics
-function unit.Add_DirDics (k, path, mask, match, n)
+function unit.Add_DirDics (k_, path_, mask, match, n)
if not mask then
return
end
- local k = k
+ local k = k_
local v = config[k]
local h = v.handle
@@ -473,7 +464,7 @@ function unit.Add_DirDics (k, path, mask, match, n)
return
end
- local path = ExpandEnv(path or v.path or config.Path)
+ local path = ExpandEnv(path_ or v.path or config.Path)
return unit.Add_ByMask(path, mask, match, h, "", n)
end ---- Add_DirDics
@@ -489,7 +480,7 @@ function unit.Add_ByMask (path, mask, match, handle, key, n)
return
end
- local t = {}
+ --local t = {}
local dics = {}
local function HandleFile (item, fullname)
@@ -509,7 +500,7 @@ function unit.Add_ByMask (path, mask, match, handle, key, n)
far.RecursiveSearch(path:gsub("\\$", ""), "*", HandleFile, F.FRS_SCANSYMLINK)
--far.Show(unpack(t))
- for i, dic in ipairs(dics) do
+ for _,dic in ipairs(dics) do
--t[#t + 1] = dic.FullName
h:add_dic(dic.FullName, key, n)
end
@@ -517,9 +508,8 @@ function unit.Add_ByMask (path, mask, match, handle, key, n)
end ---- Add_ByMask
---------------------------------------- Work
-do
- local InitDictionary = unit.InitDictionary
- local FreeDictionary = unit.FreeDictionary
+local InitDictionary = unit.InitDictionary
+local FreeDictionary = unit.FreeDictionary
function unit.Init ()
if unit.Enabled then return end
@@ -541,7 +531,6 @@ function unit.Free ()
unit.Enabled = false
end ---- Free
-end
---------------------------------------- Find
-- from LF context (context\scripts\detectType.lua):
@@ -602,33 +591,28 @@ local function ShowMenu (strings, wordLen)
y = r + 2
h = info.WindowSizeY - y + 1 - menuOverheadHeight
h = math.min(h, #strings)
-
else
-- сверху
y = r - #strings - 1
if y < 1 then y = 1 end
h = r - y - 1
-
end
-- fix menu width
if (x + w + menuOverheadWidth) > info.WindowSizeX then
w = info.WindowSizeX - x - menuOverheadWidth
-
end
+ w = w + 1 -- чтобы самые длинные слова не упирались правым краем в рамку, будто усечённые
local Form = {
{ "DI_LISTBOX", 0, 0, w + 3, h + 1, Items, 0, 0, 0, "" }
}
- local function DlgProc (dlg, msg, param1, param2)
- end -- DlgProc
-
local hDlg = far.DialogInit(config.PopupGuid,
x, y,
x + w + 3,
y + h + 1,
- nil, Form, 0, DlgProc)
+ nil, Form)
local Index = far.DialogRun(hDlg) > 0 and
far.SendDlgMessage(hDlg, F.DM_LISTGETCURPOS, 1).SelectPos or nil
far.DialogFree(hDlg)
@@ -713,12 +697,12 @@ function unit.CheckSpell ()
if h.suggest and
(not h.spell or not h:spell(w)) then
local items = h:suggest(w)
- if #items > 0 then
+ if config.ShowEmptyList or #items > 0 then
local Index = ShowMenu(items, wLen)
if Index then
- local s = line:sub(1, spos - 1)..
- items[Index]..
- line:sub(spos + wLen)
+ s = line:sub(1, spos - 1)..
+ items[Index]..
+ line:sub(spos + wLen)
EditorSetLine(-1, 0, s, eol)
end
end
@@ -761,29 +745,17 @@ local function RemoveColors (id)
end -- RemoveColors
unit.RemoveColors = RemoveColors
-do
- local Far_WinCount = F.ACTL_GETWINDOWCOUNT
- local Far_WinInfo = F.ACTL_GETWINDOWINFO
- local WinType_Editor = F.WTYPE_EDITOR
-
function unit.RemoveAllColors ()
- local Count = far.AdvControl(Far_WinCount, 0, 0)
+ local Count = far.AdvControl(F.ACTL_GETWINDOWCOUNT, 0, 0)
for i = 1, Count do
- local Info = far.AdvControl(Far_WinInfo, i, 0)
- if Info and Info.Type == WinType_Editor then
+ local Info = far.AdvControl(F.ACTL_GETWINDOWINFO, i, 0)
+ if Info and Info.Type == F.WTYPE_EDITOR then
RemoveColors(Info.Id)
end
end
end ---- RemoveAllColors
-end -- do
-
-do
- local AddColor = editor.AddColor
- local Mark_Current = F.ECF_TABMARKCURRENT
-
-function unit.CheckSpellText (Info, action)
- local Info = Info
+function unit.CheckSpellText (Info, action_)
if not Info then return end
unit.Init()
@@ -802,7 +774,7 @@ function unit.CheckSpellText (Info, action)
v.masked = not v.masks or (checkValueOver(fname, v.masks) and true)
end
- local action = action or "all"
+ local action = action_ or "all"
local data
if action == "all" then
data = RemoveColors(id)
@@ -859,7 +831,7 @@ function unit.CheckSpellText (Info, action)
brim = line:sub(bpos, bend)
end
if brim ~= "" then
- local word = v.word
+ word = v.word
v.word = word..brim
matched = CheckMatch(v, fname, line, spos, l)
v.word = word
@@ -872,12 +844,11 @@ function unit.CheckSpellText (Info, action)
if isError and brim ~= "" then
isError = not h:spell(v.word..brim)
end
-
+
if isError then
if action == "all" then
if v.color then
- AddColor(id, l, spos, send,
- Mark_Current, v.color, prio, guid)
+ editor.AddColor(id, l, spos, send, F.ECF_TABMARKCURRENT, v.color, prio, guid)
end
elseif action == "next" then
@@ -907,11 +878,12 @@ function unit.CheckSpellText (Info, action)
return true
end ---- CheckSpellText
-end -- do
-
-function unit.Misspelling ()
+function unit.NextMisspelling ()
return unit.CheckSpellText(EditorGetInfo(), "next")
-end ---- Misspelling
+end
+function unit.PrevMisspelling ()
+ return unit.CheckSpellText(EditorGetInfo(), "prior")
+end
function unit.SwitchCheck ()
--far.Show"SwitchCheck"
@@ -932,14 +904,6 @@ end
---------------------------------------- Events
local CheckSpellText = unit.CheckSpellText
-do
- local EE_READ = F.EE_READ
- --local EE_SAVE = F.EE_SAVE
- local EE_CLOSE = F.EE_CLOSE
- local EE_GOTFOCUS = F.EE_GOTFOCUS
- --local EE_CHANGE = F.EE_CHANGE
- local EE_REDRAW = F.EE_REDRAW
-
local function reloadEditorConfig (id, kind) --| editors
--logShow({ "reset", editor.GetInfo() })
@@ -965,19 +929,19 @@ Event {
group = "EditorEvent",
description = "Check spell all",
- action = function (id, event, param)
- local eid = id
- if event == EE_READ then
+ action = function (eid, event, param)
+ local _ = param
+ if event == F.EE_READ then
reloadEditorConfig(eid, 'load')
- elseif event == EE_GOTFOCUS then
+ elseif event == F.EE_GOTFOCUS then
reloadEditorConfig(eid, 'focus')
-
- elseif event == EE_CLOSE then
+
+ elseif event == F.EE_CLOSE then
editors.current, editors[eid] = nil, nil
--if useprofiler and actprofiler then profiler.stop(); actprofiler = false end
- elseif event == EE_REDRAW then
+ elseif event == F.EE_REDRAW then
if config.Enabled then
CheckSpellText(EditorGetInfo(), "all")
end
@@ -993,7 +957,6 @@ Event {
action = unit.UnloadSpell,
} -- Event "ExitFAR"
-end -- do
---------------------------------------- Macros
if config.MacroKeys.CheckSpell then
Macro {
@@ -1013,12 +976,21 @@ Macro {
} ---
end
-if config.MacroKeys.Misspelling then
+if config.MacroKeys.NextMisspelling then
Macro {
area = "Editor",
- key = config.MacroKeys.Misspelling,
+ key = config.MacroKeys.NextMisspelling,
description = "LuaSpell: Next misspelling",
- action = unit.Misspelling,
+ action = unit.NextMisspelling,
+} ---
+end
+
+if config.MacroKeys.PrevMisspelling then
+Macro {
+ area = "Editor",
+ key = config.MacroKeys.PrevMisspelling,
+ description = "LuaSpell: Previous misspelling",
+ action = unit.PrevMisspelling,
} ---
end
@@ -1030,4 +1002,3 @@ Macro {
action = unit.UnloadSpell,
} ---
end
---------------------------------------------------------------------------------