]> code.delx.au - gnu-emacs/blobdiff - src/dispnew.c
Reword header comment to prevent copyright.el wanting to update years.
[gnu-emacs] / src / dispnew.c
index 4f6e6374da3fc2c48c5e95e4bb0dce3ca7b42447..ba50b001980c6220d8732d979590cb75dda2c56c 100644 (file)
@@ -1,14 +1,14 @@
 /* Updating of data structures for redisplay.
    Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995,
                  1997, 1998, 1999, 2000, 2001, 2002, 2003,
 /* 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 Free Software Foundation, Inc.
+                 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
 
 This file is part of GNU Emacs.
 
-GNU Emacs is free software; you can redistribute it and/or modify
+GNU Emacs is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 3, or (at your option)
-any later version.
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 GNU Emacs is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -16,14 +16,13 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with GNU Emacs; see the file COPYING.  If not, write to
-the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-Boston, MA 02110-1301, USA.  */
+along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <config.h>
 #include <signal.h>
 #include <stdio.h>
 #include <ctype.h>
 
 #include <config.h>
 #include <signal.h>
 #include <stdio.h>
 #include <ctype.h>
+#include <setjmp.h>
 
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
@@ -61,9 +60,9 @@ Boston, MA 02110-1301, USA.  */
 #include "w32term.h"
 #endif /* HAVE_NTGUI */
 
 #include "w32term.h"
 #endif /* HAVE_NTGUI */
 
-#ifdef MAC_OS
-#include "macterm.h"
-#endif /* MAC_OS */
+#ifdef HAVE_NS
+#include "nsterm.h"
+#endif
 
 /* Include systime.h after xterm.h to avoid double inclusion of time.h.  */
 
 
 /* Include systime.h after xterm.h to avoid double inclusion of time.h.  */
 
@@ -324,7 +323,9 @@ static struct frame *frame_matrix_frame;
    matrix adjustments.  Redisplay must stop, and glyph matrices must
    be adjusted when this flag becomes non-zero during display.  The
    reason fonts can be loaded so late is that fonts of fontsets are
    matrix adjustments.  Redisplay must stop, and glyph matrices must
    be adjusted when this flag becomes non-zero during display.  The
    reason fonts can be loaded so late is that fonts of fontsets are
-   loaded on demand.  */
+   loaded on demand.  Another reason is that a line contains many
+   characters displayed by zero width or very narrow glyphs of
+   variable-width fonts.  */
 
 int fonts_changed_p;
 
 
 int fonts_changed_p;
 
@@ -3390,7 +3391,7 @@ DEFUN ("redraw-frame", Fredraw_frame, Sredraw_frame, 1, 1, 0,
   update_begin (f);
 #ifdef MSDOS
   if (FRAME_MSDOS_P (f))
   update_begin (f);
 #ifdef MSDOS
   if (FRAME_MSDOS_P (f))
-    set_terminal_modes (FRAME_TERMINAL (f));
+    FRAME_TERMINAL (f)->set_terminal_modes_hook (FRAME_TERMINAL (f));
 #endif
   clear_frame (f);
   clear_current_matrices (f);
 #endif
   clear_frame (f);
   clear_current_matrices (f);
@@ -3514,6 +3515,7 @@ direct_output_for_insert (g)
       || g == '\t'
       || g == '\n'
       || g == '\r'
       || 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
       /* 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
@@ -3953,11 +3955,12 @@ update_frame (f, force_p, inhibit_hairy_id_p)
       paused_p = update_frame_1 (f, force_p, inhibit_hairy_id_p);
       update_end (f);
 
       paused_p = update_frame_1 (f, force_p, inhibit_hairy_id_p);
       update_end (f);
 
-      if (FRAME_TERMCAP_P (f))
+      if (FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f))
         {
           if (FRAME_TTY (f)->termscript)
             fflush (FRAME_TTY (f)->termscript);
         {
           if (FRAME_TTY (f)->termscript)
             fflush (FRAME_TTY (f)->termscript);
-          fflush (FRAME_TTY (f)->output);
+         if (FRAME_TERMCAP_P (f))
+           fflush (FRAME_TTY (f)->output);
         }
 
       /* Check window matrices for lost pointers.  */
         }
 
       /* Check window matrices for lost pointers.  */
