<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>TeXShop</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <style type="text/css" media="screen">@import "v1.css";</style>
</head>

<body>

<!-- title and menu -->
<div id="header">
  <ul>
  <li class="titel"><img alt="Logo" src="logo_klein.png" />TeXShop</li>
  <li><a href="index.html">About</a></li>
  <li><a href="tahoe.html">Tahoe</a></li>
     <li><a href="obtaining.html">Obtaining</a></li>
    <li><a href="installing.html">Installing</a></li>
     <li id="current"><a href="history.html">History</a></li>
    <li><a href="extras.html">Extras</a></li>
    <li><a href="links.html">Links</a></li>
  </ul>
</div>

<!-- gutter with download links -->
<div id="subheader">
<center> [ Direct Download: <a href="texshop-64/texshop.zip">Latest TeXShop</a> | <a href="texshop-64//texshopsource.zip">Latest TeXShop Source</a> ] [ <a href="mailto:koch@uoregon.edu">Contact</a> ] </center> 
</div>

<!-- links on the left -->
<div id="menulinks">
<ul>
<li><a href="history.html">History</a></li>
<li><a href="collaborators.html">Collaborators</a></li>
<li><a href="intel-arm.html">Intel and Arm</a></li>
<li><a href="arc.html">ARC</a></li>
<li><a href="64bits.html">64 Bits</a></li>
<li><a href="fragilebaseclasses.html">Fragile Base Classes</a></li>
<li id="mcurrent"><a href="autosave.html">Automatic Saving</a></li>

<!--
<li><a href="texshop-64/texshop.zip">TeXShop 3 for Lion</a></li>
<li><a href="texshop-64/texshopsource.zip">Lion Source</a></li>
-->
</ul>
</div>

<!-- main content -->
<div id="main">


<h3>Automatic Saving</h3>

<p> Saving source files to disk is an essential feature of TeXShop, and a bug which broke this operation would be fatal to the future of the program. Luckily, most steps in this crucial chain are done automatically by Cocoa;  the only spot where TeXShop code is involves comes when Cocoa asks  what data to save and we point to the string containing the full source. I would not dare modify the TeXShop "Save" or "Save As" code. 

<p> However, in Lion this system was completely rewritten by Apple. The new code automatically saves files every few minutes, so it is essentially impossible to lose files you are writing. If your power goes out on a desktop without a battery, you might lose a sentence or two, but nothing more.  You do not need to save files before quitting the program, or before closing windows, because that is done automatically. In a sense, you can forget the Save operation. The system handles everything automatically.

<p> A University of Oregon faculty member once called me at midnight. He was writing the final exam for a graduate analysis course to be given at 8 AM the next morning, he was almost done, but he accidentally closed the source file without saving or typesetting. He asked what he could do. The only answer I could give was "start over." This problem cannot happen on Lion or higher.

<p> Saving every few minutes is not noticeable because the system does not save the complete file. It only saves the changes. So if your entire book is one gigantic source file, you will still not notice the  save operation. I'm sure this holds because automatic saving has been the norm on TeXShop for ten years and I have never received a complaint.

<p> Since the Macintosh is only saving changes, it has a complete record of all the versions of the document. Theoretically, you could go back to
earlier versions and reconstruct the document as it was yesterday, or last month. As we will see in a moment, this isn't just theoretically possible --- it is actually easy.

<p> You might wonder if the file containing a document has all the old versions hidden away somewhere. Could I send someone the TeX source of a letter of recommendation which currently says ``Paul is a creative student'', but whose initial version said ``Paul hasn't had a new idea in years"? Happily,
no. Files on disk only contain the latest version.

<p> What happens if I decide to experiment , get confused, lose my way, and end up with a source document that makes no sense, and then
discover that my crazy changes have been saved out from under me?
You can use undo to get
back to the original document because TeXShop's undo works even across file saves.

<p> However, Apple has a much nicer solution to this problem. The TeXShop File menu has an item named
"Revert To". Selecting this item gives a choice between two items, and one reads "Browse All Versions".

<p> The Macintosh screen then switches to a Time Machine view showing the current document on the left and a receding stack of earlier views on the right. You can leaf through these earlier versions, noting the date and time that the version was created. All
these views are alive, so you can copy and paste between versions, or restore an earlier version. 
This works even if you have not activated Time Machine. So it is a personal Time Machine just for TeXShop source documents.

<p> Additional details about Saving are in the TeXShop Manual. But perhaps this initial description is still alarming. A TeXShop preference item allows you to turn Automatic Saving off. The preference item is hidden away, but described in the manual. I really, really do not recommend using that item, and I don't know any users who now use it.

