Remove __P and P_ from .c and .m files and definition of P_
[bpt/emacs.git] / src / dispnew.c
index 94bbab2..74c41df 100644 (file)
@@ -1,7 +1,7 @@
 /* Updating of data structures for redisplay.
    Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995,
                  1997, 1998, 1999, 2000, 2001, 2002, 2003,
-                 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+                 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -47,9 +47,6 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include "blockinput.h"
 #include "process.h"
 
-/* I don't know why DEC Alpha OSF1 fail to compile this file if we
-   include the following file.  */
-/* #include "systty.h" */
 #include "syssignal.h"
 
 #ifdef HAVE_X_WINDOWS
@@ -117,73 +114,73 @@ struct dim
 \f
 /* Function prototypes.  */
 
-static struct glyph_matrix *save_current_matrix P_ ((struct frame *));
-static void restore_current_matrix P_ ((struct frame *, struct glyph_matrix *));
-static int showing_window_margins_p P_ ((struct window *));
-static void fake_current_matrices P_ ((Lisp_Object));
-static void redraw_overlapping_rows P_ ((struct window *, int));
-static void redraw_overlapped_rows P_ ((struct window *, int));
-static int count_blanks P_ ((struct glyph *, int));
-static int count_match P_ ((struct glyph *, struct glyph *,
-                           struct glyph *, struct glyph *));
-static unsigned line_draw_cost P_ ((struct glyph_matrix *, int));
-static void update_frame_line P_ ((struct frame *, int));
+static struct glyph_matrix *save_current_matrix (struct frame *);
+static void restore_current_matrix (struct frame *, struct glyph_matrix *);
+static int showing_window_margins_p (struct window *);
+static void fake_current_matrices (Lisp_Object);
+static void redraw_overlapping_rows (struct window *, int);
+static void redraw_overlapped_rows (struct window *, int);
+static int count_blanks (struct glyph *, int);
+static int count_match (struct glyph *, struct glyph *,
+                        struct glyph *, struct glyph *);
+static unsigned line_draw_cost (struct glyph_matrix *, int);
+static void update_frame_line (struct frame *, int);
 static struct dim allocate_matrices_for_frame_redisplay
-     P_ ((Lisp_Object, int, int, int, int *));
-static void allocate_matrices_for_window_redisplay P_ ((struct window *));
-static int realloc_glyph_pool P_ ((struct glyph_pool *, struct dim));
-static void adjust_frame_glyphs P_ ((struct frame *));
-struct glyph_matrix *new_glyph_matrix P_ ((struct glyph_pool *));
-static void free_glyph_matrix P_ ((struct glyph_matrix *));
-static void adjust_glyph_matrix P_ ((struct window *, struct glyph_matrix *,
-                                    int, int, struct dim));
-static void change_frame_size_1 P_ ((struct frame *, int, int, int, int, int));
-static void swap_glyph_pointers P_ ((struct glyph_row *, struct glyph_row *));
+     (Lisp_Object, int, int, int, int *);
+static void allocate_matrices_for_window_redisplay (struct window *);
+static int realloc_glyph_pool (struct glyph_pool *, struct dim);
+static void adjust_frame_glyphs (struct frame *);
+struct glyph_matrix *new_glyph_matrix (struct glyph_pool *);
+static void free_glyph_matrix (struct glyph_matrix *);
+static void adjust_glyph_matrix (struct window *, struct glyph_matrix *,
+                                 int, int, struct dim);
+static void change_frame_size_1 (struct frame *, int, int, int, int, int);
+static void swap_glyph_pointers (struct glyph_row *, struct glyph_row *);
 #if GLYPH_DEBUG
-static int glyph_row_slice_p P_ ((struct glyph_row *, struct glyph_row *));
+static int glyph_row_slice_p (struct glyph_row *, struct glyph_row *);
 #endif
