2
$\begingroup$

The function Context[] returns the context of the Notebook the function is called in.

Is there a function where we can specify e.g a Notebook object and retrieve the context from that file?

I'm creating a palette where I want to change a variable located in a Notebook that has the context local to that notebook. From the palette I would like to use SelectedNotebook[] and retrieve the context.

Thx for advise!

$\endgroup$
  • 1
    $\begingroup$ Can you give a tiny example of such a palette, to get a better idea of what you need? What if the context is unique to cell groups instead of notebooks? How does the palette obtain the variable name? $\endgroup$ – Szabolcs Sep 8 '17 at 9:55
  • 1
    $\begingroup$ Also, Context[] does not need to be notebook's CellContext, e.g. if Begin/BeginPackage was used. $\endgroup$ – Kuba Sep 8 '17 at 10:00
  • 1
    $\begingroup$ related: How does the Kernel know the $Context in a localized notebook $\endgroup$ – Kuba Sep 8 '17 at 10:03
  • $\begingroup$ I guess a more concrete question would be: How do we evaluate code as if it were entered at the current cursor position in the notebook? $\endgroup$ – Szabolcs Sep 8 '17 at 10:36
  • 1
    $\begingroup$ Do you really need a palette? Would a function (loaded from a package) work instead? How about a palette that writes myFunction[data] into the notebook (perhaps along with a Needs)? Maybe automatically insert that as an input cell, then evaluate it. Maybe even delete it after evaluation, if that's what you prefer. $\endgroup$ – Szabolcs Sep 8 '17 at 14:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.