2
$\begingroup$

It seems there is something wrong in the expected behaviour of setting an option back to its default value when this command is executed inside a *EventActions : the default (Inherited) value does not correspond to the next (up) level value it should.

Here is a simple example with the Background color option.

Without *EventActions all work as it should:

1/ Start a fresh session and create a new working notebook to input the following commands.

2/ Define a default background color for the session

SetOptions[$FrontEndSession, Background -> Yellow]
(* OK: the background is now yellow *)

3/ Modify the notebook private background color:

SetOptions[EvaluationNotebook[], Background -> LightBlue]
(* OK: the background is now LightBlue*)

4/ Revert to the default background color:

SetOptions[EvaluationNotebook[], Background -> Inherited]
(* OK: the inherited background color is now yellow -> $FrontEndSession one *)

Problem with *EventActions:

5/ Let's say now you need to automatically revert to the default background color when you press a given key:

First let's turn it blue again:

SetOptions[EvaluationNotebook[], Background -> LightBlue]

then

SetOptions[EvaluationNotebook[], 
NotebookEventActions -> {{"KeyDown", "b"} :> (SetOptions[EvaluationNotebook[], 
  Background -> Inherited])}]

and now type "b" in the notebook ...

Instead of yellow, the background color is "white" (as the hard-coded default one), it has been set to

CurrentValue[EvaluationNotebook[], Background]

None

So, what is wrong or what am i doing wrong here ?

Concerning Inherited behaviour, wouldn't it be better if it worked like Automatic, that means it is never automatically replaced by some absolute value when displayed in options settings ?

$\endgroup$
0

1 Answer 1

1
$\begingroup$

It seems that Inherited is replaced with None when the FrontEnd parses the event action, before it is sent for evaluation. Don't know why this happens and how to judge it, you can ask WRI Support.

Nevertheless, an ugly but working workaround:

SetOptions[
    EvaluationNotebook[]
  , NotebookEventActions -> {
        {"KeyDown", "b"} :> (
            SetOptions[EvaluationNotebook[], Background -> ToExpression["Inherited"]]
        )
    }
]

This prevents FrontEnd from replacing Inherited too soon.

$\endgroup$
1
  • $\begingroup$ Thank you for the workaround. It works also if I use CurrentValue instead of SetOptions. $\endgroup$
    – SquareOne
    Commented Apr 19, 2017 at 23:14

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.