(reset_buffer): Initialize `display_error_modiff'.
[bpt/emacs.git] / src / window.c
index c8a348b..6ee3086 100644 (file)
@@ -48,10 +48,6 @@ Boston, MA 02111-1307, USA.  */
 #include "macterm.h"
 #endif
 
-#ifndef max
-#define max(a, b) ((a) < (b) ? (b) : (a))
-#endif
-
 /* Values returned from coordinates_in_window.  */
 
 enum window_part
@@ -67,7 +63,7 @@ enum window_part
 
 
 Lisp_Object Qwindowp, Qwindow_live_p, Qwindow_configuration_p;
-Lisp_Object Qwindow_size_fixed, Qleft_fringe, Qright_fringe;
+Lisp_Object Qwindow_size_fixed;
 extern Lisp_Object Qheight, Qwidth;
 
 static int displayed_window_lines P_ ((struct window *));
@@ -298,7 +294,7 @@ used by that frame.  */)
 {
   if (NILP (frame))
     frame = selected_frame;
-  CHECK_LIVE_FRAME (frame, 0);
+  CHECK_LIVE_FRAME (frame);
   return FRAME_MINIBUF_WINDOW (XFRAME (frame));
 }
 
@@ -335,7 +331,7 @@ POS defaults to point in WINDOW; WINDOW defaults to the selected window.  */)
 
   if (!NILP (pos))
     {
-      CHECK_NUMBER_COERCE_MARKER (pos, 0);
+      CHECK_NUMBER_COERCE_MARKER (pos);
       posint = XINT (pos);
     }
   else if (w == XWINDOW (selected_window))
@@ -386,7 +382,7 @@ decode_window (window)
   if (NILP (window))
     return XWINDOW (selected_window);
 
-  CHECK_LIVE_WINDOW (window, 0);
+  CHECK_LIVE_WINDOW (window);
   return XWINDOW (window);
 }
 
@@ -434,7 +430,7 @@ NCOL should be zero or positive.  */)
   struct window *w = decode_window (window);
   int hscroll;
 
-  CHECK_NUMBER (ncol, 1);
+  CHECK_NUMBER (ncol);
   hscroll = max (0, XINT (ncol));
   
   /* Prevent redisplay shortcuts when changing the hscroll.  */
@@ -501,7 +497,7 @@ and BOTTOM is one more than the bottommost row used by WINDOW
    if it is on the border between the window and its right sibling,
       return 3.
    if it is on the window's top line, return 4;
-   if it is in the bitmap area to the left/right of the window,
+   if it is in left or right fringe of the window,
    return 5 or 6, and convert *X and *Y to window-relative corrdinates.
 
    X and Y are frame relative pixel coordinates.  */
@@ -515,9 +511,8 @@ coordinates_in_window (w, x, y)
      everywhere.  */
   struct frame *f = XFRAME (WINDOW_FRAME (w));
   int left_x, right_x, top_y, bottom_y;
-  int flags_area_width = FRAME_LEFT_FLAGS_AREA_WIDTH (f);
   enum window_part part;
-  int ux = CANON_X_UNIT (f), uy = CANON_Y_UNIT (f);
+  int ux = CANON_X_UNIT (f);
   int x0 = XFASTINT (w->left) * ux;
   int x1 = x0 + XFASTINT (w->width) * ux;
   /* The width of the area where the vertical line can be dragged.
@@ -588,10 +583,10 @@ coordinates_in_window (w, x, y)
   else if (*y < top_y
           || *y >= bottom_y
           || *x < (left_x
-                   - flags_area_width
+                   - FRAME_LEFT_FRINGE_WIDTH (f)
                    - FRAME_LEFT_SCROLL_BAR_WIDTH (f) * ux)
           || *x > (right_x
-                   + flags_area_width
+                   + FRAME_RIGHT_FRINGE_WIDTH (f)
                    + FRAME_RIGHT_SCROLL_BAR_WIDTH (f) * ux))
     {
       part = ON_NOTHING;
@@ -601,13 +596,13 @@ coordinates_in_window (w, x, y)
       if (!w->pseudo_window_p
          && !FRAME_HAS_VERTICAL_SCROLL_BARS (f)
          && !WINDOW_RIGHTMOST_P (w)
-         && (abs (*x - right_x - flags_area_width) < grabbable_width))
+         && (abs (*x - right_x - FRAME_RIGHT_FRINGE_WIDTH (f)) < grabbable_width))
        {
          part = ON_VERTICAL_BORDER;
        }
       else if (*x < left_x || *x > right_x)
        {
-         /* Other lines than the mode line don't include flags areas and
+         /* Other lines than the mode line don't include fringes and
             scroll bars on the left.  */
       
          /* Convert X and Y to window-relative pixel coordinates.  */
@@ -628,7 +623,7 @@ coordinates_in_window (w, x, y)
         terminals, the vertical line's x coordinate is right_x.  */
       if (*x < left_x || *x > right_x)
        {
-         /* Other lines than the mode line don't include flags areas and
+         /* Other lines than the mode line don't include fringes and
             scroll bars on the left.  */
       
          /* Convert X and Y to window-relative pixel coordinates.  */
@@ -669,9 +664,8 @@ If COORDINATES are in the text portion of WINDOW,
    the coordinates relative to the window are returned.
 If they are in the mode line of WINDOW, `mode-line' is returned.
 If they are in the top mode line of WINDOW, `header-line' is returned.
-If they are in the fringe to the left of the window,
-   `left-fringe' is returned, if they are in the area on the right of
-   the window, `right-fringe' is returned.
+If they are in the left fringe of WINDOW, `left-fringe' is returned.
+If they are in the right fringe of WINDOW, `right-fringe' is returned.
 If they are on the border between WINDOW and its right sibling,
   `vertical-line' is returned.  */)
      (coordinates, window)