@@ -4127,14 +4130,14 @@ redraw_overlapping_rows (w, yb)
 
       bottom_y = MATRIX_ROW_BOTTOM_Y (row);
 
 
       bottom_y = MATRIX_ROW_BOTTOM_Y (row);
 
-      if (row->overlapping_p && i > 0 && bottom_y < yb)
+      if (row->overlapping_p)
        {
          int overlaps = 0;
 
        {
          int overlaps = 0;
 
-         if (MATRIX_ROW_OVERLAPS_PRED_P (row)
+         if (MATRIX_ROW_OVERLAPS_PRED_P (row) && i > 0
              && !MATRIX_ROW (w->current_matrix, i - 1)->overlapped_p)
            overlaps |= OVERLAPS_PRED;
              && !MATRIX_ROW (w->current_matrix, i - 1)->overlapped_p)
            overlaps |= OVERLAPS_PRED;
-         if (MATRIX_ROW_OVERLAPS_SUCC_P (row)
+         if (MATRIX_ROW_OVERLAPS_SUCC_P (row) && bottom_y < yb
              && !MATRIX_ROW (w->current_matrix, i + 1)->overlapped_p)
            overlaps |= OVERLAPS_SUCC;
 
              && !MATRIX_ROW (w->current_matrix, i + 1)->overlapped_p)
            overlaps |= OVERLAPS_SUCC;
 
@@ -4473,6 +4476,7 @@ update_text_area (w, vpos)
       struct glyph *desired_glyph = desired_row->glyphs[TEXT_AREA];
       int overlapping_glyphs_p = current_row->contains_overlapping_glyphs_p;
       int desired_stop_pos = desired_row->used[TEXT_AREA];
       struct glyph *desired_glyph = desired_row->glyphs[TEXT_AREA];
       int overlapping_glyphs_p = current_row->contains_overlapping_glyphs_p;
       int desired_stop_pos = desired_row->used[TEXT_AREA];
+      int abort_skipping = 0;
 
       /* If the desired row extends its face to the text area end, and
         unless the current row also does so at the same position,
 
       /* If the desired row extends its face to the text area end, and
         unless the current row also does so at the same position,
@@ -4492,7 +4496,7 @@ update_text_area (w, vpos)
         in common.  */
       while (i < stop)
        {
         in common.  */
       while (i < stop)
        {
-         int can_skip_p = 1;
+         int can_skip_p = !abort_skipping;
 
          /* Skip over glyphs that both rows have in common.  These
             don't have to be written.  We can't skip if the last
 
          /* Skip over glyphs that both rows have in common.  These
             don't have to be written.  We can't skip if the last
@@ -4509,11 +4513,13 @@ update_text_area (w, vpos)
 
              rif->get_glyph_overhangs (glyph, XFRAME (w->frame),
                                        &left, &right);
 
              rif->get_glyph_overhangs (glyph, XFRAME (w->frame),
                                        &left, &right);
-             can_skip_p = right == 0;
+             can_skip_p = (right == 0 && !abort_skipping);
            }
 
          if (can_skip_p)
            {
            }
 
          if (can_skip_p)
            {
+             int start_hpos = i;
+
              while (i < stop
                     && GLYPH_EQUAL_P (desired_glyph, current_glyph))
                {
              while (i < stop
                     && GLYPH_EQUAL_P (desired_glyph, current_glyph))
                {
@@ -4545,6 +4551,12 @@ update_text_area (w, vpos)
                      x -= desired_glyph->pixel_width;
                      left -= desired_glyph->pixel_width;
                    }
                      x -= desired_glyph->pixel_width;
                      left -= desired_glyph->pixel_width;
                    }
+
+                 /* Abort the skipping algorithm if we end up before
+                    our starting point, to avoid looping (bug#1070).
+                    This can happen when the lbearing is larger than
+                    the pixel width.  */
+                 abort_skipping = (i < start_hpos);
                }
            }
 
                }
            }
 
