summaryrefslogtreecommitdiff
path: root/tex/context/modules/mkxl/s-languages-goodies.lmt
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/modules/mkxl/s-languages-goodies.lmt')
-rw-r--r--tex/context/modules/mkxl/s-languages-goodies.lmt99
1 files changed, 99 insertions, 0 deletions
diff --git a/tex/context/modules/mkxl/s-languages-goodies.lmt b/tex/context/modules/mkxl/s-languages-goodies.lmt
new file mode 100644
index 000000000..7256fd35d
--- /dev/null
+++ b/tex/context/modules/mkxl/s-languages-goodies.lmt
@@ -0,0 +1,99 @@
+if not modules then modules = { } end modules ['s-languages-goodies'] = {
+ version = 1.001,
+ comment = "companion to s-languages-goodies.mkxl",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+moduledata.languages = moduledata.languages or { }
+moduledata.languages.goodies = moduledata.languages.goodies or { }
+
+function moduledata.languages.goodies.show(specification)
+ specification = interfaces.checkedspecification(specification)
+ local filename = specification.file
+ if filename and filename ~= "" then
+ local list = table.load(resolvers.findfile(filename))
+ if list then
+ list = list.options
+ if list then
+ for i=1,#list do
+ local l = list[i]
+ local w = l.words
+ if w then
+ local pre = l.prefixes
+ local suf = l.suffixes
+ context.startsubject { title = table.concat(table.sortedkeys(l.patterns)," ") }
+ context(languages.strippedgoodiewords(w))
+ if pre then
+ context.blank()
+ context.bold("prefixes: ")
+ context(languages.strippedgoodiewords(pre))
+ end
+ if suf then
+ context.blank()
+ context.bold("suffixes: ")
+ context(languages.strippedgoodiewords(suf))
+ end
+ context.stopsubject()
+ end
+ end
+ end
+ end
+ end
+end
+
+local lpegmatch = lpeg.match
+
+moduledata.languages.goodies.ligaturehandlers = { }
+
+function moduledata.languages.goodies.ligatures(specification)
+
+ specification = interfaces.checkedspecification(specification)
+ local language = specification.language
+ local filename = specification.file
+
+ if not language then
+ elseif moduledata.languages.goodies.ligaturehandlers[language] then
+ else
+ -- fb ff ffb fff ffh ffi ffj ffk ffl fft fi fk fl ft
+ local list = specification.list or "ff fi fl ffi fff ffl"
+ local hash = table.tohash(lpeg.split(" ",list)) -- also strip
+ local pattern = (1-lpeg.utfchartabletopattern(hash))^1 * lpeg.P(-1)
+ local checked = { }
+
+ moduledata.languages.goodies.ligaturehandlers[language] = function(original)
+ if not checked[original] and not lpegmatch(pattern,original) then
+ checked[original] = true
+ end
+ return original
+ end
+
+ languages.installhandler(language,"moduledata.languages.goodies.ligaturehandlers." .. language .. "")
+
+ statistics.register(string.formatters["'% t' ligatures checked for language %a"](table.sortedkeys(hash), language), function()
+ return next(checked) and table.concat(table.sortedkeys(checked)," ") or nil
+ end)
+
+ local applied = languages.appliedoptions[language]
+
+ trackers.enable("languages.applied")
+
+ if applied then
+ statistics.register(string.formatters["options applied for language %a"](language), function()
+ return next(applied) and table.concat(table.sortedkeys(applied)," ") or nil
+ end)
+ statistics.register(string.formatters["missed ligatures for language %a"](language), function()
+ for k, v in next, applied do
+ checked[k] = nil
+ end
+ for k, v in next, hash do
+ checked[k] = nil
+ end
+ return next(checked) and table.concat(table.sortedkeys(checked)," ") or nil
+ end)
+ end
+
+ end
+
+end