]> code.delx.au - gnu-emacs/blobdiff - src/dispnew.c
(MSDOS_SUPPORT): Remove ccl.elc and codepage.elc.
[gnu-emacs] / src / dispnew.c
index 1778d5c818b6227e4e97f351b05796d400cff748..307515f7bfbca76c5e736d51a0a29f516c547588 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,
-                 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+                 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 
 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
-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
@@ -16,9 +16,7 @@ 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
-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>
@@ -36,7 +34,7 @@ Boston, MA 02110-1301, USA.  */
 #include "dispextern.h"
 #include "cm.h"
 #include "buffer.h"
-#include "charset.h"
+#include "character.h"
 #include "keyboard.h"
 #include "frame.h"
 #include "termhooks.h"
@@ -61,9 +59,9 @@ Boston, MA 02110-1301, USA.  */
 #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.  */
 
@@ -324,7 +322,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
-   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;
 
@@ -633,7 +633,7 @@ adjust_glyph_matrix (w, matrix, x, y, dim)
   int header_line_changed_p = 0;
   int header_line_p = 0;
   int left = -1, right = -1;
-  int window_width = -1, window_height;
+  int window_width = -1, window_height = -1;
 
   /* See if W had a header line that has disappeared now, or vice versa.
      Get W's size.  */
@@ -1468,9 +1468,11 @@ line_draw_cost (matrix, vpos)
       len = 0;
       while (beg < end)
        {
-         GLYPH g = GLYPH_FROM_CHAR_GLYPH (*beg);
+         GLYPH g;
+
+         SET_GLYPH_FROM_CHAR_GLYPH (g, *beg);
 
-         if (g < 0
+         if (GLYPH_INVALID_P (g)
              || GLYPH_SIMPLE_P (glyph_table_base, glyph_table_len, g))
            len += 1;
          else
@@ -2175,7 +2177,7 @@ showing_window_margins_p (w)
       else if (!NILP (w->left_margin_cols)
               || !NILP (w->right_margin_cols))
        return 1;
+
       w = NILP (w->next) ? 0 : XWINDOW (w->next);
     }
   return 0;
@@ -2740,7 +2742,9 @@ build_frame_matrix_from_leaf_window (frame_matrix, w)
   struct glyph_matrix *window_matrix;
   int window_y, frame_y;
   /* If non-zero, a glyph to insert at the right border of W.  */
-  GLYPH right_border_glyph = 0;
+  GLYPH right_border_glyph;
+
+  SET_GLYPH_FROM_CHAR (right_border_glyph, 0);
 
   /* Set window_matrix to the matrix we have to add to FRAME_MATRIX.  */
   if (w->must_be_updated_p)
@@ -2751,15 +2755,19 @@ build_frame_matrix_from_leaf_window (frame_matrix, w)
       if (!WINDOW_RIGHTMOST_P (w))
        {
          struct Lisp_Char_Table *dp = window_display_table (w);
+         Lisp_Object gc;
 
-         right_border_glyph
-           = ((dp && INTEGERP (DISP_BORDER_GLYPH (dp)))
-              ? spec_glyph_lookup_face (w, XINT (DISP_BORDER_GLYPH (dp)))
-              : '|');
+         SET_GLYPH_FROM_CHAR (right_border_glyph, '|');
+         if (dp
+             && (gc = DISP_BORDER_GLYPH (dp), GLYPH_CODE_P (gc))
+             && GLYPH_CODE_CHAR_VALID_P (gc))
+           {
+             SET_GLYPH_FROM_GLYPH_CODE (right_border_glyph, gc);
+             spec_glyph_lookup_face (w, &right_border_glyph);
+           }
 
-         if (FAST_GLYPH_FACE (right_border_glyph) <= 0)
-           right_border_glyph
-             = FAST_MAKE_GLYPH (right_border_glyph, VERTICAL_BORDER_FACE_ID);
+         if (GLYPH_FACE (right_border_glyph) <= 0)
+           SET_GLYPH_FACE (right_border_glyph, VERTICAL_BORDER_FACE_ID);
        }
     }
   else