@@ -5302,22 +5314,26 @@ update_frame_1 (f, force_p, inhibit_id_p)
                 Also flush out if likely to have more than 1k buffered
                 otherwise.   I'm told that some telnet connections get
                 really screwed by more than 1k output at once.  */
                 Also flush out if likely to have more than 1k buffered
                 otherwise.   I'm told that some telnet connections get
                 really screwed by more than 1k output at once.  */
-             int outq = PENDING_OUTPUT_COUNT (FRAME_TTY (f)->output);
-             if (outq > 900
-                 || (outq > 20 && ((i - 1) % preempt_count == 0)))
+             FILE *display_output = FRAME_TTY (f)->output;
+             if (display_output)
                {
                {
-                 fflush (FRAME_TTY (f)->output);
-                 if (preempt_count == 1)
+                 int outq = PENDING_OUTPUT_COUNT (display_output);
+                 if (outq > 900
+                     || (outq > 20 && ((i - 1) % preempt_count == 0)))
                    {
                    {
+                     fflush (display_output);
+                     if (preempt_count == 1)
+                       {
 #ifdef EMACS_OUTQSIZE
 #ifdef EMACS_OUTQSIZE
-                     if (EMACS_OUTQSIZE (0, &outq) < 0)
-                       /* Probably not a tty.  Ignore the error and reset
-                          the outq count.  */
-                       outq = PENDING_OUTPUT_COUNT (FRAME_TTY (f->output));
+                         if (EMACS_OUTQSIZE (0, &outq) < 0)
+                           /* Probably not a tty.  Ignore the error and reset
+                              the outq count.  */
+                           outq = PENDING_OUTPUT_COUNT (FRAME_TTY (f->output));
 #endif
 #endif
-                     outq *= 10;
-                     if (baud_rate <= outq && baud_rate > 0)
-                       sleep (outq / baud_rate);
+                         outq *= 10;
+                         if (baud_rate <= outq && baud_rate > 0)
+                           sleep (outq / baud_rate);
+                       }
                    }
                }
            }
                    }
                }
            }
