Fix bug #8487 with invisible text at EOB under bidi.
[bpt/emacs.git] / src / xdisp.c
index 1cf58ed..2a6e857 100644 (file)
@@ -754,7 +754,7 @@ static void setup_for_ellipsis (struct it *, int);
 static void mark_window_display_accurate_1 (struct window *, int);
 static int single_display_spec_string_p (Lisp_Object, Lisp_Object);
 static int display_prop_string_p (Lisp_Object, Lisp_Object);
-static int cursor_row_p (struct window *, struct glyph_row *);
+static int cursor_row_p (struct glyph_row *);
 static int redisplay_mode_lines (Lisp_Object, int);
 static char *decode_mode_spec_coding (Lisp_Object, char *, int);
 
@@ -763,7 +763,7 @@ static Lisp_Object get_it_property (struct it *it, Lisp_Object prop);
 static void handle_line_prefix (struct it *);
 
 static void pint2str (char *, int, EMACS_INT);
-static void pint2hrstr (char *, int, int);
+static void pint2hrstr (char *, int, EMACS_INT);
 static struct text_pos run_window_scroll_functions (Lisp_Object,
                                                     struct text_pos);
 static void reconsider_clip_changes (struct window *, struct buffer *);
@@ -774,6 +774,7 @@ static int store_mode_line_noprop (const char *, int, int);
 static void handle_stop (struct it *);
 static void handle_stop_backwards (struct it *, EMACS_INT);
 static int single_display_spec_intangible_p (Lisp_Object);
+static void vmessage (const char *, va_list) ATTRIBUTE_FORMAT_PRINTF (1, 0);
 static void ensure_echo_area_buffers (void);
 static Lisp_Object unwind_with_echo_area_buffer (Lisp_Object);
 static Lisp_Object with_echo_area_buffer_unwind_data (struct window *);
@@ -802,13 +803,12 @@ static int cursor_row_fully_visible_p (struct window *, int, int);
 static int try_scrolling (Lisp_Object, int, EMACS_INT, EMACS_INT, int, int);
 static int try_cursor_movement (Lisp_Object, struct text_pos, int *);
 static int trailing_whitespace_p (EMACS_INT);
-static unsigned long int message_log_check_duplicate (EMACS_INT, EMACS_INT,
-                                                     EMACS_INT, EMACS_INT);
+static unsigned long int message_log_check_duplicate (EMACS_INT, EMACS_INT);
 static void push_it (struct it *);
 static void pop_it (struct it *);
 static void sync_frame_with_window_matrix_rows (struct window *);
 static void select_frame_for_redisplay (Lisp_Object);
-static void redisplay_internal (int);
+static void redisplay_internal (void);
 static int echo_area_display (int);
 static void redisplay_windows (Lisp_Object);
 static void redisplay_window (Lisp_Object, int);
@@ -823,11 +823,10 @@ static int display_mode_lines (struct window *);
 static int display_mode_line (struct window *, enum face_id, Lisp_Object);
 static int display_mode_element (struct it *, int, int, int, Lisp_Object, Lisp_Object, int);
 static int store_mode_line_string (const char *, Lisp_Object, int, int, int, Lisp_Object);
-static const char *decode_mode_spec (struct window *, int, int, int,
-                                    Lisp_Object *);
+static const char *decode_mode_spec (struct window *, int, int, Lisp_Object *);
 static void display_menu_bar (struct window *);
-static int display_count_lines (EMACS_INT, EMACS_INT, EMACS_INT, int,
-                               EMACS_INT *);
+static EMACS_INT display_count_lines (EMACS_INT, EMACS_INT, EMACS_INT,
+                                     EMACS_INT *);
 static int display_string (const char *, Lisp_Object, Lisp_Object,
                            EMACS_INT, EMACS_INT, struct it *, int, int, int, int);
 static void compute_line_metrics (struct it *);
