a caveat in `Iconize`
It is not a bug. Iconize
works with expressions. Comments / line breaks / indentation and other box/input features are stripped by the FrontEnd before sending it to the Kernel.
Iconize[
Hold@Range[1,
10
]
]
(*evaluate and convert to StandardForm*)
Hold[Range[1, 10]] (*no line breaks, indentation or @ *)
Here's a follow up from Kuba's point. If you wanted to pass a few Cell
s around (say storing a function definition) you can cache them in an Unevaluated
manner so that they auto-write when evaluated. For instance:
iconizeCell[c_CellObject] :=
With[{cont = NotebookRead[c]},
Iconize[Unevaluated[NotebookWrite[EvaluationNotebook[], cont]]]
]
(* insert a cell break here *)
iconizeCell@PreviousCell[]
and evaluating that gets me a Cell
with:
iconizeCell[c_CellObject] :=
With[{cont = NotebookRead[c]},
Iconize[Unevaluated[NotebookWrite[EvaluationNotebook[], cont]]]
]
as its content
Note that this strategy could work for function definitions too. e.g.:
iconizeDefinition[fn_] :=
With[{defs = Association@Language`ExtendedFullDefinition[fn][[1, 2]]},
Iconize[
Unevaluated[
KeyValueMap[
Function[#[fn] = #2],
defs
];
]
]
]
iconizeDefinition[iconizeDefinition]
Then running ClearAll[iconizeDefinition]
and evaluating that blob gets me my definitions back.