@@ -682,14 +676,14 @@ If they are on the border between WINDOW and its right sibling,
   int x, y;
   Lisp_Object lx, ly;
 
-  CHECK_LIVE_WINDOW (window, 0);
+  CHECK_LIVE_WINDOW (window);
   w = XWINDOW (window);
   f = XFRAME (w->frame);
-  CHECK_CONS (coordinates, 1);
+  CHECK_CONS (coordinates);
   lx = Fcar (coordinates);
   ly = Fcdr (coordinates);
-  CHECK_NUMBER_OR_FLOAT (lx, 1);
-  CHECK_NUMBER_OR_FLOAT (ly, 1);
+  CHECK_NUMBER_OR_FLOAT (lx);
+  CHECK_NUMBER_OR_FLOAT (ly);
   x = PIXEL_X_FROM_CANON_X (f, lx);
   y = PIXEL_Y_FROM_CANON_Y (f, ly);
 
@@ -820,12 +814,12 @@ column 0.  */)
 
   if (NILP (frame))
     frame = selected_frame;
-  CHECK_LIVE_FRAME (frame, 2);
+  CHECK_LIVE_FRAME (frame);
   f = XFRAME (frame);
 
   /* Check that arguments are integers or floats.  */
-  CHECK_NUMBER_OR_FLOAT (x, 0);
-  CHECK_NUMBER_OR_FLOAT (y, 1);
+  CHECK_NUMBER_OR_FLOAT (x);
+  CHECK_NUMBER_OR_FLOAT (y);
 
   return window_from_coordinates (f, 
                                  PIXEL_X_FROM_CANON_X (f, x),
@@ -889,7 +883,7 @@ if it isn't already recorded.  */)
   Lisp_Object buf;
 
   buf = w->buffer;
-  CHECK_BUFFER (buf, 0);
+  CHECK_BUFFER (buf);
 
 #if 0 /* This change broke some things.  We should make it later.  */
   /* If we don't know the end position, return nil.
@@ -950,7 +944,7 @@ DEFUN ("set-window-point", Fset_window_point, Sset_window_point, 2, 2, 0,
 {
   register struct window *w = decode_window (window);
 
-  CHECK_NUMBER_COERCE_MARKER (pos, 1);
+  CHECK_NUMBER_COERCE_MARKER (pos);
   if (w == XWINDOW (selected_window)
       && XBUFFER (w->buffer) == current_buffer)
     Fgoto_char (pos);
@@ -974,7 +968,7 @@ from overriding motion of point in order to display at this exact start.  */)
 {
   register struct window *w = decode_window (window);
 
-  CHECK_NUMBER_COERCE_MARKER (pos, 1);
+  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. */
   w->start_at_line_beg = Qnil;
@@ -1199,7 +1193,7 @@ delete_window (window)
   if (NILP (window))
     window = selected_window;
   else
-    CHECK_WINDOW (window, 0);
+    CHECK_WINDOW (window);
   p = XWINDOW (window);
 
   /* It's okay to delete an already-deleted window.  */
@@ -1452,7 +1446,7 @@ decode_next_window_args (window, minibuf, all_frames)
   if (NILP (*window))
     *window = selected_window;
   else
-    CHECK_LIVE_WINDOW (*window, 0);
+    CHECK_LIVE_WINDOW (*window);
   
   /* MINIBUF nil may or may not include minibuffers.  Decide if it
      does.  */
@@ -1636,7 +1630,7 @@ argument ALL_FRAMES is non-nil, cycle through all frames.  */)
   Lisp_Object window;
   int i;
 
