5

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?

xzczd
  • 65,995
  • 9
  • 163
  • 468
swish
  • 7,881
  • 26
  • 48
  • Auto completion for ordinary user functions is discussed here https://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. – N0va Nov 04 '20 at 23:02
  • 1
    @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. – swish Nov 05 '20 at 11:49

1 Answers1

-2

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.