summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/mtx-context-meaning.tex
blob: 88b81ef041ea98c419b02fc16015a49f02f0df38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
%D \module
%D   [       file=mtx-context-meaning,
%D        version=2018.01.12,
%D          title=\CONTEXT\ Extra Trickry,
%D       subtitle=Show Meanings,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

% begin help
%
% usage: context --extra=meaning [options] list-of-commands
%
% --pattern : match given pattern
%
% example: context --extra=meaning --pattern=*paper*
%          context --extra=meaning setuplayout
%          context --extra=meaning setup_layout
%          context --extra=meaning --once --noconsole --nostatistics setuplayout
%          mtxrun --silent --script context --extra=meaning --once  --noconsole --nostatistics setuplayout
%          mtxrun --script interface --meaning setuplayout
%
% end help

\input mtx-context-common.tex

\setupbodyfont
  [dejavu]

\def\showmeaning#1%
  {\ctxlua{logs.pushtarget("both")}%
   \writestatus{meaning}{\strippedcsname#1}%
   \writestring{}%
   \writestring{\expandafter\meaning\begincsname#1\endcsname}%
   \ctxlua{logs.poptarget()}}

\starttext

\usemodule[setups-macros]

\startluacode
    local h = tex.hashtokens()

    local function showmeaning(str)
        local h = interfaces.macros.collect(str)
        context("pattern: ")
        context.type(str)
        context.blank()
        for i=1,#h do
            local hi = h[i]
            context.type(hi)
            context.par()
            context.showmeaning(hi)
        end
        context.page()
    end

    local done    = false
    local pattern = document.arguments.pattern

    if pattern then
        pattern = { pattern}
    else
        pattern = document.files
    end

    if type(pattern) == "table" then
        table.sort(pattern)
        for i=1,#pattern do
            local p = pattern[i]
            if not string.find(p,"^mtx%-context%-") then
                done = true
                showmeaning(p)
            end
        end
    end

    if not done then
        context("no search pattern given")
    end
\stopluacode

\stoptext