* window.h (struct window): Convert left_col, top_line, total_lines
[bpt/emacs.git] / src / window.c
index 0e5ba04..875d777 100644 (file)
@@ -84,8 +84,8 @@ static int foreach_window_1 (struct window *,
                              int (* fn) (struct window *, void *),
                              void *);
 static Lisp_Object window_list_1 (Lisp_Object, Lisp_Object, Lisp_Object);
-static int window_resize_check (struct window *, int);
-static void window_resize_apply (struct window *, int);
+static int window_resize_check (struct window *, bool);
+static void window_resize_apply (struct window *, bool);
 static Lisp_Object select_window (Lisp_Object, Lisp_Object, int);
 static void select_window_1 (Lisp_Object, bool);
 
@@ -116,9 +116,6 @@ Lisp_Object minibuf_selected_window;
 /* Hook run at end of temp_output_buffer_show.  */
 static Lisp_Object Qtemp_buffer_show_hook;
 
-/* Incremented for each window created.  */
-static int sequence_number;
-
 /* Nonzero after init_window_once has finished.  */
 static int window_initialized;
 
@@ -286,6 +283,9 @@ adjust_window_count (struct window *w, int arg)
        b = b->base_buffer;
       b->window_count += arg;
       eassert (b->window_count >= 0);
+      /* These should be recalculated by redisplay code.  */
+      w->window_end_valid = 0;
+      w->base_line_pos = 0;
     }
 }
 
@@ -300,15 +300,6 @@ wset_buffer (struct window *w, Lisp_Object val)
   adjust_window_count (w, 1);
 }
 
-/* Build a frequently used 4-integer (X Y W H) list.  */
-
-static Lisp_Object
-list4i (EMACS_INT x, EMACS_INT y, EMACS_INT w, EMACS_INT h)
-{
-  return list4 (make_number (x), make_number (y),
-               make_number (w), make_number (h));
-}
-
 DEFUN ("windowp", Fwindowp, Swindowp, 1, 1, 0,
        doc: /* Return t if OBJECT is a window and nil otherwise.  */)
   (Lisp_Object object)
@@ -644,30 +635,37 @@ Return nil if WINDOW has no previous sibling.  */)
 
 DEFUN ("window-combination-limit", Fwindow_combination_limit, Swindow_combination_limit, 1, 1, 0,
        doc: /* Return combination limit of window WINDOW.
+WINDOW must be a valid window used in horizontal or vertical combination.
 If the return value is nil, child windows of WINDOW can be recombined with
 WINDOW's siblings.  A return value of t means that child windows of
-WINDOW are never \(re-)combined with WINDOW's siblings.
-
-WINDOW must be a valid window.  The return value is meaningful for
-internal windows only.  */)
+WINDOW are never \(re-)combined with WINDOW's siblings.  */)
   (Lisp_Object window)
 {
+  struct window *w;
+
   CHECK_VALID_WINDOW (window);
+  w = XWINDOW (window);
+  if (!NILP (w->buffer))
+    error ("Combination limit is meaningful for internal windows only");
   return XWINDOW (window)->combination_limit;
 }
 
 DEFUN ("set-window-combination-limit", Fset_window_combination_limit, Sset_window_combination_limit, 2, 2, 0,
        doc: /* Set combination limit of window WINDOW to LIMIT; return LIMIT.
+WINDOW must be a valid window used in horizontal or vertical combination.
 If LIMIT is nil, child windows of WINDOW can be recombined with WINDOW's
 siblings.  LIMIT t means that child windows of WINDOW are never
 \(re-)combined with WINDOW's siblings.  Other values are reserved for
-future use.
-
-WINDOW must be a valid window.  Setting the combination limit is
-meaningful for internal windows only.  */)
+future use.  */)
   (Lisp_Object window, Lisp_Object limit)
 {
-  wset_combination_limit (decode_valid_window (window), limit);
+  struct window *w;
+
+  CHECK_VALID_WINDOW (window);
+  w = XWINDOW (window);
+  if (!NILP (w->buffer))
+    error ("Combination limit is meaningful for internal windows only");
+  wset_combination_limit (w, limit);
   return limit;
 }
 
