summaryrefslogtreecommitdiff
path: root/scripts/context
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2006-01-09 00:00:00 +0100
committerHans Hagen <pragma@wxs.nl>2006-01-09 00:00:00 +0100
commite5b96502040aa3c41bbd6a175ce4316bf21d8570 (patch)
treec8d1f983bb2ce4c2b37e331645dacd9991d23df6 /scripts/context
parent28b6768726b1fc30e1bae370cfa04632b52542c3 (diff)
downloadcontext-e5b96502040aa3c41bbd6a175ce4316bf21d8570.tar.gz
stable 2006.01.09
Diffstat (limited to 'scripts/context')
-rw-r--r--scripts/context/lua/scite-ctx.lua291
-rw-r--r--scripts/context/perl/mptopdf.pl2
-rw-r--r--scripts/context/perl/texexec.pl11
-rw-r--r--scripts/context/ruby/base/tex.rb10
-rw-r--r--scripts/context/ruby/ctxtools.rb4
-rw-r--r--scripts/context/ruby/newtexexec.rb44
6 files changed, 294 insertions, 68 deletions
diff --git a/scripts/context/lua/scite-ctx.lua b/scripts/context/lua/scite-ctx.lua
index 1f58b123d..fae9e0fb9 100644
--- a/scripts/context/lua/scite-ctx.lua
+++ b/scripts/context/lua/scite-ctx.lua
@@ -169,7 +169,8 @@ end
function string.replace(original,pattern,replacement)
local str = string.gsub(original,pattern,replacement)
- print(str) -- indirect, since else str + nofsubs
+--~ print(str) -- indirect, since else str + nofsubs
+ return str -- indirect, since else str + nofsubs
end
-- support functions, maybe editor namespace
@@ -238,6 +239,30 @@ function getfiletype()
end
end
+-- inspired by LuaExt's scite_Files
+
+function get_dir_list(mask)
+ local f
+ if props['PLAT_GTK'] and props['PLAT_GTK'] ~= "" then
+ f = io.popen('ls -1 ' .. mask)
+ else
+ mask = string.gsub(mask, '/','\\')
+ local tmpfile = 'scite-ctx.tmp'
+ local cmd = 'dir /b "' .. mask .. '" > ' .. tmpfile
+ os.execute(cmd)
+ f = io.open(tmpfile)
+ end
+ local files = {}
+ if not f then -- path check added
+ return files
+ end
+ for line in f:lines() do
+ table.insert(files, line)
+ end
+ f:close()
+ return files
+end
+
-- banner
print("loading scite-ctx.lua definition file")
@@ -639,58 +664,252 @@ function reset_text()
editor:SetStyling(editor.TextLength,INDIC_PLAIN)
end
--- templates
-
---~ function insert_text()
-
---~ local templatelist = props["ctx.template.list"]
-
---~ editor:insert(editor.CurrentPos,templatelist)
---~ show_menu(templatelist)
---~ end
-
-
-- menu
-local menuactions = {}
-local menutrigger = 12
+local menuactions = {}
+local menufunctions = {}
-function UserListShow(menuspec)
+function UserListShow(menutrigger, menulist)
local menuentries = {}
- local list = string.grab(menuspec,'[^%|]+')
- props["ctx.menulist.saved"] = menuspec
+ local list = string.grab(menulist,"[^%|]+")
+ menuactions = {}
for i=1, table.len(list) do
if list[i] ~= '' then
for key, val in string.gfind(list[i],"%s*(.+)=(.+)%s*") do
- if not string.find(val,"%(%)$") then
- val = val .. "()"
- end
table.insert(menuentries,key)
rawset(menuactions,key,val)
end
end
end
- editor.AutoCSeparator = string.byte('|')
- editor:UserListShow(menutrigger,table.join(menuentries,'|'))
- editor.AutoCSeparator = string.byte(' ')
-end
-
-function DoOnUserListSelection(trigger,choice,redoonerror)
- if trigger == menutrigger then
- if menuactions[choice] then
- assert(loadstring(menuactions[choice]))()
- elseif redoonerror then -- handy when reloaded lua script
- -- traceln("unknown action '" .. choice .. "', retrying")
- UserListShow(props["ctx.menulist.saved"])
- DoOnUserListSelection (trigger,choice,false)
- end
+ local menustring = table.join(menuentries,'|')
+ if menustring == "" then
+ traceln("There are no templates defined for this file type.")
+ else
+ editor.AutoCSeparator = string.byte('|')
+ editor:UserListShow(menutrigger,menustring)
+ editor.AutoCSeparator = string.byte(' ')
end
end
function OnUserListSelection(trigger,choice)
- DoOnUserListSelection(trigger,choice,true)
+ if menufunctions[trigger] and menuactions[choice] then
+ return menufunctions[trigger](menuactions[choice])
+ else
+ return false
+ end
end
+-- main menu
+
+local menutrigger = 12
+
function show_menu(menulist)
- UserListShow(menulist)
+ UserListShow(menutrigger, menulist)
end
+
+function process_menu(action)
+ if not string.find(action,"%(%)$") then
+ assert(loadstring(action .. "()"))()
+ else
+ assert(loadstring(action))()
+ end
+end
+
+menufunctions[12] = process_menu
+
+-- templates
+
+local templatetrigger = 13
+
+--~ local ctx_template_paths = { "./ctx-templates", "../ctx-templates", "../../ctx-templates" }
+--~ local ctx_auto_templates = false
+--~ local ctx_template_list = ""
+--~ local ctx_dir_list = { }
+--~ local ctx_dir_name = "./ctx-templates"
+
+--~ local ctx_path_list = {}
+--~ local ctx_path_done = {}
+
+--~ function ctx_list_loaded()
+--~ return ctx_dir_list and table.getn(ctx_dir_list) > 0
+--~ end
+
+--~ function insert_template(templatelist)
+--~ if props["ctx.template.scan"] == "yes" then
+--~ local current = props["FileDir"] .. "+" .. props["FileExt"] -- no name
+--~ local rescan = props["ctx.template.rescan"] == "yes"
+--~ local suffix = props["ctx.template.suffix."..props["FileExt"]] -- alas, no suffix expansion here
+--~ if rescan then
+--~ print("re-scanning enabled")
+--~ end
+--~ if current ~= ctx_file_path then
+--~ rescan = true
+--~ ctx_file_path = current
+--~ ctx_file_done = false
+--~ ctx_template_list = ""
+--~ end
+--~ if not ctx_file_done or rescan then
+--~ local pattern = "*.*"
+--~ for i, pathname in ipairs(ctx_template_paths) do
+--~ print("scanning " .. pathname .. " for " .. pattern)
+--~ ctx_dir_name = pathname
+--~ ctx_dir_list = get_dir_list(pathname .. "/" .. pattern)
+--~ if ctx_list_loaded() then
+--~ break
+--~ end
+--~ end
+--~ ctx_file_done = true
+--~ end
+--~ if ctx_list_loaded() then
+--~ ctx_template_list = ""
+--~ local pattern = "%." .. suffix .. "$"
+--~ for j, filename in ipairs(ctx_dir_list) do
+--~ if string.find(filename,pattern) then
+--~ local menuname = string.gsub(filename,"%..-$","")
+--~ if ctx_template_list ~= "" then
+--~ ctx_template_list = ctx_template_list .. "|"
+--~ end
+--~ ctx_template_list = ctx_template_list .. menuname .. "=" .. ctx_dir_name .. "/" .. filename
+--~ end
+--~ end
+--~ else
+--~ print("no template files found")
+--~ end
+--~ if ctx_template_list == "" then
+--~ ctx_auto_templates = false
+--~ print("no file related templates found")
+--~ else
+--~ ctx_auto_templates = true
+--~ templatelist = ctx_template_list
+--~ end
+--~ end
+--~ if templatelist ~= "" then
+--~ UserListShow(templatetrigger, templatelist)
+--~ end
+--~ end
+
+local ctx_template_paths = { "./ctx-templates", "../ctx-templates", "../../ctx-templates" }
+local ctx_auto_templates = false
+local ctx_template_list = ""
+
+local ctx_path_list = {}
+local ctx_path_done = {}
+local ctx_path_name = {}
+
+function ctx_list_loaded(path)
+ return ctx_path_list[path] and table.getn(ctx_path_list[path]) > 0
+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 " .. string.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")
+ break
+ end
+ end
+ if ctx_list_loaded(path) then
+ print(table.getn(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 string.find(filename,pattern) then
+ n = n + 1
+ local menuname = string.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
+ end
+ ctx_path_done[path] = true
+ if ctx_template_list == "" then
+ ctx_auto_templates = false
+ else
+ ctx_auto_templates = true
+ templatelist = ctx_template_list
+ 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 = string.gsub(f:read("*all"),"\n$","")
+ f:close()
+ else
+ print("unable to auto load template file " .. text)
+ text = nil
+ end
+ 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 = string.gsub(f:read("*all"),"\n$","")
+ f:close()
+ else
+ print("unable to load template file " .. text)
+ text = nil
+ end
+ end
+ end
+ if text then
+ text = string.replace(text,"\\n","\n")
+ local pos = string.find(text,"%?")
+ text = string.replace(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
+ end
+end
+
+menufunctions[13] = process_template_one
+menufunctions[14] = process_template_two
+
diff --git a/scripts/context/perl/mptopdf.pl b/scripts/context/perl/mptopdf.pl
index fc1be6a84..5f19ecaf4 100644
--- a/scripts/context/perl/mptopdf.pl
+++ b/scripts/context/perl/mptopdf.pl
@@ -37,7 +37,7 @@ my $PassOn = '' ;
"latex" => \$Latex ) ;
my $program = "MPtoPDF 1.3" ;
-my $pattern = $ARGV[0] ;
+my $pattern = "@ARGV" ; # was $ARGV[0]
my $done = 0 ;
my $report = '' ;
my $texlatexswitch = " --tex=latex --format=latex " ;
diff --git a/scripts/context/perl/texexec.pl b/scripts/context/perl/texexec.pl
index e60a7745f..aab5888f9 100644
--- a/scripts/context/perl/texexec.pl
+++ b/scripts/context/perl/texexec.pl
@@ -902,7 +902,7 @@ $OutputFormats{dviwindo} = "dviwindo";
$OutputFormats{dviview} = "dviview";
-my @ConTeXtFormats = ( "nl", "en", "de", "cz", "uk", "it", "ro", "xx");
+my @ConTeXtFormats = ( "nl", "en", "de", "fr", "cz", "uk", "it", "ro", "xx");
sub SetInterfaces {
my ( $short, $long, $full ) = @_;
@@ -917,6 +917,7 @@ sub SetInterfaces {
SetInterfaces( "nl", "dutch", "dutch" );
SetInterfaces( "en", "english", "english" );
SetInterfaces( "de", "german", "german" );
+SetInterfaces( "fr", "french", "french" );
SetInterfaces( "cz", "czech", "czech" );
SetInterfaces( "uk", "brittish", "english" );
SetInterfaces( "it", "italian", "italian" );
@@ -1205,6 +1206,11 @@ sub MakeOptionFile {
print OPT "\\setupcolors[\\c!split=$Separation]\n";
}
if ($SetupPath) { print OPT "\\setupsystem[\\c!directory=\{$SetupPath\}]\n" }
+ if ($dosish) {
+ print OPT "\\setupsystem[\\c!type=mswin]\n"
+ } else { # no darwin handling in old texexec
+ print OPT "\\setupsystem[\\c!type=unix]\n"
+ }
print OPT "\\setupsystem[\\c!n=$KindOfRun]\n";
$_ = $PaperFormat;
#unless (($PdfArrange)||($PdfSelect)||($PdfCombine)||($PdfCopy))
@@ -3021,7 +3027,7 @@ sub show_version_info {
print " tex : $texengine\n" ;
print " context : ver: $contextversion\n" ;
print " cont-en : $type\n" ;
- foreach my $a (qw(cz de it nl ro uk xx)) {
+ foreach my $a (qw(cz de fr it nl ro uk xx)) {
my $test = Pipe("$kpsewhich -format='fmt' cont-$a") ;
if (defined $test && $test) {
$Format = 'cont-' . $a;
@@ -3122,6 +3128,7 @@ interface user interface
=en English
=nl Dutch
=de German
+=fr French
=cz Czech
=uk Brittish
=it Italian
diff --git a/scripts/context/ruby/base/tex.rb b/scripts/context/ruby/base/tex.rb
index 316cc6941..968d66ed7 100644
--- a/scripts/context/ruby/base/tex.rb
+++ b/scripts/context/ruby/base/tex.rb
@@ -88,6 +88,7 @@ class TEX
['cont-nl','nl','dutch'] .each do |f| @@texformats[f] = 'cont-nl' end
['cont-de','de','german'] .each do |f| @@texformats[f] = 'cont-de' end
['cont-it','it','italian'] .each do |f| @@texformats[f] = 'cont-it' end
+ ['cont-fr','fr','french'] .each do |f| @@texformats[f] = 'cont-fr' end
['cont-cz','cz','czech'] .each do |f| @@texformats[f] = 'cont-cz' end
['cont-ro','ro','romanian'] .each do |f| @@texformats[f] = 'cont-ro' end
['cont-uk','uk','brittish'] .each do |f| @@texformats[f] = 'cont-uk' end
@@ -103,7 +104,7 @@ class TEX
['plain','default','standard','mptopdf'] .each do |f| @@texmethods[f] = 'plain' end
['cont-en','cont-nl','cont-de','cont-it',
- 'cont-cz','cont-ro','cont-uk'] .each do |f| @@texmethods[f] = 'context' end
+ 'cont-fr','cont-cz','cont-ro','cont-uk'] .each do |f| @@texmethods[f] = 'context' end
['latex'] .each do |f| @@texmethods[f] = 'latex' end
['plain','default','standard'] .each do |f| @@mpsmethods[f] = 'plain' end
@@ -113,7 +114,7 @@ class TEX
@@mpsmakestr['plain'] = "\\dump"
['cont-en','cont-nl','cont-de','cont-it',
- 'cont-cz','cont-ro','cont-uk'] .each do |f| @@texprocstr[f] = "\\emergencyend" end
+ 'cont-fr','cont-cz','cont-ro','cont-uk'] .each do |f| @@texprocstr[f] = "\\emergencyend" end
@@runoptions['xetex'] = ['--no-pdf']
@@ -134,7 +135,7 @@ class TEX
'modefile', 'result', 'suffix', 'response', 'path',
'filters', 'usemodules', 'environments', 'separation', 'setuppath',
'arguments', 'input', 'output', 'randomseed', 'modes', 'mode', 'filename',
- 'ctxfile'
+ 'ctxfile', 'printformat', 'paperformat'
]
@@standardvars = [
'mainlanguage', 'bodyfont', 'language'
@@ -876,6 +877,7 @@ class TEX
elsif (str = getvariable('suffix')) && ! str.empty? then
opt << "\\setupsystem[file=#{jobname}.#{str}]\n"
end
+ opt << "\\setupsystem[\\c!type=#{Tool.ruby_platform()}]\n"
if (str = File.unixfied(getvariable('path'))) && ! str.empty? then
opt << "\\usepath[#{str}]\n" unless str.empty?
end
@@ -928,7 +930,7 @@ class TEX
arrangement = Array.new
if finalrun then
arrangement << "\\v!doublesided" unless getvariable('noduplex')
- case printformat
+ case getvariable('printformat')
when '' then arrangement << "\\v!normal"
when /.*up/oi then arrangement << "\\v!rotated"
when /.*down/oi then arrangement << ["2DOWN","\\v!rotated"]
diff --git a/scripts/context/ruby/ctxtools.rb b/scripts/context/ruby/ctxtools.rb
index 1ba4dce12..948c19d58 100644
--- a/scripts/context/ruby/ctxtools.rb
+++ b/scripts/context/ruby/ctxtools.rb
@@ -353,6 +353,10 @@ class Commands
data.i_translate('cd:inherit' , 'name' , strings)
# data.i_translate('cd:command' , 'name' , strings)
+ data.gsub!(/(\<cd\:interface[^\>]*?language=")en(")/) do
+ $1 + interface + $2
+ end
+
report("saving #{outfile}")
begin
diff --git a/scripts/context/ruby/newtexexec.rb b/scripts/context/ruby/newtexexec.rb
index 8caf9de0f..dc06a3831 100644
--- a/scripts/context/ruby/newtexexec.rb
+++ b/scripts/context/ruby/newtexexec.rb
@@ -234,7 +234,7 @@ class Commands
end
end
- def arrange
+ def arrangeoutput
if job = TEX.new(logger) then
prepare(job)
job.cleanuptemprunfiles
@@ -266,7 +266,7 @@ class Commands
report("arranging file #{filename}")
f << "\\insertpages\n"
f << " [#{filename}]\n"
- f << " [#{addempty}]\n" unless addempty.empty?
+ f << " [#{emptypages}]\n" unless emptypages.empty?
f << " [width=#{textwidth}]\n"
end
f << "\\stoptext\n"
@@ -286,7 +286,7 @@ class Commands
end
end
- def select
+ def selectoutput
if job = TEX.new(logger) then
prepare(job)
job.cleanuptemprunfiles
@@ -348,11 +348,11 @@ class Commands
end
end
- def copy
+ def copyoutput
copyortrim(false,'copy')
end
- def trim
+ def trimoutput
copyortrim(true,'trim')
end
@@ -411,7 +411,7 @@ class Commands
end
end
- def combine
+ def combineoutput
if job = TEX.new(logger) then
prepare(job)
job.cleanuptemprunfiles
@@ -541,14 +541,14 @@ commandline.registeraction('process', 'process file')
commandline.registeraction('mptex', 'process mp file')
commandline.registeraction('mpxtex', 'process mpx file')
-commandline.registeraction('listing', 'list of file content')
-commandline.registeraction('figures', 'generate overview of figures')
-commandline.registeraction('modules', 'generate module documentation')
-commandline.registeraction('arrange', 'impose pages (booklets)')
-commandline.registeraction('select', 'select pages from file(s)')
-commandline.registeraction('copy', 'copy pages from file(s)')
-commandline.registeraction('trim', 'trim pages from file(s)')
-commandline.registeraction('combine', 'combine multiple pages')
+commandline.registeraction('listing', 'list of file content')
+commandline.registeraction('figures', 'generate overview of figures')
+commandline.registeraction('modules', 'generate module documentation')
+commandline.registeraction('pdfarrange', 'impose pages (booklets)')
+commandline.registeraction('pdfselect', 'select pages from file(s)')
+commandline.registeraction('pdfcopy', 'copy pages from file(s)')
+commandline.registeraction('pdftrim', 'trim pages from file(s)')
+commandline.registeraction('pdfcombine', 'combine multiple pages')
# compatibility switch
@@ -556,20 +556,14 @@ class Commands
include CommandBase
- alias pdfarrange :arrange
- alias pdfselect :select
- alias pdfcopy :copy
- alias pdftrim :trim
- alias pdfcombine :combine
+ alias pdfarrange :arrangeoutput
+ alias pdfselect :selectoutput
+ alias pdfcopy :copyoutput
+ alias pdftrim :trimoutput
+ alias pdfcombine :combineoutput
end
-commandline.registeraction('pdfarrange')
-commandline.registeraction('pdfselect')
-commandline.registeraction('pdfcopy')
-commandline.registeraction('pdftrim')
-commandline.registeraction('pdfcombine')
-
# so far for compatibility
@@extrastringvars = [