@@ -5918,7 +5934,7 @@ buffer_posn_from_coords (w, x, y, pos, object, dx, dy, width, height)
      int *width, *height;
 {
   struct it it;
      int *width, *height;
 {
   struct it it;
-  struct buffer *old_current_buffer = current_buffer;
+  Lisp_Object old_current_buffer = Fcurrent_buffer ();
   struct text_pos startp;
   Lisp_Object string;
   struct glyph_row *row;
   struct text_pos startp;
   Lisp_Object string;
   struct glyph_row *row;
@@ -5927,7 +5943,9 @@ buffer_posn_from_coords (w, x, y, pos, object, dx, dy, width, height)
 #endif
   int x0, x1;
 
 #endif
   int x0, x1;
 
-  current_buffer = XBUFFER (w->buffer);
+  /* We used to set current_buffer directly here, but that does the
+     wrong thing with `face-remapping-alist' (bug#2044).  */
+  Fset_buffer (w->buffer);
   SET_TEXT_POS_FROM_MARKER (startp, w->start);
   CHARPOS (startp) = min (ZV, max (BEGV, CHARPOS (startp)));
   BYTEPOS (startp) = min (ZV_BYTE, max (BEGV_BYTE, BYTEPOS (startp)));
   SET_TEXT_POS_FROM_MARKER (startp, w->start);
   CHARPOS (startp) = min (ZV, max (BEGV, CHARPOS (startp)));
   BYTEPOS (startp) = min (ZV_BYTE, max (BEGV_BYTE, BYTEPOS (startp)));
@@ -5937,7 +5955,7 @@ buffer_posn_from_coords (w, x, y, pos, object, dx, dy, width, height)
   move_it_to (&it, -1, x0 + it.first_visible_x, *y, -1,
              MOVE_TO_X | MOVE_TO_Y);
 
   move_it_to (&it, -1, x0 + it.first_visible_x, *y, -1,
              MOVE_TO_X | MOVE_TO_Y);
 
-  current_buffer = old_current_buffer;
+  Fset_buffer (old_current_buffer);
 
   *dx = x0 + it.first_visible_x - it.current_x;
   *dy = *y - it.current_y;
 
   *dx = x0 + it.first_visible_x - it.current_x;
   *dy = *y - it.current_y;
@@ -6201,6 +6219,11 @@ window_change_signal (signalnum) /* If we don't have an argument, */
     if (! tty->term_initted)
       continue;
 
     if (! tty->term_initted)
       continue;
 
+    /* Suspended tty frames have tty->input == NULL avoid trying to
+       use it.  */
+    if (!tty->input)
+      continue;
+
     get_tty_size (fileno (tty->input), &width, &height);
 
     if (width > 5 && height > 2) {
     get_tty_size (fileno (tty->input), &width, &height);
 
     if (width > 5 && height > 2) {
@@ -6341,7 +6364,7 @@ change_frame_size_1 (f, newheight, newwidth, pretend, delay, safe)
                             (newheight
                              - 1
                              - FRAME_TOP_MARGIN (f)),
                             (newheight
                              - 1
                              - FRAME_TOP_MARGIN (f)),
-                             0);
+                            2);
          XSETFASTINT (XWINDOW (FRAME_MINIBUF_WINDOW (f))->top_line,
                       newheight - 1);
          set_window_height (FRAME_MINIBUF_WINDOW (f), 1, 0);
          XSETFASTINT (XWINDOW (FRAME_MINIBUF_WINDOW (f))->top_line,
                       newheight - 1);
          set_window_height (FRAME_MINIBUF_WINDOW (f), 1, 0);
@@ -6349,19 +6372,23 @@ change_frame_size_1 (f, newheight, newwidth, pretend, delay, safe)
       else
        /* Frame has just one top-level window.  */
        set_window_height (FRAME_ROOT_WINDOW (f),
       else
        /* Frame has just one top-level window.  */
        set_window_height (FRAME_ROOT_WINDOW (f),
-                          newheight - FRAME_TOP_MARGIN (f), 0);
+                          newheight - FRAME_TOP_MARGIN (f), 2);
 
 
-      if (FRAME_TERMCAP_P (f) && !pretend)
+      /* MSDOS frames cannot PRETEND, as they change frame size by
+        manipulating video hardware.  */
+      if ((FRAME_TERMCAP_P (f) && !pretend) || FRAME_MSDOS_P (f))
        FrameRows (FRAME_TTY (f)) = newheight;
     }
 
   if (new_frame_total_cols != FRAME_TOTAL_COLS (f))
     {
        FrameRows (FRAME_TTY (f)) = newheight;
     }
 
   if (new_frame_total_cols != FRAME_TOTAL_COLS (f))
     {
-      set_window_width (FRAME_ROOT_WINDOW (f), new_frame_total_cols, 0);
+      set_window_width (FRAME_ROOT_WINDOW (f), new_frame_total_cols, 2);
       if (FRAME_HAS_MINIBUF_P (f))
        set_window_width (FRAME_MINIBUF_WINDOW (f), new_frame_total_cols, 0);
 
       if (FRAME_HAS_MINIBUF_P (f))
        set_window_width (FRAME_MINIBUF_WINDOW (f), new_frame_total_cols, 0);
 
-      if (FRAME_TERMCAP_P (f) && !pretend)
+      /* MSDOS frames cannot PRETEND, as they change frame size by
+        manipulating video hardware.  */
+      if ((FRAME_TERMCAP_P (f) && !pretend) || FRAME_MSDOS_P (f))
        FrameCols (FRAME_TTY (f)) = newwidth;
 
       if (WINDOWP (f->tool_bar_window))
        FrameCols (FRAME_TTY (f)) = newwidth;
 
       if (WINDOWP (f->tool_bar_window))
@@ -6412,7 +6439,8 @@ FILE = nil means just close any termscript file currently open.  */)
 {
   struct tty_display_info *tty;
 
 {
   struct tty_display_info *tty;
 
-  if (! FRAME_TERMCAP_P (SELECTED_FRAME ()))
+  if (! FRAME_TERMCAP_P (SELECTED_FRAME ())
+      && ! FRAME_MSDOS_P (SELECTED_FRAME ()))
     error ("Current frame is not on a tty device");
 
   tty = CURTTY ();
     error ("Current frame is not on a tty device");
 
   tty = CURTTY ();
@@ -6442,14 +6470,15 @@ DEFUN ("send-string-to-terminal", Fsend_string_to_terminal,
 Control characters in STRING will have terminal-dependent effects.
 
 Optional parameter TERMINAL specifies the tty terminal device to use.
 Control characters in STRING will have terminal-dependent effects.
 
 Optional parameter TERMINAL specifies the tty terminal device to use.
-It may be a terminal id, a frame, or nil for the terminal used by the
-currently selected frame.  */)
+It may be a terminal object, a frame, or nil for the terminal used by
+the currently selected frame.  In batch mode, STRING is sent to stdout
+when TERMINAL is nil.  */)
   (string, terminal)
      Lisp_Object string;
      Lisp_Object terminal;
 {
   (string, terminal)
      Lisp_Object string;
      Lisp_Object terminal;
 {
-  struct terminal *t = get_tty_terminal (terminal, 1);
-  struct tty_display_info *tty;
+  struct terminal *t = get_terminal (terminal, 1);
+  FILE *out;
 
   /* ??? Perhaps we should do something special for multibyte strings here.  */
   CHECK_STRING (string);
 
   /* ??? Perhaps we should do something special for multibyte strings here.  */
   CHECK_STRING (string);
@@ -6458,15 +6487,26 @@ currently selected frame.  */)
   if (!t)
     error ("Unknown terminal device");
 
   if (!t)
     error ("Unknown terminal device");
 
-  tty = t->display_info.tty;
-
-  if (tty->termscript)
+  if (t->type == output_initial)
+    out = stdout;
+  else if (t->type != output_termcap && t->type != output_msdos_raw)
+    error ("Device %d is not a termcap terminal device", t->id);
+  else
     {
     {
-      fwrite (SDATA (string), 1, SBYTES (string), tty->termscript);
-      fflush (tty->termscript);
+      struct tty_display_info *tty = t->display_info.tty;
+
+      if (! tty->output)
+       error ("Terminal is currently suspended");
+
+      if (tty->termscript)
+       {
+         fwrite (SDATA (string), 1, SBYTES (string), tty->termscript);
+         fflush (tty->termscript);
+       }
+      out = tty->output;
     }
     }
-  fwrite (SDATA (string), 1, SBYTES (string), tty->output);
-  fflush (tty->output);
+  fwrite (SDATA (string), 1, SBYTES (string), out);
+  fflush (out);
   UNBLOCK_INPUT;
   return Qnil;
 }
   UNBLOCK_INPUT;
   return Qnil;
 }
@@ -6819,6 +6859,10 @@ init_display ()
     signal (SIGWINCH, window_change_signal);
 #endif /* SIGWINCH */
 
     signal (SIGWINCH, window_change_signal);
 #endif /* SIGWINCH */
 
+  /* If running as a daemon, no need to initialize any frames/terminal. */
+  if (IS_DAEMON)
+      return;
+
   /* If the user wants to use a window system, we shouldn't bother
      initializing the terminal.  This is especially important when the
      terminal is so dumb that emacs gives up before and doesn't bother
   /* If the user wants to use a window system, we shouldn't bother
      initializing the terminal.  This is especially important when the
      terminal is so dumb that emacs gives up before and doesn't bother
@@ -6831,12 +6875,7 @@ init_display ()
   if (! inhibit_window_system && ! display_arg)
     {
       char *display;
   if (! inhibit_window_system && ! display_arg)
     {
       char *display;
-#ifdef VMS
-      display = getenv ("DECW$DISPLAY");
-#else
       display = getenv ("DISPLAY");
       display = getenv ("DISPLAY");
-#endif
-
       display_arg = (display != 0 && *display != 0);
 
       if (display_arg && !x_display_ok (display))
       display_arg = (display != 0 && *display != 0);
 
       if (display_arg && !x_display_ok (display))
@@ -6853,11 +6892,9 @@ init_display ()
 #endif
      )
     {
 #endif
      )
     {
-      Vinitial_window_system = intern ("x");
+      Vinitial_window_system = Qx;
 #ifdef HAVE_X11
       Vwindow_system_version = make_number (11);
 #ifdef HAVE_X11
       Vwindow_system_version = make_number (11);
-#else
-      Vwindow_system_version = make_number (10);
 #endif
 #if defined (GNU_LINUX) && defined (HAVE_LIBNCURSES)
       /* In some versions of ncurses,
 #endif
 #if defined (GNU_LINUX) && defined (HAVE_LIBNCURSES)
       /* In some versions of ncurses,
@@ -6873,22 +6910,26 @@ init_display ()
 #ifdef HAVE_NTGUI
   if (!inhibit_window_system)
     {
 #ifdef HAVE_NTGUI
   if (!inhibit_window_system)
     {
-      Vinitial_window_system = intern ("w32");
+      Vinitial_window_system = Qw32;
       Vwindow_system_version = make_number (1);
       adjust_frame_glyphs_initially ();
       return;
     }
 #endif /* HAVE_NTGUI */
 
       Vwindow_system_version = make_number (1);
       adjust_frame_glyphs_initially ();
       return;
     }
 #endif /* HAVE_NTGUI */
 
