6
$\begingroup$

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

$\endgroup$
5
  • 1
    $\begingroup$ 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. $\endgroup$ Aug 11, 2013 at 14:49
  • $\begingroup$ 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? $\endgroup$
    – Mr.Wizard
    Aug 12, 2013 at 1:13
  • $\begingroup$ 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. $\endgroup$
    – Hector
    Aug 13, 2013 at 13:22
  • $\begingroup$ 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? $\endgroup$
    – Mr.Wizard
    Aug 13, 2013 at 14:11
  • 1
    $\begingroup$ @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. $\endgroup$
    – Hector
    Aug 13, 2013 at 14:28

2 Answers 2

6
$\begingroup$

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.

$\endgroup$
10
  • $\begingroup$ Very nice! You were quick too :) $\endgroup$ Aug 11, 2013 at 14:53
  • $\begingroup$ Duh!, the manual does say that InputAliases accepts "strings or box expressions." $\endgroup$
    – Hector
    Aug 11, 2013 at 14:54
  • $\begingroup$ @Hector There are lots of things the manual says that I didn't understand until someone gave me an example, or sometimes several examples. $\endgroup$
    – Mr.Wizard
    Aug 11, 2013 at 14:56
  • $\begingroup$ I updated the question to make explicit the requirement on the string within the placeholder … $\endgroup$
    – Hector
    Aug 11, 2013 at 15:11
  • $\begingroup$ @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. $\endgroup$
    – Mr.Wizard
    Aug 11, 2013 at 15:15
3
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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