-static void fill_up_frame_row_with_spaces P_ ((struct glyph_row *, int));
-static void build_frame_matrix_from_window_tree P_ ((struct glyph_matrix *,
-                                                    struct window *));
-static void build_frame_matrix_from_leaf_window P_ ((struct glyph_matrix *,
-                                                    struct window *));
-static struct glyph_pool *new_glyph_pool P_ ((void));
-static void free_glyph_pool P_ ((struct glyph_pool *));
-static void adjust_frame_glyphs_initially P_ ((void));
-static void adjust_frame_message_buffer P_ ((struct frame *));
-static void adjust_decode_mode_spec_buffer P_ ((struct frame *));
-static void fill_up_glyph_row_with_spaces P_ ((struct glyph_row *));
-static void build_frame_matrix P_ ((struct frame *));
-void clear_current_matrices P_ ((struct frame *));
-void scroll_glyph_matrix_range P_ ((struct glyph_matrix *, int, int,
-                                   int, int));
-static void clear_window_matrices P_ ((struct window *, int));
-static void fill_up_glyph_row_area_with_spaces P_ ((struct glyph_row *, int));
-static int scrolling_window P_ ((struct window *, int));
-static int update_window_line P_ ((struct window *, int, int *));
-static void update_marginal_area P_ ((struct window *, int, int));
-static int update_text_area P_ ((struct window *, int));
-static void make_current P_ ((struct glyph_matrix *, struct glyph_matrix *,
-                             int));
-static void mirror_make_current P_ ((struct window *, int));
-void check_window_matrix_pointers P_ ((struct window *));
+static void fill_up_frame_row_with_spaces (struct glyph_row *, int);
+static void build_frame_matrix_from_window_tree (struct glyph_matrix *,
+                                                 struct window *);
+static void build_frame_matrix_from_leaf_window (struct glyph_matrix *,
+                                                 struct window *);
+static struct glyph_pool *new_glyph_pool (void);
+static void free_glyph_pool (struct glyph_pool *);
+static void adjust_frame_glyphs_initially (void);
+static void adjust_frame_message_buffer (struct frame *);
+static void adjust_decode_mode_spec_buffer (struct frame *);
+static void fill_up_glyph_row_with_spaces (struct glyph_row *);
+static void build_frame_matrix (struct frame *);
+void clear_current_matrices (struct frame *);
+void scroll_glyph_matrix_range (struct glyph_matrix *, int, int,
+                                int, int);
+static void clear_window_matrices (struct window *, int);
+static void fill_up_glyph_row_area_with_spaces (struct glyph_row *, int);
+static int scrolling_window (struct window *, int);
+static int update_window_line (struct window *, int, int *);
+static void update_marginal_area (struct window *, int, int);
+static int update_text_area (struct window *, int);
+static void make_current (struct glyph_matrix *, struct glyph_matrix *,
+                          int);
+static void mirror_make_current (struct window *, int);
+void check_window_matrix_pointers (struct window *);
 #if GLYPH_DEBUG
-static void check_matrix_pointers P_ ((struct glyph_matrix *,
-                                      struct glyph_matrix *));
+static void check_matrix_pointers (struct glyph_matrix *,
+                                   struct glyph_matrix *);
 #endif