-#ifdef MAC_OS
-  if (!inhibit_window_system)
+#ifdef HAVE_NS
+  if (!inhibit_window_system
+#ifndef CANNOT_DUMP
+     && initialized
+#endif
+      )
     {
     {
-      Vinitial_window_system = intern ("mac");
-      Vwindow_system_version = make_number (1);
+      Vinitial_window_system = Qns;
+      Vwindow_system_version = make_number(10);
       adjust_frame_glyphs_initially ();
       return;
     }
       adjust_frame_glyphs_initially ();
       return;
     }
-#endif /* MAC_OS */
+#endif
 
   /* If no window system has been specified, try to use the terminal.  */
   if (! isatty (0))
 
   /* If no window system has been specified, try to use the terminal.  */
   if (! isatty (0))
@@ -6905,40 +6946,15 @@ init_display ()
 #endif
   if (!terminal_type)
     {
 #endif
   if (!terminal_type)
     {
-#ifdef VMS
-      fprintf (stderr, "Please specify your terminal type.\n\
-For types defined in VMS, use  set term /device=TYPE.\n\
-For types not defined in VMS, use  define emacs_term \"TYPE\".\n\
-\(The quotation marks are necessary since terminal types are lower case.)\n");
-#else /* not VMS */
-
 #ifdef HAVE_WINDOW_SYSTEM
       if (! inhibit_window_system)
        fprintf (stderr, "Please set the environment variable DISPLAY or TERM (see `tset').\n");
       else
 #endif /* HAVE_WINDOW_SYSTEM */
        fprintf (stderr, "Please set the environment variable TERM; see `tset'.\n");
 #ifdef HAVE_WINDOW_SYSTEM
       if (! inhibit_window_system)
        fprintf (stderr, "Please set the environment variable DISPLAY or TERM (see `tset').\n");
       else
 #endif /* HAVE_WINDOW_SYSTEM */
        fprintf (stderr, "Please set the environment variable TERM; see `tset'.\n");
-#endif /* not VMS */
       exit (1);
     }
 
       exit (1);
     }
 
