Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

While working on my own plotLegends package I encoutered some weird behaviour of the front end's syntax highlighting. I reduced the problem to the following minimal example:

Unprotect[Plot];
AppendTo[Options[Plot], opt1 -> True];

Plot[a_, b_, c___, opt1 -> opt_, d___] :=
 foo[Plot[a, b, c, d], opt]

Plot[a_, b_, c___, opt1 -> opt_, d___] /; True :=
 foo[Plot[a, b, c, d], opt]
Protect[Plot];

Unprotect[ListPlot];
AppendTo[Options[ListPlot], opt1 -> True];

ListPlot[a_, c___, opt1 -> opt_, d___] :=
 foo[ListPlot[a, c, d], opt]

ListPlot[a_, c___, opt1 -> opt_, d___] /; True :=
 foo[ListPlot[a, c, d], opt]

Protect[ListPlot];

You can see what I mean by "weird behaviour" in the following screenshot:

enter image description here

For both Plot and ListPlot, adding /;True leads to the option being highlighted red (which it otherwise isn't) . But only for Plot the default green highlighting of the patterns gets lost too. Can anyone reproduce this? Is there any reason why Plot should differ from ListPlot?

I'm using version 8.0 on Windows 7.

share|improve this question
add comment

1 Answer

I can reproduce this on OSX, but it is not specific to Plot. There are many other functions showing the same behavior. Try for instance

Integrate[a___] /; True := blub

When you delete the last e of Integrate, you see that the pattern a___ is highlighted in green again.

All this happens in the front end where you cannot get much insight. A possible solution is to write the Condition explicitely:

Condition[Plot[a_, b_, c___, opt1 -> opt_, d___], True] := foo[Plot[a, b, c, d], opt]

This looks like you expected it here

Mathematica graphics

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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