-static void mirror_line_dance P_ ((struct window *, int, int, int *, char *));
-static int update_window_tree P_ ((struct window *, int));
-static int update_window P_ ((struct window *, int));
-static int update_frame_1 P_ ((struct frame *, int, int));
-static void set_window_cursor_after_update P_ ((struct window *));
-static int row_equal_p P_ ((struct window *, struct glyph_row *,
-                           struct glyph_row *, int));
-static void adjust_frame_glyphs_for_window_redisplay P_ ((struct frame *));
-static void adjust_frame_glyphs_for_frame_redisplay P_ ((struct frame *));
-static void reverse_rows P_ ((struct glyph_matrix *, int, int));
-static int margin_glyphs_to_reserve P_ ((struct window *, int, Lisp_Object));
-static void sync_window_with_frame_matrix_rows P_ ((struct window *));
-struct window *frame_row_to_window P_ ((struct window *, int));
+static void mirror_line_dance (struct window *, int, int, int *, char *);
+static int update_window_tree (struct window *, int);
+static int update_window (struct window *, int);
+static int update_frame_1 (struct frame *, int, int);
+static void set_window_cursor_after_update (struct window *);
+static int row_equal_p (struct window *, struct glyph_row *,
+                        struct glyph_row *, int);
+static void adjust_frame_glyphs_for_window_redisplay (struct frame *);
+static void adjust_frame_glyphs_for_frame_redisplay (struct frame *);
+static void reverse_rows (struct glyph_matrix *, int, int);
+static int margin_glyphs_to_reserve (struct window *, int, Lisp_Object);
+static void sync_window_with_frame_matrix_rows (struct window *);
+struct window *frame_row_to_window (struct window *, int);
 
 \f
 /* Non-zero means don't pause redisplay for pending input.  (This is
@@ -302,12 +299,6 @@ int updated_area;
 
 struct glyph space_glyph;
 
-/* Non-zero means update has been performed directly, so that there's
-   no need for redisplay_internal to do much work.  Set by
-   direct_output_for_insert.  */
-
-int redisplay_performed_directly_p;
-
 /* Counts of allocated structures.  These counts serve to diagnose
    memory leaks and double frees.  */
 
@@ -334,8 +325,8 @@ int fonts_changed_p;
 
 #if GLYPH_DEBUG
 
-static int window_to_frame_vpos P_ ((struct window *, int));
-static int window_to_frame_hpos P_ ((struct window *, int));
+static int window_to_frame_vpos (struct window *, int);
+static int window_to_frame_hpos (struct window *, int);
 #define WINDOW_TO_FRAME_VPOS(W, VPOS) window_to_frame_vpos ((W), (VPOS))
 #define WINDOW_TO_FRAME_HPOS(W, HPOS) window_to_frame_hpos ((W), (HPOS))
 
@@ -364,8 +355,8 @@ static int history_idx;
 
 static unsigned history_tick;
 
-static void add_frame_display_history P_ ((struct frame *, int));
-static void add_window_display_history P_ ((struct window *, char *, int));
+static void add_frame_display_history (struct frame *, int);
+static void add_window_display_history (struct window *, char *, int);
 \f
 /* Add to the redisplay history how window W has been displayed.
    MSG is a trace containing the information how W's glyph matrix
@@ -1194,6 +1185,10 @@ increment_row_positions (row, delta, delta_bytes)
   MATRIX_ROW_START_BYTEPOS (row) += delta_bytes;
   MATRIX_ROW_END_CHARPOS (row) += delta;
   MATRIX_ROW_END_BYTEPOS (row) += delta_bytes;
+  CHARPOS (row->start.pos) += delta;
+  BYTEPOS (row->start.pos) += delta_bytes;
+  CHARPOS (row->end.pos) += delta;
+  BYTEPOS (row->end.pos) += delta_bytes;
 
   if (!row->enabled_p)
     return;
@@ -1388,8 +1383,11 @@ prepare_desired_row (row)
 {
   if (!row->enabled_p)
     {
+      unsigned rp = row->reversed_p;
+
       clear_glyph_row (row);
       row->enabled_p = 1;
+      row->reversed_p = rp;
     }
 }
 
@@ -1540,6 +1538,7 @@ row_equal_p (w, a, b, mouse_face_p)
          || a->overlapped_p != b->overlapped_p
          || (MATRIX_ROW_CONTINUATION_LINE_P (a)
              != MATRIX_ROW_CONTINUATION_LINE_P (b))
+         || a->reversed_p != b->reversed_p
          /* Different partially visible characters on left margin.  */
          || a->x != b->x
          /* Different height.  */
@@ -1750,13 +1749,19 @@ check_matrix_invariants (w)
       /* Check that character and byte positions are in sync.  */
       xassert (MATRIX_ROW_START_BYTEPOS (row)
               == CHAR_TO_BYTE (MATRIX_ROW_START_CHARPOS (row)));