-  CHECK_NUMBER (arg, 0);
+  CHECK_NUMBER (arg);
   window = selected_window;
   
   for (i = XINT (arg); i > 0; --i)
@@ -1994,7 +1988,7 @@ value is reasonable when this function is called.  */)
   if (NILP (window))
     window = selected_window;
   else
-    CHECK_LIVE_WINDOW (window, 0);
+    CHECK_LIVE_WINDOW (window);
   w = XWINDOW (window);
 
   startpos = marker_position (w->start);
@@ -2060,7 +2054,7 @@ If FRAME is a frame, search only that frame.  */)
   if (!NILP (buffer))
     {
       buffer = Fget_buffer (buffer);
-      CHECK_BUFFER (buffer, 0);
+      CHECK_BUFFER (buffer);
       window_loop (DELETE_BUFFER_WINDOWS, buffer, 0, frame);
     }
   
@@ -2077,7 +2071,7 @@ DEFUN ("replace-buffer-in-windows", Freplace_buffer_in_windows,
   if (!NILP (buffer))
     {
       buffer = Fget_buffer (buffer);
-      CHECK_BUFFER (buffer, 0);
+      CHECK_BUFFER (buffer);
       window_loop (UNSHOW_BUFFER, buffer, 0, Qt);
     }
   return Qnil;
@@ -2664,7 +2658,7 @@ BUFFER can be a buffer or buffer name.  */)
 
   XSETWINDOW (window, w);
   buffer = Fget_buffer (buffer);
-  CHECK_BUFFER (buffer, 1);
+  CHECK_BUFFER (buffer);
 
   if (NILP (XBUFFER (buffer)->name))
     error ("Attempt to display deleted buffer");
@@ -2709,7 +2703,7 @@ select_window_1 (window, recordflag)
   register struct window *ow;
   struct frame *sf;
 
-  CHECK_LIVE_WINDOW (window, 0);
+  CHECK_LIVE_WINDOW (window);
 
   w = XWINDOW (window);
   w->frozen_window_start_p = 0;
@@ -2806,7 +2800,7 @@ See `special-display-buffer-names', and `special-display-regexps'.  */)
 {
   Lisp_Object tem;
 
-  CHECK_STRING (buffer_name, 1);
+  CHECK_STRING (buffer_name);
 
   tem = Fmember (buffer_name, Vspecial_display_buffer_names);
   if (!NILP (tem))
@@ -2838,7 +2832,7 @@ See `same-window-buffer-names' and `same-window-regexps'.  */)
 {
   Lisp_Object tem;
 
-  CHECK_STRING (buffer_name, 1);
+  CHECK_STRING (buffer_name);
 
   tem = Fmember (buffer_name, Vsame_window_buffer_names);
   if (!NILP (tem))
@@ -2899,7 +2893,7 @@ displayed.  */)
 
   swp = Qnil;
   buffer = Fget_buffer (buffer);
-  CHECK_BUFFER (buffer, 0);
+  CHECK_BUFFER (buffer);
 
   if (!NILP (Vdisplay_buffer_function))
     return call2 (Vdisplay_buffer_function, buffer, not_this_window);
@@ -3169,7 +3163,7 @@ SIZE includes that window's scroll bar, or the divider column to its right.  */)
   if (NILP (window))
     window = selected_window;
   else
-    CHECK_LIVE_WINDOW (window, 0);
+    CHECK_LIVE_WINDOW (window);
 
   o = XWINDOW (window);
   fo = XFRAME (WINDOW_FRAME (o));
@@ -3187,7 +3181,7 @@ SIZE includes that window's scroll bar, or the divider column to its right.  */)
     }
   else
     {
-      CHECK_NUMBER (size, 1);
+      CHECK_NUMBER (size);
       size_int = XINT (size);
     }
 
