mtx-context-listing.tex /size: 4325 b    last modification: 2020-07-01 14:35
1%D \module
2%D   [       file=mtx-context-listing,
3%D        version=2008.11.10, % about that time i started playing with this
4%D          title=\CONTEXT\ Extra Trickry,
5%D       subtitle=Listing Files,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14%D This is a \TEXEXEC\ feature that has been moved to \MKIV.
15
16% begin help
17%
18% usage: context --extra=listing [options] list-of-files
19%
20% --sort                : sort filenames first
21% --topspace=dimension  : distance above first line
22% --backspace=dimension : distance before left margin
23% --pretty              : pretty print comform suffix
24% --scite               : pretty print comform suffix using scite lexer
25% --bodyfont=list       : additional bodyfont settings
26% --paperformat=spec    : paper*print or paperxprint
27% --compact             : small margins, 8pt font
28% --verycompact         : small margins, 7pt font
29%
30% end help
31
32\input mtx-context-common.tex
33
34\doifdocumentargument {compact} {
35    \setdocumentargument{topspace} {5mm}
36    \setdocumentargument{backspace}{5mm}
37    \setdocumentargument{bodyfont} {8pt}
38}
39
40\doifdocumentargument {verycompact} {
41    \setdocumentargument{topspace} {5mm}
42    \setdocumentargument{backspace}{5mm}
43    \setdocumentargument{bodyfont} {7pt}
44}
45
46\setupbodyfont
47  [dejavu,9pt,tt,\getdocumentargument{bodyfont}] % dejavu is more complete
48
49\setuptyping
50  [lines=yes]
51
52\setuplayout
53  [header=0cm,
54   footer=1.5cm,
55   topspace=\getdocumentargumentdefault{topspace}{1.5cm},
56   backspace=\getdocumentargumentdefault{backspace}{1.5cm},
57   width=middle,
58   height=middle]
59
60\setuppapersize
61  [\getdocumentargument{paperformat_paper}]
62  [\getdocumentargument{paperformat_print}]
63
64% \startluacode
65%     -- syntax check
66%     local topspace  = dimen(document.arguments.topspace  or 0)
67%     local backspace = dimen(document.arguments.backspace or 0)
68%     local zeropoint = dimen(0)
69%     if topspace > zeropoint then
70%         context.setuplayout { topspace = tostring(topspace) }
71%     end
72%     if backspace > zeropoint then
73%         context.setuplayout { backspace = tostring(backspace) }
74%     end
75% \stopluacode
76
77\starttext
78
79\startluacode
80    local types = {
81        mkiv = "tex",
82        mkii = "tex",
83        cld  = "lua",
84        lfg  = "lua",
85        mpiv = "mp",
86        mpii = "mp",
87    }
88
89    local pattern = document.arguments.pattern
90    local scite   = document.arguments.scite
91
92    if pattern then
93        document.files = dir.glob(pattern)
94    end
95
96    if scite then
97        context.usemodule { "scite" }
98    end
99
100    local done  = false
101    local files = document.files
102
103    if #files > 0 then
104        if document.arguments.sort then
105            table.sort(files)
106        end
107        for i=1,#files do
108            local filename = files[i]
109            if not string.find(filename,"^mtx%-context%-") then
110                local pretty = document.arguments.pretty
111                if pretty == true then
112                    pretty = file.extname(filename) or ""
113                elseif pretty == false then
114                    pretty = ""
115                else
116                    -- forced
117                end
118                context.page()
119                context.setupfootertexts( -- return true: we need to keep this entry
120                    { function() context.detokenize(pattern and filename or file.basename(filename)) return true end },
121                    { function() context.pagenumber() return true end }
122                )
123                if scite then
124                    context.scitefile { filename } -- here { }
125                elseif pretty then
126                    if type(pretty) ~= "string" or pretty == "" then
127                        context.setuptyping { option = "color" }
128                    else
129                        context.setuptyping { option = types[pretty] or pretty }
130                    end
131                    context.typefile(filename)
132                else
133                    context.typefile(filename)
134                end
135                done = true
136            end
137        end
138    end
139
140    if not done then
141        context("no files given")
142    end
143
144\stopluacode
145
146\stoptext
147