+      xassert (BYTEPOS (row->start.pos)
+              == CHAR_TO_BYTE (CHARPOS (row->start.pos)));
 
       /* CHAR_TO_BYTE aborts when invoked for a position > Z.  We can
         have such a position temporarily in case of a minibuffer
         displaying something like `[Sole completion]' at its end.  */
       if (MATRIX_ROW_END_CHARPOS (row) < BUF_ZV (current_buffer))
-       xassert (MATRIX_ROW_END_BYTEPOS (row)
-                == CHAR_TO_BYTE (MATRIX_ROW_END_CHARPOS (row)));
+       {
+         xassert (MATRIX_ROW_END_BYTEPOS (row)
+                  == CHAR_TO_BYTE (MATRIX_ROW_END_CHARPOS (row)));
+         xassert (BYTEPOS (row->end.pos)
+                  == CHAR_TO_BYTE (CHARPOS (row->end.pos)));
+       }
 
       /* Check that end position of `row' is equal to start position
         of next row.  */
@@ -1766,6 +1771,8 @@ check_matrix_invariants (w)
                   == MATRIX_ROW_START_CHARPOS (next));
          xassert (MATRIX_ROW_END_BYTEPOS (row)
                   == MATRIX_ROW_START_BYTEPOS (next));
+         xassert (CHARPOS (row->end.pos) == CHARPOS (next->start.pos));
+         xassert (BYTEPOS (row->end.pos) == BYTEPOS (next->start.pos));
        }
       row = next;
     }
@@ -3451,401 +3458,6 @@ redraw_garbaged_frames ()
 
 
 \f
