summaryrefslogtreecommitdiff
path: root/context
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2018-10-10 21:09:32 +0200
committerContext Git Mirror Bot <phg@phi-gamma.net>2018-10-10 21:09:32 +0200
commit9f36318b0e571bcbc93dc2112d01bbf2178ed020 (patch)
treed6b075357717f7fde0bdf73aa364dbbca5417c50 /context
parent753dd0cbafc567d4960c5fc4888ccb4e2302c64d (diff)
downloadcontext-9f36318b0e571bcbc93dc2112d01bbf2178ed020.tar.gz
2018-10-08 17:52:00
Diffstat (limited to 'context')
-rw-r--r--context/data/scite/context/documents/scite-context-readme.pdfbin212702 -> 212528 bytes
-rw-r--r--context/data/scite/context/documents/scite-context-readme.tex160
-rw-r--r--context/data/scite/context/scite-ctx-context.properties50
-rw-r--r--context/data/scite/context/scite-ctx-example.properties24
-rw-r--r--context/data/scite/context/scite-ctx-templates.lua31
-rw-r--r--context/data/scite/context/scite-ctx.lua249
6 files changed, 244 insertions, 270 deletions
diff --git a/context/data/scite/context/documents/scite-context-readme.pdf b/context/data/scite/context/documents/scite-context-readme.pdf
index 3abc5f16d..834cd54da 100644
--- a/context/data/scite/context/documents/scite-context-readme.pdf
+++ b/context/data/scite/context/documents/scite-context-readme.pdf
Binary files differ
diff --git a/context/data/scite/context/documents/scite-context-readme.tex b/context/data/scite/context/documents/scite-context-readme.tex
index d9fca8640..fe5120264 100644
--- a/context/data/scite/context/documents/scite-context-readme.tex
+++ b/context/data/scite/context/documents/scite-context-readme.tex
@@ -1,7 +1,8 @@
% interface=en modes=icon,screen language=uk
-\usemodule[art-01]
-\usemodule[abr-02]
+\usemodule[article-basic]
+\usemodule[abbreviations-smallcaps]
+\usemodule[scite]
\unexpanded\def\METAPOST{MetaPost}
\unexpanded\def\METAFUN {MetaFun}
@@ -60,21 +61,21 @@
\startmode[icon,screen]
- \setuppapersize[S66][S66]
+ \setuppapersize[S66][S66]
- \setupbodyfont[10pt]
+ \setupbodyfont[10pt]
\stopmode
\startmode[icon]
- \starttext
+ \starttext
- \startTEXpage
- \useMPgraphic{TitlePage}{darkness=0.4}
- \stopTEXpage
+ \startTEXpage
+ \useMPgraphic{TitlePage}{darkness=0.4}
+ \stopTEXpage
- \stoptext
+ \stoptext
\stopmode
@@ -104,12 +105,12 @@
\definedfont[SerifBold sa 2.48]IN CONTEXT MkIV\kern.25\bodyfontsize}
\startTEXpage
- \tightlayer[TitlePage]
+ \tightlayer[TitlePage]
\stopTEXpage
% main text
-\subject{Warning}
+\startsubject[title={Warning}]
\SCITE\ version 3.61 works ok but 3.62 crashes. It'a a real pity that \SCITE\
doesn't have the scintillua lexer built in, which would also make integration a
@@ -117,7 +118,7 @@ bit nicer by sharing the \LUA\ instance. The \CONTEXT\ lexing discussed here is
the lexing I assume when using \CONTEXT\ \MKIV, but alas it's not easy to get it
running on \UNIX\ and on \MACOSX\ there is no \LUA\ lexing available.
-\subject{About \SCITE}
+\startsubject[title={About \SCITE}]
For a long time at \PRAGMA\ we used \TEXEDIT, an editor we'd written in \MODULA.
It had some project management features and recognized the project structure in
@@ -154,7 +155,9 @@ under:
Normally a user will not have to dive into the implementation details but in
principle you can tweak the properties files to suit your purpose.
-\subject{The look and feel}
+\stopsubject
+
+\startsubject[title={The look and feel}]
The color scheme that we use is consistent over the lexers but we use more colors
that in the traditional lexing. For instance, \TEX\ primitives, low level \TEX\
@@ -175,7 +178,9 @@ for instance because they have an uppercase character. In \in {figure}
[maxheight=1.2\textwidth,
maxwidth=.9\textheight]}}
-\subject{Installing \SCITE}
+\stopsubject
+
+\startsubject[title={Installing \SCITE}]
Installing \SCITE\ is straightforward. We are most familiar with \MSWINDOWS\ but
for other operating systems installation is not much different. First you need to
@@ -220,7 +225,9 @@ On \LINUX\ the files end up in:
Where the second path is the path we will put more files.
-\subject{Installing \type {scintillua}}
+\stopsubject
+
+\startsubject[title={Installing \type {scintillua}}]
Next you need to install the lpeg lexers. \footnote {Versions later than 2.11
will not run on \MSWINDOWS\ 2K. In that case you need to comment the external
@@ -258,7 +265,9 @@ a case you should downgrade or use \type {wine} with the \MSWINDOWS\ binaries
instead. After installation you need to restart \SCITE\ in order to see if things
work out as expected.
-\subject{Installing the \CONTEXT\ lexers}
+\stopsubject
+
+\startsubject[title={Installing the \CONTEXT\ lexers}]
When we started using this nice extension, we ran into issues and as a
consequence shipped a patched \LUA\ code. We also needed some more control as we
@@ -321,7 +330,9 @@ as well).
% \item rxvt (a console, only needed on \UNIX)
% \stopitemize
-\subject{Fonts}
+\stopsubject
+
+\startsubject[title={Fonts}]
The configuration file defaults to the Dejavu fonts. These free fonts are part of
the \CONTEXT\ suite (also known as the standalone distribution). Of course you
@@ -333,13 +344,17 @@ in:
<contextroot>/tex/texmf/fonts/truetype/public/dejavu
\stoptyping
-\subject{Extensions}
+\stopsubject
+
+\startsubject[title={Extensions}]
Just a quick note to some extensions. If you select a part of the text (normally
you do this with the shift key pressed) and you hit \type {Shift-F11}, you get a
menu with some options. More (robust) ones will be provided at some point.
-\subject{Spell checking}
+\stopsubject
+
+\startsubject[title={Spell checking}]
If you want to have spell checking, you need have files with correct words on
each line. The first line of a file determines the language:
@@ -427,7 +442,9 @@ usual \XML\ marker line:
<?context-directive editor language uk ?>
\stoptyping
-\subject{Interface selection}
+\stopsubject
+
+\startsubject[title={Interface selection}]
In a similar fashion you can drive the interface checking:
@@ -435,7 +452,9 @@ In a similar fashion you can drive the interface checking:
% interface=nl
\stoptyping
-\subject{Property files}
+\stopsubject
+
+\startsubject[title={Property files}]
The internal lexers are controlled by the property files while the external ones
are steered with themes. Unfortunately there is hardly any access to properties
@@ -444,7 +463,9 @@ programs like \type {mtxrun}. This means that we cannot use configuration files
in the \CONTEXT\ distribution directly. Hopefully this changes with future
releases.
-\subject{The external lexers}
+\stopsubject
+
+\startsubject[title={The external lexers}]
These are the more advanced lexers. They provide more detail and the \CONTEXT\
lexer also supports nested \METAPOST\ and \LUA. Currently there is no detailed
@@ -475,7 +496,9 @@ indicates that there is a special space character there, for instance \type
{0xA0}, the nonbreakable space. Of course we assume that you use \UTF8 as input
encoding.
-\subject{The internal lexers}
+\stopsubject
+
+\startsubject[title={The internal lexers}]
\SCITE\ has quite some built in lexers. A lexer is responsible for highlighting
the syntax of your document. The way a \TEX\ file is treated is configured in the
@@ -563,7 +586,9 @@ seen as a command. When set to zero, only the primitive \type {\if}'s will be
treated. In order not to confuse you, when this property is set to one, the lexer
will not color an \type {\ifwhatever} that follows an \type {\newif}.
-\subject{The \METAPOST\ lexer}
+\stopsubject
+
+\startsubject[title={The \METAPOST\ lexer}]
The \METAPOST\ lexer is set up slightly different from its \TEX\ counterpart,
first of all because \METAPOST\ is more a language that \TEX. As with the \TEX\
@@ -626,7 +651,9 @@ The lexer is able to recognize \type {btex}||\type {etex} and will treat anythin
in between as just text. The same happens with strings (between \type {"}). Both
act on a per line basis.
-\subject{Using \ConTeXt}
+\stopsubject
+
+\startsubject[title={Using \ConTeXt}]
When \type {mtxrun} is in your path, \CONTEXT\ should run out of the box. You can
find \type {mtxrun} in:
@@ -640,7 +667,9 @@ or in a similar path that suits the operating system that you use.
When you hit \type{CTRL-12} your document will be processed. Take a look at the
\type {Tools} menu to see what more is provided.
-\subject{Extensions (using \LUA)}
+\stopsubject
+
+\startsubject[title={Extensions (using \LUA)}]
When the \LUA\ extensions are loaded, you will see a message in the log pane that
looks like:
@@ -676,79 +705,38 @@ in a (chosen) language. This is handy when you occasionally have to key in (snip
a language you're not familiar with. More alphabets will be added (we take data from some
\CONTEXT\ language relates files).
-\subject{Templates}
+\stopsubject
-There is an experimental template mechanism. One option is to define templates in
-a properties file. The property file \type {scite-ctx-context} contains
-definitions like:
+\startsubject[title={Templates}]
-\starttyping
-command.25.$(file.patterns.context)=insert_template \
-$(ctx.template.list.context)
+It is possible to define (and use) templates. There is a demo file in the distribution called
+\type {scite-ctx-templates.lua}. You can put a similar file in your working path or one or two
+levels up from there. If not found, the default (demo) file will be used. a manu is called up
+with \type {ctrl-i}.
-ctx.template.list.context=\
- itemize=structure.itemize.context|\
- tabulate=structure.tabulate.context|\
- natural TABLE=structure.TABLE.context|\
- use MP graphic=graphics.usemp.context|\
- reuse MP graphic=graphics.reusemp.context|\
- typeface definition=fonts.typeface.context
+A template file is a \LUA\ file and looks like this:
-ctx.template.structure.itemize.context=\
-\startitemize\n\
-\item ?\n\
-\item ?\n\
-\item ?\n\
-\stopitemize\n
-\stoptyping
+\typefile{../scite-ctx-templates.lua}
-The file \type {scite-ctx-example} defines \XML\ variants:
+In \XML\ sources you can add a line:
\starttyping
-command.25.$(file.patterns.example)=insert_template \
-$(ctx.template.list.example)
-
-ctx.template.list.example=\
- bold=font.bold.example|\
- emphasized=font.emphasized.example|\
- |\
- inline math=math.inline.example|\
- display math=math.display.example|\
- |\
- itemize=structure.itemize.example
-
-ctx.template.structure.itemize.example=\
-<itemize>\n\
-<item>?</item>\n\
-<item>?</item>\n\
-<item>?</item>\n\
-</itemize>\n
+<?context-directive job ctxtemplate mytemplates.lua ?>
\stoptyping
-For larger projects it makes sense to keep templates with the project. In one of
-our projects we have a directory in the path where the project files are kept
-which holds template files:
+The file will be searched for in the current direct and upto two levels higher. When no file
+is found the \TEX\ distribution is checked.
-\starttyping
-..../ctx-templates/achtergronden.xml
-..../ctx-templates/bewijs.xml
-\stoptyping
-
-One could define a template menu like we did previously:
+The files \type {scite-ctx-example} and \type {scite-ctx-context} define the menu commands,
+like:
\starttyping
-ctx.templatelist.example=\
- achtergronden=mathadore.achtergronden|\
- bewijs=mathadore.bewijs|\
-
-ctx.template.mathadore.achtergronden.file=smt-achtergronden.xml
-ctx.template.mathadore.bewijs.file=smt-bewijs.xml
+command.25.$(file.patterns.example)=insert_template
\stoptyping
-However, when no such menu is defined, we will automatically scan the directory
-and build the menu without user intervention.
+\stopsubject
-\subject{Using \SCITE}
+\startsubject[title={Using \SCITE}]
The following keybindings are available in \SCITE. Most of this list is taken
from the on|-|line help pages.
@@ -821,7 +809,9 @@ from the on|-|line help pages.
\page
-\subject{Affiliation}
+\stopsubject
+
+\startsubject[title={Affiliation}]
\starttabulate[|l|l|]
\NC author \NC Hans Hagen \NC \NR
diff --git a/context/data/scite/context/scite-ctx-context.properties b/context/data/scite/context/scite-ctx-context.properties
index f984f5104..40ad49ded 100644
--- a/context/data/scite/context/scite-ctx-context.properties
+++ b/context/data/scite/context/scite-ctx-context.properties
@@ -1,49 +1 @@
-command.name.25.$(file.patterns.context)=Whatever
-command.25.$(file.patterns.context)=insert_template $(ctx.template.list.context)
-
-ctx.template.list.context=\
- itemize=structure.itemize.context|\
- tabulate=structure.tabulate.context|\
- natural TABLE=structure.TABLE.context|\
- use MP graphic=graphics.usemp.context|\
- reuse MP graphic=graphics.reusemp.context|\
- typeface definition=fonts.typeface.context
-
-ctx.template.structure.itemize.context=\
-\startitemize\n\
-\item ?\n\
-\item ?\n\
-\item ?\n\
-\stopitemize\n
-
-ctx.template.structure.tabulate.context=\
-\starttabulate[|l|p|]\n\
-\NC ? \NC \NC \NR\n\
-\NC ? \NC \NC \NR\n\
-\NC ? \NC \NC \NR\n\
-\stoptabulate\n
-
-ctx.template.structure.TABLE.context=\
-\bTABLE\n\
-\bTR \bTD ? \eTD \bTD \eTD \eTR\n\
-\bTR \bTD ? \eTD \bTD \eTD \eTR\n\
-\bTR \bTD ? \eTD \bTD \eTD \eTR\n\
-\eTABLE\n
-
-ctx.template.graphics.usemp.context=\
-\defineoverlay[?][\useMPgraphic{}]\n\n\
-\startuseMPgraphic{}\n\n\
-\stopuseMPgraphic\n
-
-ctx.template.graphics.reusemp.context=\
-\defineoverlay[?][\reuseMPgraphic{}]\n\n\
-\startreusableMPgraphic{}\n\n\
-\stopreusableMPgraphic\n
-
-ctx.template.fonts.typeface.context=\
-\definetypeface[mainface][rm][serif][?][default][features=default]\n\
-\definetypeface[mainface][ss][sans] [?][default][features=default]\n\
-\definetypeface[mainface][tt][mono] [?][default][features=default]\n\
-\definetypeface[mainface][mm][math] [?][default][features=default]\n\
-\n\
-\setupbodyfont[mainface,10pt]\n
+command.25.$(file.patterns.context)=insert_template
diff --git a/context/data/scite/context/scite-ctx-example.properties b/context/data/scite/context/scite-ctx-example.properties
index 78b2f2859..58c0acc34 100644
--- a/context/data/scite/context/scite-ctx-example.properties
+++ b/context/data/scite/context/scite-ctx-example.properties
@@ -1,23 +1 @@
-command.25.$(file.patterns.example)=insert_template $(ctx.template.list.example)
-
-ctx.template.list.example=\
- bold=font.bold.example|\
- emphasized=font.emphasized.example|\
- |\
- inline math=math.inline.example|\
- display math=math.display.example|\
- |\
- itemize=structure.itemize.example
-
-ctx.template.font.bold.example=<b>?</b>
-ctx.template.font.emphasized.example=<em>?</em>
-
-ctx.template.math.inline.example=<m>?</m>
-ctx.template.math.display.example=<math>?</math>
-
-ctx.template.structure.itemize.example=\
-<itemize>\n\
-<item>?</item>\n\
-<item>?</item>\n\
-<item>?</item>\n\
-</itemize>\n
+command.25.$(file.patterns.example)=insert_template
diff --git a/context/data/scite/context/scite-ctx-templates.lua b/context/data/scite/context/scite-ctx-templates.lua
new file mode 100644
index 000000000..72b981c81
--- /dev/null
+++ b/context/data/scite/context/scite-ctx-templates.lua
@@ -0,0 +1,31 @@
+-- this is just an example
+
+return {
+ xml = {
+ {
+ name = "bold",
+ nature = "inline",
+ template = "<b>?</b>",
+ },
+ {
+ name = "emphasized",
+ nature = "inline",
+ template = "<em>?</em>",
+ },
+ {
+ name = "inline",
+ nature = "inline",
+ template = "<m>?</m>",
+ },
+ {
+ name = "display",
+ nature = "display",
+ template = "<math>?</math>",
+ },
+ {
+ name = "itemize",
+ nature = "display",
+ template = "<itemize>\n <item>?</item>\n <item>?</item>\n <item>?</item>\n</itemize>",
+ },
+ },
+}
diff --git a/context/data/scite/context/scite-ctx.lua b/context/data/scite/context/scite-ctx.lua
index f2f33ecbb..126f6b8f3 100644
--- a/context/data/scite/context/scite-ctx.lua
+++ b/context/data/scite/context/scite-ctx.lua
@@ -72,7 +72,9 @@
props = props or { } -- setmetatable(props,{ __index = function(k,v) props[k] = "unknown" return "unknown" end } )
-local byte, lower, upper, gsub, sub, find, rep, match, gmatch, format, char = string.byte, string.lower, string.upper, string.gsub, string.sub, string.find, string.rep, string.match, string.gmatch, string.format, string.char
+local byte, char = string.byte, string.char
+local lower, upper, format = string.lower, string.upper, string.format
+local gsub, sub, find, rep, match, gmatch = string.gsub, string.sub, string.find, string.rep, string.match, string.gmatch
local sort, concat = table.sort, table.concat
-- helpers : utf
@@ -115,6 +117,17 @@ function io.exists(filename)
end
end
+local function resultof(command)
+ local handle = io.popen(command,"r") -- already has flush
+ if handle then
+ local result = handle:read("*all") or ""
+ handle:close()
+ return result
+ else
+ return ""
+ end
+end
+
function os.envvar(str)
local s = os.getenv(str)
if s ~= '' then
@@ -974,22 +987,28 @@ end
local menuactions = { }
local menufunctions = { }
+local menuentries = { }
function UserListShow(menutrigger, menulist)
- local menuentries = { }
- local list = grab(menulist,"[^%|]+")
- menuactions = { }
- for i=1, #list do
- if list[i] ~= '' then
- for key, val in gmatch(list[i],"%s*(.+)=(.+)%s*") do
- menuentries[#menuentries+1] = key
- menuactions[key] = val
+ if type(menulist) == "string" then
+ menuentries = { }
+ menuactions = { }
+ for item in gmatch(menulist,"[^%|]+") do
+ if item ~= "" then
+ -- why not just a split
+ for key, value in gmatch(item,"%s*(.+)=(.+)%s*") do
+ menuentries[#menuentries+1] = key
+ menuactions[key] = value
+ end
end
end
+ else
+ menuentries = menulist
+ menuactions = false
end
local menustring = concat(menuentries,'|')
if menustring == "" then
- report("there are no templates defined for this file type")
+ report("there are no (further) options defined for this file type")
else
editor.AutoCSeparator = byte('|')
editor:UserListShow(menutrigger,menustring)
@@ -998,8 +1017,8 @@ function UserListShow(menutrigger, menulist)
end
function OnUserListSelection(trigger,choice)
- if menufunctions[trigger] and menuactions[choice] then
- return menufunctions[trigger](menuactions[choice])
+ if menufunctions[trigger] then
+ return menufunctions[trigger](menuactions and menuactions[choice] or choice)
else
return false
end
@@ -1025,131 +1044,135 @@ menufunctions[12] = process_menu
-- templates
-local templatetrigger = 13
+-- <?context-directive job ctxtemplate demotemplate.lua ?>
-local ctx_template_paths = { "./ctx-templates", "../ctx-templates", "../../ctx-templates" }
-local ctx_auto_templates = false
-local ctx_template_list = ""
+local templatetrigger = 13
-local ctx_path_list = { }
-local ctx_path_done = { }
-local ctx_path_name = { }
+local ctx_template_file = "scite-ctx-templates.lua"
+local ctx_template_list = { }
+local ctx_template_menu = { }
function ctx_list_loaded(path)
return ctx_path_list[path] and #ctx_path_list[path] > 0
end
+local function loadtable(name)
+ local f = io.open(name,"rb")
+ if f then
+ f:close()
+ return dofile(name)
+ end
+end
+
+local patterns = {
+ xml = "<%?context%-directive job ctxtemplate (.-) %?>"
+}
+
+local function loadtemplate(name)
+ local temp = gsub(name,"\\","/")
+ local okay = loadtable(temp)
+ if okay then
+ print("template loaded: " .. name)
+ end
+ return okay
+end
+
+local function loadtemplatefrompaths(path,name)
+ return loadtemplate(path .. "/" .. name) or
+ loadtemplate(path .. "/../" .. name) or
+ loadtemplate(path .. "/../../" .. name)
+end
+
function insert_template(templatelist)
- if props["ctx.template.scan"] == "yes" then
- local path = props["FileDir"]
- local rescan = props["ctx.template.rescan"] == "yes"
- local suffix = props["ctx.template.suffix." .. props["FileExt"]] -- alas, no suffix expansion here
- local current = path .. "+" .. props["FileExt"]
- if rescan then
- print("re-scanning enabled")
- end
- ctx_template_list = ""
- if not ctx_path_done[path] or rescan then
- local pattern = "*.*"
- for i, pathname in ipairs(ctx_template_paths) do
- print("scanning " .. gsub(path,"\\","/") .. "/" .. pathname)
- ctx_path_name[path] = pathname
- ctx_path_list[path] = get_dir_list(pathname .. "/" .. pattern)
- if ctx_list_loaded(path) then
- print("finished locating template files")
+ local path = props["FileDir"]
+ local suffix = props["FileExt"]
+ local list = ctx_template_list[path]
+ if list == nil then
+ local pattern = patterns[suffix]
+ local okay = false
+ if pattern then
+ for i=0,9 do
+ local line = editor:GetLine(i) or ""
+ local name = match(line,pattern)
+ if name then
+ okay = loadtemplatefrompaths(path,name)
+ if not okay then
+ name = resultof("mtxrun --find-file " .. name)
+ if name then
+ name = gsub(name,"\n","")
+ okay = loadtemplate(name)
+ end
+ end
break
end
end
- if ctx_list_loaded(path) then
- print(#ctx_path_list[path] .. " template files found")
- else
- print("no template files found")
- end
end
- if ctx_list_loaded(path) then
- ctx_template_list = ""
- local pattern = "%." .. suffix .. "$"
- local n = 0
- for j, filename in ipairs(ctx_path_list[path]) do
- if find(filename,pattern) then
- n = n + 1
- local menuname = gsub(filename,"%..-$","")
- if ctx_template_list ~= "" then
- ctx_template_list = ctx_template_list .. "|"
- end
- ctx_template_list = ctx_template_list .. menuname .. "=" .. ctx_path_name[path] .. "/" .. filename
- end
- end
- if not ctx_path_done[path] then
- print(n .. " suitable template files found")
- end
+ if not okay then
+ okay = loadtemplatefrompaths(path,ctx_template_file)
end
- ctx_path_done[path] = true
- if ctx_template_list == "" then
- ctx_auto_templates = false
- else
- ctx_auto_templates = true
- templatelist = ctx_template_list
+ if not okay then
+ okay = loadtemplate(props["SciteDefaultHome"] .. "/context/" .. ctx_template_file)
end
- else
- ctx_auto_templates = false
- end
- if templatelist ~= "" then
- UserListShow(templatetrigger, templatelist)
- end
-end
-
--- ctx.template.[whatever].[filetype]
--- ctx.template.[whatever].data.[filetype]
--- ctx.template.[whatever].file.[filetype]
--- ctx.template.[whatever].list.[filetype]
-
-function process_template_one(action)
- local text = nil
- if ctx_auto_templates then
- local f = io.open(action,"r")
- if f then
- text = gsub(f:read("*all"),"\n$","")
- f:close()
+ if okay then
+ list = okay
else
- print("unable to auto load template file " .. text)
- text = nil
+ list = false
+ print("no template file found")
end
+ ctx_template_list[path] = list
end
- if not text or text == "" then
- text = props["ctx.template." .. action .. ".file"]
- if not text or text == "" then
- text = props["ctx.template." .. action .. ".data"]
- if not text or text == "" then
- text = props["ctx.template." .. action]
- end
- else
- local f = io.open(text,"r")
- if f then
- text = gsub(f:read("*all"),"\n$","")
- f:close()
- else
- print("unable to load template file " .. text)
- text = nil
+ ctx_template_menu = { }
+ if list then
+ local okay = list[suffix]
+ if okay then
+ local menu = { }
+ for i=1,#okay do
+ local o = okay[i]
+ local n = o.name
+ menu[#menu+1] = n
+ ctx_template_menu[n] = o
end
+ UserListShow(templatetrigger, menu, true)
end
end
- if text then
- text = gsub(text,"\\n","\n")
- local pos = find(text,"%?")
- text = gsub(text,"%?","")
- editor:insert(editor.CurrentPos,text)
- if pos then
- editor.CurrentPos = editor.CurrentPos + pos - 1
- editor.SelectionStart = editor.CurrentPos
- editor.SelectionEnd = editor.CurrentPos
- editor:GotoPos(editor.CurrentPos)
+end
+
+function inject_template(action)
+ if ctx_template_menu then
+ local a = ctx_template_menu[action]
+ if a then
+ local template = a.template
+ local nature = a.nature
+ if template then
+ local margin = props['SelectionStartColumn'] - 1
+ -- template = gsub(template,"\\n","\n")
+ template = gsub(template,"%?%?","_____")
+ local pos = find(template,"%?")
+ template = gsub(template,"%?","")
+ template = gsub(template,"_____","?")
+ if nature == "display" then
+ local spaces = rep(" ",margin)
+ if not find(template,"\n$") then
+ template = template .. "\n"
+ end
+ template = gsub(template,"\n",function(s)
+ return "\n" .. spaces
+ end)
+ pos = pos + margin -- todo: check for first line
+ end
+ editor:insert(editor.CurrentPos,template)
+ if pos then
+ editor.CurrentPos = editor.CurrentPos + pos - 1
+ editor.SelectionStart = editor.CurrentPos
+ editor.SelectionEnd = editor.CurrentPos
+ editor:GotoPos(editor.CurrentPos)
+ end
+ end
end
end
end
-menufunctions[13] = process_template_one
-menufunctions[14] = process_template_two
+menufunctions[13] = inject_template
-- command.name.26.*=Open Logfile
-- command.subsystem.26.*=3