9
$\begingroup$

When doing calculations in notebook, I modify the code a lot, and there are several versions of similar codes in the same notebook. But I found myself easily forgot which version is the newest, and I have to confirm which cell is the newest.

So if mathematica can provide a menu options like "cell latest modification time" will be useful. But now, I can't find this option.

However, mathematica provide a menu option "Cell-> Notebook History" can do this job.

The problem is that on my computer, mathematica ver 10.3, if the notebook has a long and rich history, then the Notebook History makes mma froze again and again, keep popping dialog of "Formatting Notebook Contents" as follows

enter image description here

How can I start the notebook history for example only recent 3 days or more generally between specific date 10 Nov to 13 Nov? And also how to start notebook history with selected cell as default?

$\endgroup$
  • $\begingroup$ Is the "Formatting Notebook Contenst" a problem while you are editing or only when you show the history dialog? For the former I don't know a solution. But if you are only searching for a less demanding way to get at those parts of the history data that you are interested in that should be relatively simple as that data is available in the CellChangeTimes options for every cell... $\endgroup$ – Albert Retey Nov 30 '15 at 13:05
  • $\begingroup$ @AlbertRetey yeah, "Formatting Notebook Content" keeps popping, and mma froze, I almost can't do anything. And where is "CellChangeTimes options"? $\endgroup$ – matheorem Nov 30 '15 at 13:24
  • $\begingroup$ My question was whether this happens just because you have switched on notebook history tracking for those notebooks in the preferences or whether this only happens when the notebook history dialog is open as your screenshot shows? As for the CellChangeTimes option, that is an option for Cells which the notebook history feature uses to store the editing timestamps. It is what you'd have to READ when you want to just see the last cell change times... $\endgroup$ – Albert Retey Nov 30 '15 at 13:27
  • $\begingroup$ @AlbertRetey Well, what I mean is that the picture I show is the default startup image, I didn't check anything, and I don't want to, because mma is already frozen to dead. I can only click "x" wait for 20 sec for mma respond to close the notebook history dialog. And I am sorry, I still don't understand what you mean about "CellChangeTimes option"? $\endgroup$ – matheorem Nov 30 '15 at 13:32
  • $\begingroup$ When you close the window which is titled "Notebook Modification History Overview", is Mathematica then still not responsive? $\endgroup$ – Albert Retey Nov 30 '15 at 14:15
6
$\begingroup$

From the OPs comments I deduce that the problem is only the dialog that opens when one opens with the menu entry "Cell" -> "Notebook History" and which shows a relatively involved visualization of the history and defaults to analyze the whole notebook. Obviously that is too slow for really large notebooks. But if one only is interested in the last change of a single cell, one can use code like the following to just get that information, and I'd guess that this should work even for huge notebooks as long as these still work in general.

Here is the code which generates a palette with one button which shows the last change time for the selected cell(s):

CreatePalette@Button["Show Last Cell-Change", MessageDialog[
 SelectionMove[InputNotebook[], All, Cell];
  Grid[
  MapIndexed[Flatten[{#2, #1}] &, Replace[
  Cases[{NotebookRead[InputNotebook[]]}, Cell[___], Infinity], {
   Cell[___, CellChangeTimes -> t_] :> DateString[Max[t]+3600*$TimeZone],
   Cell[___] :> None
   }, {1}]
 ]
 ]
], Method -> "Queued"]

for the interested here is what it does: The notebook history feature can be switched on either globally with Edit -> Preferences -> Advanced -> "Enable notebook history tracking" or just for the current notebook with e.g. SetOptions[EvaluationNotebook[],TrackCellChangeTimes -> True]. Once that settings has been made, the Mathmatica FrontEnd adds timestamps to cells when these are edited. These timestamps are aggregated within the Cell-Option CellChangeTimes. What my code does is to just extract that information which is in the form of timestamps as given by AbsoluteTime[] but obviously for UTC that is TimeZone->0. The Max of all those values is the last time the cell has changed and that is shown in human readable form with DateString. I have adjusted for the time zone in a somewhat ad hoc way which I have not tested for other timezones than my own but think should work. I could imagine that other things would also need improvement but it should basically work, show the idea and I would expect it to not create problems when a notebook gets large or the history is long.

EDIT

As the OP has mentioned in comments he is still searching for a way to change the default setting for the selection toggle. While a programmatic change of that might be possible it would certainly be somewhat involved and "dirty". On the other side it seems to be easy enough to just edit the system dialog definition which one can find here:

What you could do is to replace the default palette notebook which you can find here:

FileNameJoin[{$InstallationDirectory, "SystemFiles", "FrontEnd", 
  "SystemResources", "HistoryOverview.nb"}] 

with one where the corresponding default settings is changed. To do that, I would suggest to:

  1. make a copy of that notebook
  2. open the copy in a text editor
  3. replace $CellContext`selectionOnly$$ = False with $CellContext`selectionOnly$$ = True
  4. safe the file
  5. open the edited file in mathematica and save it (to avoid messages about it being edited outside of mathematica). As the notebook has settings specific to palettes it can only be saved programmatically. To do that, you have to get a handle to the corresponding notebook object and then call NotebookSave for that. The following code will do that:

    NotebookSave[
     First[Select[
       Notebooks[], 
       Not[FreeQ[CurrentValue[#, WindowTitle], "HistoryOverviewDialog"]] &]
     ]
    ]
    
  6. replace the original notebook with the edited one, probably making a backup copy of the original before that.

the last step (replacing that file in $InstallationDirectory) will of course only be possible with corresponding file permissions.

If you now restart mathematica the history overview dialog should now open always with the "selection only" setting...

$\endgroup$
  • $\begingroup$ Wow, great button for directly give latest cell modification time ! Thank you so much! But now the timezone remains a problem. $\endgroup$ – matheorem Dec 1 '15 at 1:15
  • $\begingroup$ I just found a another workaround, come and have a look : ) But I still think, if we can set the default option as "selected cell" is better. Do you know how to set this? $\endgroup$ – matheorem Dec 1 '15 at 1:26
  • $\begingroup$ @matheorem: I have edited my answer and added a description of how you can change the default option. As for the timezone> $\endgroup$ – Albert Retey Dec 1 '15 at 11:19
  • $\begingroup$ wonderful! But I don't know how to save the .nb $\endgroup$ – matheorem Dec 1 '15 at 11:40
  • $\begingroup$ @matheorem: what is the problem with saving? Which step are you talking about? It will be easiest to do steps 1-5 with a copy within one of your personal directories. Then you just have to do the final replacement e.g. as an administrator... $\endgroup$ – Albert Retey Dec 1 '15 at 11:45
4
$\begingroup$

Albert Retey just created a great button that can give a cell's latest modification time directly.

Here is a another workaround. It is small trick I just found, but works perfectly : )

The frozen of mma when open Notebook History windows is due to the default setting is checked for "All cell" instead of "selected cell". So mma collecting too many data to analysis dynamically.

If we could make "selected cell" the default option, then we solve the problem. But I don't know how to do it.

Anyway, here is the "bug" trick.

First, you have to open a fresh new notebook.

second, in this new notebook, you open Notebook History window, and check the "selected cell" option. like this

enter image description here

Third, switch back to the large notebook, now since "Notebook History window" is already set to analyze only selected cell, frozen problem is solved and you can select any cell to see its history smoothly without lag.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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