-/***********************************************************************
-                         Direct Operations
- ***********************************************************************/
-
-/* Try to update display and current glyph matrix directly.
-
-   This function is called after a character G has been inserted into
-   current_buffer.  It tries to update the current glyph matrix and
-   perform appropriate screen output to reflect the insertion.  If it
-   succeeds, the global flag redisplay_performed_directly_p will be
-   set to 1, and thereby prevent the more costly general redisplay
-   from running (see redisplay_internal).
-
-   This function is not called for `hairy' character insertions.
-   In particular, it is not called when after or before change
-   functions exist, like they are used by font-lock.  See keyboard.c
-   for details where this function is called.  */
-
-int
-direct_output_for_insert (g)
-     int g;
-{
-  register struct frame *f = SELECTED_FRAME ();
-  struct window *w = XWINDOW (selected_window);
-  struct it it, it2;
-  struct glyph_row *glyph_row;
-  struct glyph *glyphs, *glyph, *end;
-  int n;
-  /* Non-null means that redisplay of W is based on window matrices.  */
-  int window_redisplay_p = FRAME_WINDOW_P (f);
-  /* Non-null means we are in overwrite mode.  */
-  int overwrite_p = !NILP (current_buffer->overwrite_mode);
-  int added_width;
-  struct text_pos pos;
-  int delta, delta_bytes;
-
-  /* Not done directly.  */
-  redisplay_performed_directly_p = 0;
-
-  /* Quickly give up for some common cases.  */
-  if (cursor_in_echo_area
-      /* Give up if fonts have changed.  */
-      || fonts_changed_p
-      /* Give up if face attributes have been changed.  */
-      || face_change_count
-      /* Give up if cursor position not really known.  */
-      || !display_completed
-      /* Give up if buffer appears in two places.  */
-      || buffer_shared > 1
-      /* Give up if we need to reorder bidirectional text.  */
-      || !NILP (current_buffer->bidi_display_reordering)
-      /* Give up if currently displaying a message instead of the
-        minibuffer contents.  */
-      || (EQ (selected_window, minibuf_window)
-         && EQ (minibuf_window, echo_area_window))
-      /* Give up for hscrolled mini-buffer because display of the prompt
-        is handled specially there (see display_line).  */
-      || (MINI_WINDOW_P (w) && XFASTINT (w->hscroll))
-      /* Give up if overwriting in the middle of a line.  */
-      || (overwrite_p
-         && PT != ZV
-         && FETCH_BYTE (PT) != '\n')
-      /* Give up for tabs and line ends.  */
-      || g == '\t'
-      || g == '\n'
-      || g == '\r'
-      || (g == ' ' && !NILP (current_buffer->word_wrap))
-      /* Give up if unable to display the cursor in the window.  */
-      || w->cursor.vpos < 0
-      /* Give up if we are showing a message or just cleared the message
-        because we might need to resize the echo area window.  */
-      || !NILP (echo_area_buffer[0])
-      || !NILP (echo_area_buffer[1])
-      || (glyph_row = MATRIX_ROW (w->current_matrix, w->cursor.vpos),
-         /* Can't do it in a continued line because continuation
-            lines would change.  */
-         (glyph_row->continued_p
-          || glyph_row->exact_window_width_line_p
-          /* Can't use this method if the line overlaps others or is
-             overlapped by others because these other lines would
-             have to be redisplayed.  */
-          || glyph_row->overlapping_p
-          || glyph_row->overlapped_p))
-      /* Can't do it for partial width windows on terminal frames
-        because we can't clear to eol in such a window.  */
-      || (!window_redisplay_p && !WINDOW_FULL_WIDTH_P (w)))
-    return 0;
-
-  /* If we can't insert glyphs, we can use this method only
-     at the end of a line.  */
-  if (!FRAME_CHAR_INS_DEL_OK (f))
-    if (PT != ZV && FETCH_BYTE (PT_BYTE) != '\n')
-      return 0;
-
-  /* Set up a display iterator structure for W.  Glyphs will be
-     produced in scratch_glyph_row.  Current position is W's cursor
-     position.  */
-  clear_glyph_row (&scratch_glyph_row);
-  SET_TEXT_POS (pos, PT, PT_BYTE);
-  DEC_TEXT_POS (pos, !NILP (current_buffer->enable_multibyte_characters));
-  init_iterator (&it, w, CHARPOS (pos), BYTEPOS (pos), &scratch_glyph_row,
-                DEFAULT_FACE_ID);
-
-  glyph_row = MATRIX_ROW (w->current_matrix, w->cursor.vpos);
-  if (glyph_row->mouse_face_p)
-    return 0;
-
-  /* Give up if highlighting trailing whitespace and we have trailing
-     whitespace in glyph_row.  We would have to remove the trailing
-     whitespace face in that case.  */
-  if (!NILP (Vshow_trailing_whitespace)
-      && glyph_row->used[TEXT_AREA])
-    {
-      struct glyph *last;
-
-      last = glyph_row->glyphs[TEXT_AREA] + glyph_row->used[TEXT_AREA] - 1;
-      if (last->type == STRETCH_GLYPH
-         || (last->type == CHAR_GLYPH
-             && last->u.ch == ' '))
-       return 0;
-    }
-
-  /* Give up if there are overlay strings at pos.  This would fail
-     if the overlay string has newlines in it.  */
-  if (STRINGP (it.string))
-    return 0;
-
-  it.hpos = w->cursor.hpos;
-  it.vpos = w->cursor.vpos;
-  it.current_x = w->cursor.x + it.first_visible_x;
-  it.current_y = w->cursor.y;
-  it.end_charpos = PT;
-  it.stop_charpos = min (PT, it.stop_charpos);
-  it.stop_charpos = max (IT_CHARPOS (it), it.stop_charpos);
-
-  /* More than one display element may be returned for PT - 1 if
-     (i) it's a control character which is translated into `\003' or
-     `^C', or (ii) it has a display table entry, or (iii) it's a
-     combination of both.  */
-  delta = delta_bytes = 0;
-  while (get_next_display_element (&it))
-    {
-      PRODUCE_GLYPHS (&it);
-
-      /* Give up if glyph doesn't fit completely on the line.  */
-      if (it.current_x >= it.last_visible_x)
-       return 0;
-
-      /* Give up if new glyph has different ascent or descent than
-        the original row, or if it is not a character glyph.  */
-      if (glyph_row->ascent != it.ascent
-         || glyph_row->height != it.ascent + it.descent
-         || glyph_row->phys_ascent != it.phys_ascent
-         || glyph_row->phys_height != it.phys_ascent + it.phys_descent
-         || it.what != IT_CHARACTER)
-       return 0;
-
-      delta += 1;
-      delta_bytes += it.len;
-      set_iterator_to_next (&it, 1);
-    }
-
-  /* Give up if we hit the right edge of the window.  We would have
-     to insert truncation or continuation glyphs.  */
-  added_width = it.current_x - (w->cursor.x + it.first_visible_x);
-  if (glyph_row->pixel_width + added_width >= it.last_visible_x)
-    return 0;
-
-  /* Give up if there is a \t following in the line.  */
-  it2 = it;
-  it2.end_charpos = ZV;
-  it2.stop_charpos = min (it2.stop_charpos, ZV);
-  while (get_next_display_element (&it2)
-        && !ITERATOR_AT_END_OF_LINE_P (&it2))
-    {
-      if (it2.c == '\t')
-       return 0;
-      set_iterator_to_next (&it2, 1);
-    }
-
-  /* Number of new glyphs produced.  */
-  n = it.glyph_row->used[TEXT_AREA];
-
-  /* Start and end of glyphs in original row.  */
-  glyphs = glyph_row->glyphs[TEXT_AREA] + w->cursor.hpos;
-  end = glyph_row->glyphs[1 + TEXT_AREA];
-
-  /* Make room for new glyphs, then insert them.  */
-  xassert (end - glyphs - n >= 0);
-  safe_bcopy ((char *) glyphs, (char *) (glyphs + n),
-             (end - glyphs - n) * sizeof (*end));
-  bcopy (it.glyph_row->glyphs[TEXT_AREA], glyphs, n * sizeof *glyphs);
-  glyph_row->used[TEXT_AREA] = min (glyph_row->used[TEXT_AREA] + n,
-                                   end - glyph_row->glyphs[TEXT_AREA]);
-
-  /* Compute new line width.  */
-  glyph = glyph_row->glyphs[TEXT_AREA];
-  end = glyph + glyph_row->used[TEXT_AREA];
-  glyph_row->pixel_width = glyph_row->x;
-  while (glyph < end)
-    {
-      glyph_row->pixel_width += glyph->pixel_width;
-      ++glyph;
-    }
-
-  /* Increment buffer positions for glyphs following the newly
-     inserted ones.  */
-  for (glyph = glyphs + n; glyph < end; ++glyph)
-    if (glyph->charpos > 0 && BUFFERP (glyph->object))
-      glyph->charpos += delta;
-
-  if (MATRIX_ROW_END_CHARPOS (glyph_row) > 0)
-    {
-      MATRIX_ROW_END_CHARPOS (glyph_row) += delta;
-      MATRIX_ROW_END_BYTEPOS (glyph_row) += delta_bytes;
-    }
-
-  /* Adjust positions in lines following the one we are in.  */
-  increment_matrix_positions (w->current_matrix,
-                             w->cursor.vpos + 1,
-                             w->current_matrix->nrows,
-                             delta, delta_bytes);
-
-  glyph_row->contains_overlapping_glyphs_p
-    |= it.glyph_row->contains_overlapping_glyphs_p;
-
-  glyph_row->displays_text_p = 1;
-  w->window_end_vpos = make_number (max (w->cursor.vpos,
-                                        XFASTINT (w->window_end_vpos)));
-
-  if (!NILP (Vshow_trailing_whitespace))
-    highlight_trailing_whitespace (it.f, glyph_row);
-
-  /* Write glyphs.  If at end of row, we can simply call write_glyphs.
-     In the middle, we have to insert glyphs.  Note that this is now
-     implemented for X frames.  The implementation uses updated_window
-     and updated_row.  */
-  updated_row = glyph_row;
-  updated_area = TEXT_AREA;
-  update_begin (f);
-  if (FRAME_RIF (f))
-    {
-      FRAME_RIF (f)->update_window_begin_hook (w);
-
-      if (glyphs == end - n
-         /* In front of a space added by append_space.  */
-         || (glyphs == end - n - 1
-             && (end - n)->charpos <= 0))
-       FRAME_RIF (f)->write_glyphs (glyphs, n);
-      else
-       FRAME_RIF (f)->insert_glyphs (glyphs, n);
-    }
-  else
-    {
-      if (glyphs == end - n)
-       write_glyphs (f, glyphs, n);
-      else
-       insert_glyphs (f, glyphs, n);
-    }
-
-  w->cursor.hpos += n;
-  w->cursor.x = it.current_x - it.first_visible_x;
-  xassert (w->cursor.hpos >= 0
-          && w->cursor.hpos < w->desired_matrix->matrix_w);
-
-  /* How to set the cursor differs depending on whether we are
-     using a frame matrix or a window matrix.   Note that when
-     a frame matrix is used, cursor_to expects frame coordinates,
-     and the X and Y parameters are not used.  */
-  if (window_redisplay_p)
-    FRAME_RIF (f)->cursor_to (w->cursor.vpos, w->cursor.hpos,
-                              w->cursor.y, w->cursor.x);
-  else
-    {
-      int x, y;
-      x = (WINDOW_TO_FRAME_HPOS (w, w->cursor.hpos)
-          + (INTEGERP (w->left_margin_cols)
-             ? XFASTINT (w->left_margin_cols)
-             : 0));
-      y = WINDOW_TO_FRAME_VPOS (w, w->cursor.vpos);
-      cursor_to (f, y, x);
-    }
-
-#ifdef HAVE_WINDOW_SYSTEM
-  update_window_fringes (w, 0);
-#endif
-
-  if (FRAME_RIF (f))
-    FRAME_RIF (f)->update_window_end_hook (w, 1, 0);
-  update_end (f);
-  updated_row = NULL;
-  if (FRAME_TERMCAP_P (f))
-    fflush (FRAME_TTY (f)->output);
-
-  TRACE ((stderr, "direct output for insert\n"));
-  mark_window_display_accurate (it.window, 1);
-  redisplay_performed_directly_p = 1;
-  return 1;
-}
-
-
-/* Perform a direct display update for moving PT by N positions
-   left or right.  N < 0 means a movement backwards.  This function
-   is currently only called for N == 1 or N == -1.  */
-
-int
-direct_output_forward_char (n)
-     int n;
-{
-  struct frame *f = SELECTED_FRAME ();
-  struct window *w = XWINDOW (selected_window);
-  struct glyph_row *row;
-
-  /* Give up if point moved out of or into a composition.  */
-  if (check_point_in_composition (current_buffer, XINT (w->last_point),
-                                 current_buffer, PT))
-    return 0;
-
-  /* Give up if face attributes have been changed.  */
-  if (face_change_count)
-    return 0;
-
-  /* Give up if current matrix is not up to date or we are
-     displaying a message.  */
-  if (!display_completed || cursor_in_echo_area)
-    return 0;
-
-  /* Give up if we need to reorder bidirectional text.  */
-  if (!NILP (XBUFFER (w->buffer)->bidi_display_reordering))
-    return 0;
-
-  /* Give up if the buffer's direction is reversed.  */
-  if (!NILP (XBUFFER (w->buffer)->direction_reversed))
-    return 0;
-
-  /* Can't use direct output if highlighting a region.  */
-  if (!NILP (Vtransient_mark_mode) && !NILP (current_buffer->mark_active))
-    return 0;
-
-  /* Can't use direct output if highlighting trailing whitespace.  */
-  if (!NILP (Vshow_trailing_whitespace))
-    return 0;
-
-  /* Give up if we are showing a message or just cleared the message
-     because we might need to resize the echo area window.  */
-  if (!NILP (echo_area_buffer[0]) || !NILP (echo_area_buffer[1]))
-    return 0;
-
-  /* Give up if currently displaying a message instead of the
-     minibuffer contents.  */
-  if (XWINDOW (minibuf_window) == w
-      && EQ (minibuf_window, echo_area_window))
-    return 0;
-
-  /* Give up if we don't know where the cursor is.  */
-  if (w->cursor.vpos < 0)
-    return 0;
-
-  row = MATRIX_ROW (w->current_matrix, w->cursor.vpos);
-
-  /* Give up if PT is outside of the last known cursor row.  */
-  if (PT <= MATRIX_ROW_START_CHARPOS (row)
-      || PT >= MATRIX_ROW_END_CHARPOS (row))
-    return 0;
-
-  set_cursor_from_row (w, row, w->current_matrix, 0, 0, 0, 0);
-
-  w->last_cursor = w->cursor;
-  XSETFASTINT (w->last_point, PT);
-
-  xassert (w->cursor.hpos >= 0
-          && w->cursor.hpos < w->desired_matrix->matrix_w);
-
-  if (FRAME_WINDOW_P (f))
-    FRAME_RIF (f)->cursor_to (w->cursor.vpos, w->cursor.hpos,
-                              w->cursor.y, w->cursor.x);
-  else
-    {
-      int x, y;
-      x = (WINDOW_TO_FRAME_HPOS (w, w->cursor.hpos)
-          + (INTEGERP (w->left_margin_cols)
-             ? XFASTINT (w->left_margin_cols)
-             : 0));
-      y = WINDOW_TO_FRAME_VPOS (w, w->cursor.vpos);
-      cursor_to (f, y, x);
-    }
-
-  if (FRAME_TERMCAP_P (f))
-    fflush (FRAME_TTY (f)->output);
-  redisplay_performed_directly_p = 1;
-  return 1;
-}
-
-
-\f
 /***********************************************************************
                             Frame Update
  ***********************************************************************/
