MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Preserve notebook's $ContextPath between sessions / store custom

  • To: mathgroup at smc.vnet.net
  • Subject: [mg105014] Re: [mg104967] Preserve notebook's $ContextPath between sessions / store custom
  • From: John Fultz <jfultz at wolfram.com>
  • Date: Tue, 17 Nov 2009 05:18:03 -0500 (EST)
  • Reply-to: jfultz at wolfram.com

Yes, that's right.  Mathematica is not just changing the context, but trying to 
sandbox a number of evaluation side effects from notebooks which are operating 
in another context, including...

* $Context (of course)
* $ContextPath
* The state of In[]/Out[] numbering
* The Out[] history

In a notebook set with a unique notebook-level context, no attempt is made to 
recover the same context when you close and open the notebook again, and the
context you used isn't stored anywhere in the file.  I don't think that occurred 
to anyone here when designing the feature, and I'm not entirely certain whether 
it would be generally desirable to do so.

But, what you want to do is easy enough.  Instead of specifying a 
notebook-unique context, specify a named context of your choice (i.e., the 
"Other..." option).  Everything will be remembered as long as it's using the
same context name, and by hard-coding the name, you can guarantee that. Down 
side...you'll have to make sure you pick a unique name.  But that's probably not 
so difficult...you could choose a name based upon the file name, for example.  
You could write a button which does this, too.  I'll leave that as an exercise 
for the reader.

Sincerely,
 
John Fultz
jfultz at wolfram.com
User Interface Group
Wolfram Research, Inc.


On Sun, 15 Nov 2009 05:56:32 -0500 (EST), dnquark wrote:
> I have fallen into the habit of making the default context of the
> notebooks private by issuing the command
> SetOptions[EvaluationNotebook[], CellContext->Notebook]
> at the start of every notebook session.  However, I typically add
> several other contexts to $ContextPath; I even wrote a utility
> function to easily do all this automatically.
>
> It turns out, though, that upon closing and reopening the notebook
> Mathematica puts only "Notebook$$xx`" and "System`" contexts in
> $ContextPath.  My question is -- is there a way to make _my custom_
> $ContextPath persistent between sessions in the same way as {"Notebook$
> $xx`", "System`"} context list is persistent?..  Or at least, can I
> store custom metadata with the notebook -- i can always write a
> wrapper function to retrieve it.
>
> Thanks,
> --Leo





  • Prev by Date: Re: Re: Non-Linear pendulum
  • Next by Date: Re: Preserve notebook's $ContextPath between sessions / store custom
  • Previous by thread: Re: Preserve notebook's $ContextPath between sessions /
  • Next by thread: Re: Preserve notebook's $ContextPath between sessions / store custom