use dynwind_begin and dynwind_end
[bpt/emacs.git] / src / window.c
index 919cc7b..2fa89e8 100644 (file)
@@ -27,6 +27,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include "buffer.h"
 #include "keyboard.h"
 #include "keymap.h"
+#include "menu.h"
 #include "frame.h"
 #include "window.h"
 #include "commands.h"
@@ -2802,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
@@ -3314,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)))
@@ -3345,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,
@@ -3393,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);
@@ -3465,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,
@@ -3604,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);
@@ -3618,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 ();
       }
     }
 }
@@ -4867,7 +4870,7 @@ window_scroll_pixel_based (Lisp_Object window, int n, bool whole, int noerror)
   /* If PT is not visible in WINDOW, move back one half of
      the screen.  Allow PT to be partially visible, otherwise
      something like (scroll-down 1) with PT in the line before
-     the partially visible one would recenter. */
+     the partially visible one would recenter.  */
 
   if (!pos_visible_p (w, PT, &x, &y, &rtop, &rbot, &rowh, &vpos))
     {
@@ -4896,7 +4899,7 @@ window_scroll_pixel_based (Lisp_Object window, int n, bool whole, int noerror)
     }
   else if (auto_window_vscroll_p)
     {
-      if (rtop || rbot)                /* partially visible */
+      if (rtop || rbot)                /* Partially visible.  */
        {
          int px;
          int dy = frame_line_height;
@@ -5367,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);
 
@@ -5389,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",
@@ -5481,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);
@@ -5505,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;
 }
@@ -5643,14 +5646,16 @@ and redisplay normally--don't erase and redraw the frame.  */)
 {
   struct window *w = XWINDOW (selected_window);
   struct buffer *buf = XBUFFER (w->contents);
-  struct buffer *obuf = current_buffer;
   bool center_p = 0;
   ptrdiff_t charpos, bytepos;
   EMACS_INT iarg IF_LINT (= 0);
   int this_scroll_margin;
 
+  if (buf != current_buffer)
+    error ("`recenter'ing a window that does not display current-buffer.");
+  
   /* If redisplay is suppressed due to an error, try again.  */
-  obuf->display_error_modiff = 0;
+  buf->display_error_modiff = 0;
 
   if (NILP (arg))
     {
@@ -5672,7 +5677,7 @@ and redisplay normally--don't erase and redraw the frame.  */)
 
       center_p = 1;
     }
-  else if (CONSP (arg)) /* Just C-u. */
+  else if (CONSP (arg)) /* Just C-u.  */
     center_p = 1;
   else
     {
@@ -5681,12 +5686,10 @@ and redisplay normally--don't erase and redraw the frame.  */)
       iarg = XINT (arg);
     }
 
-  set_buffer_internal (buf);
-
   /* Do this after making BUF current
      in case scroll_margin is buffer-local.  */
-  this_scroll_margin =
-    max (0, min (scroll_margin, w->total_lines / 4));
+  this_scroll_margin
+    max (0, min (scroll_margin, w->total_lines / 4));
 
   /* Handle centering on a graphical frame specially.  Such frames can
      have variable-height lines and centering point on the basis of
@@ -5734,7 +5737,7 @@ and redisplay normally--don't erase and redraw the frame.  */)
            h -= it.current_y;
          else
            {
-             /* Last line has no newline */
+             /* Last line has no newline */
              h -= line_bottom_y (&it);
              it.vpos++;
            }
@@ -5813,10 +5816,9 @@ and redisplay normally--don't erase and redraw the frame.  */)
 
   w->optional_new_start = 1;
 
-  w->start_at_line_beg = (bytepos == BEGV_BYTE ||
-                         FETCH_BYTE (bytepos - 1) == '\n');
+  w->start_at_line_beg = (bytepos == BEGV_BYTE
+                         || FETCH_BYTE (bytepos - 1) == '\n');
 
-  set_buffer_internal (obuf);
   return Qnil;
 }
 
@@ -7128,6 +7130,8 @@ init_window (void)
 void
 syms_of_window (void)
 {
+#include "window.x"
+
   DEFSYM (Qscroll_up, "scroll-up");
   DEFSYM (Qscroll_down, "scroll-down");
   DEFSYM (Qscroll_command, "scroll-command");
@@ -7316,119 +7320,6 @@ Note that when a frame's pixel size is not a multiple of the
 frame's character size, at least one window may get resized
 pixelwise even if this option is nil.  */);
   window_resize_pixelwise = 0;
