4
$\begingroup$

Entities have this nice autocompletion of properties: enter image description here

How do I define autocompletion for my own boxes that behave the same way?

$\endgroup$
2
  • $\begingroup$ Auto completion for ordinary user functions is discussed here mathematica.stackexchange.com/q/56984 I am not sure how to apply the methods mentioned there (all related to AddSpecialArgCompletion from FEPrivate) to Subvalue functions/boes. $\endgroup$ – N0va Nov 4 '20 at 23:02
  • 1
    $\begingroup$ @N0va Yeah, I wasn't sure either. That's why I'm asking this question, really want to have autocompletion for my custom objects and not just for some function arguments. $\endgroup$ – swish Nov 5 '20 at 11:49
-2
$\begingroup$

Here is a simple example to implement custom do...end box:

ClearAll@do


SetAttributes[do, HoldAll];
do[var_, begin_, end_, body_] := Do[body, {var, begin, end}]


Hold[do /: MakeBoxes[do[var_, begin_, end_, body_], StandardForm] := 
     TemplateBox[MakeBoxes /@ Unevaluated@{var, begin, end, body}, 
      "do", DisplayFunction -> (GridBox[{{RowBox@{RowBox[{style@"do", 
                " ", #}], "=", 
              RowBox[{#2, " ", style@"to", 
                " ", #3}]}}, {RowBox@{"", #4}}, {style@"end"}}, 
          ColumnAlignments -> Left] &)]] /. 
   style[str_] -> StyleBox[str, FontColor -> Darker@Green] // 
  ReleaseHold // ReleaseHold


Hold[CurrentValue[EvaluationNotebook[], {InputAliases, "do"}] = 
    TemplateBox[{"\[SelectionPlaceholder]", "\[Placeholder]", 
      "\[Placeholder]", "\[Placeholder]"}, "do", 
     DisplayFunction -> (GridBox[{{RowBox@{RowBox[{style@"do", 
               " ", #}], "=", 
             RowBox[{#2, " ", style@"to", 
               " ", #3}]}}, {RowBox@{"", #4}}, {style@"end"}}, 
         ColumnAlignments -> Left] &)]] /. 
  style[str_] -> 
   StyleBox[str, FontColor -> Darker@Green] // ReleaseHold

When using, first press Esc key, then input do, then press Esc key to automatically incomplete.

$\endgroup$
2
  • 1
    $\begingroup$ (-1)This isn't an answer to OP's question at all. $\endgroup$ – xzczd Nov 4 '20 at 4:07
  • $\begingroup$ @xzczd Recently, due to the Great Firewall (block), I can't see the picture in the question. I just guess the answer to this question. $\endgroup$ – A little mouse on the pampas Nov 5 '20 at 0:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.