<p> Automatic saving is a courageous and enormous change by Apple, made possible by the solution of the fragile base class problem. You might wonder how much TeXShop code we had to change to activate this change. It is easy to answer that question. We had to add the following lines. The top line reads the hidden preference to obtain YES if we want automatic saving and NO otherwise. The bottom lines return this answer to a Cocoa procedure which asks if we should "autosaveInPlace".
<pre>
   doAutoSave = [SUD boolForKey:AutoSaveEnabledKey];
   
   + (BOOL)autosavesInPlace
       {
         return doAutoSave;
       }
</pre>

<p> There is one other surprise. The TeXShop source code contains a file named MainMenu.nib which displays the various menus in the program. If you compare the File menu described by this file with the actual File menu displayed by TeXShop when running, you will discover that the two menus do not agree. The running program contains several items related to Automatic Saving, including that "Revert To:" menu item mentioned earlier. That item is not mentioned in the TeXShop source code because the TeXShop menus were created long before automatic saving was even a dream in an Apple programmer's eye. But fixing the fragile base class problem allows Apple to reach into those menu objects and rewrite them on the fly whenever TeXShop starts up. That is possible because TeXShop used the default File menu items recommended by Apple long ago. Apple knows about those items, so it knows how to change them.





<!--
<h4>Tiger; PDF Kit</h4>

On April 29, 2005, Apple released Mac OS X 10.4, Tiger.  This release contained PDF Kit, a software
framework to display PDF code.  I converted TeXShop to that system, replacing Shishikura's code
with Apple's version. As a final complement to Shishikura, Apple's system was mostly parallel to his,
so the conversion was easy. Shishikura's code is still in place to display some image formats. Developers
working with the TeXShop code base may wonder why there are two objects, MyPDFView and MyPDFKitView,
in the code. Now they know.

<p> The conversion to PDF Kit was the right move because Apple continues to develop
PDF Kit and TeXShop then automatically inherits their improvements. This conversion also
marked the end of TeXShop's 1.** system of releases, and the beginning of the 2.** releases which
only work on Tiger and higher systems.

<p> There is one very significant bug in Tiger's PDF Kit implementation. That bug causes
significant memory problems when a pdf document is changed and the display must switch to the new version.
Of course, TeX often changes the pdf output as source files are retypeset. 

<p> On Tiger, TeXShop has some "band-aid" code to work around this bug. That code causes
TeXShop to retain old versions, gradually using up system memory. The PDF Kit bug was fixed in
Mac OS X, Leopard, released on October 26, 2007, and TeXShop automatically adjusts and
removes its band-aid code. For that reason, the TeXShop web site for many years has stated that
"System 10.5 or Higher Strongly Recommended."



<h4>Leopard and Snow Leopard</h4>

In the Leopard and Snow Leopard years, the most significant change in TeXShop was a rewriting of the code
base by Max Horn. As Horn improved the code, certain features of TeXShop became more stable and
worked faster, while other features stopped working entirely. I found the process rather frustrating, but as I look
back on the process, I realize that  it was extremely important to make these changes.

<p> I'm sure Horn was frustrated, too. He switched TeXShop to use svn, an entirely reasonable change. But
I found svn impossible to use. Occasionally users would suggest a TeXShop improvement, I'd add the improvement,
and then do battle with svn and the improvement wouldn't be released. Later I began releasing versions of TeXShop 
that weren't in the svn and the entire process fell apart. In the end, Horn wasn't able
to complete his revision because someone (me) wasn't cooperating.

<p> I tell you these details  to explain that the life of my collaborators hasn't always been a picnic. Collaboration
has worked best when a developer submitted code with changes clearly marked, and allowed me to select
those changes to include. More professional collaboration, of the type used for most open source projects,
hasn't worked because the guy in charge, namely me, isn't competent enough to adjust. Apologies all around.

<p> After Horn's changes were released, in version 2.10, other collaborators again began advancing TeXShop
with new localizations, improvements in the Key Bindings and Auto Completion editors, improved handling of
matching parentheses, and many other changes.  Consult TeXShop's version history web page for details.

<p> Since the release of Tiger, TeXShop has not made use of operating system advances except in minor details, and
version 2.43 still runs on Tiger. Of course Apple deliberately didn't change the interface in Snow Leopard,
concentrating instead on fundamental changes in the underlying foundation of the system. One opportunity
these later systems afforded was the ability to rewrite programs for 64 bit operation. I wasn't convinced that
this change would improve TeXShop and didn't switch it to 64 bits until very recently.


<h4>Lion</h4>

But Lion is different. Using lessons learned form iOS, the iPhone, and the iPad, Apple has modified the
user experience in very significant way in this system, and provided new interfaces for developers to exploit.
 And TeXShop begins to take advantage of these
new opportunities.

<p> 
-->
 </div>


</body>
</html>