First, let me illustrate what I'm trying to do. FormatOptions
is a programming utility that will Echo
a given Symbol
-'s Options
in a Column
or a multicolumn Grid
table (to be added later as an Option) so that they are Sort
-ed (also to be added later) in some particular fashion. The goal is creating a tool that doesn't just spit out a raw list that is difficult to read. The only problem with it is that long Rule
-s can misshapen the output. Therefore, it would be expedient to automate the Iconize
step with a ReplaceAll
(or one like it) Rule
.
The code below works. As you can see I have one long string pre-Iconized. This works, but I would like to create an expression that will test every RHS Rule
for example, StringLength[expr] >= 35
, and Iconize
them.
(* This works, but it's not automated *)
ClearSystemCache[];
ClearAll[FormatOptions, stage, rules];
Options[FormatOptions] = {"rawlist" -> True, "iconize" -> True};
FormatOptions[sym_Symbol, OptionsPattern[]] := Module[{
nam =
Style[("Options[" <> (ToString[Evaluate[sym]]) <> "]"), Bold],
rul = Evaluate[Options[sym]],
lab, raw, ops
},
lab :=
"raw list: " <> (ToString[Evaluate[Length[rul]]]) <> " " <>
"items";
raw := If[OptionValue["iconize"], Iconize[rul, lab], rul];
ops = If[OptionValue["rawlist"], AppendTo[rul, Evaluate[raw]], rul];
Echo[Row[{nam, Style[" \[Rule] ", Orange], "{ ", Column[ops],
" }"}]]
];
Options[stage] = {"backuprate" -> 2,
"source" -> Iconize[NotebookFileName[], NotebookFileName],
"makefolder" -> Automatic , "fileinfix" -> Automatic,
"fileappend" -> Automatic, "echoalerts" -> Automatic,
"soundalerts" -> Automatic, "volume" -> .25, "limitalerts" -> 3,
OverwriteTarget -> True, Options[CreateDirectory]};
FormatOptions[stage];
Below is my attempt at automating the Iconize
step with a Replace
-ment Rule
. There are three strings in the rules
that should have been Iconize
-ed. Instead it drops the entire list, only returning one icon from the first long string it encounters. Also, please allow me to stress that the OptionValues
in this example are not the same as the prior example.
Please help. Thank you.
(* almost slightly works *)
ClearSystemCache[];
ClearAll[stage, rules];
Options[stage] = {"backuprate" -> 2, "source" -> NotebookFileName[],
"makefolder" -> "this-folder-name-is-38-charscters-long",
"fileinfix" ->
"this-string-that-will-be-infixed-to-a-filename-is-55-charscters-\
long", "fileappend" -> "too-short-to-iconize-33-chracters",
"echoalerts" -> Automatic, "soundalerts" -> Automatic,
"volume" -> .25, "limitalerts" -> 3, OverwriteTarget -> True,
Options[CreateDirectory]};
FormatOptions[stage];
rules = Options[stage]
rules /.
KeyValuePattern[x_ -> y_String?(StringLength[#] >= 35 &)] ->
x -> Iconize[y, "String"]