Index: nsfns.m
===================================================================
RCS file: /sources/emacs/emacs/src/nsfns.m,v
retrieving revision 1.55
diff -u -p -r1.55 nsfns.m
--- nsfns.m	24 Oct 2009 18:58:51 -0000	1.55
+++ nsfns.m	29 Mar 2010 21:56:36 -0000
@@ -80,6 +80,7 @@ extern Lisp_Object Qface_set_after_frame
 extern Lisp_Object Qunderline, Qundefined;
 extern Lisp_Object Qheight, Qminibuffer, Qname, Qonly, Qwidth;
 extern Lisp_Object Qunsplittable, Qmenu_bar_lines, Qbuffer_predicate, Qtitle;
+extern Lisp_Object Vframe_title_format;
 
 Lisp_Object Qnone;
 Lisp_Object Qbuffered;
@@ -586,7 +587,12 @@ x_implicitly_set_name (FRAME_PTR f, Lisp
   if (FRAME_ICONIFIED_P (f))
     ns_set_name_iconic (f, arg, 0);
   else
-    ns_set_name (f, arg, 0);
+    {
+      if (FRAME_NS_P (f) && EQ (Vframe_title_format, Qt))
+        ns_set_name_as_filename (f);
+      else
+        ns_set_name (f, arg, 0);
+    }
 }
 
 
@@ -685,15 +691,18 @@ ns_set_name_as_filename (struct frame *f
 
 
 void
-ns_set_doc_edited (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
+ns_set_doc_edited (struct frame *f, Lisp_Object arg)
 {
   NSView *view = FRAME_NS_VIEW (f);
   NSAutoreleasePool *pool;
-  BLOCK_INPUT;
-  pool = [[NSAutoreleasePool alloc] init];
-  [[view window] setDocumentEdited: !NILP (arg)];
-  [pool release];
-  UNBLOCK_INPUT;
+
+  if (!MINI_WINDOW_P (XWINDOW(f->selected_window))) {
+    BLOCK_INPUT;
+    pool = [[NSAutoreleasePool alloc] init];
+    [[view window] setDocumentEdited: !NILP (arg)];
+    [pool release];
+    UNBLOCK_INPUT;
+  }
 }
 
 
Index: nsterm.h
===================================================================
RCS file: /sources/emacs/emacs/src/nsterm.h,v
retrieving revision 1.29
diff -u -p -r1.29 nsterm.h
--- nsterm.h	16 Oct 2009 03:09:06 -0000	1.29
+++ nsterm.h	29 Mar 2010 21:56:36 -0000
@@ -708,6 +708,8 @@ extern void nxatoms_of_nsselect ();
 extern int ns_lisp_to_cursor_type ();
 extern Lisp_Object ns_cursor_type_to_lisp (int arg);
 extern Lisp_Object Qnone;
+extern void ns_set_name_as_filename (struct frame *f);
+extern void ns_set_doc_edited (struct frame *f, Lisp_Object arg);
 
 extern int
 ns_defined_color (struct frame *f, char *name, XColor *color_def, int alloc,
Index: nsterm.m
===================================================================
RCS file: /sources/emacs/emacs/src/nsterm.m,v
retrieving revision 1.95
diff -u -p -r1.95 nsterm.m
--- nsterm.m	19 Oct 2009 16:58:20 -0000	1.95
+++ nsterm.m	29 Mar 2010 21:56:36 -0000
@@ -4191,7 +4191,6 @@ ns_term_shutdown (int sig)
   ns_send_appdefined (-2);
 }
 
-extern void update_window_cursor (struct window *w, int on);
 
 - (void)fd_handler: (NSTimer *) fdEntry
 /* --------------------------------------------------------------------------
Index: xdisp.c
===================================================================
RCS file: /sources/emacs/emacs/src/xdisp.c,v
retrieving revision 1.1328
diff -u -p -r1.1328 xdisp.c
--- xdisp.c	15 Dec 2009 22:53:39 -0000	1.1328
+++ xdisp.c	29 Mar 2010 21:56:38 -0000
@@ -9494,31 +9494,8 @@ x_consider_frame_title (frame)
 	  || SBYTES (f->name) != len
 	  || bcmp (title, SDATA (f->name), len) != 0)
         {
-#ifdef HAVE_NS
-          if (FRAME_NS_P (f))
-            {
-              if (!MINI_WINDOW_P(XWINDOW(f->selected_window)))
-                {
-                  if (EQ (fmt, Qt))
-                    ns_set_name_as_filename (f);
-                  else
-                    x_implicitly_set_name (f, make_string(title, len),
-                                           Qnil);
-                }
-            }
-          else
-#endif
 	    x_implicitly_set_name (f, make_string (title, len), Qnil);
         }
-#ifdef HAVE_NS
-      if (FRAME_NS_P (f))
-        {
-          /* do this also for frames with explicit names */
-          ns_implicitly_set_icon_type(f);
-          ns_set_doc_edited(f, Fbuffer_modified_p
-                            (XWINDOW (f->selected_window)->buffer), Qnil);
-        }
-#endif
     }
 }
 
@@ -9615,6 +9592,11 @@ prepare_menu_bars ()
 #ifdef HAVE_WINDOW_SYSTEM
 	  update_tool_bar (f, 0);
 #endif
+#ifdef HAVE_NS
+          if (windows_or_buffers_changed)
+            ns_set_doc_edited (f, Fbuffer_modified_p
+                                    (XWINDOW (f->selected_window)->buffer));
+#endif
 	  UNGCPRO;
 	}
 
@@ -22669,9 +22653,6 @@ display_and_set_cursor (w, on, hpos, vpo
 /* Switch the display of W's cursor on or off, according to the value
    of ON.  */
 
-#ifndef HAVE_NS
-static
-#endif
 void
 update_window_cursor (w, on)
      struct window *w;