-#ifdef VMS
-  /* VMS DCL tends to up-case things, so down-case term type.
-     Hardly any uppercase letters in terminal types; should be none.  */
-  {
-    char *new = (char *) xmalloc (strlen (terminal_type) + 1);
-    char *p;
-
-    strcpy (new, terminal_type);
-
-    for (p = new; *p; p++)
-      if (isupper (*p))
-       *p = tolower (*p);
-
-    terminal_type = new;
-  }
-#endif /* VMS */
-
   {
     struct terminal *t;
     struct frame *f = XFRAME (selected_frame);
   {
     struct terminal *t;
     struct frame *f = XFRAME (selected_frame);
@@ -6967,7 +6983,13 @@ For types not defined in VMS, use  define emacs_term \"TYPE\".\n\
     Fmodify_frame_parameters
       (selected_frame, Fcons (Fcons (Qtty_type,
                                      Ftty_type (selected_frame)), Qnil));
     Fmodify_frame_parameters
       (selected_frame, Fcons (Fcons (Qtty_type,
                                      Ftty_type (selected_frame)), Qnil));
-    Fmodify_frame_parameters (selected_frame, Fcons (Fcons (Qtty, Qnil), Qnil));
+    if (t->display_info.tty->name)
+      Fmodify_frame_parameters (selected_frame,
+                               Fcons (Fcons (Qtty, build_string (t->display_info.tty->name)),
+                                      Qnil));
+    else
+      Fmodify_frame_parameters (selected_frame, Fcons (Fcons (Qtty, Qnil),
+                                                      Qnil));
   }
 
   {
   }
 
   {
@@ -6989,13 +7011,6 @@ For types not defined in VMS, use  define emacs_term \"TYPE\".\n\
   /* Set up faces of the initial terminal frame of a dumped Emacs.  */
   if (initialized
       && !noninteractive
   /* Set up faces of the initial terminal frame of a dumped Emacs.  */
   if (initialized
       && !noninteractive
-#ifdef MSDOS
-      /* The MSDOS terminal turns on its ``window system'' relatively
-        late into the startup, so we cannot do the frame faces'
-        initialization just yet.  It will be done later by pc-win.el
-        and internal_terminal_init.  */
-      && (strcmp (terminal_type, "internal") != 0 || inhibit_window_system)
-#endif
       && NILP (Vinitial_window_system))
     {
       /* For the initial frame, we don't have any way of knowing what
       && NILP (Vinitial_window_system))
     {
       /* For the initial frame, we don't have any way of knowing what
@@ -7057,6 +7072,18 @@ WINDOW nil or omitted means report on the selected window.  */)
   return w->cursor_off_p ? Qnil : Qt;
 }
 
   return w->cursor_off_p ? Qnil : Qt;
 }
 
+DEFUN ("last-nonminibuffer-frame", Flast_nonminibuf_frame,
+       Slast_nonminibuf_frame, 0, 0, 0,
+       doc: /* Value is last nonminibuffer frame. */)
+     ()
+{
+  Lisp_Object frame = Qnil;
+
+  if (last_nonminibuf_frame)
+    XSETFRAME (frame, last_nonminibuf_frame);
+
+  return frame;
+}
 \f
 /***********************************************************************
                            Initialization
 \f
 /***********************************************************************
                            Initialization
@@ -7075,6 +7102,7 @@ syms_of_display ()
   defsubr (&Ssend_string_to_terminal);
   defsubr (&Sinternal_show_cursor);
   defsubr (&Sinternal_show_cursor_p);
   defsubr (&Ssend_string_to_terminal);
   defsubr (&Sinternal_show_cursor);
   defsubr (&Sinternal_show_cursor_p);
+  defsubr (&Slast_nonminibuf_frame);
 
 #if GLYPH_DEBUG
   defsubr (&Sdump_redisplay_history);
 
 #if GLYPH_DEBUG
   defsubr (&Sdump_redisplay_history);