Re: Preserve notebook's $ContextPath between sessions / store custom
- To: mathgroup at smc.vnet.net
- Subject: [mg105010] Re: Preserve notebook's $ContextPath between sessions / store custom
- From: dnquark <dnquark at gmail.com>
- Date: Tue, 17 Nov 2009 05:17:13 -0500 (EST)
- References: <hdon5g$9es$1@smc.vnet.net>
I am continuing my quest of setting up and saving a persistent custom $ContextPath. After some experimentation, I discovered that by SetOption [EvaluationNotebook[],MyOption->optVal] one can set one (and only one!) persistent custom option for a notebook. Currently, I have a wrapper function that 1. does SetOptions[EvaluationNotebook[], CellContext->Notebook] 2. Adds some contexts to $ContextPath 3. Saves it in a notebook option. The problem is, I cannot do (1) and (2) in the same function call: the following doesn't work test[] := (SetOptions[EvaluationNotebook[],CellContext- >Notebook];oldct=$ContextPath; AppendTo[System` $ContextPath,"MyContext`"]); In fact, the only way I got this to work was by manipulating Notebook cells from the function via NotebookWrite[], SelectionMove[], etc to set up and evaluate cells corresponding to steps (1) and (2). The result is an ugly kludge that mostly works (although I still cannot understand what exactly happens with cell evaluation... When I try to programmatically delete the temporary cells in the front end notebook, everything starts breaking.) Can anyone enlighten me as to why this is so difficult to do in a function -- or if it's not, what is the proper way of doing this?.. And is there any documentation on setting notebook options?.. Why am I only able to set one?.. --Leo On 15 Nov, 06:03, dnquark <dnqu... at gmail.com> 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