-
-  defsubr (&Sselected_window);
-  defsubr (&Sminibuffer_window);
-  defsubr (&Swindow_minibuffer_p);
-  defsubr (&Swindowp);
-  defsubr (&Swindow_valid_p);
-  defsubr (&Swindow_live_p);
-  defsubr (&Swindow_frame);
-  defsubr (&Sframe_root_window);
-  defsubr (&Sframe_first_window);
-  defsubr (&Sframe_selected_window);
-  defsubr (&Sset_frame_selected_window);
-  defsubr (&Spos_visible_in_window_p);
-  defsubr (&Swindow_line_height);
-  defsubr (&Swindow_buffer);
-  defsubr (&Swindow_parent);
-  defsubr (&Swindow_top_child);
-  defsubr (&Swindow_left_child);
-  defsubr (&Swindow_next_sibling);
-  defsubr (&Swindow_prev_sibling);
-  defsubr (&Swindow_combination_limit);
-  defsubr (&Sset_window_combination_limit);
-  defsubr (&Swindow_use_time);
-  defsubr (&Swindow_pixel_width);
-  defsubr (&Swindow_pixel_height);
-  defsubr (&Swindow_total_width);
-  defsubr (&Swindow_total_height);
-  defsubr (&Swindow_normal_size);
-  defsubr (&Swindow_new_pixel);
-  defsubr (&Swindow_new_total);
-  defsubr (&Swindow_new_normal);
-  defsubr (&Swindow_pixel_left);
-  defsubr (&Swindow_pixel_top);
-  defsubr (&Swindow_left_column);
-  defsubr (&Swindow_top_line);
-  defsubr (&Sset_window_new_pixel);
-  defsubr (&Sset_window_new_total);
-  defsubr (&Sset_window_new_normal);
-  defsubr (&Swindow_resize_apply);
-  defsubr (&Swindow_resize_apply_total);
-  defsubr (&Swindow_body_height);
-  defsubr (&Swindow_body_width);
-  defsubr (&Swindow_hscroll);
-  defsubr (&Sset_window_hscroll);
-  defsubr (&Swindow_redisplay_end_trigger);
-  defsubr (&Sset_window_redisplay_end_trigger);
-  defsubr (&Swindow_edges);
-  defsubr (&Swindow_pixel_edges);
-  defsubr (&Swindow_absolute_pixel_edges);
-  defsubr (&Swindow_mode_line_height);
-  defsubr (&Swindow_header_line_height);
-  defsubr (&Swindow_right_divider_width);
-  defsubr (&Swindow_bottom_divider_width);
-  defsubr (&Swindow_scroll_bar_width);
-  defsubr (&Swindow_inside_edges);
-  defsubr (&Swindow_inside_pixel_edges);
-  defsubr (&Swindow_inside_absolute_pixel_edges);
-  defsubr (&Scoordinates_in_window_p);
-  defsubr (&Swindow_at);
-  defsubr (&Swindow_point);
-  defsubr (&Swindow_start);
-  defsubr (&Swindow_end);
-  defsubr (&Sset_window_point);
-  defsubr (&Sset_window_start);
-  defsubr (&Swindow_dedicated_p);
-  defsubr (&Sset_window_dedicated_p);
-  defsubr (&Swindow_display_table);
-  defsubr (&Sset_window_display_table);
-  defsubr (&Snext_window);
-  defsubr (&Sprevious_window);
-  defsubr (&Sget_buffer_window);
-  defsubr (&Sdelete_other_windows_internal);
-  defsubr (&Sdelete_window_internal);
-  defsubr (&Sresize_mini_window_internal);
-  defsubr (&Sset_window_buffer);
-  defsubr (&Srun_window_configuration_change_hook);
-  defsubr (&Srun_window_scroll_functions);
-  defsubr (&Sselect_window);
-  defsubr (&Sforce_window_update);
-  defsubr (&Ssplit_window_internal);
-  defsubr (&Sscroll_up);
-  defsubr (&Sscroll_down);
-  defsubr (&Sscroll_left);
-  defsubr (&Sscroll_right);
-  defsubr (&Sother_window_for_scrolling);
-  defsubr (&Sscroll_other_window);
-  defsubr (&Sminibuffer_selected_window);
-  defsubr (&Srecenter);
-  defsubr (&Swindow_text_width);
-  defsubr (&Swindow_text_height);
-  defsubr (&Smove_to_window_line);
-  defsubr (&Swindow_configuration_p);
-  defsubr (&Swindow_configuration_frame);
-  defsubr (&Sset_window_configuration);
-  defsubr (&Scurrent_window_configuration);
-  defsubr (&Sset_window_margins);
-  defsubr (&Swindow_margins);
-  defsubr (&Sset_window_fringes);
-  defsubr (&Swindow_fringes);
-  defsubr (&Sset_window_scroll_bars);
-  defsubr (&Swindow_scroll_bars);
-  defsubr (&Swindow_vscroll);
-  defsubr (&Sset_window_vscroll);
-  defsubr (&Scompare_window_configurations);
-  defsubr (&Swindow_list);
-  defsubr (&Swindow_list_1);
-  defsubr (&Swindow_prev_buffers);
-  defsubr (&Sset_window_prev_buffers);
-  defsubr (&Swindow_next_buffers);
-  defsubr (&Sset_window_next_buffers);
-  defsubr (&Swindow_parameters);
-  defsubr (&Swindow_parameter);
-  defsubr (&Sset_window_parameter);
 }
 
 void