use dynwind_begin and dynwind_end
[bpt/emacs.git] / src / window.c
index 259ffcd..2fa89e8 100644 (file)
@@ -2803,7 +2803,7 @@ window_loop (enum window_loop type, Lisp_Object obj, int mini, Lisp_Object frame
              {
                if (EQ (window, selected_window))
                  /* Preferably return the selected window.  */
-                 RETURN_UNGCPRO (window);
+                 return window;
                else if (EQ (XWINDOW (window)->frame, selected_frame)
                         && !frame_best_window_flag)
                  /* Prefer windows on the current frame (but don't
@@ -3315,13 +3315,15 @@ select_frame_norecord (Lisp_Object frame)
 void
 run_window_configuration_change_hook (struct frame *f)
 {
-  ptrdiff_t count = SPECPDL_INDEX ();
+  dynwind_begin ();
   Lisp_Object frame, global_wcch
     = Fdefault_value (Qwindow_configuration_change_hook);
   XSETFRAME (frame, f);
 
-  if (NILP (Vrun_hooks) || !NILP (inhibit_lisp_code))
+  if (NILP (Vrun_hooks) || !NILP (inhibit_lisp_code)) {
+    dynwind_end ();
     return;
+  }
 
   /* Use the right buffer.  Matters when running the local hooks.  */
   if (current_buffer != XBUFFER (Fwindow_buffer (Qnil)))
@@ -3346,18 +3348,18 @@ run_window_configuration_change_hook (struct frame *f)
        if (!NILP (Flocal_variable_p (Qwindow_configuration_change_hook,
                                      buffer)))
          {
-           ptrdiff_t inner_count = SPECPDL_INDEX ();
+           dynwind_begin ();
            record_unwind_protect (select_window_norecord, selected_window);
            select_window_norecord (window);
            run_funs (Fbuffer_local_value (Qwindow_configuration_change_hook,
                                           buffer));
-           unbind_to (inner_count, Qnil);
+           dynwind_end ();
          }
       }
   }
 
   run_funs (global_wcch);
-  unbind_to (count, Qnil);
+  dynwind_end ();
 }
 
 DEFUN ("run-window-configuration-change-hook", Frun_window_configuration_change_hook,
@@ -3394,7 +3396,7 @@ set_window_buffer (Lisp_Object window, Lisp_Object buffer,
 {
   struct window *w = XWINDOW (window);
   struct buffer *b = XBUFFER (buffer);
-  ptrdiff_t count = SPECPDL_INDEX ();
+  dynwind_begin ();
   bool samebuf = EQ (buffer, w->contents);
 
   wset_buffer (w, buffer);
@@ -3466,7 +3468,7 @@ set_window_buffer (Lisp_Object window, Lisp_Object buffer,
        run_window_configuration_change_hook (XFRAME (WINDOW_FRAME (w)));
     }
 
-  unbind_to (count, Qnil);
+  dynwind_end ();
 }
 
 DEFUN ("set-window-buffer", Fset_window_buffer, Sset_window_buffer, 2, 3, 0,
@@ -3605,7 +3607,7 @@ temp_output_buffer_show (register Lisp_Object buf)
       /* Run temp-buffer-show-hook, with the chosen window selected
         and its buffer current.  */
       {
-        ptrdiff_t count = SPECPDL_INDEX ();
+        dynwind_begin ();
         Lisp_Object prev_window, prev_buffer;
         prev_window = selected_window;
         XSETBUFFER (prev_buffer, old);
@@ -3619,7 +3621,7 @@ temp_output_buffer_show (register Lisp_Object buf)
         Fselect_window (window, Qt);
         Fset_buffer (w->contents);
         Frun_hooks (1, &Qtemp_buffer_show_hook);
-        unbind_to (count, Qnil);
+        dynwind_end ();
       }
     }
 }
@@ -5368,7 +5370,7 @@ window_scroll_line_based (Lisp_Object window, int n, bool whole, int noerror)
 static void
 scroll_command (Lisp_Object n, int direction)
 {
-  ptrdiff_t count = SPECPDL_INDEX ();
+  dynwind_begin ();
 
   eassert (eabs (direction) == 1);
 
@@ -5390,7 +5392,7 @@ scroll_command (Lisp_Object n, int direction)
       window_scroll (selected_window, XINT (n) * direction, 0, 0);
     }
 
-  unbind_to (count, Qnil);
+  dynwind_end ();
 }
 
 DEFUN ("scroll-up", Fscroll_up, Sscroll_up, 0, 1, "^P",
@@ -5482,7 +5484,7 @@ specifies the window to scroll.  This takes precedence over
 {
   Lisp_Object window;
   struct window *w;
-  ptrdiff_t count = SPECPDL_INDEX ();
+  dynwind_begin ();
 
   window = Fother_window_for_scrolling ();
   w = XWINDOW (window);
@@ -5506,7 +5508,7 @@ specifies the window to scroll.  This takes precedence over
     }
 
   set_marker_both (w->pointm, Qnil, PT, PT_BYTE);
-  unbind_to (count, Qnil);
+  dynwind_end ();
 
   return Qnil;
 }