@@ -4648,7 +4260,9 @@ update_text_area (w, vpos)
             doesn't work with lbearing/rbearing), so we must do it
             this way.  */
          if (vpos == w->phys_cursor.vpos
-             && w->phys_cursor.hpos >= desired_row->used[TEXT_AREA])
+             && (desired_row->reversed_p
+                 ? (w->phys_cursor.hpos < 0)
+                 : (w->phys_cursor.hpos >= desired_row->used[TEXT_AREA])))
            {
              w->phys_cursor_on_p = 0;
              x = -1;
@@ -4812,7 +4426,7 @@ set_window_cursor_after_update (w)
     }
 
   /* Window cursor can be out of sync for horizontally split windows.  */
-  hpos = max (0, hpos);
+  hpos = max (-1, hpos); /* -1 is for when cursor is on the left fringe */
   hpos = min (w->current_matrix->matrix_w - 1, hpos);
   vpos = max (0, vpos);
   vpos = min (w->current_matrix->nrows - 1, vpos);
@@ -6206,9 +5820,6 @@ window_change_signal (signalnum) /* If we don't have an argument, */
      int signalnum;            /* some compilers complain in signal calls.  */
 {
   int width, height;
-#ifndef USE_CRT_DLL
-  extern int errno;
-#endif
   int old_errno = errno;
 
   struct tty_display_info *tty;
@@ -6346,8 +5957,11 @@ change_frame_size_1 (f, newheight, newwidth, pretend, delay, safe)
   check_frame_size (f, &newheight, &newwidth);
 
   /* If we're not changing the frame size, quit now.  */
+  /* Frame width may be unchanged but the text portion may change, for example,
+     fullscreen and remove/add scroll bar.  */
   if (newheight == FRAME_LINES (f)
-      && new_frame_total_cols == FRAME_TOTAL_COLS (f))
+      && newwidth == FRAME_COLS  (f) // text portion unchanged
+      && new_frame_total_cols == FRAME_TOTAL_COLS (f)) // frame width unchanged
     return;
 
   BLOCK_INPUT;