Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Templates from Usage Messages

  • To: mathgroup at smc.vnet.net
  • Subject: [mg110959] Templates from Usage Messages
  • From: "David Park" <djmpark at comcast.net>
  • Date: Wed, 14 Jul 2010 05:35:45 -0400 (EDT)

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 at comcast.net

 <http://home.comcast.net/~djmpark> http://home.comcast.net/~djmpark/  

 


  • Prev by Date: Re: Primitive Disk Gradient Fills in Graphics
  • Next by Date: Re: File names and strings
  • Previous by thread: Re: Primitive Disk Gradient Fills in Graphics
  • Next by thread: Re: Templates from Usage Messages