Re: Initialization cell appearance

*To*: mathgroup at smc.vnet.net*Subject*: [mg74395] Re: Initialization cell appearance*From*: Albert <awnl at arcor.net>*Date*: Mon, 19 Mar 2007 22:06:54 -0500 (EST)*References*: <etb5c3$k2f$1@smc.vnet.net> <etcoj8$9ub$1@smc.vnet.net> <etg40k$igp$1@smc.vnet.net> <etlq16$r7e$1@smc.vnet.net>

Hi, > There is a small bug in your code though (the definition of isinit). oops, did not check the last change I guess, sorry. It was just a sketch of how this can be handled, for production use you might need some additional checks, e.g. to make sure that the selections are what you think... > Typically I would use this with > > nb = NotebookOpen[<path to some notebook file>] > > and I think I will turn it into a utility function. I suppose it could also > be implemented as a replacement rule on the notebook expression. Would > this be faster, I wonder ? I don't know if it would be faster, probably yes, but there are issues with this approach which might or might not be a problem for your use case: - You will have to read the Notebook-EXPRESSION from the Notebook-OBJECT and transform it. This will be _another_ Notebook-EXPRESSION, which you can turn into a new Notebook-OBJECT (and show it in a window) with NotebookPut or write it back to a file. Would you want to replace the old file, what happens with the still open and unchanged Notebook? You probably need to close it before overwriting it. I think you will need to be careful about what you are doing with this approach, otherwise you might even loose data. Anyway it is for sure different from changing the actual Notebook-OBJECT "in place"... - _If_ you are using a StyleSheet which has definitions of Cell-Styles that are Initialization-Cells by default, you cannot detect that by simple Pattern-Matching of the Notebook-Expression but have to analyse the StyleSheet as well. This might not be an issue for you, but has to be considered if you want robust code... hth, albert