@@ -3282,7 +3276,7 @@ Interactively, if an argument is not given, make the window one line bigger.  */
      (arg, side)
      register Lisp_Object arg, side;
 {
-  CHECK_NUMBER (arg, 0);
+  CHECK_NUMBER (arg);
   enlarge_window (selected_window, XINT (arg), !NILP (side));
 
   if (! NILP (Vwindow_configuration_change_hook))
@@ -3298,7 +3292,7 @@ Interactively, if an argument is not given, make the window one line smaller.  *
      (arg, side)
      register Lisp_Object arg, side;
 {
-  CHECK_NUMBER (arg, 0);
+  CHECK_NUMBER (arg);
   enlarge_window (selected_window, -XINT (arg), !NILP (side));
 
   if (! NILP (Vwindow_configuration_change_hook))
@@ -3755,7 +3749,9 @@ grow_mini_window (w, delta)
     {
       int min_height = window_min_size (root, 0, 0, 0);
       if (XFASTINT (root->height) - delta < min_height)
-       delta = XFASTINT (root->height) - min_height;
+       /* Note that the root window may already be smaller than
+          min_height.  */
+       delta = max (0, XFASTINT (root->height) - min_height);
     }
     
   if (delta)
@@ -3878,9 +3874,9 @@ window_internal_width (w)
     width -= 1;
 
   /* On window-systems, areas to the left and right of the window
-     are used to display bitmaps there.  */
+     are used as fringes.  */
   if (FRAME_WINDOW_P (f))
-    width -= FRAME_FLAGS_AREA_COLS (f);
+    width -= FRAME_FRINGE_COLS (f);
 
   return width;
 }
@@ -4351,7 +4347,7 @@ showing that buffer is used.  */)
               && ! EQ (window, selected_window));
     }
 
-  CHECK_LIVE_WINDOW (window, 0);
+  CHECK_LIVE_WINDOW (window);
 
   if (EQ (window, selected_window))
     error ("There is no other window");
@@ -4396,7 +4392,7 @@ showing that buffer, popping the buffer up if necessary.  */)
     {
       if (CONSP (arg))
        arg = Fcar (arg);
-      CHECK_NUMBER (arg, 0);
+      CHECK_NUMBER (arg);
       window_scroll (window, XINT (arg), 0, 1);
     }
 
@@ -4408,7 +4404,13 @@ showing that buffer, popping the buffer up if necessary.  */)
 \f
 DEFUN ("scroll-left", Fscroll_left, Sscroll_left, 0, 1, "P",
        doc: /* Scroll selected window display ARG columns left.
-Default for ARG is window width minus 2.  */)
+Default for ARG is window width minus 2.
+Value is the total amount of leftward horizontal scrolling in
+effect after the change.
+If `automatic-hscrolling' is non-nil, the argument ARG modifies
+a lower bound for automatic scrolling, i.e. automatic scrolling
+will not scroll a window to a column less than the value returned
+by this function.  */)
      (arg)
      register Lisp_Object arg;
 {
@@ -4432,7 +4434,13 @@ Default for ARG is window width minus 2.  */)
 
 DEFUN ("scroll-right", Fscroll_right, Sscroll_right, 0, 1, "P",
        doc: /* Scroll selected window display ARG columns right.
-Default for ARG is window width minus 2.  */)
+Default for ARG is window width minus 2.
+Value is the total amount of leftward horizontal scrolling in
+effect after the change.
+If `automatic-hscrolling' is non-nil, the argument ARG modifies
+a lower bound for automatic scrolling, i.e. automatic scrolling
+will not scroll a window to a column less than the value returned
+by this function.  */)
      (arg)
      register Lisp_Object arg;
 {
@@ -4539,7 +4547,7 @@ and redisplay normally--don't erase and redraw the frame.  */)
   else
     {
       arg = Fprefix_numeric_value (arg);
-      CHECK_NUMBER (arg, 0);
+      CHECK_NUMBER (arg);
     }
 
   set_buffer_internal (buf);
@@ -4576,18 +4584,17 @@ and redisplay normally--don't erase and redraw the frame.  */)
          nlines = - XINT (arg) - 1;
          move_it_by_lines (&it, nlines, 1);
 
-         y1 = it.current_y - y0;
-         h = line_bottom_y (&it) - y1;
+         y1 = line_bottom_y (&it);
 
          /* If we can't move down NLINES lines because we hit
             the end of the buffer, count in some empty lines.  */
          if (it.vpos < nlines)
            y1 += (nlines - it.vpos) * CANON_Y_UNIT (it.f);
          
-         y0 = it.last_visible_y - y1 - h;
-         
+         h = window_box_height (w) - (y1 - y0);
+
          start_display (&it, w, pt);
-         move_it_vertically (&it, - y0);
+         move_it_vertically (&it, - h);
          charpos = IT_CHARPOS (it);
          bytepos = IT_BYTEPOS (it);
        }
