1

已经有一个问题“以编程方式关闭 Mathematica 中的所有单元组?”

奇怪的是,尚未提出二元化问题:是否可以在笔记本中以编程方式打开所有封闭单元组?

现在提高它的原因是使用 SelectionMove 您可以选择一个属于封闭组的单元格。如果在以下示例中,将通过适当的 SelectionMove 命令选择的最后一个单元格是封闭组的一部分,则尽管 AutoScroll->True (与描述相反),它在封闭组中仍然不可见:

这一系列命令选择笔记本中的最后一个单元格:

nb = EvaluationNotebook[]; SelectionMove[nb, All, Notebook]
SelectionMove[nb, After, Cell]
SelectionMove[nb, Previous, Cell, AutoScroll -> True]

哪个附加命令将打开包含最后一个单元格的组,使其可见并被选为整个单元格?(它可能是几个嵌套单元组的一部分!)

4

1 回答 1

1

线索是两个命令

FrontEndTokenExecute[nb, "ExpandSelection"] 
FrontEndTokenExecute[nb, "SelectionOpenAllGroups"]

但是,在这两个命令之后,必须再次重新应用我最初的帖子中提到的方法。

Sample Select Last Celle Programatically.nb

nb = EvaluationNotebook[];
SelectionMove[nb, All, Notebook]                                             (* \
this one selects all cells in this notebook *)
SelectionMove[nb, After, Cell]                                                \
  (* this one moves the insertion point below everything *)
SelectionMove[nb, Previous, Cell, 
 AutoScroll -> 
  True]   (* if the last cell is part of a closed group, the selection stays \
invisible *)
FrontEndTokenExecute[nb, "ExpandSelection"]                    (* this one \
selects the group enclosing the last cell *)
FrontEndTokenExecute[nb, "SelectionOpenAllGroups"]    (* this one opens it *)
\

SelectionMove[nb, After, Cell]                                                \
  (* like command 4 steps above, this one moves the insertion point below \
everything *)
SelectionMove[nb, Previous, Cell, 
 AutoScroll -> 
  True]  (* now it is no longer part of a closed group, therefore it becomes \
visible *)


10 outmost group: Several groups are stacked one ontop the next. All cells groups are closed individually. This is a test case for the program above.

9 intermediate group

8 intermediate group

7 intermediate group

6 intermediate group

5 intermediate group

4 intermediate group

3 intermediate group

2 intermediate group

1 innermost group

f /@ Range[3]

{f[1], f[2], f[3]}

(我把这一切都放在笔记本上,但我找不到上传它的方法......将所有这些复制到笔记本后,将所有内容设置为手动分组,然后将最后一个单元格逐个嵌套在上面的下一行然后关闭所有子组。)

随附的笔记本显示了它是如何完成的,它还包含一个测试示例,该示例在选择的最后一个单元格组的深度嵌套。但是,仍然缺少证明这始终有效且永不失败的证据,因为我既没有 ExpandSelection 也没有 SelectionOpenAllGroups 的“公理”描述。

我希望帮助系统中有更多“另见”链接,尤其是关于前端相关功能的链接。

于 2016-03-29T15:58:27.730 回答