# Syntax information for pure functions

Mathematica's help on SyntaxInformation does not rule out syntax information for pure functions.

SyntaxInformation[f] gives information used to generate syntax coloring and other advisories when f[…] is entered as input.

The naive code

f = # &;
SyntaxInformation[f] = {"ArgumentsPattern" -> {_}}


fails with a message about the first argument. Using the string instead of the symbol

SyntaxInformation["f"] = {"ArgumentsPattern" -> {_}}


does not throw a message but it does not produce the expected red parameters in f[a,b].

Is there any way to specify syntax information on pure functions?

• SyntaxInformation works at the Symbol level. Call it before assigning to f. – b3m2a1 Jan 17 '18 at 20:11
• Although the solution is quite simple, it is far from trivial. Write it as an answer, I will accept it. – Hector Jan 17 '18 at 20:15

SyntaxInformation does not hold its arguments so you can hold it:

f // ClearAll
f = # &;
f // Unevaluated // SyntaxInformation = {"ArgumentsPattern" -> {_}};


as an alternative to altering the order:

f // ClearAll
f // SyntaxInformation = {"ArgumentsPattern" -> {_}};
f = # &;