diff --git a/frontend/apps/reader/modules/readerdictionary.lua b/frontend/apps/reader/modules/readerdictionary.lua index b1a57dfc6..258938fad 100644 --- a/frontend/apps/reader/modules/readerdictionary.lua +++ b/frontend/apps/reader/modules/readerdictionary.lua @@ -811,7 +811,7 @@ function ReaderDictionary:startSdcv(word, dict_names, fuzzy_search) end end - lookup_cancelled, results = self:rawSdcv(words, dict_names, fuzzy_search, self.lookup_progress_msg or false) + local lookup_cancelled, results = self:rawSdcv(words, dict_names, fuzzy_search, self.lookup_progress_msg or false) if results == nil then -- no dictionaries found return { { diff --git a/frontend/languagesupport.lua b/frontend/languagesupport.lua index ee9906b1d..38d732a1c 100644 --- a/frontend/languagesupport.lua +++ b/frontend/languagesupport.lua @@ -20,7 +20,6 @@ knowledge may be necessary (such as during text selection and dictionary lookup of a text fragment). ]] -local UIManager = require("ui/uimanager") local WidgetContainer = require("ui/widget/container/widgetcontainer") local dbg = require("dbg") local logger = require("logger") @@ -115,8 +114,8 @@ local function callPlugin(plugin, handler_name, ...) return end -- Handler could return any number of values, collect them all. - ret = {pcall(handler, plugin, ...)} - ok = table.remove(ret, 1) + local ret = {pcall(handler, plugin, ...)} + local ok = table.remove(ret, 1) if not ok then logger.err("language plugin", plugin, "crashed during", handler_name, "handler:", unpack(ret)) return @@ -130,7 +129,7 @@ function LanguageSupport:_findAndCallPlugin(language_code, handler_name, ...) for name, plugin in pairs(self.plugins) do if plugin:supportsLanguage(language_code) then logger.dbg("language support: trying", name, "plugin's", handler_name) - ret = callPlugin(plugin, handler_name, ...) + local ret = callPlugin(plugin, handler_name, ...) if ret ~= nil then return unpack(ret) end @@ -143,7 +142,7 @@ function LanguageSupport:_findAndCallPlugin(language_code, handler_name, ...) for name, plugin in pairs(self.plugins) do if not plugin:supportsLanguage(language_code) then logger.dbg("language support (fallback): trying", name, "plugin's", handler_name) - ret = callPlugin(plugin, handler_name, ...) + local ret = callPlugin(plugin, handler_name, ...) if ret ~= nil then return unpack(ret) end @@ -195,14 +194,14 @@ function LanguageSupport:improveWordSelection(selection) return end - language_code = self.document:getProps().language or "unknown" + local language_code = self.document:getProps().language or "unknown" logger.dbg("language support: improving", language_code, "selection", selection) -- Rather than requiring each language plugin to use document: methods -- correctly, return a set of callbacks that are document-agnostic (and -- have the document handle as an upvalue of the closure) and could be used -- for non-EPUB formats in the future. - callbacks = createDocumentCallbacks(self.document) + local callbacks = createDocumentCallbacks(self.document) if not callbacks then return end @@ -251,7 +250,7 @@ end function LanguageSupport:extraDictionaryFormCandidates(text) if not self:hasActiveLanguagePlugins() then return end -- nothing to do - language_code = self.document and self.document:getProps().language or "unknown" + local language_code = self.document and self.document:getProps().language or "unknown" logger.dbg("language support: convert", text, "to dictionary form (marked as", language_code..")") return self:_findAndCallPlugin( @@ -263,16 +262,17 @@ end function LanguageSupport:addToMainMenu(menu_items) if not self:hasActiveLanguagePlugins() then return end -- nothing to do - local sub_table = {} - -- Sort the plugin keys so we have consistent ordering in the menu. local plugin_names = {} for name in pairs(self.plugins) do table.insert(plugin_names, name) end table.sort(plugin_names) + + -- Link up each plugin's submenu. + local sub_table = {} for _, name in ipairs(plugin_names) do - plugin = self.plugins[name] + local plugin = self.plugins[name] if plugin.genMenuItem ~= nil then local menuItem = plugin:genMenuItem() -- Set help_text in case the plugin hasn't. @@ -281,8 +281,8 @@ function LanguageSupport:addToMainMenu(menu_items) end table.insert(sub_table, menuItem) else - -- A basic fallback menu, showing a description of the plugin when - -- tapped (if supplied). + -- Plugin didn't have a menu defined so use a basic fallback menu, + -- showing a description of the plugin when held for help. table.insert(sub_table, { text = plugin.pretty_name or plugin.fullname or name, help_text = plugin.description, diff --git a/frontend/util.lua b/frontend/util.lua index c298a4f70..99779e953 100644 --- a/frontend/util.lua +++ b/frontend/util.lua @@ -601,7 +601,7 @@ function util.isCJKChar(c) if #c < 3 then return false end - code = BaseUtil.utf8charcode(c) + local code = BaseUtil.utf8charcode(c) -- The weird bracketing is intentional -- we use the lowest possible -- codepoint as a shortcut so if the codepoint is below U+1100 we -- immediately return false. diff --git a/plugins/japanese.koplugin/deinflector.lua b/plugins/japanese.koplugin/deinflector.lua index 72b3a9dd0..68db9b323 100644 --- a/plugins/japanese.koplugin/deinflector.lua +++ b/plugins/japanese.koplugin/deinflector.lua @@ -37,7 +37,7 @@ local RULE_TYPES = { } local function toRuleTypes(...) - final = 0 + local final = 0 for _, ruleType in ipairs({...}) do if RULE_TYPES[ruleType] then final = bit.bor(final, RULE_TYPES[ruleType]) @@ -102,7 +102,7 @@ function Deinflector:deinflectVerbatim(text) -- Check if we've already found this deinflection. If so, -- that means there was a shorter reason path to it and -- this deinflection is almost certainly theoretical. - new_term = current.term:sub(1, -#rule.kanaIn-1) .. rule.kanaOut + local new_term = current.term:sub(1, -#rule.kanaIn-1) .. rule.kanaOut if not seen[new_term] then table.insert(results, makeDeinflectionResult( new_term, @@ -435,14 +435,14 @@ function Deinflector:init() DEFAULT_TEXT_CONVERSIONS if self.rules ~= nil then return end -- already loaded - --- @todo Maybe make this location configurable? - inflections = parsePluginJson("yomichan-deinflect.json") + --- @todo Maybe make this location configurable or look in the user-controlled data directory too? + local inflections = parsePluginJson("yomichan-deinflect.json") -- Normalise the reasons and convert the rules to the rule_types bitflags. self.rules = {} local nrules, nvariants = 0, 0 for reason, rules in pairs(inflections) do - variants = {} + local variants = {} for i, variant in ipairs(rules) do variants[i] = { kanaIn = variant.kanaIn, diff --git a/plugins/japanese.koplugin/main.lua b/plugins/japanese.koplugin/main.lua index 37d873b5a..8d544c5e6 100644 --- a/plugins/japanese.koplugin/main.lua +++ b/plugins/japanese.koplugin/main.lua @@ -19,11 +19,9 @@ -- together in order to reduce the impact we have on text selection. local Deinflector = require("deinflector") -local InfoMessage = require("ui/widget/infomessage") local LanguageSupport = require("languagesupport") local ReaderDictionary = require("apps/reader/modules/readerdictionary") local UIManager = require("ui/uimanager") -local JSON = require("json") local WidgetContainer = require("ui/widget/container/widgetcontainer") local logger = require("logger") local util = require("util") @@ -77,7 +75,7 @@ function Japanese:onWordLookup(args) -- extra work to be efficient (since we need to remove the last -- character in the string). - results = self.deinflector:deinflect(text) + local results = self.deinflector:deinflect(text) logger.dbg("japanese.koplugin: deinflection of", text, "results:", results) --- @todo Pass up the reasons list (formatted Yomichan style) to the @@ -86,7 +84,7 @@ function Japanese:onWordLookup(args) -- metadata that we have to pass through from the lookup to the -- dictionary pop-up. - candidates = {} + local candidates = {} for i, result in ipairs(results) do candidates[i] = result.term end @@ -112,7 +110,6 @@ end -- @see languagesupport.improveWordSelection -- @see languagesupport.registerPlugin function Japanese:onWordSelection(args) - local pos0, pos1 = args.pos0, args.pos1 local callbacks = args.callbacks local current_text = args.text @@ -128,7 +125,7 @@ function Japanese:onWordSelection(args) -- We reset the end of the range to pos0+1 because crengine will select -- half-width katakana (カタカナ) in strange ways that often overshoots the -- end of words. - pos1 = callbacks.get_next_char_pos(pos0) + local pos0, pos1 = args.pos0, callbacks.get_next_char_pos(args.pos0) -- We try to advance the end position until we hit a word. --