@@ -694,7 +692,7 @@ On a graphical display, this total height is reported as an
 integer multiple of the default character height.  */)
   (Lisp_Object window)
 {
-  return decode_valid_window (window)->total_lines;
+  return make_number (decode_valid_window (window)->total_lines);
 }
 
 DEFUN ("window-total-width", Fwindow_total_width, Swindow_total_width, 0, 1, 0,
@@ -709,7 +707,7 @@ On a graphical display, this total width is reported as an
 integer multiple of the default character width.  */)
   (Lisp_Object window)
 {
-  return decode_valid_window (window)->total_cols;
+  return make_number (decode_valid_window (window)->total_cols);
 }
 
 DEFUN ("window-new-total", Fwindow_new_total, Swindow_new_total, 0, 1, 0,
@@ -748,7 +746,7 @@ value is 0 if there is no window to the left of WINDOW.
 WINDOW must be a valid window and defaults to the selected one.  */)
   (Lisp_Object window)
 {
-  return decode_valid_window (window)->left_col;
+  return make_number (decode_valid_window (window)->left_col);
 }
 
 DEFUN ("window-top-line", Fwindow_top_line, Swindow_top_line, 0, 1, 0,
@@ -760,7 +758,7 @@ there is no window above WINDOW.
 WINDOW must be a valid window and defaults to the selected one.  */)
   (Lisp_Object window)
 {
-  return decode_valid_window (window)->top_line;
+  return make_number (decode_valid_window (window)->top_line);
 }
 
 /* Return the number of lines of W's body.  Don't count any mode or
@@ -769,7 +767,7 @@ WINDOW must be a valid window and defaults to the selected one.  */)
 static int
 window_body_lines (struct window *w)
 {
-  int height = XFASTINT (w->total_lines);
+  int height = w->total_lines;
 
   if (!MINI_WINDOW_P (w))
     {
@@ -791,7 +789,7 @@ int
 window_body_cols (struct window *w)
 {
   struct frame *f = XFRAME (WINDOW_FRAME (w));
-  int width = XINT (w->total_cols);
+  int width = w->total_cols;
 
   if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w))
     /* Scroll bars occupy a few columns.  */
@@ -1377,7 +1375,7 @@ check_window_containing (struct window *w, void *user_data)
 
 Lisp_Object
 window_from_coordinates (struct frame *f, int x, int y,
-                        enum window_part *part, int tool_bar_p)
+                        enum window_part *part, bool tool_bar_p)
 {
   Lisp_Object window;
   struct check_window_data cw;
@@ -1436,7 +1434,7 @@ window were selected.
 
 Note that, when WINDOW is selected, the value returned is the same as
 that returned by `point' for WINDOW's buffer.  It would be more strictly
-correct to return the `top-level' value of `point', outside of any
+correct to return the top-level value of `point', outside of any
 `save-excursion' forms.  But that is hard to define.  */)
   (Lisp_Object window)
 {
@@ -1489,17 +1487,8 @@ if it isn't already recorded.  */)
   CHECK_BUFFER (buf);
   b = XBUFFER (buf);
 
-#if 0 /* This change broke some things.  We should make it later.  */
-  /* If we don't know the end position, return nil.
-     The user can compute it with vertical-motion if he wants to.
-     It would be nicer to do it automatically,
-     but that's so slow that it would probably bother people.  */
-  if (NILP (w->window_end_valid))
-    return Qnil;
-#endif
-
   if (! NILP (update)
-      && (windows_or_buffers_changed || NILP (w->window_end_valid))
+      && (windows_or_buffers_changed || !w->window_end_valid)
       && !noninteractive)
     {
       struct text_pos startp;
@@ -1553,7 +1542,7 @@ Return POS.  */)
 {
   register struct window *w = decode_live_window (window);
 
-  CHECK_NUMBER_COERCE_MARKER (pos);
+  /* Type of POS is checked by Fgoto_char or set_marker_restricted ...  */
 
   if (w == XWINDOW (selected_window))
     {
@@ -1563,6 +1552,8 @@ Return POS.  */)
        {
          struct buffer *old_buffer = current_buffer;
 
+         /* ... but here we want to catch type error before buffer change.  */
+         CHECK_NUMBER_COERCE_MARKER (pos);
          set_buffer_internal (XBUFFER (w->buffer));
          Fgoto_char (pos);
          set_buffer_internal (old_buffer);
@@ -1588,9 +1579,8 @@ overriding motion of point in order to display at this exact start.  */)
 {
   register struct window *w = decode_live_window (window);
 
-  CHECK_NUMBER_COERCE_MARKER (pos);
   set_marker_restricted (w->start, pos, w->buffer);
-  /* this is not right, but much easier than doing what is right. */
+  /* This is not right, but much easier than doing what is right.  */
   w->start_at_line_beg = 0;
   if (NILP (noforce))
     w->force_start = 1;
@@ -1706,7 +1696,7 @@ Return nil if window display is not up-to-date.  In that case, use
   b = XBUFFER (w->buffer);
 
   /* Fail if current matrix is not up-to-date.  */
-  if (NILP (w->window_end_valid)
+  if (!w->window_end_valid
       || current_buffer->clip_changed
       || current_buffer->prevent_redisplay_optimizations_p
       || w->last_modified < BUF_MODIFF (b)
@@ -2017,12 +2007,12 @@ replace_window (Lisp_Object old, Lisp_Object new, int setflag)
   if (EQ (old, FRAME_ROOT_WINDOW (XFRAME (o->frame))))
     fset_root_window (XFRAME (o->frame), new);
 
-   if (setflag)
-     {
-      wset_left_col (n, o->left_col);
-      wset_top_line (n, o->top_line);
-      wset_total_cols (n, o->total_cols);
-      wset_total_lines (n, o->total_lines);
+  if (setflag)
+    {
+      n->left_col = o->left_col;
+      n->top_line = o->top_line;
+      n->total_cols = o->total_cols;
+      n->total_lines = o->total_lines;
       wset_normal_cols (n, o->normal_cols);
       wset_normal_cols (o, make_float (1.0));
       wset_normal_lines (n, o->normal_lines);
@@ -2038,7 +2028,7 @@ replace_window (Lisp_Object old, Lisp_Object new, int setflag)
       n->pseudo_window_p = 0;
       wset_window_end_vpos (n, make_number (0));
       wset_window_end_pos (n, make_number (0));
-      wset_window_end_valid (n, Qnil);
+      n->window_end_valid = 0;
       n->frozen_window_start_p = 0;
     }
 
@@ -2072,7 +2062,7 @@ recombine_windows (Lisp_Object window)
 {
   struct window *w, *p, *c;
   Lisp_Object parent, child;
-  int horflag;
+  bool horflag;
 
   w = XWINDOW (window);
   parent = w->parent;
@@ -2107,12 +2097,12 @@ recombine_windows (Lisp_Object window)
 
              if (horflag)
                wset_normal_cols (c,
-                                 make_float (XFLOATINT (c->total_cols)
-                                             / XFLOATINT (p->total_cols)));
+                                 make_float ((double) c->total_cols
+                                             / (double) p->total_cols));
              else
                wset_normal_lines (c,
-                                  make_float (XFLOATINT (c->total_lines)
-                                              / XFLOATINT (p->total_lines)));
+                                  make_float ((double) c->total_lines
+                                              / (double) p->total_lines));
 
              if (NILP (c->next))
                {
@@ -2238,7 +2228,6 @@ candidate_window_p (Lisp_Object window, Lisp_Object owindow, Lisp_Object minibuf
     }
   else if (EQ (all_frames, Qvisible))
     {
-      FRAME_SAMPLE_VISIBILITY (f);
       candidate_p = FRAME_VISIBLE_P (f)
        && (FRAME_TERMINAL (XFRAME (w->frame))
            == FRAME_TERMINAL (XFRAME (selected_frame)));
@@ -2246,7 +2235,6 @@ candidate_window_p (Lisp_Object window, Lisp_Object owindow, Lisp_Object minibuf
     }
   else if (INTEGERP (all_frames) && XINT (all_frames) == 0)
     {
-      FRAME_SAMPLE_VISIBILITY (f);
       candidate_p = (FRAME_VISIBLE_P (f) || FRAME_ICONIFIED_P (f)
 #ifdef HAVE_X_WINDOWS
                     /* Yuck!!  If we've just created the frame and the
@@ -2762,7 +2750,7 @@ window-start value is reasonable when this function is called.  */)
   struct window *w, *r, *s;
   struct frame *f;
   Lisp_Object sibling, pwindow, swindow IF_LINT (= Qnil), delta;
-  ptrdiff_t startpos IF_LINT (= 0);
+  ptrdiff_t startpos IF_LINT (= 0), startbyte IF_LINT (= 0);
   int top IF_LINT (= 0), new_top, resize_failed;
 
   w = decode_valid_window (window);
@@ -2801,6 +2789,7 @@ window-start value is reasonable when this function is called.  */)
   if (!NILP (w->buffer))
     {
       startpos = marker_position (w->start);
+      startbyte = marker_byte_position (w->start);
       top = WINDOW_TOP_EDGE_LINE (w)
        - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w)));
       /* Make sure WINDOW is the frame's selected window.  */
@@ -2872,9 +2861,8 @@ window-start value is reasonable when this function is called.  */)
   if (NILP (w->buffer))
     {
       /* Resize child windows vertically.  */
-      XSETINT (delta, XINT (r->total_lines)
-              - XINT (w->total_lines));
-      wset_top_line (w, r->top_line);
+      XSETINT (delta, r->total_lines - w->total_lines);
+      w->top_line = r->top_line;
       resize_root_window (window, delta, Qnil, Qnil);
       if (window_resize_check (w, 0))
        window_resize_apply (w, 0);
@@ -2890,10 +2878,8 @@ window-start value is reasonable when this function is called.  */)
       /* Resize child windows horizontally.  */
       if (!resize_failed)
        {
-         wset_left_col (w, r->left_col);
-         XSETINT (delta,
-                  XINT (r->total_cols) - XINT (w->total_cols));
-         wset_left_col (w, r->left_col);
+         w->left_col = r->left_col;
+         XSETINT (delta, r->total_cols - w->total_cols);
          resize_root_window (window, delta, Qt, Qnil);
          if (window_resize_check (w, 1))
            window_resize_apply (w, 1);
@@ -2970,10 +2956,10 @@ window-start value is reasonable when this function is called.  */)
          Fset_buffer (w->buffer);
          /* This computation used to temporarily move point, but that
             can have unwanted side effects due to text properties.  */
-         pos = *vmotion (startpos, -top, w);
+         pos = *vmotion (startpos, startbyte, -top, w);
 
          set_marker_both (w->start, w->buffer, pos.bufpos, pos.bytepos);
-         wset_window_end_valid (w, Qnil);
+         w->window_end_valid = 0;
          w->start_at_line_beg = (pos.bytepos == BEGV_BYTE
                                    || FETCH_BYTE (pos.bytepos - 1) == '\n');
          /* We need to do this, so that the window-scroll-functions
@@ -3166,7 +3152,8 @@ If FRAME is omitted or nil, it defaults to the selected frame.  */)
    reset from the buffer's local settings.  */
 
 void
-set_window_buffer (Lisp_Object window, Lisp_Object buffer, int run_hooks_p, int keep_margins_p)
+set_window_buffer (Lisp_Object window, Lisp_Object buffer,
+                  bool run_hooks_p, bool keep_margins_p)
 {
   struct window *w = XWINDOW (window);
   struct buffer *b = XBUFFER (buffer);
@@ -3189,7 +3176,7 @@ set_window_buffer (Lisp_Object window, Lisp_Object buffer, int run_hooks_p, int
   wset_window_end_pos (w, make_number (0));
   wset_window_end_vpos (w, make_number (0));
   memset (&w->last_cursor, 0, sizeof w->last_cursor);
-  wset_window_end_valid (w, Qnil);
+
   if (!(keep_margins_p && samebuf))
     { /* If we're not actually changing the buffer, don't reset hscroll and
         vscroll.  This case happens for example when called from
@@ -3424,7 +3411,7 @@ temp_output_buffer_show (register Lisp_Object buf)
    WINDOW its only vertical child (HORFLAG 1 means make WINDOW its only
    horizontal child).   */
 static void
-make_parent_window (Lisp_Object window, int horflag)
+make_parent_window (Lisp_Object window, bool horflag)
 {
   Lisp_Object parent;
   register struct window *o, *p;
@@ -3438,8 +3425,6 @@ make_parent_window (Lisp_Object window, int horflag)
   adjust_window_count (p, 1);
   XSETWINDOW (parent, p);
 
-  p->sequence_number = ++sequence_number;
-
   replace_window (window, parent, 1);
 
   wset_next (o, Qnil);
@@ -3465,10 +3450,6 @@ make_window (void)
   w = allocate_window ();
   /* Initialize Lisp data.  Note that allocate_window initializes all
      Lisp data to nil, so do it only for slots which should not be nil.  */
-  wset_left_col (w, make_number (0));
-  wset_top_line (w, make_number (0));
-  wset_total_lines (w, make_number (0));
-  wset_total_cols (w, make_number (0));
   wset_normal_lines (w, make_float (1.0));
   wset_normal_cols (w, make_float (1.0));
   wset_new_total (w, make_number (0));
@@ -3488,7 +3469,7 @@ make_window (void)
   w->nrows_scale_factor = w->ncols_scale_factor = 1;
   w->phys_cursor_type = -1;
   w->phys_cursor_width = -1;
-  w->sequence_number = ++sequence_number;
+  w->column_number_displayed = -1;
 
   /* Reset window_list.  */
   Vwindow_list = Qnil;
@@ -3539,7 +3520,7 @@ Note: This function does not operate on any child windows of WINDOW.  */)
    `window-min-height' or `window-min-width'.  It does check that window
    sizes do not drop below one line (two columns). */
 static int
-window_resize_check (struct window *w, int horflag)
+window_resize_check (struct window *w, bool horflag)
 {
   struct window *c;
 
@@ -3620,7 +3601,7 @@ window_resize_check (struct window *w, int horflag)
    This function does not perform any error checks.  Make sure you have
    run window_resize_check on W before applying this function.  */
 static void
-window_resize_apply (struct window *w, int horflag)
+window_resize_apply (struct window *w, bool horflag)
 {
   struct window *c;
   int pos;
@@ -3629,19 +3610,19 @@ window_resize_apply (struct window *w, int horflag)
      parent window has been set *before*.  */
   if (horflag)
     {
-      wset_total_cols (w, w->new_total);
+      w->total_cols = XFASTINT (w->new_total);
       if (NUMBERP (w->new_normal))
        wset_normal_cols (w, w->new_normal);
 
-      pos = XINT (w->left_col);
+      pos = w->left_col;
     }
   else
     {
-      wset_total_lines (w, w->new_total);
+      w->total_lines = XFASTINT (w->new_total);
       if (NUMBERP (w->new_normal))
        wset_normal_lines (w, w->new_normal);
 
-      pos = XINT (w->top_line);
+      pos = w->top_line;
     }
 
   if (!NILP (w->vchild))
@@ -3651,12 +3632,12 @@ window_resize_apply (struct window *w, int horflag)
       while (c)
        {
          if (horflag)
-           wset_left_col (c, make_number (pos));
+           c->left_col = pos;
          else
-           wset_top_line (c, make_number (pos));
+           c->top_line = pos;
          window_resize_apply (c, horflag);
          if (!horflag)
-           pos = pos + XINT (c->total_lines);
+           pos = pos + c->total_lines;
          c = NILP (c->next) ? 0 : XWINDOW (c->next);
        }
     }
@@ -3667,12 +3648,12 @@ window_resize_apply (struct window *w, int horflag)
       while (c)
        {
          if (horflag)
-           wset_left_col (c, make_number (pos));
+           c->left_col = pos;
          else
-           wset_top_line (c, make_number (pos));
+           c->top_line = pos;
          window_resize_apply (c, horflag);
          if (horflag)
-           pos = pos + XINT (c->total_cols);
+           pos = pos + c->total_cols;
          c = NILP (c->next) ? 0 : XWINDOW (c->next);
        }
     }
@@ -3701,11 +3682,11 @@ be applied on the Elisp level.  */)
 {
   struct frame *f = decode_live_frame (frame);
   struct window *r = XWINDOW (FRAME_ROOT_WINDOW (f));
-  int horflag = !NILP (horizontal);
+  bool horflag = !NILP (horizontal);
 
   if (!window_resize_check (r, horflag)
-      || ! EQ (r->new_total,
-              (horflag ? r->total_cols : r->total_lines)))
+      || (XINT (r->new_total)
+         != (horflag ? r->total_cols : r->total_lines)))
     return Qnil;
 
   block_input ();
@@ -3731,7 +3712,7 @@ be applied on the Elisp level.  */)
    satisfy the request.  The result will be meaningful if and only if
    F's windows have meaningful sizes when you call this.  */
 void
-resize_frame_windows (struct frame *f, int size, int horflag)
+resize_frame_windows (struct frame *f, int size, bool horflag)
 {
   Lisp_Object root = f->root_window;
   struct window *r = XWINDOW (root);
@@ -3745,18 +3726,17 @@ resize_frame_windows (struct frame *f, int size, int horflag)
                     - ((FRAME_HAS_MINIBUF_P (f) && !FRAME_MINIBUF_ONLY_P (f))
                        ? 1 : 0)));
 
-  wset_top_line (r, make_number (FRAME_TOP_MARGIN (f)));
+  r->top_line = FRAME_TOP_MARGIN (f);
   if (NILP (r->vchild) && NILP (r->hchild))
     /* For a leaf root window just set the size.  */
     if (horflag)
-      wset_total_cols (r, make_number (new_size));
+      r->total_cols = new_size;
     else
-      wset_total_lines (r, make_number (new_size));
+      r->total_lines = new_size;
   else
     {
       /* old_size is the old size of the frame's root window.  */
-      int old_size = XFASTINT (horflag ? r->total_cols
-                              : r->total_lines);
+      int old_size = horflag ? r->total_cols : r->total_lines;
       Lisp_Object delta;
 
       XSETINT (delta, new_size - old_size);
@@ -3786,9 +3766,9 @@ resize_frame_windows (struct frame *f, int size, int horflag)
                  root = f->selected_window;
                  Fdelete_other_windows_internal (root, Qnil);
                  if (horflag)
-                   wset_total_cols (XWINDOW (root), make_number (new_size));
+                   XWINDOW (root)->total_cols = new_size;
                  else
-                   wset_total_lines (XWINDOW (root), make_number (new_size));
+                   XWINDOW (root)->total_lines = new_size;
                }
            }
        }
@@ -3798,13 +3778,12 @@ resize_frame_windows (struct frame *f, int size, int horflag)
     {
       m = XWINDOW (mini);
       if (horflag)
-       wset_total_cols (m, make_number (size));
+       m->total_cols = size;
       else
        {
          /* Are we sure we always want 1 line here?  */
-         wset_total_lines (m, make_number (1));
-         wset_top_line
-           (m, make_number (XINT (r->top_line) + XINT (r->total_lines)));
+         m->total_lines = 1;
+         m->top_line = r->top_line + r->total_lines;
        }
     }
 
@@ -3845,7 +3824,7 @@ set correctly.  See the code of `split-window' for how this is done.  */)
   register Lisp_Object new, frame, reference;
   register struct window *o, *p, *n, *r;
   struct frame *f;
-  int horflag
+  bool horflag
     /* HORFLAG is 1 when we split side-by-side, 0 otherwise.  */
     = EQ (side, Qt) || EQ (side, Qleft) || EQ (side, Qright);
   int combination_limit = 0;
@@ -3888,20 +3867,21 @@ set correctly.  See the code of `split-window' for how this is done.  */)
       p = XWINDOW (o->parent);
       /* Temporarily pretend we split the parent window.  */
       wset_new_total
-       (p, make_number (XINT (horflag ? p->total_cols : p->total_lines)
+       (p, make_number ((horflag ? p->total_cols : p->total_lines)
                         - XINT (total_size)));
       if (!window_resize_check (p, horflag))
        error ("Window sizes don't fit");
       else
        /* Undo the temporary pretension.  */
-       wset_new_total (p, horflag ? p->total_cols : p->total_lines);
+       wset_new_total (p, make_number
+                       (horflag ? p->total_cols : p->total_lines));
     }
   else
     {
       if (!window_resize_check (o, horflag))
        error ("Resizing old window failed");
       else if (XINT (total_size) + XINT (o->new_total)
-              != XINT (horflag ? o->total_cols : o->total_lines))
+              != (horflag ? o->total_cols : o->total_lines))
        error ("Sum of sizes of old and new window don't fit");
     }
 
@@ -3921,7 +3901,8 @@ set correctly.  See the code of `split-window' for how this is done.  */)
           that its children get merged into another window.  */
        wset_combination_limit (p, Qt);
       /* These get applied below.  */
-      wset_new_total (p, horflag ? o->total_cols : o->total_lines);
+      wset_new_total (p, make_number
+                     (horflag ? o->total_cols : o->total_lines));
       wset_new_normal (p, new_normal);
     }
   else
@@ -3958,7 +3939,7 @@ set correctly.  See the code of `split-window' for how this is done.  */)
       wset_next (o, new);
     }
 
-  wset_window_end_valid (n, Qnil);
+  n->window_end_valid = 0;
   memset (&n->last_cursor, 0, sizeof n->last_cursor);
 
   /* Get special geometry settings from reference window.  */
@@ -3973,13 +3954,13 @@ set correctly.  See the code of `split-window' for how this is done.  */)
   /* Directly assign orthogonal coordinates and sizes.  */
   if (horflag)
     {
-      wset_top_line (n, o->top_line);
-      wset_total_lines (n, o->total_lines);
+      n->top_line = o->top_line;
+      n->total_lines = o->total_lines;
     }
   else
     {
-      wset_left_col (n, o->left_col);
-      wset_total_cols (n, o->total_cols);
+      n->left_col = o->left_col;
+      n->total_cols = o->total_cols;
     }
 
   /* Iso-coordinates and sizes are assigned by window_resize_apply,
@@ -4014,7 +3995,7 @@ Signal an error when WINDOW is the only window on its frame.  */)
   register Lisp_Object parent, sibling, frame, root;
   struct window *w, *p, *s, *r;
   struct frame *f;
-  int horflag;
+  bool horflag;
   int before_sibling = 0;
 
   w = decode_any_window (window);
@@ -4068,8 +4049,8 @@ Signal an error when WINDOW is the only window on its frame.  */)
     }
 
   if (window_resize_check (r, horflag)
-      && EQ (r->new_total,
-            (horflag ? r->total_cols : r->total_lines)))
+      && (XINT (r->new_total)
+         == (horflag ? r->total_cols : r->total_lines)))
     /* We can delete WINDOW now.  */
     {
 
@@ -4215,10 +4196,8 @@ grow_mini_window (struct window *w, int delta)
       window_resize_apply (r, 0);
 
       /* Grow the mini-window.  */
-      wset_top_line
-       (w, make_number (XFASTINT (r->top_line) + XFASTINT (r->total_lines)));
-      wset_total_lines
-       (w, make_number (XFASTINT (w->total_lines) - XINT (value)));
+      w->top_line = r->top_line + r->total_lines;
+      w->total_lines -= XINT (value);
       w->last_modified = 0;
       w->last_overlay_modified = 0;
 
@@ -4240,7 +4219,7 @@ shrink_mini_window (struct window *w)
 
   eassert (MINI_WINDOW_P (w));
 
-  size = XINT (w->total_lines);
+  size = w->total_lines;
   if (size > 1)
     {
       root = FRAME_ROOT_WINDOW (f);
@@ -4253,9 +4232,8 @@ shrink_mini_window (struct window *w)
          window_resize_apply (r, 0);
 
          /* Shrink the mini-window.  */
-         wset_top_line (w, make_number (XFASTINT (r->top_line)
-                                        + XFASTINT (r->total_lines)));
-         wset_total_lines (w, make_number (1));
+         w->top_line = r->top_line + r->total_lines;
+         w->total_lines = 1;
 
          w->last_modified = 0;
          w->last_overlay_modified = 0;
@@ -4289,7 +4267,7 @@ DEFUN ("resize-mini-window-internal", Fresize_mini_window_internal, Sresize_mini
     error ("Cannot resize a minibuffer-only frame");
 
   r = XWINDOW (FRAME_ROOT_WINDOW (f));
-  height = XINT (r->total_lines) + XINT (w->total_lines);
+  height = r->total_lines + w->total_lines;
   if (window_resize_check (r, 0)
       && XINT (w->new_total) > 0
       && height == XINT (r->new_total) + XINT (w->new_total))
@@ -4297,9 +4275,8 @@ DEFUN ("resize-mini-window-internal", Fresize_mini_window_internal, Sresize_mini
       block_input ();
       window_resize_apply (r, 0);
 
-      wset_total_lines (w, w->new_total);
-      wset_top_line (w, make_number (XINT (r->top_line)
-                                    + XINT (r->total_lines)));
+      w->total_lines = XFASTINT (w->new_total);
+      w->top_line = r->top_line + r->total_lines;
 
       windows_or_buffers_changed++;
       FRAME_WINDOW_SIZES_CHANGED (f) = 1;
@@ -4339,7 +4316,7 @@ mark_window_cursors_off (struct window *w)
 int
 window_internal_height (struct window *w)
 {
-  int ht = XFASTINT (w->total_lines);
+  int ht = w->total_lines;
 
   if (!MINI_WINDOW_P (w))
     {
@@ -4628,8 +4605,8 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
        }
 
       /* Set the window start, and set up the window for redisplay.  */
-      set_marker_restricted (w->start, make_number (pos),
-                            w->buffer);
+      set_marker_restricted_both (w->start, w->buffer, IT_CHARPOS (it),
+                                 IT_BYTEPOS (it));
       bytepos = marker_byte_position (w->start);
       w->start_at_line_beg = (pos == BEGV || FETCH_BYTE (bytepos - 1) == '\n');
       w->update_mode_line = 1;
@@ -4649,7 +4626,7 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
      even if there is a header line.  */
   this_scroll_margin = max (0, scroll_margin);
   this_scroll_margin
-    = min (this_scroll_margin, XFASTINT (w->total_lines) / 4);
+    = min (this_scroll_margin, w->total_lines / 4);
   this_scroll_margin *= FRAME_LINE_HEIGHT (it.f);
 
   if (n > 0)
@@ -4769,7 +4746,8 @@ window_scroll_line_based (Lisp_Object window, int n, int whole, int noerror)
   register Lisp_Object tem;
   int lose;
   Lisp_Object bolp;
-  ptrdiff_t startpos;
+  ptrdiff_t startpos = marker_position (w->start);
+  ptrdiff_t startbyte = marker_byte_position (w->start);
   Lisp_Object original_pos = Qnil;
 
   /* If scrolling screen-fulls, compute the number of lines to
@@ -4777,8 +4755,6 @@ window_scroll_line_based (Lisp_Object window, int n, int whole, int noerror)
   if (whole)
     n *= max (1, ht - next_screen_context_lines);
 
-  startpos = marker_position (w->start);
-
   if (!NILP (Vscroll_preserve_screen_position))
     {
       if (window_scroll_preserve_vpos <= 0
@@ -4786,10 +4762,8 @@ window_scroll_line_based (Lisp_Object window, int n, int whole, int noerror)
          || NILP (Fget (KVAR (current_kboard, Vlast_command), Qscroll_command)))
        {
          struct position posit
-           = *compute_motion (startpos, 0, 0, 0,
-                              PT, ht, 0,
-                              -1, w->hscroll,
-                              0, w);
+           = *compute_motion (startpos, startbyte, 0, 0, 0,
+                              PT, ht, 0, -1, w->hscroll, 0, w);
          window_scroll_preserve_vpos = posit.vpos;
          window_scroll_preserve_hpos = posit.hpos + w->hscroll;
        }
@@ -4805,9 +4779,10 @@ window_scroll_line_based (Lisp_Object window, int n, int whole, int noerror)
     {
       Fvertical_motion (make_number (- (ht / 2)), window);
       startpos = PT;
+      startbyte = PT_BYTE;
     }
 
-  SET_PT (startpos);
+  SET_PT_BOTH (startpos, startbyte);
   lose = n < 0 && PT == BEGV;
   Fvertical_motion (make_number (n), window);
   pos = PT;
@@ -4828,7 +4803,7 @@ window_scroll_line_based (Lisp_Object window, int n, int whole, int noerror)
     {
       /* Don't use a scroll margin that is negative or too large.  */
       int this_scroll_margin =
-       max (0, min (scroll_margin, XINT (w->total_lines) / 4));
+       max (0, min (scroll_margin, w->total_lines / 4));
 
       set_marker_restricted_both (w->start, w->buffer, pos, pos_byte);
       w->start_at_line_beg = !NILP (bolp);
@@ -5043,7 +5018,7 @@ specifies the window to scroll.  This takes precedence over
   ++windows_or_buffers_changed;
 
   Fset_buffer (w->buffer);
-  SET_PT (marker_position (w->pointm));
+  SET_PT_BOTH (marker_position (w->pointm), marker_byte_position (w->pointm));
 
   if (NILP (arg))
     window_scroll (window, 1, 1, 1);
@@ -5185,7 +5160,7 @@ displayed_window_lines (struct window *w)
 
 DEFUN ("recenter", Frecenter, Srecenter, 0, 1, "P",
        doc: /* Center point in selected window and maybe redisplay frame.
-With prefix argument ARG, recenter putting point on screen line ARG
+With a numeric prefix argument ARG, recenter putting point on screen line ARG
 relative to the selected window.  If ARG is negative, it counts up from the
 bottom of the window.  (ARG should be less than the height of the window.)
 
@@ -5245,7 +5220,7 @@ and redisplay normally--don't erase and redraw the frame.  */)
   /* Do this after making BUF current
      in case scroll_margin is buffer-local.  */
   this_scroll_margin =
-    max (0, min (scroll_margin, XFASTINT (w->total_lines) / 4));
+    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
@@ -5342,7 +5317,7 @@ and redisplay normally--don't erase and redraw the frame.  */)
 
          iarg = max (iarg, this_scroll_margin);
 
-         pos = *vmotion (PT, -iarg, w);
+         pos = *vmotion (PT, PT_BYTE, -iarg, w);
          charpos = pos.bufpos;
          bytepos = pos.bytepos;
        }
@@ -5361,14 +5336,14 @@ and redisplay normally--don't erase and redraw the frame.  */)
       iarg = clip_to_bounds (this_scroll_margin, iarg,
                             ht - this_scroll_margin - 1);
 
-      pos = *vmotion (PT, - iarg, w);
+      pos = *vmotion (PT, PT_BYTE, - iarg, w);
       charpos = pos.bufpos;
       bytepos = pos.bytepos;
     }
 
   /* Set the new window start.  */
   set_marker_both (w->start, w->buffer, charpos, bytepos);
-  wset_window_end_valid (w, Qnil);
+  w->window_end_valid = 0;
 
   w->optional_new_start = 1;
 
@@ -5719,7 +5694,7 @@ the return value is nil.  Otherwise the value is t.  */)
              wset_prev (w, Qnil);
              if (!NILP (w->parent))
                {
-                 if (EQ (p->total_cols, XWINDOW (w->parent)->total_cols))
+                 if (XINT (p->total_cols) == XWINDOW (w->parent)->total_cols)
                    {
                      wset_vchild (XWINDOW (w->parent), p->window);
                      wset_hchild (XWINDOW (w->parent), Qnil);
@@ -5732,14 +5707,13 @@ the return value is nil.  Otherwise the value is t.  */)
                }
            }
 
-         /* If we squirreled away the buffer in the window's height,
-            restore it now.  */
-         if (BUFFERP (w->total_lines))
-           wset_buffer (w, w->total_lines);
-         wset_left_col (w, p->left_col);
-         wset_top_line (w, p->top_line);
-         wset_total_cols (w, p->total_cols);
-         wset_total_lines (w, p->total_lines);
+         /* If we squirreled away the buffer, restore it now.  */
+         if (BUFFERP (w->combination_limit))
+           wset_buffer (w, w->combination_limit);
+         w->left_col = XFASTINT (p->left_col);
+         w->top_line = XFASTINT (p->top_line);
+         w->total_cols = XFASTINT (p->total_cols);
+         w->total_lines = XFASTINT (p->total_lines);
          wset_normal_cols (w, p->normal_cols);
          wset_normal_lines (w, p->normal_lines);
          w->hscroll = XFASTINT (p->hscroll);
@@ -5808,8 +5782,7 @@ the return value is nil.  Otherwise the value is t.  */)
             {
               /* Set window markers at start of visible range.  */
               if (XMARKER (w->start)->buffer == 0)
-                set_marker_restricted (w->start, make_number (0),
-                                       w->buffer);
+                set_marker_restricted_both (w->start, w->buffer, 0, 0);
               if (XMARKER (w->pointm)->buffer == 0)
                 set_marker_restricted_both
                   (w->pointm, w->buffer,
@@ -5827,10 +5800,8 @@ the return value is nil.  Otherwise the value is t.  */)
              wset_buffer (w, other_buffer_safely (Fcurrent_buffer ()));
              /* This will set the markers to beginning of visible
                 range.  */
-             set_marker_restricted (w->start,
-                                    make_number (0), w->buffer);
-             set_marker_restricted (w->pointm,
-                                    make_number (0), w->buffer);
+             set_marker_restricted_both (w->start, w->buffer, 0, 0);
+             set_marker_restricted_both (w->pointm, w->buffer, 0, 0);
              w->start_at_line_beg = 1;
              if (!NILP (w->dedicated))
                /* Record this window as dead.  */
@@ -5942,9 +5913,6 @@ delete_all_child_windows (Lisp_Object window)
     /* Delete WINDOW's siblings (we traverse postorderly).  */
     delete_all_child_windows (w->next);
 
-  /* See Fset_window_configuration for excuse.  */
-  wset_total_lines (w, w->buffer);
-
   if (!NILP (w->vchild))
     {
       delete_all_child_windows (w->vchild);
@@ -5960,6 +5928,10 @@ delete_all_child_windows (Lisp_Object window)
       unshow_buffer (w);
       unchain_marker (XMARKER (w->pointm));
       unchain_marker (XMARKER (w->start));
+      /* Since combination limit makes sense for an internal windows
+        only, we use this slot to save the buffer for the sake of
+        possible resurrection in Fset_window_configuration.  */
+      wset_combination_limit (w, w->buffer);
       wset_buffer (w, Qnil);
     }
 
@@ -6055,10 +6027,10 @@ save_window_save (Lisp_Object window, struct Lisp_Vector *vector, int i)
       wset_temslot (w, make_number (i)); i++;
       p->window = window;
       p->buffer = w->buffer;
-      p->left_col = w->left_col;
-      p->top_line = w->top_line;
-      p->total_cols = w->total_cols;
-      p->total_lines = w->total_lines;
+      p->left_col = make_number (w->left_col);
+      p->top_line = make_number (w->top_line);
+      p->total_cols = make_number (w->total_cols);
+      p->total_lines = make_number (w->total_lines);
       p->normal_cols = w->normal_cols;
       p->normal_lines = w->normal_lines;
       XSETFASTINT (p->hscroll, w->hscroll);
@@ -6203,11 +6175,11 @@ saved by this function.  */)
   data->minibuf_selected_window = minibuf_level > 0 ? minibuf_selected_window : Qnil;
   data->root_window = FRAME_ROOT_WINDOW (f);
   data->focus_frame = FRAME_FOCUS_FRAME (f);
-  tem = Fmake_vector (make_number (n_windows), Qnil);
+  tem = make_uninit_vector (n_windows);
   data->saved_windows = tem;
   for (i = 0; i < n_windows; i++)
     ASET (tem, i,
-         Fmake_vector (make_number (VECSIZE (struct saved_window)), Qnil));
+         Fmake_vector (make_number (VECSIZE (struct saved_window)), Qnil));
   save_window_save (FRAME_ROOT_WINDOW (f), XVECTOR (tem), 0);
   XSETWINDOW_CONFIGURATION (tem, data);
   return (tem);
@@ -6319,7 +6291,7 @@ display marginal areas and the text area.  */)
       adjust_window_margins (w);
 
       clear_glyph_matrix (w->current_matrix);
-      wset_window_end_valid (w, Qnil);
+      w->window_end_valid = 0;
 
       ++windows_or_buffers_changed;
       adjust_glyphs (XFRAME (WINDOW_FRAME (w)));
@@ -6389,7 +6361,7 @@ Fourth parameter HORIZONTAL-TYPE is currently unused.  */)
       adjust_window_margins (w);
 
       clear_glyph_matrix (w->current_matrix);
-      wset_window_end_valid (w, Qnil);
+      w->window_end_valid = 0;
 
       ++windows_or_buffers_changed;
       adjust_glyphs (XFRAME (WINDOW_FRAME (w)));
@@ -6552,7 +6524,7 @@ freeze_window_start (struct window *w, void *freeze_p)
    means freeze the window start.  */
 
 void
-freeze_window_starts (struct frame *f, int freeze_p)
+freeze_window_starts (struct frame *f, bool freeze_p)
 {
   foreach_window (f, freeze_window_start, (void *) (freeze_p ? f : 0));
 }
@@ -6793,7 +6765,8 @@ same combination.
 
 Other values are reserved for future use.
 
-This variable takes no effect if `window-combination-limit' is non-nil.  */);
+This variable takes no effect if the variable `window-combination-limit' is
+non-nil.  */);
   Vwindow_combination_resize = Qnil;
 
   DEFVAR_LISP ("window-combination-limit", Vwindow_combination_limit,