@@ -2809,7 +2817,7 @@ build_frame_matrix_from_leaf_window (frame_matrix, w)
 
           /* Maybe insert a vertical border between horizontally adjacent
             windows.  */
-          if (right_border_glyph)
+          if (GLYPH_CHAR (right_border_glyph) != 0)
            {
               struct glyph *border = window_row->glyphs[LAST_AREA] - 1;
              SET_CHAR_GLYPH_FROM_GLYPH (*border, right_border_glyph);
@@ -2845,21 +2853,19 @@ build_frame_matrix_from_leaf_window (frame_matrix, w)
    This is used for glyphs displayed specially and not part of the text;
    for instance, vertical separators, truncation markers, etc.  */
 
-GLYPH
+void
 spec_glyph_lookup_face (w, glyph)
      struct window *w;
-     GLYPH glyph;
+     GLYPH *glyph;
 {
-  int lface_id = FAST_GLYPH_FACE (glyph);
+  int lface_id = GLYPH_FACE (*glyph);
   /* Convert the glyph's specified face to a realized (cache) face.  */
   if (lface_id > 0)
     {
       int face_id = merge_faces (XFRAME (w->frame),
                                 Qt, lface_id, DEFAULT_FACE_ID);
-      glyph
-       = FAST_MAKE_GLYPH (FAST_GLYPH_CHAR (glyph), face_id);
+      SET_GLYPH_FACE (*glyph, face_id);
     }
-  return glyph;
 }
 
 /* Add spaces to a glyph row ROW in a window matrix.
@@ -3384,7 +3390,7 @@ DEFUN ("redraw-frame", Fredraw_frame, Sredraw_frame, 1, 1, 0,
   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);
@@ -3508,6 +3514,7 @@ direct_output_for_insert (g)
       || 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
@@ -4058,7 +4065,7 @@ redraw_overlapped_rows (w, yb)
 {
   int i;
   struct frame *f = XFRAME (WINDOW_FRAME (w));
-  
+
   /* If rows overlapping others have been changed, the rows being
      overlapped have to be redrawn.  This won't draw lines that have
      already been drawn in update_window_line because overlapped_p in
@@ -4109,7 +4116,7 @@ redraw_overlapping_rows (w, yb)
   int i, bottom_y;
   struct glyph_row *row;
   struct redisplay_interface *rif = FRAME_RIF (XFRAME (WINDOW_FRAME (w)));
-  
+
   for (i = 0; i < w->current_matrix->nrows; ++i)
     {
       row = w->current_matrix->rows + i;
@@ -5296,22 +5303,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.  */
-             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
-                     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
-                     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);
+                       }
                    }
                }
            }
@@ -6196,10 +6207,10 @@ window_change_signal (signalnum) /* If we don't have an argument, */
       continue;
 
     get_tty_size (fileno (tty->input), &width, &height);
-    
+
     if (width > 5 && height > 2) {
       Lisp_Object tail, frame;
-      
+
       FOR_EACH_FRAME (tail, frame)
         if (FRAME_TERMCAP_P (XFRAME (frame)) && FRAME_TTY (XFRAME (frame)) == tty)
           /* Record the new sizes, but don't reallocate the data
@@ -6208,7 +6219,7 @@ window_change_signal (signalnum) /* If we don't have an argument, */
           change_frame_size (XFRAME (frame), height, width, 0, 1, 0);
     }
   }
-  
+
   errno = old_errno;
 }
 #endif /* SIGWINCH */
@@ -6335,7 +6346,7 @@ change_frame_size_1 (f, newheight, newwidth, pretend, delay, safe)
                             (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);
@@ -6343,7 +6354,7 @@ 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),
-                          newheight - FRAME_TOP_MARGIN (f), 0);
+                          newheight - FRAME_TOP_MARGIN (f), 2);
 
       if (FRAME_TERMCAP_P (f) && !pretend)
        FrameRows (FRAME_TTY (f)) = newheight;
@@ -6351,7 +6362,7 @@ change_frame_size_1 (f, newheight, newwidth, pretend, delay, safe)
 
   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);
 