@@ -5261,7 +5268,7 @@ redirection (see `redirect-frame-focus').  */)
 
   if (NILP (frame))
     frame = selected_frame;
-  CHECK_LIVE_FRAME (frame, 0);
+  CHECK_LIVE_FRAME (frame);
   f = XFRAME (frame);
 
   n_windows = count_windows (XWINDOW (FRAME_ROOT_WINDOW (f)));
@@ -5297,7 +5304,8 @@ Restore which buffer appears in which window, where display starts,
 and the value of point and mark for each window.
 Also restore the choice of selected window.
 Also restore which buffer is current.
-Does not restore the value of point in current buffer.  */)
+Does not restore the value of point in current buffer.
+usage: (save-window-excursion BODY ...)  */)
      (args)
      Lisp_Object args;
 {
@@ -5329,9 +5337,9 @@ A nil width parameter means no margin.  */)
   struct window *w = decode_window (window);
 
   if (!NILP (left))
-    CHECK_NUMBER_OR_FLOAT (left, 1);
+    CHECK_NUMBER_OR_FLOAT (left);
   if (!NILP (right))
-    CHECK_NUMBER_OR_FLOAT (right, 2);
+    CHECK_NUMBER_OR_FLOAT (right);
 
   /* Check widths < 0 and translate a zero width to nil.
      Margins that are too wide have to be checked elsewhere.  */
@@ -5390,7 +5398,7 @@ Value is a multiple of the canonical character height of WINDOW.  */)
   if (NILP (window))
     window = selected_window;
   else
-    CHECK_WINDOW (window, 0);
+    CHECK_WINDOW (window);
   w = XWINDOW (window);
   f = XFRAME (w->frame);
   
@@ -5405,8 +5413,8 @@ Value is a multiple of the canonical character height of WINDOW.  */)
 DEFUN ("set-window-vscroll", Fset_window_vscroll, Sset_window_vscroll,
        2, 2, 0,
        doc: /* Set amount by which WINDOW should be scrolled vertically to VSCROLL.
-WINDOW nil or omitted means use the selected window.  VSCROLL is a
-non-negative multiple of the canonical character height of WINDOW.  */)
+WINDOW nil means use the selected window.  VSCROLL is a non-negative
+multiple of the canonical character height of WINDOW.  */)
      (window, vscroll)
      Lisp_Object window, vscroll;
 {
@@ -5416,8 +5424,8 @@ non-negative multiple of the canonical character height of WINDOW.  */)
   if (NILP (window))
     window = selected_window;
   else
-    CHECK_WINDOW (window, 0);
-  CHECK_NUMBER_OR_FLOAT (vscroll, 1);
+    CHECK_WINDOW (window);
+  CHECK_NUMBER_OR_FLOAT (vscroll);
   
   w = XWINDOW (window);
   f = XFRAME (w->frame);
@@ -5664,11 +5672,6 @@ init_window ()
 void
 syms_of_window ()
 {
-  Qleft_fringe = intern ("left-fringe");
-  staticpro (&Qleft_fringe);
-  Qright_fringe = intern ("right-fringe");
-  staticpro (&Qright_fringe);
-  
   Qwindow_size_fixed = intern ("window-size-fixed");
   staticpro (&Qwindow_size_fixed);