3
$\begingroup$

I'd like to get a clickable list of all "Sections" that have been recently modified in my notebook, grouped by day of modification. "Modified" Section means, some cell under that Section heading has been modified.

The following gives the list of most recently modified cells, but I'd like this to point to the "Section" object instead of the actual cell, I guess this needs some kind of traversal up the cell hierarchy, any tips?

notebookCellData = 
  ResourceFunction["NotebookCellData", 
   ResourceSystemBase -> 
    "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"];
Take[ReverseSortBy[
  notebookCellData[
   EvaluationNotebook[], {"CellChangeTimes"}], #CellChangeTimes &], 
 UpTo[10]]
$\endgroup$
1
  • 1
    $\begingroup$ replace EvaluationNotebook[] with Cells[CellStyle -> "Section"]? $\endgroup$
    – kglr
    Dec 2, 2023 at 1:28

1 Answer 1

2
$\begingroup$

You can find the section containing a given cell by using the {"CounterValue", "Section"} current value. Leveraging this idea produces:

cellButton[cell_] := Button[RawBoxes @ NotebookRead[cell], SelectionMove[cell, All, Cell]]

ModifiedSections[date_:0] := Module[{sections=Cells[CellStyle->"Section"], data, abs = AbsoluteTime[date]},
    data = Cases[
        Thread[{Max/@CurrentValue[Cells[], CellChangeTimes], Cells[], CurrentValue[Cells[], {"CounterValue","Section"}]}],
        {s_, c_, i_?Positive} /; s>abs :> {s, c, sections[[i]]}
    ];
    CreateWindow @ PaletteNotebook @ Dataset @ Reverse @ KeySort @ GroupBy[
        data, 
        DayRound @* First -> Rest, 
        GroupBy[#, cellButton @* Last -> First, Column]&
    ]
]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.