Mechanism to Monkey Patch core files? #433
-
Hi, I have been playing with some alterations to the core lua files which define Textadept. e.g. -- TextAdept\core\ui.lua:269
-- Change title format
local function set_title()
local filename = buffer.filename or buffer._type or _L['Untitled']
if buffer.filename then
filename = select(2, pcall(string.iconv, filename, 'UTF-8', _CHARSET))
end
local basename = buffer.filename and filename:match('[^/\\]+$') or filename
-- **
ui.title = string.format('Textadept %s %s', filename:gsub([[\\]],[[\]]), buffer.modify and '*' or '-' )
--**
buffer.tab_label = basename..(buffer.modify and '*' or '')
end and -- TextAdept\core\file_io.lua:304
-- Use textredux
function io.open_recent_file()
local utf8_list = {}
for i = 1, #io.recent_files do
utf8_list[#utf8_list + 1] = io.recent_files[i]:iconv('UTF-8', _CHARSET)
end
local results_list = textredux.core.list.new('Open Recent File')
results_list.search_fuzzy = true
results_list.column_styles = {
textredux.core.style.string,
textredux.core.style.string
}
results_list.headers = {
'Files'
}
results_list.items = utf8_list
results_list.on_selection = function(list, item)
io.open_file(item)
results_list:close()
end
results_list:show()
end and -- TextAdept\modules\textredux\util\matcher.lua:95
-- Modifiy to only sort results if search_fuzzy=true
-- see https://github.com/rgieseke/textredux/issues/31
function M:match(search)
if not search or #search == 0 then return self.candidates end
local cache = self.cache
if self.search_case_insensitive then search = search:lower() end
local matches = cache.matches[search] or {}
if #matches > 0 then return matches end
local lines = cache.lines[string.sub(search, 1, -2)] or self.lines
local matchers = self:_matchers_for_search(search)
local matching_lines = {}
for _, line in ipairs(lines) do
local score = match_score(line.text, matchers)
if score then
matches[#matches + 1] = { index = line.index, score = score }
matching_lines[#matching_lines + 1] = line
end
end
cache.lines[search] = matching_lines
-- **
if self.search_fuzzy then
table.sort(matches, function(a ,b) return a.score < b.score end)
end
-- **
local matching_candidates = {}
for _, match in ipairs(matches) do
matching_candidates[#matching_candidates + 1] = self.candidates[match.index]
end
self.cache.matches[search] = matching_candidates
return matching_candidates
end I have previously done this all manually, not good when I download new releases! I would like to make more alterations, but need a system to apply these to new releases. The very reasonable advice to keep most module functions local, seems to prevent me from redefining them?
Kind Regards Gavin Holt PS I do not have, nor want; a compiler, GIT, VS Code, Electron anything! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
For Lines 269 to 274 in 19cfa3c Lines 355 to 361 in 19cfa3c All you have to do is connect to those events with your own For
Note that the latest nightly allows for this menu syntax. Previous versions of Textadept need the I don't know about your |
Beta Was this translation helpful? Give feedback.
For
set_title()
, just take a look and see what event is calling it. For the latest nightly, it's 5 events:textadept/core/ui.lua
Lines 269 to 274 in 19cfa3c
textadept/core/ui.lua
Lines 355 to 361 in 19cfa3c