summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/mtx-context-meaning.tex
blob: 88ca21759ad388035976b89faa84281401ffb4e1 (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
%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
%
% end help

\input mtx-context-common.tex

\setupbodyfont
  [dejavu]

\def\showmeaning#1%
  {\writestatus{meaning}{\strippedcsname#1}%
   \writestring{}%
   \writestring{\expandafter\meaning\begincsname#1\endcsname}}

\starttext

\startluacode
    local h = tex.hashtokens()

    local function showmeaning(str)
        local s = string.gsub(str,"^\\","")
        local p = "^" .. string.topattern(s) .. "$"
        context("pattern: ")
        context.type(s)
        context.blank()
        for i=1,#h do
            local hi = h[i]
            if string.find(h[i],p) then
                context.type(hi)
                context.par()
                context.showmeaning(hi)
            end
        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