@@ -6386,9 +6397,7 @@ change_frame_size_1 (f, newheight, newwidth, pretend, delay, safe)
 
   record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
 
-  /* This isn't quite a no-op: it runs window-configuration-change-hook.  */
-  Fset_window_buffer (FRAME_SELECTED_WINDOW (f),
-                     XWINDOW (FRAME_SELECTED_WINDOW (f))->buffer, Qt);
+  run_window_configuration_change_hook (f);
 
   unbind_to (count, Qnil);
 }
@@ -6455,7 +6464,7 @@ currently selected frame.  */)
     error ("Unknown terminal device");
 
   tty = t->display_info.tty;
-  
+
   if (tty->termscript)
     {
       fwrite (SDATA (string), 1, SBYTES (string), tty->termscript);
@@ -6794,7 +6803,7 @@ init_display ()
 
   /* Construct the space glyph.  */
   space_glyph.type = CHAR_GLYPH;
-  SET_CHAR_GLYPH_FROM_GLYPH (space_glyph, ' ');
+  SET_CHAR_GLYPH (space_glyph, ' ', DEFAULT_FACE_ID, 0);
   space_glyph.charpos = -1;
 
   inverse_video = 0;
@@ -6815,6 +6824,10 @@ init_display ()
     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
@@ -6827,12 +6840,7 @@ init_display ()
   if (! inhibit_window_system && ! display_arg)
     {
       char *display;
-#ifdef VMS
-      display = getenv ("DECW$DISPLAY");
-#else
       display = getenv ("DISPLAY");
-#endif
-
       display_arg = (display != 0 && *display != 0);
 
       if (display_arg && !x_display_ok (display))
@@ -6852,8 +6860,6 @@ init_display ()
       Vinitial_window_system = intern ("x");
 #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,
@@ -6876,15 +6882,19 @@ init_display ()
     }
 #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 = intern("ns");
+      Vwindow_system_version = make_number(10);
       adjust_frame_glyphs_initially ();
       return;
     }
-#endif /* MAC_OS */
+#endif
 
   /* If no window system has been specified, try to use the terminal.  */
   if (! isatty (0))
@@ -6893,44 +6903,23 @@ init_display ()
       exit (1);
     }
 
+#ifdef WINDOWSNT
+  terminal_type = "w32console";
+#else
   /* Look at the TERM variable.  */
   terminal_type = (char *) getenv ("TERM");
+#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");
-#endif /* not VMS */
       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);
@@ -6956,13 +6945,18 @@ For types not defined in VMS, use  define emacs_term \"TYPE\".\n\
       (*initial_terminal->delete_terminal_hook) (initial_terminal);
 
     /* Update frame parameters to reflect the new type. */
-    Fmodify_frame_parameters (selected_frame, Fcons (Fcons (Qwindow_system, Qnil), 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));
   }
-  
+
   {
     struct frame *sf = SELECTED_FRAME ();
     int width = FRAME_TOTAL_COLS (sf);
@@ -6982,13 +6976,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
-#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
@@ -7050,6 +7037,18 @@ WINDOW nil or omitted means report on the selected window.  */)
   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
@@ -7068,6 +7067,7 @@ syms_of_display ()
   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);
@@ -7106,9 +7106,14 @@ It is up to you to set this variable if your terminal can do that.  */);
 The value is a symbol--for instance, `x' for X windows.
 The value is nil if Emacs is using a text-only terminal.  */);
 
+  DEFVAR_KBOARD ("window-system", Vwindow_system,
+                doc: /* Name of window system through which the selected frame is displayed.
+The value is a symbol--for instance, `x' for X windows.
+The value is nil if the selected frame is on a text-only-terminal.  */);
+
   DEFVAR_LISP ("window-system-version", &Vwindow_system_version,
               doc: /* The version number of the window system in use.
-For X windows, this is 10 or 11.  */);
+For X windows, this is 11.  */);
 
   DEFVAR_BOOL ("cursor-in-echo-area", &cursor_in_echo_area,
               doc: /* Non-nil means put cursor in minibuffer, at end of any message there.  */);