6

If one executes the following code

SetOptions[EvaluationNotebook[], InputAliases -> {"aa" -> 
 "AFunctionWithAVeryLongName[\!\(\*TagBox[FrameBox[\"input\"],\"Placeholder\"]\)]"}]

the front end will change ESC+a+a+Esc into a long expression with a placeholder. I want the placeholder selected after the replacement.

If I try to use SelectionPlaceholder, instead of Placeholder, then a character from AFunctionWithAVeryLongName gets selected.

If I try to include a tab at the end of the string,

SetOptions[EvaluationNotebook[], InputAliases -> {"aa" -> 
 "AFunctionWithAVeryLongName[\!\(\*TagBox[FrameBox[\"input\"],\"Placeholder\"]\:0009\)]"}]

the tab goes in literally as a tab character, not a tab command.

Also, I want the output to have a string, say "input", in the placeholder.

enter image description here

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
Hector
  • 6,428
  • 15
  • 34
  • 1
    Related. The answer there by the user matTECmatica appears to answer your question. I think that code could be slightly improved, maybe also see my comment there. – Jacob Akkerboom Aug 11 '13 at 14:49
  • Hector, you haven't answered my question: if as I believe this is not possible from InputAliases what alternatives are acceptable to you? What about a shortcut-key, or a palette button? – Mr.Wizard Aug 12 '13 at 01:13
  • Unfortunately, I do not see how Mathematica would allow key modifiers for shortcuts. I am working on a palette button to be controlled by AutoHotkey. – Hector Aug 13 '13 at 13:22
  • Hector, I'm not sure what you mean. If you doubt it is possible to create your own keyboard shortcuts please see this search result as it surely is. Are you going to post a new question? – Mr.Wizard Aug 13 '13 at 14:11
  • 1
    @Mr.Wizard I am looking for shortcuts available only when a package has been loaded (as opposed to system-wide ones). Also, I will post a new question because creating palette brought new challenges. – Hector Aug 13 '13 at 14:28

2 Answers2

6

Please try:

SetOptions[EvaluationNotebook[], 
 InputAliases -> {
   "aa" -> RowBox[{"AFunctionWithAVeryLongName", "[", "\[SelectionPlaceholder]", "]"}]
 }
]

enter image description here

A placeholder with a name does not seem possible with Input Aliases.

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
  • Very nice! You were quick too :) – Jacob Akkerboom Aug 11 '13 at 14:53
  • Duh!, the manual does say that InputAliases accepts "strings or box expressions." – Hector Aug 11 '13 at 14:54
  • @Hector There are lots of things the manual says that I didn't understand until someone gave me an example, or sometimes several examples. – Mr.Wizard Aug 11 '13 at 14:56
  • I updated the question to make explicit the requirement on the string within the placeholder … – Hector Aug 11 '13 at 15:11
  • @Hector I'm not certain that is possible from an input alias (I'll be happy to see it if it is). Things like command completion templates are inserted programmatically and use e.g. SelectionMove to select the labels. At least that's my recollection. – Mr.Wizard Aug 11 '13 at 15:15
  • @Hector would it be acceptable to make this insertion using a shortcut-key rather than an input alias? Such things are possible with that functionality I believe. – Mr.Wizard Aug 11 '13 at 15:24
  • @Mr.Wizard I think that would be ok. Should I open a different question? – Hector Aug 12 '13 at 20:26
  • @Hector That's up to you. Since the text placeholder was there in the original question this isn't a case of "moving goalposts" and you don't need to post a new question. On the other hand a new question may bring fresh eyes and more/better solutions. At the moment I'm busy with another post and can't work on this. – Mr.Wizard Aug 13 '13 at 09:46
  • This doesn't work in MMA 10. The placeholder is not selected, instead the cursor is to the right of it. – Prastt Nov 23 '15 at 15:33
  • @Barefeg That is a known bug; see (54595) and (55734). Sadly it has been there since 10.0.0 and it still has not been corrected. :-( – Mr.Wizard Nov 24 '15 at 13:48
3

You can create a placeholder with a name if you use a TemplateBox:

CurrentValue[EvaluationNotebook[], {InputAliases,"aa"}] = RowBox[{
    "AFunctionWithAVeryLongName",
    "[",
    TemplateBox[{},"SelectionPlaceholder",DisplayFunction->(FrameBox["\"input\""]&)],
    "]"
}];

Then, using the alias "aa" produces:

enter image description here

which can be selected by tabbing. Alas, the placeholder is still not selected when you use the alias.

Carl Woll
  • 130,679
  • 6
  • 243
  • 355