mtx-context-meaning.tex /size: 2650 b    last modification: 2021-10-28 13:50
1%D \module
2%D   [       file=mtx-context-meaning,
3%D        version=2018.01.12,
4%D          title=\CONTEXT\ Extra Trickry,
5%D       subtitle=Show Meanings,
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% begin help
15%
16% usage: context --extra=meaning [options] list-of-commands
17%
18% --pattern : match given pattern
19%
20% example: context --extra=meaning --pattern=*paper*
21%          context --extra=meaning setuplayout
22%          context --extra=meaning setup_layout
23%          context --extra=meaning --once --noconsole --nostatistics setuplayout
24%          mtxrun --silent --script context --extra=meaning --once  --noconsole --nostatistics setuplayout
25%          mtxrun --script interface --meaning setuplayout
26%
27% end help
28
29\input mtx-context-common.tex
30
31\setupbodyfont
32  [dejavu]
33
34\unexpanded\def\ShowMeaning#1%
35  {\ctxlua{logs.pushtarget("both")}%
36   \writestatus{meaning}{\strippedcsname#1}%
37   \writestring{}%
38   \writestring{\expandafter\meaning\begincsname#1\endcsname}%
39   \ctxlua{logs.poptarget()}}
40
41\unexpanded\def\ShowTokens#1%
42  {\ctxlua{logs.pushtarget("both")}%
43   \writestatus{tokens}{\strippedcsname#1}%
44   \writestring{}%
45   \ifcase\contextlmtxmode
46      \writestring{only supported in lmtx}%
47   \else
48      \expandafter\showluatokens\begincsname#1\endcsname
49   \fi
50   \ctxlua{logs.poptarget()}}
51
52\starttext
53
54\usemodule[setups-macros]
55
56\startluacode
57    local h = tex.hashtokens()
58    local t = environment.arguments.tokens
59
60    local function showmeaning(str)
61        local h = interfaces.macros.collect(str)
62        context("pattern: ")
63        context.type(str)
64        context.blank()
65        for i=1,#h do
66            local hi = h[i]
67            context.type(hi)
68            context.par()
69            if t then
70                context.ShowTokens(hi)
71            else
72                context.ShowMeaning(hi)
73            end
74        end
75        context.page()
76    end
77
78    local done    = false
79    local pattern = document.arguments.pattern
80
81    if pattern then
82        pattern = { pattern}
83    else
84        pattern = document.files
85    end
86
87    if type(pattern) == "table" then
88        table.sort(pattern)
89        for i=1,#pattern do
90            local p = pattern[i]
91            if not string.find(p,"^mtx%-context%-") then
92                done = true
93                showmeaning(p)
94            end
95        end
96    end
97
98    if not done then
99        context("no search pattern given")
100    end
101\stopluacode
102
103\stoptext
104