From: David Park on 14 Jul 2010 05:35 I would like to have a form of input arguments that contain operational symbols as well as variables, and especially I would like to use the Span operation. Here is an example: foo::usage = "foo[a, b;;c] will operate on structure a between parts b and c."; foo[a_, (b_Integer?Positive) ;; (c_Integer?Positive)] := {a, b, c} foo[a, 2;;3] {a,2,3} The problem is that I don't know how to write the first part of the usage message such that the command completion template will come out with two variable slots for a and b with a ";;" between. Try using command completion of foo. However, I was able to write a routine that creates this type of template. makeTemplate::usage = "makeTemplate[splvar, {plvars}][function[args\[Ellipsis]] will make \ a template for function in which splvar is a selected placeholder, \ and the symbols listed in plvars are placeholders."; makeTemplate[splvar_, plvars_] := Function[expr, Module[ {spl = SymbolName[splvar], pl, splrule, plrules}, If[Length[plvars] > 0, pl = SymbolName /@ plvars; plrules = (# -> TagBox[FrameBox[#], "Placeholder"]) & /@ pl, plrules = {}]; splrule = spl -> TagBox[FrameBox[spl], "SelectionPlaceholder"]; (MakeBoxes[expr] /. splrule /. plrules) // DisplayForm ], HoldFirst] makeTemplate[a, {b, c}][foo[a, b ;; c]] gives the desired template, and I can, for example, use that in an ActionMenu drop-down paste operation. I just can't get it into a usage message and normal command completion. David Park UMLF djmpark(a)comcast.net <http://home.comcast.net/~djmpark> http://home.comcast.net/~djmpark/
From: magma on 16 Jul 2010 05:17 I was confronted with a similar problem a couple of months ago, while developing my package xPrint, a point-and-click interface to the tensor algebra suite xAct. You can read more on xPrint here http://sites.google.com/site/xprintforxact/ I needed to create custom made menu-driven templates for the functions used to define various geometric objects (manifolds,tensors, covariant derivatives, ect). I ended up developing what I called enhanced-template-technology, which basically recreated the exact look and feel of the normal templates, but with some extra features and completely programmable and menu-driven. Although Mathematica offers the ctrl-shift-K (Make Template) menu facility, to this functionality there does not seem to correspond any programmable function, so I had to create the input cell (with the template) from scratch. In David's specific case however, this might not be necessary. Consider this workaround: foo::usage = "foo[a, Span[b,c]] will operate on structure a between parts b and \ c."; foo[a_, (b_Integer?Positive) ;; (c_Integer?Positive)] := {a, b, c} Now you can achieve the same ";;" effect using the standard template technology. If this is not good enough, I suppose one could intercept the ctrl- shift-K command (or create another one) and insert her/his own special function, like David's makeTemplate.
|
Pages: 1 Prev: Mathematica link to a c++ lib Next: Using GatherBy, Select, and Sort to process data. |