@@ -1147,7 +1146,7 @@ line_bottom_y (struct it *it)
        line_height = last_height;
       else if (IT_CHARPOS (*it) < ZV)
        {
-         move_it_by_lines (it, 1, 1);
+         move_it_by_lines (it, 1);
          line_height = (it->max_ascent || it->max_descent
                         ? it->max_ascent + it->max_descent
                         : last_height);
@@ -1271,7 +1270,7 @@ pos_visible_p (struct window *w, EMACS_INT charpos, int *x, int *y,
 
       it2 = it;
       if (IT_CHARPOS (it) < ZV && FETCH_BYTE (IT_BYTEPOS (it)) != '\n')
-       move_it_by_lines (&it, 1, 0);
+       move_it_by_lines (&it, 1);
       if (charpos < IT_CHARPOS (it)
          || (it.what == IT_EOB && charpos == IT_CHARPOS (it)))
        {
@@ -2181,7 +2180,7 @@ safe_eval_handler (Lisp_Object arg)
    redisplay during the evaluation.  */
 
 Lisp_Object
-safe_call (int nargs, Lisp_Object *args)
+safe_call (size_t nargs, Lisp_Object *args)
 {
   Lisp_Object val;
 
@@ -4420,20 +4419,18 @@ display_prop_string_p (Lisp_Object prop, Lisp_Object string)
   return 0;
 }
 
-/* Look for STRING in overlays and text properties in W's buffer,
-   between character positions FROM and TO (excluding TO).
+/* Look for STRING in overlays and text properties in the current
+   buffer, between character positions FROM and TO (excluding TO).
    BACK_P non-zero means look back (in this case, TO is supposed to be
    less than FROM).
    Value is the first character position where STRING was found, or
    zero if it wasn't found before hitting TO.
 
-   W's buffer must be current.
-
    This function may only use code that doesn't eval because it is
    called asynchronously from note_mouse_highlight.  */
 
 static EMACS_INT
-string_buffer_position_lim (struct window *w, Lisp_Object string,
+string_buffer_position_lim (Lisp_Object string,
                            EMACS_INT from, EMACS_INT to, int back_p)
 {
   Lisp_Object limit, prop, pos;
@@ -4471,27 +4468,25 @@ string_buffer_position_lim (struct window *w, Lisp_Object string,
   return found ? XINT (pos) : 0;
 }
 
-/* Determine which buffer position in W's buffer STRING comes from.
+/* Determine which buffer position in current buffer STRING comes from.
    AROUND_CHARPOS is an approximate position where it could come from.
    Value is the buffer position or 0 if it couldn't be determined.
 
-   W's buffer must be current.
-
    This function is necessary because we don't record buffer positions
    in glyphs generated from strings (to keep struct glyph small).
    This function may only use code that doesn't eval because it is
    called asynchronously from note_mouse_highlight.  */
 
-EMACS_INT
-string_buffer_position (struct window *w, Lisp_Object string, EMACS_INT around_charpos)
+static EMACS_INT
+string_buffer_position (Lisp_Object string, EMACS_INT around_charpos)
 {
   const int MAX_DISTANCE = 1000;
-  EMACS_INT found = string_buffer_position_lim (w, string, around_charpos,
+  EMACS_INT found = string_buffer_position_lim (string, around_charpos,
                                                around_charpos + MAX_DISTANCE,
                                                0);
 
   if (!found)
-    found = string_buffer_position_lim (w, string, around_charpos,
+    found = string_buffer_position_lim (string, around_charpos,
                                        around_charpos - MAX_DISTANCE, 1);
   return found;
 }
@@ -7643,7 +7638,7 @@ move_it_vertically_backward (struct it *it, int dy)
       /* DY == 0 means move to the start of the screen line.  The
         value of nlines is > 0 if continuation lines were involved.  */
       if (nlines > 0)
-       move_it_by_lines (it, nlines, 1);
+       move_it_by_lines (it, nlines);
     }
   else
     {
@@ -7687,7 +7682,7 @@ move_it_vertically_backward (struct it *it, int dy)
            {
              do
                {
-                 move_it_by_lines (it, 1, 1);
+                 move_it_by_lines (it, 1);
                }
              while (target_y >= line_bottom_y (it) && IT_CHARPOS (*it) < ZV);
            }
@@ -7717,7 +7712,7 @@ move_it_vertically (struct it *it, int dy)
       if (IT_CHARPOS (*it) == ZV
          && ZV > BEGV
          && FETCH_BYTE (IT_BYTEPOS (*it) - 1) != '\n')
-       move_it_by_lines (it, 0, 0);
+       move_it_by_lines (it, 0);
     }
 }
 
@@ -7737,15 +7732,14 @@ move_it_past_eol (struct it *it)
 
 /* Move IT by a specified number DVPOS of screen lines down.  DVPOS
    negative means move up.  DVPOS == 0 means move to the start of the
-   screen line.  NEED_Y_P non-zero means calculate IT->current_y.  If
-   NEED_Y_P is zero, IT->current_y will be left unchanged.
+   screen line.
 
-   Further optimization ideas: If we would know that IT->f doesn't use
+   Optimization idea: If we would know that IT->f doesn't use
    a face with proportional font, we could be faster for
    truncate-lines nil.  */
 
 void
-move_it_by_lines (struct it *it, int dvpos, int need_y_p)
+move_it_by_lines (struct it *it, int dvpos)
 {
 
   /* The commented-out optimization uses vmotion on terminals.  This
@@ -7967,7 +7961,7 @@ message_dolog (const char *m, EMACS_INT nbytes, int nlflag, int multibyte)
              c = string_char_and_length (msg + i, &char_bytes);
              work[0] = (ASCII_CHAR_P (c)
                         ? c
-                        : multibyte_char_to_unibyte (c, Qnil));
+                        : multibyte_char_to_unibyte (c));
              insert_1_both (work, 1, 1, 1, 0, 0);
            }
        }
@@ -8008,8 +8002,8 @@ message_dolog (const char *m, EMACS_INT nbytes, int nlflag, int multibyte)
              prev_bol = PT;
              prev_bol_byte = PT_BYTE;
 
-             dups = message_log_check_duplicate (prev_bol, prev_bol_byte,
-                                                 this_bol, this_bol_byte);
+             dups = message_log_check_duplicate (prev_bol_byte,
+                                                  this_bol_byte);
              if (dups)
                {
                  del_range_both (prev_bol, prev_bol_byte,
@@ -8084,8 +8078,7 @@ message_dolog (const char *m, EMACS_INT nbytes, int nlflag, int multibyte)
    value N > 1 if we should also append " [N times]".  */
 
 static unsigned long int
-message_log_check_duplicate (EMACS_INT prev_bol, EMACS_INT prev_bol_byte,
-                            EMACS_INT this_bol, EMACS_INT this_bol_byte)
+message_log_check_duplicate (EMACS_INT prev_bol_byte, EMACS_INT this_bol_byte)
 {
   EMACS_INT i;
   EMACS_INT len = Z_BYTE - 1 - this_bol_byte;
@@ -8415,10 +8408,22 @@ vmessage (const char *m, va_list ap)
        {
          if (m)
            {
-             EMACS_INT len;
+             char *buf = FRAME_MESSAGE_BUF (f);
+             size_t bufsize = FRAME_MESSAGE_BUF_SIZE (f);
+             int len;
 
-             len = doprnt (FRAME_MESSAGE_BUF (f),
-                           FRAME_MESSAGE_BUF_SIZE (f), m, (char *)0, ap);
+             memset (buf, 0, bufsize);
+             len = vsnprintf (buf, bufsize, m, ap);
+
+             /* Do any truncation at a character boundary.  */
+             if (! (0 <= len && len < bufsize))
+               {
+                 char *end = memchr (buf, 0, bufsize);
+                 for (len = end ? end - buf : bufsize;
+                      len && ! CHAR_HEAD_P (buf[len - 1]);
+                      len--)
+                   continue;
+               }
 
              message2 (FRAME_MESSAGE_BUF (f), len, 0);
            }
@@ -8442,6 +8447,7 @@ message (const char *m, ...)
 }
 
 
+#if 0
 /* The non-logging version of message.  */
 
 void
@@ -8456,6 +8462,7 @@ message_nolog (const char *m, ...)
   Vmessage_log_max = old_log_max;
   va_end (ap);
 }
+#endif
 
 
 /* Display the current message in the current mini-buffer.  This is
@@ -8843,7 +8850,7 @@ resize_echo_area_exactly (void)
        {
          ++windows_or_buffers_changed;
          ++update_mode_lines;
-         redisplay_internal (0);
+         redisplay_internal ();
        }
     }
 }
@@ -9228,7 +9235,7 @@ set_message_1 (EMACS_INT a1, Lisp_Object a2, EMACS_INT nbytes, EMACS_INT multiby
              c = string_char_and_length (msg + i, &n);
              work[0] = (ASCII_CHAR_P (c)
                         ? c
-                        : multibyte_char_to_unibyte (c, Qnil));
+                        : multibyte_char_to_unibyte (c));
              insert_1_both (work, 1, 1, 1, 0, 0);
            }
        }
@@ -9384,7 +9391,7 @@ echo_area_display (int update_frame_p)
              int count = SPECPDL_INDEX ();
              specbind (Qredisplay_dont_pause, Qt);
              windows_or_buffers_changed = 1;
-             redisplay_internal (0);
+             redisplay_internal ();
              unbind_to (count, Qnil);
            }
          else if (FRAME_WINDOW_P (f) && n == 0)
@@ -11155,7 +11162,7 @@ text_outside_line_unchanged_p (struct window *w,
 void
 redisplay (void)
 {
-  redisplay_internal (0);
+  redisplay_internal ();
 }
 
 
@@ -11419,14 +11426,11 @@ do { if (polling_stopped_here) start_polling ();      \
        polling_stopped_here = 0; } while (0)
 
 
-/* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
-   response to any user action; therefore, we should preserve the echo
-   area.  (Actually, our caller does that job.)  Perhaps in the future
-   avoid recentering windows if it is not necessary; currently that
-   causes some problems.  */
+/* Perhaps in the future avoid recentering windows if it
+   is not necessary; currently that causes some problems.  */
 
 static void
-redisplay_internal (int preserve_echo_area)
+redisplay_internal (void)
 {
   struct window *w = XWINDOW (selected_window);
   struct window *sw;
@@ -12186,11 +12190,11 @@ redisplay_preserve_echo_area (int from_where)
       /* We have a previously displayed message, but no current
         message.  Redisplay the previous message.  */
       display_last_displayed_message_p = 1;
-      redisplay_internal (1);
+      redisplay_internal ();
       display_last_displayed_message_p = 0;
     }
   else
-    redisplay_internal (1);
+    redisplay_internal ();
 
   if (FRAME_RIF (SELECTED_FRAME ()) != NULL
       && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional)
@@ -12731,7 +12735,7 @@ set_cursor_from_row (struct window *w, struct glyph_row *row,
                  EMACS_INT tem;
 
                  str = glyph->object;
-                 tem = string_buffer_position_lim (w, str, pos, pos_after, 0);
+                 tem = string_buffer_position_lim (str, pos, pos_after, 0);
                  if (tem == 0  /* from overlay */
                      || pos <= tem)
                    {
@@ -13152,14 +13156,14 @@ try_scrolling (Lisp_Object window, int just_this_one_p,
          int start_y = line_bottom_y (&it1);
 
          do {
-           move_it_by_lines (&it, 1, 1);
+           move_it_by_lines (&it, 1);
            it1 = it;
          } while (line_bottom_y (&it1) - start_y < amount_to_scroll);
        }
 
       /* If STARTP is unchanged, move it down another screen line.  */
       if (CHARPOS (it.current.pos) == CHARPOS (startp))
-       move_it_by_lines (&it, 1, 1);
+       move_it_by_lines (&it, 1);
       startp = it.current.pos;
     }
   else
@@ -13329,7 +13333,7 @@ compute_window_start_on_continuation_line (struct window *w)
            {
              min_distance = distance;
              pos = it.current.pos;
-             move_it_by_lines (&it, 1, 0);
+             move_it_by_lines (&it, 1);
            }
 
          /* Set the window start there.  */
@@ -13474,7 +13478,7 @@ try_cursor_movement (Lisp_Object window, struct text_pos startp, int *scroll_ste
                     && row < w->current_matrix->rows
                                + w->current_matrix->nrows - 1
                     && MATRIX_ROW_START_CHARPOS (row+1) == PT
-                    && !cursor_row_p (w, row))
+                    && !cursor_row_p (row))
                ++row;
 
              /* If within the scroll margin, scroll.  Note that
@@ -13526,7 +13530,7 @@ try_cursor_movement (Lisp_Object window, struct text_pos startp, int *scroll_ste
                 skip forward over overlay strings.  */
              while (MATRIX_ROW_BOTTOM_Y (row) < last_y
                     && MATRIX_ROW_END_CHARPOS (row) == PT
-                    && !cursor_row_p (w, row))
+                    && !cursor_row_p (row))
                ++row;
 
              /* If within the scroll margin, scroll.  */
@@ -13622,7 +13626,7 @@ try_cursor_movement (Lisp_Object window, struct text_pos startp, int *scroll_ste
                {
                  if (MATRIX_ROW_START_CHARPOS (row) <= PT
                      && PT <= MATRIX_ROW_END_CHARPOS (row)
-                     && cursor_row_p (w, row))
+                     && cursor_row_p (row))
                    rv |= set_cursor_from_row (w, row, w->current_matrix,
                                               0, 0, 0, 0);
                  /* As soon as we've found the first suitable row
@@ -13661,7 +13665,7 @@ try_cursor_movement (Lisp_Object window, struct text_pos startp, int *scroll_ste
                }
              while (MATRIX_ROW_BOTTOM_Y (row) < last_y
                     && MATRIX_ROW_START_CHARPOS (row) == PT
-                    && cursor_row_p (w, row));
+                    && cursor_row_p (row));
            }
        }
     }
@@ -14365,13 +14369,13 @@ redisplay_window (Lisp_Object window, int just_this_one_p)
          && PT >= Z - XFASTINT (w->window_end_pos))
        {
          clear_glyph_matrix (w->desired_matrix);
-         move_it_by_lines (&it, 1, 0);
+         move_it_by_lines (&it, 1);
          try_window (window, it.current.pos, 0);
        }
       else if (PT < IT_CHARPOS (it))
        {
          clear_glyph_matrix (w->desired_matrix);
-         move_it_by_lines (&it, -1, 0);
+         move_it_by_lines (&it, -1);
          try_window (window, it.current.pos, 0);
        }
       else
@@ -14734,8 +14738,6 @@ try_window_reusing_current_matrix (struct window *w)
 
   if (CHARPOS (new_start) <= CHARPOS (start))
     {
-      int first_row_y;
-
       /* Don't use this method if the display starts with an ellipsis
         displayed for invisible text.  It's not easy to handle that case
         below, and it's certainly not worth the effort since this is
@@ -14750,7 +14752,6 @@ try_window_reusing_current_matrix (struct window *w)
         text.  Note that it.vpos == 0 if or if not there is a
          header-line; it's not the same as the MATRIX_ROW_VPOS!  */
       start_display (&it, w, new_start);
-      first_row_y = it.current_y;
       w->cursor.vpos = -1;
       last_text_row = last_reused_text_row = NULL;
 
@@ -16479,7 +16480,7 @@ With ARG, turn tracing on if and only if ARG is positive.  */)
 DEFUN ("trace-to-stderr", Ftrace_to_stderr, Strace_to_stderr, 1, MANY, "",
        doc: /* Like `format', but print result to stderr.
 usage: (trace-to-stderr STRING &rest OBJECTS)  */)
-  (int nargs, Lisp_Object *args)
+  (size_t nargs, Lisp_Object *args)
 {
   Lisp_Object s = Fformat (nargs, args);
   fprintf (stderr, "%s", SDATA (s));
@@ -17062,11 +17063,11 @@ highlight_trailing_whitespace (struct frame *f, struct glyph_row *row)
 }
 
 
-/* Value is non-zero if glyph row ROW in window W should be
+/* Value is non-zero if glyph row ROW should be
    used to hold the cursor.  */
 
 static int
-cursor_row_p (struct window *w, struct glyph_row *row)
+cursor_row_p (struct glyph_row *row)
 {
   int result = 1;
 
@@ -17979,7 +17980,7 @@ display_line (struct it *it)
           && !MATRIX_ROW (it->w->desired_matrix, cvpos)->ends_at_zv_p))
       && PT >= MATRIX_ROW_START_CHARPOS (row)
       && PT <= MATRIX_ROW_END_CHARPOS (row)
-      && cursor_row_p (it->w, row))
+      && cursor_row_p (row))
     set_cursor_from_row (it->w, row, it->w->desired_matrix, 0, 0, 0, 0);
 
   /* Highlight trailing whitespace.  */
@@ -18631,7 +18632,7 @@ display_mode_element (struct it *it, int depth, int field_width, int precision,
                    charpos = (STRING_MULTIBYTE (elt)
                               ? string_byte_to_char (elt, bytepos)
                               : bytepos);
-                   spec = decode_mode_spec (it->w, c, field, prec, &string);
+                   spec = decode_mode_spec (it->w, c, field, &string);
                    multibyte = STRINGP (string) && STRING_MULTIBYTE (string);
 
                    switch (mode_line_target)
@@ -19128,11 +19129,11 @@ static const char power_letter[] =
   };
 
 static void
-pint2hrstr (char *buf, int width, int d)
+pint2hrstr (char *buf, int width, EMACS_INT d)
 {
   /* We aim to represent the nonnegative integer D as
      QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
-  int quotient = d;
+  EMACS_INT quotient = d;
   int remainder = 0;
   /* -1 means: do not use TENTHS. */
   int tenths = -1;
@@ -19302,9 +19303,8 @@ decode_mode_spec_coding (Lisp_Object coding_system, register char *buf, int eol_
 }
 
 /* Return a string for the output of a mode line %-spec for window W,
-   generated by character C.  PRECISION >= 0 means don't return a
-   string longer than that value.  FIELD_WIDTH > 0 means pad the
-   string returned with spaces to that value.  Return a Lisp string in
+   generated by character C.  FIELD_WIDTH > 0 means pad the string
+   returned with spaces to that value.  Return a Lisp string in
    *STRING if the resulting string is taken from that Lisp string.
 
    Note we operate on the current buffer for most purposes,
@@ -19314,7 +19314,7 @@ static char lots_of_dashes[] = "------------------------------------------------
 
 static const char *
 decode_mode_spec (struct window *w, register int c, int field_width,
-                 int precision, Lisp_Object *string)
+                 Lisp_Object *string)
 {
   Lisp_Object obj;
   struct frame *f = XFRAME (WINDOW_FRAME (w));
@@ -19459,7 +19459,7 @@ decode_mode_spec (struct window *w, register int c, int field_width,
     case 'l':
       {
        EMACS_INT startpos, startpos_byte, line, linepos, linepos_byte;
-       int topline, nlines, height;
+       EMACS_INT topline, nlines, height;
        EMACS_INT junk;
 
        /* %c and %l are ignored in `frame-title-format'.  */
@@ -19503,7 +19503,7 @@ decode_mode_spec (struct window *w, register int c, int field_width,
          }
 
        /* Count lines from base line to window start position.  */
-       nlines = display_count_lines (linepos, linepos_byte,
+       nlines = display_count_lines (linepos_byte,
                                      startpos_byte,
                                      startpos, &junk);
 
@@ -19524,7 +19524,8 @@ decode_mode_spec (struct window *w, register int c, int field_width,
            EMACS_INT limit = BUF_BEGV (b);
            EMACS_INT limit_byte = BUF_BEGV_BYTE (b);
            EMACS_INT position;
-           int distance = (height * 2 + 30) * line_number_display_limit_width;
+           EMACS_INT distance =
+             (height * 2 + 30) * line_number_display_limit_width;
 
            if (startpos - distance > limit)
              {
@@ -19532,7 +19533,7 @@ decode_mode_spec (struct window *w, register int c, int field_width,
                limit_byte = CHAR_TO_BYTE (limit);
              }
 
-           nlines = display_count_lines (startpos, startpos_byte,
+           nlines = display_count_lines (startpos_byte,
                                          limit_byte,
                                          - (height * 2 + 30),
                                          &position);
@@ -19551,7 +19552,7 @@ decode_mode_spec (struct window *w, register int c, int field_width,
          }
 
        /* Now count lines from the start pos to point.  */
-       nlines = display_count_lines (startpos, startpos_byte,
+       nlines = display_count_lines (startpos_byte,
                                      PT_BYTE, PT, &junk);
 
        /* Record that we did display the line number.  */
@@ -19721,23 +19722,23 @@ decode_mode_spec (struct window *w, register int c, int field_width,
 }
 
 
-/* Count up to COUNT lines starting from START / START_BYTE.
+/* Count up to COUNT lines starting from START_BYTE.
    But don't go beyond LIMIT_BYTE.
    Return the number of lines thus found (always nonnegative).
 
    Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT.  */
 
-static int
-display_count_lines (EMACS_INT start, EMACS_INT start_byte,
-                    EMACS_INT limit_byte, int count,
+static EMACS_INT
+display_count_lines (EMACS_INT start_byte,
+                    EMACS_INT limit_byte, EMACS_INT count,
                     EMACS_INT *byte_pos_ptr)
 {
   register unsigned char *cursor;
   unsigned char *base;
 
-  register int ceiling;
+  register EMACS_INT ceiling;
   register unsigned char *ceiling_addr;
-  int orig_count = count;
+  EMACS_INT orig_count = count;
 
   /* If we are not in selective display mode,
      check only for newlines.  */
@@ -20492,16 +20493,15 @@ append_glyph_string (struct glyph_string **head, struct glyph_string **tail,
 }
 
 
-/* Get face and two-byte form of character C in face FACE_ID on frame
-   F.  The encoding of C is returned in *CHAR2B.  MULTIBYTE_P non-zero
-   means we want to display multibyte text.  DISPLAY_P non-zero means
+/* Get face and two-byte form of character C in face FACE_ID on frame F.
+   The encoding of C is returned in *CHAR2B.  DISPLAY_P non-zero means
    make sure that X resources for the face returned are allocated.
    Value is a pointer to a realized face that is ready for display if
    DISPLAY_P is non-zero.  */
 
 static INLINE struct face *
 get_char_face_and_encoding (struct frame *f, int c, int face_id,
-                           XChar2b *char2b, int multibyte_p, int display_p)
+                           XChar2b *char2b, int display_p)
 {
   struct face *face = FACE_FROM_ID (f, face_id);
 
@@ -20621,7 +20621,7 @@ fill_composite_glyph_string (struct glyph_string *s, struct face *base_face,
                                       -1, Qnil);
 
          face = get_char_face_and_encoding (s->f, c, face_id,
-                                            s->char2b + i, 1, 1);
+                                            s->char2b + i, 1);
          if (face)
            {
              if (! s->face)
@@ -20820,15 +20820,13 @@ fill_image_glyph_string (struct glyph_string *s)
 
 /* Fill glyph string S from a sequence of stretch glyphs.
 
-   ROW is the glyph row in which the glyphs are found, AREA is the
-   area within the row.  START is the index of the first glyph to
-   consider, END is the index of the last + 1.
+   START is the index of the first glyph to consider,
+   END is the index of the last + 1.
 
    Value is the index of the first glyph not in S.  */
 
 static int
-fill_stretch_glyph_string (struct glyph_string *s, struct glyph_row *row,
-                          enum glyph_row_area area, int start, int end)
+fill_stretch_glyph_string (struct glyph_string *s, int start, int end)
 {
   struct glyph *glyph, *last;
   int voffset, face_id;
@@ -20862,7 +20860,7 @@ fill_stretch_glyph_string (struct glyph_string *s, struct glyph_row *row,
 }
 
 static struct font_metrics *
-get_per_char_metric (struct frame *f, struct font *font, XChar2b *char2b)
+get_per_char_metric (struct font *font, XChar2b *char2b)
 {
   static struct font_metrics metrics;
   unsigned code = (XCHAR2B_BYTE1 (char2b) << 8) | XCHAR2B_BYTE2 (char2b);
@@ -20890,7 +20888,7 @@ x_get_glyph_overhangs (struct glyph *glyph, struct frame *f, int *left, int *rig
       struct font_metrics *pcm;
 
       face = get_glyph_face_and_encoding (f, glyph, &char2b, NULL);
-      if (face->font && (pcm = get_per_char_metric (f, face->font, &char2b)))
+      if (face->font && (pcm = get_per_char_metric (face->font, &char2b)))
        {
          if (pcm->rbearing > pcm->width)
            *right = pcm->rbearing - pcm->width;
@@ -21124,7 +21122,7 @@ compute_overhangs_and_x (struct glyph_string *s, int x, int backward_p)
        {                                                                   \
         s = (struct glyph_string *) alloca (sizeof *s);                    \
         INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL);              \
-        START = fill_stretch_glyph_string (s, row, area, START, END);      \
+        START = fill_stretch_glyph_string (s, START, END);                 \
         append_glyph_string (&HEAD, &TAIL, s);                             \
          s->x = (X);                                                       \
        }                                                                   \
@@ -22497,7 +22495,7 @@ x_produce_glyphs (struct it *it)
 
          if (get_char_glyph_code (it->char_to_display, font, &char2b))
            {
-             pcm = get_per_char_metric (it->f, font, &char2b);
+             pcm = get_per_char_metric (font, &char2b);
              if (pcm->width == 0
                  && pcm->rbearing == 0 && pcm->lbearing == 0)
                pcm = NULL;
@@ -22799,8 +22797,8 @@ x_produce_glyphs (struct it *it)
          if (! font_not_found_p)
            {
              get_char_face_and_encoding (it->f, c, it->face_id,
-                                         &char2b, it->multibyte_p, 0);
-             pcm = get_per_char_metric (it->f, font, &char2b);
+                                         &char2b, 0);
+             pcm = get_per_char_metric (font, &char2b);
            }
 
          /* Initialize the bounding box.  */
@@ -22848,7 +22846,6 @@ x_produce_glyphs (struct it *it)
              int ch = COMPOSITION_GLYPH (cmp, i);
              int face_id;
              struct face *this_face;
-             int this_boff;
 
              if (ch == '\t')
                ch = ' ';
@@ -22860,12 +22857,9 @@ x_produce_glyphs (struct it *it)
                pcm = NULL;
              else
                {
-                 this_boff = font->baseline_offset;
-                 if (font->vertical_centering)
-                   this_boff = VCENTER_BASELINE_OFFSET (font, it->f) - boff;
                  get_char_face_and_encoding (it->f, ch, face_id,
-                                             &char2b, it->multibyte_p, 0);
-                 pcm = get_per_char_metric (it->f, font, &char2b);
+                                             &char2b, 0);
+                 pcm = get_per_char_metric (font, &char2b);
                }
              if (! pcm)
                cmp->offsets[i * 2] = cmp->offsets[i * 2 + 1] = 0;
@@ -24415,7 +24409,7 @@ mouse_face_from_buffer_pos (Lisp_Object window,
             END_CHARPOS, or if they come from an overlay.  */
          if (EQ (glyph->object, before_string))
            {
-             pos = string_buffer_position (w, before_string,
+             pos = string_buffer_position (before_string,
                                            start_charpos);
              /* If pos == 0, it means before_string came from an
                 overlay, not from a buffer position.  */
@@ -24424,7 +24418,7 @@ mouse_face_from_buffer_pos (Lisp_Object window,
            }
          else if (EQ (glyph->object, after_string))
            {
-             pos = string_buffer_position (w, after_string, end_charpos);
+             pos = string_buffer_position (after_string, end_charpos);
              if (!pos || (pos >= start_charpos && pos < end_charpos))
                break;
            }
@@ -24466,7 +24460,7 @@ mouse_face_from_buffer_pos (Lisp_Object window,
             END_CHARPOS, or if they come from an overlay.  */
          if (EQ (glyph->object, before_string))
            {
-             pos = string_buffer_position (w, before_string, start_charpos);
+             pos = string_buffer_position (before_string, start_charpos);
              /* If pos == 0, it means before_string came from an
                 overlay, not from a buffer position.  */
              if (!pos || (pos >= start_charpos && pos < end_charpos))
@@ -24474,7 +24468,7 @@ mouse_face_from_buffer_pos (Lisp_Object window,
            }
          else if (EQ (glyph->object, after_string))
            {
-             pos = string_buffer_position (w, after_string, end_charpos);
+             pos = string_buffer_position (after_string, end_charpos);
              if (!pos || (pos >= start_charpos && pos < end_charpos))
                break;
            }
@@ -24532,13 +24526,13 @@ mouse_face_from_buffer_pos (Lisp_Object window,
             END_CHARPOS, or if they come from an overlay.  */
          if (EQ (end->object, before_string))
            {
-             pos = string_buffer_position (w, before_string, start_charpos);
+             pos = string_buffer_position (before_string, start_charpos);
              if (!pos || (pos >= start_charpos && pos < end_charpos))
                break;
            }
          else if (EQ (end->object, after_string))
            {
-             pos = string_buffer_position (w, after_string, end_charpos);
+             pos = string_buffer_position (after_string, end_charpos);
              if (!pos || (pos >= start_charpos && pos < end_charpos))
                break;
            }
@@ -24582,13 +24576,13 @@ mouse_face_from_buffer_pos (Lisp_Object window,
             END_CHARPOS, or if they come from an overlay.  */
          if (EQ (end->object, before_string))
            {
-             pos = string_buffer_position (w, before_string, start_charpos);
+             pos = string_buffer_position (before_string, start_charpos);
              if (!pos || (pos >= start_charpos && pos < end_charpos))
                break;
            }
          else if (EQ (end->object, after_string))
            {
-             pos = string_buffer_position (w, after_string, end_charpos);
+             pos = string_buffer_position (after_string, end_charpos);
              if (!pos || (pos >= start_charpos && pos < end_charpos))
                break;
            }
@@ -25065,10 +25059,9 @@ note_mode_line_or_margin_highlight (Lisp_Object window, int x, int y,
              CONSP (hotspot))
          && (hotspot = XCDR (hotspot), CONSP (hotspot)))
        {
-         Lisp_Object area_id, plist;
+         Lisp_Object plist;
 
-         area_id = XCAR (hotspot);
-         /* Could check AREA_ID to see if we enter/leave this hot-spot.
+         /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
             If so, we could look for mouse-enter, mouse-leave
             properties in PLIST (and do something...).  */
          hotspot = XCDR (hotspot);
@@ -25403,10 +25396,10 @@ note_mouse_highlight (struct frame *f, int x, int y)
                      CONSP (hotspot))
                  && (hotspot = XCDR (hotspot), CONSP (hotspot)))
                {
-                 Lisp_Object area_id, plist;
+                 Lisp_Object plist;
 
-                 area_id = XCAR (hotspot);
-                 /* Could check AREA_ID to see if we enter/leave this hot-spot.
+                 /* Could check XCAR (hotspot) to see if we enter/leave
+                    this hot-spot.
                     If so, we could look for mouse-enter, mouse-leave
                     properties in PLIST (and do something...).  */
                  hotspot = XCDR (hotspot);
@@ -25572,7 +25565,7 @@ note_mouse_highlight (struct frame *f, int x, int y)
                     check if the text under it has one.  */
                  struct glyph_row *r = MATRIX_ROW (w->current_matrix, vpos);
                  EMACS_INT start = MATRIX_ROW_START_CHARPOS (r);
-                 pos = string_buffer_position (w, object, start);
+                 pos = string_buffer_position (object, start);
                  if (pos > 0)
                    {
                      mouse_face = get_char_property_and_overlay
@@ -25682,7 +25675,7 @@ note_mouse_highlight (struct frame *f, int x, int y)
                    struct glyph_row *r
                      = MATRIX_ROW (w->current_matrix, vpos);
                    EMACS_INT start = MATRIX_ROW_START_CHARPOS (r);
-                   EMACS_INT p = string_buffer_position (w, obj, start);
+                   EMACS_INT p = string_buffer_position (obj, start);
                    if (p > 0)
                      {
                        help = Fget_char_property (make_number (p),
@@ -25738,7 +25731,7 @@ note_mouse_highlight (struct frame *f, int x, int y)
                      struct glyph_row *r
                        = MATRIX_ROW (w->current_matrix, vpos);
                      EMACS_INT start = MATRIX_ROW_START_CHARPOS (r);
-                     EMACS_INT p = string_buffer_position (w, obj, start);
+                     EMACS_INT p = string_buffer_position (obj, start);
                      if (p > 0)
                        pointer = Fget_char_property (make_number (p),
                                                      Qpointer, w->buffer);