context commands in lua-files
Hello, Here some new ideas: http://pmrb.free.fr/tmp/context-commands/ All feedback is welcome! Cheers, Peter -- Contact information: http://pmrb.free.fr/contact/
On 07/16/2010 04:41 PM, Peter Münster wrote:
Hello,
Here some new ideas:
http://pmrb.free.fr/tmp/context-commands/
All feedback is welcome!
FWIW, I actually like this: I find it more readable than the XML version, and the inline descriptions and comments are clearly helpful. Best wishes, Taco
On Fri, Jul 16, 2010 at 4:41 PM, Peter Münster
Hello,
Here some new ideas:
http://pmrb.free.fr/tmp/context-commands/
All feedback is welcome!
Cheers, Peter
-- Contact information: http://pmrb.free.fr/contact/
_______________________________________________ dev-context mailing list dev-context@ntg.nl http://www.ntg.nl/mailman/listinfo/dev-context
Why don't put them into a table as is in http://www.lua.org/pil/10.1.html For exampl e placefloat.lua should be placefloat ={ props = { generated = true, -- default = false fixpart = "place", varpart = "float", generator = "definefloat", categories = {"Structure", "Graphic"} -- first category is main category, in the other categories, there are -- just references } -- ... more data } It's very powerful then to manage this file with lua functions. -- luigi
On Sat, Jul 17 2010, luigi scarso wrote:
Why don't put them into a table as is in http://www.lua.org/pil/10.1.html For exampl e placefloat.lua should be placefloat ={ props = { [...]
Because I like to avoid redundancy. It's easy to do things like this automatically: local placefloat = {} setfenv(0, placefloat) dofile("placefloat.lua") setfenv(0, _G) print(placefloat.props.fixpart) Or like this: placefloat.lua: entry = { -- or "command" props = ..., args = ..., ... } And then: local commands = {} dofile("placefloat.lua") commands.placefloat = entry (or command) print(placefloat.props.fixpart) Cheers, Peter -- Contact information: http://pmrb.free.fr/contact/
On Sat, Jul 17 2010, luigi scarso wrote:
Why don't put them into a table as is in http://www.lua.org/pil/10.1.html
Ok, now one file defines exactly one "command" table. I added also other minor enhancements. Cheers, Peter -- Contact information: http://pmrb.free.fr/contact/
On Sat, Jul 17, 2010 at 21:32, Peter Münster wrote:
On Sat, Jul 17 2010, luigi scarso wrote:
Why don't put them into a table as is in http://www.lua.org/pil/10.1.html
Ok, now one file defines exactly one "command" table.
For my taste this is better as well. A few random comments from externalfigure: - Despite the fact that the command name is known from filename, wouldn't it be nice to have externalfigure string defined somewhere? - It is not really needed, but it helps when cross-referencing: I would nevertheless leave the [1] = {...}, [2] = {...} for arguments - The following: settings = { inherit = "useexternalfigure", -- n = 3 not needed, since one command has only one settings-option }, is a bit weird to me. Why not putting the "inherit" already under arguments above? And yes, you probably do need to tell from which argument of \useexternalfigure you want to inherit the settings. - If all the three arguments are optional, it's a bit difficult to tell what combination of arguments is allowed, so it might make sense to be a bit more verbose in that (to tell somehow that for example only 123 and 23 and 3 is allowed, but not 13 for example), but this is not too important. Mojca
On 07/17/2010 11:09 PM, Mojca Miklavec wrote:
- The following: settings = { inherit = "useexternalfigure", -- n = 3 not needed, since one command has only one settings-option }, is a bit weird to me. Why not putting the "inherit" already under arguments above? And yes, you probably do need to tell from which argument of \useexternalfigure you want to inherit the settings.
I also think inline is better, even though it adds redundancy. The 'n' is probably not needed in practice even though conceptually Mojca is right.
- If all the three arguments are optional, it's a bit difficult to tell what combination of arguments is allowed, so it might make sense to be a bit more verbose in that (to tell somehow that for example only 123 and 23 and 3 is allowed, but not 13 for example), but this is not too important.
One way around that (and the 'n' issue) is to do something like this: arguments = { ["label_arg"] = { type = label, }, ["filename_arg"] = { type = file, }, ["settings_arg"] = { type = settings, comment = "short comment for this option", description = "long description for this option", inherit = { "useexternalfigure", 'settings_arg' } }, ["parent_arg"] = { type = parent, comment = "short comment for this option", description = "long description for this option" }, }, variants = { -- just an example { "filename_arg" }, { "label_arg", "filename_arg" }, { "label_arg", "filename_arg", "settings_arg" }, { "filename_arg", "parent_arg" }, } }, but I am not sure this is really better ? Best wishes, Taco
On Sun, Jul 18 2010, Taco Hoekwater wrote:
arguments = { ["label_arg"] = { type = label, }, ["filename_arg"] = { type = file, }, ["settings_arg"] = { type = settings, comment = "short comment for this option", description = "long description for this option", inherit = { "useexternalfigure", 'settings_arg' }
}, ["parent_arg"] = { type = parent, comment = "short comment for this option", description = "long description for this option" }, }, variants = { -- just an example { "filename_arg" }, { "label_arg", "filename_arg" }, { "label_arg", "filename_arg", "settings_arg" }, { "filename_arg", "parent_arg" },
} },
but I am not sure this is really better ?
Seems to be ok for \externalfigure but not for \setupheadertexts... Peter -- Contact information: http://pmrb.free.fr/contact/
On Sun, Jul 18 2010, Taco Hoekwater wrote:
variants = { -- just an example { "filename_arg" }, { "label_arg", "filename_arg" }, { "label_arg", "filename_arg", "settings_arg" }, { "filename_arg", "parent_arg" },
Now I see the big benefit! Instead of having 2 concepts (optional arguments and variants), we keep only the concept of variants! Very good! Peter -- Contact information: http://pmrb.free.fr/contact/
On Sat, Jul 17 2010, Mojca Miklavec wrote: > A few random comments from externalfigure: > - Despite the fact that the command name is known from filename, > wouldn't it be nice to have externalfigure string defined somewhere? Ok, see response to Taco. > - It is not really needed, but it helps when cross-referencing: I > would nevertheless leave the [1] = {...}, [2] = {...} for arguments > - The following: > settings = { > inherit = "useexternalfigure", > -- n = 3 not needed, since one command has only one settings-option > }, > is a bit weird to me. Why not putting the "inherit" already under > arguments above? And yes, you probably do need to tell from which > argument of \useexternalfigure you want to inherit the settings. >From my very small ConTeXt experience, I made some assumptions: - one command has no more than one settings-option (key-val-pairs) - one command has no more than one keywords-option If this is true, then there is no problem with cross-referencing. The n = X would be even difficult, when there a variants: imagine, \useexternalfigure can have settings at n = 2 or n = 4 and so on. And I like the separate settings-table, because it can be very big and would clutter the arguments table. If my assumptions are wrong, then there will be more problems: perhaps the settings must go into the arguments table or we need a lot of numbering (n = X here and there). > - If all the three arguments are optional, it's a bit difficult to > tell what combination of arguments is allowed, so it might make sense > to be a bit more verbose in that (to tell somehow that for example > only 123 and 23 and 3 is allowed, but not 13 for example), but this is > not too important. I think, there has to be some introduction chapter for the user with the general rules in ConTeXt-commands. I suppose these rules: - when a command has an optional keyword-option and an optional settings-option and you use only one of them, you don't need a placeholder (empty bracket pair) example: \setupitemize[packed] or \setupitemize[start=5] (context is intelligent here) - context cannot distinguish between label and keyword, so if you want to use a label in \placefloat, you must add a placeholder for the keyword Hans can tell us perhaps more about these rules... Furthermore, we can add in this introduction some notes about spaces: - space is allowed between 2 bracket options - space is allowed after a comma - space is not allowed before and after the = - space is gobbled after ] if not all optional arguments are used Cheers, Peter -- Contact information: http://pmrb.free.fr/contact/
On Sun, Jul 18, 2010 at 09:38, Peter Münster wrote:
On Sat, Jul 17 2010, Mojca Miklavec wrote:
- It is not really needed, but it helps when cross-referencing: I would nevertheless leave the [1] = {...}, [2] = {...} for arguments - The following: settings = { inherit = "useexternalfigure", -- n = 3 not needed, since one command has only one settings-option }, is a bit weird to me. Why not putting the "inherit" already under arguments above? And yes, you probably do need to tell from which argument of \useexternalfigure you want to inherit the settings.
From my very small ConTeXt experience, I made some assumptions: - one command has no more than one settings-option (key-val-pairs) - one command has no more than one keywords-option
If this is true, then there is no problem with cross-referencing. The n = X would be even difficult, when there a variants: imagine, \useexternalfigure can have settings at n = 2 or n = 4 and so on.
I didn't understand the last paragraph, but while it's not a problem for a human to determine where to inherit from, it might be a problem for a computer if you want to print the complete command. Mojca
On Sun, Jul 18 2010, Mojca Miklavec wrote:
I didn't understand the last paragraph, but while it's not a problem for a human to determine where to inherit from, it might be a problem for a computer if you want to print the complete command.
There is no problem for a computer, it's just jumping from the settings of \externalfigure to the settings-table of \useexternalfigure. Peter -- Contact information: http://pmrb.free.fr/contact/
On Sun, Jul 18 2010, Peter Münster wrote:
- If all the three arguments are optional, it's a bit difficult to tell what combination of arguments is allowed, so it might make sense to be a bit more verbose in that (to tell somehow that for example only 123 and 23 and 3 is allowed, but not 13 for example), but this is not too important.
I think, there has to be some introduction chapter for the user with the general rules in ConTeXt-commands. I suppose these rules: [...]
And when a command does not follow these rules (perhaps \externalfigure is such a case), then there must be some notes about this in the description. Peter -- Contact information: http://pmrb.free.fr/contact/
On 07/17/2010 09:32 PM, Peter Münster wrote:
On Sat, Jul 17 2010, luigi scarso wrote:
Why don't put them into a table as is in http://www.lua.org/pil/10.1.html
Ok, now one file defines exactly one "command" table. I added also other minor enhancements.
If you start your files like this: command = command or {} command['placefloat'] = { comment = "Insert a floating element.", ... } then they could easily all be merged into a single command table during loading or even via 'cat'. Like Mojca says, it is better not to be dependent on the file name, and also it is more efficient to have a single lua file than 500-600 separate ones. There is no need to combine them immediately, but if this goes into the distro at some point then a single large file is definitely better than lots of smaller ones. Best wishes, Taco
On Sun, Jul 18 2010, Taco Hoekwater wrote:
If you start your files like this:
command = command or {} command['placefloat'] = { comment = "Insert a floating element.", ... }
then they could easily all be merged into a single command table during loading or even via 'cat'.
Like Mojca says, it is better not to be dependent on the file name, and also it is more efficient to have a single lua file than 500-600 separate ones. There is no need to combine them immediately, but if this goes into the distro at some point then a single large file is definitely better than lots of smaller ones.
Ok, I agree. The very strong reason for one file per command is the better comfort when editing the files. And the big file for the distribution can be generated with cat * >commands.lua Peter -- Contact information: http://pmrb.free.fr/contact/
On 18-7-2010 8:09, Taco Hoekwater wrote:
On 07/17/2010 09:32 PM, Peter Münster wrote:
On Sat, Jul 17 2010, luigi scarso wrote:
Why don't put them into a table as is in http://www.lua.org/pil/10.1.html
Ok, now one file defines exactly one "command" table. I added also other minor enhancements.
If you start your files like this:
command = command or {} command['placefloat'] = { comment = "Insert a floating element.", ... }
then they could easily all be merged into a single command table during loading or even via 'cat'.
I'd rather go for this (see lfg file for examples): return { name = "placefloat", version = "1.00", comment = "Insert a floating element.", } and give the files names like placefloat.cid (context interface definition) and then load them using a lua script (this also permits us to load several definitions named placefloat e.g. for comparison of versions). Another aspect is shared definitions. Settings like style and align are often shared so there we need a way to refer to that like align = interfaces.resolve("align"), and so. In a similar way inheritance can be dealt with. I'm not sure what the final purpose of this exercise is (intended usage and so), but if it's to be integrated (or loaded in context) it has to fit in the general way such data is stored. In that case I have to make a loader (in the interfaces namespace), one that probably drops not needed data, and caches relevant info for runtime usage. Also, as I cannot drop the xml counterpart now so I need to be able to generate that file from it as I don't want to keep that (also mkii) downward compatibility aspect (once the lua format is known I can do the reverse as exercise), so we need at least the level of detail from the xml file, including value types and (this cd:number tagging). So, given this thread .. can we summarize the state of a couple of commands? Say: - setupframed (inherited) - framed (inherits, resolving) - setupheadertexts (several arg configurations) - externalfigure (several arg configurations) - itemize (start command) Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On Sun, Jul 18 2010, Hans Hagen wrote:
then they could easily all be merged into a single command table during loading or even via 'cat'.
I'd rather go for this (see lfg file for examples):
return { name = "placefloat", version = "1.00", comment = "Insert a floating element.", }
Hello Hans, No problem for me, but the suggested "cat *.cid >all-commands" would not work.
and give the files names like placefloat.cid (context interface definition) and then load them using a lua script (this also permits us to load several definitions named placefloat e.g. for comparison of versions).
My purpose is to stay in sync (as good as possible) with the latest mkiv but not to manage versions (I'm lazy, svn is doing that for me in general ;). But it's no real problem of course, to add some "version = xxx", we only need to remember to increment it sometimes.
Another aspect is shared definitions. Settings like style and align are often shared so there we need a way to refer to that like
align = interfaces.resolve("align"),
I agree.
I'm not sure what the final purpose of this exercise is (intended usage and so),
My personal motivation is a new version of setup-en.pdf, more verbose (detailed description of all options), complete (even for low-level commands, but no obsolete commands), and with some additional features (categories, index, cross-references). See also: http://archive.contextgarden.net/message/20100508.204345.b5003312.en.html But it's even better, if this exercise can serve also other goals (for example syntax-checking, replacing cont-en.xml, replacing texshow-wiki etc.).
but if it's to be integrated (or loaded in context) it has to fit in the general way such data is stored.
My idea was to put these command-descriptions on an svn-server, for example here: http://foundry.supelec.fr/svn/contextman/context-commands So, that all can contribute. If the files were in the context-distribution, I don't know, how others than you can contribute.
So, given this thread .. can we summarize the state of a couple of commands? Say:
- setupframed (inherited) - framed (inherits, resolving) - setupheadertexts (several arg configurations) - externalfigure (several arg configurations) - itemize (start command)
It's here: http://pmrb.free.fr/tmp/context-commands/ Cheers, Peter -- Contact information: http://pmrb.free.fr/contact/
On Fri, Jul 16, 2010 at 16:41, Peter Münster
Hello,
Here some new ideas:
Wow! I like it very much. Mojca
On 17-7-2010 7:39, Mojca Miklavec wrote:
On Fri, Jul 16, 2010 at 16:41, Peter Münster
wrote: Hello,
Here some new ideas:
Wow! I like it very much.
i'll come back to this later, just a few comments now: - props -> properties (or whatever, but no shortcuts) - args -> arguments - [=[ looks rather bad but anyhow, examples should probably not be done this way (examples can be go into tex files) Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On Sat, Jul 17 2010, Hans Hagen wrote:
- props -> properties (or whatever, but no shortcuts)
No more needed.
- args -> arguments
Done.
- [=[ looks rather bad but anyhow, examples should probably not be done this way (examples can be go into tex files)
Ok, why not! Peter -- Contact information: http://pmrb.free.fr/contact/
participants (5)
-
Hans Hagen
-
luigi scarso
-
Mojca Miklavec
-
Peter Münster
-
Taco Hoekwater