I ran into this when I was working with an example from the Help Pages of V9. Cells
is a new function added in V9. The following appears to work the first time it is evaluated in a notebook with nb
assigned to some appropriate value, say, EvaluationNotebook[]
.
Scan[(CurrentValue[#, StyleNames] = "Title") &, Cells[nb, CellStyle -> "Section"]]
However, if I try again to change the cells affected by the first evaluation to another style or back to the original style, nothing changes. Neither this
Scan[(CurrentValue[#, StyleNames] = "Text") &, Cells[nb, CellStyle -> "Title"]]
nor this
Scan[(CurrentValue[#, StyleNames] = "Section") &, Cells[nb, CellStyle -> "Title"]]
has any effect.
For other CurrenValue
targets such as FontSize
, it's easy to change the value repeatedly.
Scan[(CurrentValue[#, FontSize] = 100) &, Cells[nb, CellStyle -> "Section"]]
Scan[(CurrentValue[#, FontSize] = 30) &, Cells[nb, CellStyle -> "Section"]]
Answer
It appears that it only works once because it messes up the cell expressions it modifies the first time it is evaluated.
I started with a notebook with several kinds of cells but only one text cell, which had the cell expresion
Cell["Some text", "Text"]
I evaluated
nb = EvaluationNotebook[];
Scan[(CurrentValue[#, StyleNames] = "Section") &, Cells[nb, CellStyle -> "Text"]]
and everything looked good -- the text cell was reformatted to a section cell. However, the cell expression was now
Cell["Some text", "Text", "Section"]
It should have been
Cell["Some text", "Section"]
So I think we are looking at a bug.
Comments
Post a Comment