summaryrefslogtreecommitdiff
path: root/tex/plain
diff options
context:
space:
mode:
authorPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2012-02-21 12:22:39 +0100
committerPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2012-02-21 12:22:39 +0100
commit893ee900813683b35a88199025e6d6620e14a8e5 (patch)
tree8fc8666374056e72f84ec1714e0e9f57b9110a11 /tex/plain
parent7477a9e3c3e955307558d7ed0ae47d68d24d156d (diff)
downloadenigma-893ee900813683b35a88199025e6d6620e14a8e5.tar.gz
lazy machine macros
Diffstat (limited to 'tex/plain')
-rw-r--r--tex/plain/enigma/enigma.tex48
1 files changed, 34 insertions, 14 deletions
diff --git a/tex/plain/enigma/enigma.tex b/tex/plain/enigma/enigma.tex
index 6827878..1849103 100644
--- a/tex/plain/enigma/enigma.tex
+++ b/tex/plain/enigma/enigma.tex
@@ -1,4 +1,5 @@
\input{luatexbase.sty}
+\catcode`\_=11 % There’s no reason why this shouldn’t be the case.
%D \startsection[title=Prerequisites]
%D \startparagraph
%D Package loading and the namespacing issue are commented on in
@@ -42,15 +43,18 @@
\directlua{
local enigma = packagedata.enigma
local current_args = enigma.parse_args([====[\detokenize{#1}]====])
- enigma.current = enigma.new_callback(enigma.new_machine(current_args, "aaa"))
+ enigma.new_callback(enigma.new_machine(current_args,
+ [====[\currentenigmaid]====]),
+ [====[\currentenigmaid]====])
}%
\egroup%
}
%D The module setup \texmacro{setupenigma} expects key=value, notation.
%D All the logic is at the Lua end, not much to see here …
-\def\setupenigma{%
+\def\setupenigma#1{%
\bgroup
+ \edef\currentenigmaid{#1}
\luatexcatcodetable \enigmasetupcatcodes
\do_setup_enigma%
}
@@ -62,22 +66,38 @@
%D allow enabling of Enigma encoding in different parts of the document.
%D \stopparagraph
-\def\startenigma{%
- \bgroup%
- \directlua{%
- if packagedata.enigma and packagedata.enigma.current then
- luatexbase.add_to_callback("pre_linebreak_filter",
- packagedata.enigma.current,
- "enigma")
- end
+\def\do_define_enigma#1{
+ \@EA\gdef\csname start\enigmaid\endcsname{%
+ \bgroup%
+ % \edef\currentenigmaid{\enigmaid}%
+ \directlua{%
+ if packagedata.enigma and packagedata.enigma.machines["#1"] then
+ luatexbase.add_to_callback("pre_linebreak_filter",
+ packagedata.enigma.callbacks["#1"],
+ "#1")
+ else
+ print([[ENIGMA: No machine of that name: #1!]])
+ os.exit()
+ end
+ }%
+ }
+
+ \@EA\gdef\csname stop\enigmaid\endcsname{%
+ \directlua{luatexbase.remove_from_callback("pre_linebreak_filter",
+ "#1")
+ packagedata.enigma.machines["#1"]:processed_chars()}%
+ \egroup%
}%
}
-\def\stopenigma{%
- \directlua{luatexbase.remove_from_callback("pre_linebreak_filter", "enigma")
- packagedata.enigma.current_machine:processed_chars()}%
- \egroup%
+\def\defineenigma#1{%
+ \begingroup
+ \let\@EA\expandafter
+ \edef\enigmaid{#1}%
+ \@EA\do_define_enigma\@EA{\enigmaid}%
+ \endgroup%
}
%D \stopsection
+\catcode`\_=8
% vim:ft=tex:sw=2:ts=2:expandtab:tw=72