*** empty log message ***
[bpt/emacs.git] / src / term.c
index 2133382..d829332 100644 (file)
@@ -1,12 +1,12 @@
 /* Terminal control module for terminals described by TERMCAP
    Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1998, 2000, 2001,
-                 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+                 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
 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 2, or (at your option)
+the Free Software Foundation; either version 3, or (at your option)
 any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
@@ -25,7 +25,6 @@ Boston, MA 02110-1301, USA.  */
 #include <stdio.h>
 #include <ctype.h>
 #include <string.h>
-#include <stdarg.h>
 
 #include "termchar.h"
 #include "termopts.h"
@@ -39,6 +38,7 @@ Boston, MA 02110-1301, USA.  */
 #include "dispextern.h"
 #include "window.h"
 #include "keymap.h"
+#include "blockinput.h"
 
 /* For now, don't try to include termcap.h.  On some systems,
    configure finds a non-standard termcap.h that the main build
@@ -88,6 +88,10 @@ extern Lisp_Object Qspace, QCalign_to, QCwidth;
 
 Lisp_Object Vring_bell_function;
 
+/* If true, use "vs", otherwise use "ve" to make the cursor visible.  */
+
+static int visible_cursor;
+
 /* Terminal characteristics that higher levels want to look at.
    These are all extern'd in termchar.h */
 
@@ -187,6 +191,11 @@ void (*frame_rehighlight_hook) P_ ((FRAME_PTR f));
 
 void (*frame_raise_lower_hook) P_ ((FRAME_PTR f, int raise));
 
+/* If the value of the frame parameter changed, whis hook is called.
+   For example, if going from fullscreen to not fullscreen this hook
+   may do something OS dependent, like extended window manager hints on X11.  */
+void (*fullscreen_hook) P_ ((struct frame *f));
+
 /* Set the vertical scroll bar for WINDOW to have its upper left corner
    at (TOP, LEFT), and be LENGTH rows high.  Set its handle to
    indicate that we are displaying PORTION characters out of a total
@@ -461,7 +470,7 @@ set_terminal_modes ()
            putchar ('\n');
        }
 
-      OUTPUT_IF (TS_cursor_visible);
+      OUTPUT_IF (visible_cursor ? TS_cursor_visible : TS_cursor_normal);
       OUTPUT_IF (TS_keypad_mode);
       losecursor ();
     }
@@ -616,7 +625,8 @@ tty_show_cursor ()
     {
       tty_cursor_hidden = 0;
       OUTPUT_IF (TS_cursor_normal);
-      OUTPUT_IF (TS_cursor_visible);
+      if (visible_cursor)
+       OUTPUT_IF (TS_cursor_visible);
     }
 }
 
@@ -817,7 +827,7 @@ encode_terminal_code (src, src_len, coding)
      int src_len;
      struct coding_system *coding;
 {
-  struct glyph *src_start = src, *src_end = src + src_len;
+  struct glyph *src_end = src + src_len;
   register GLYPH g;
   unsigned char *buf;
   int nchars, nbytes, required;
@@ -902,7 +912,7 @@ encode_terminal_code (src, src_len, coding)
   if (SYMBOLP (coding->pre_write_conversion)
       && ! NILP (Ffboundp (coding->pre_write_conversion)))
     {
-      run_pre_write_conversin_on_c_str (&encode_terminal_buf, 
+      run_pre_write_conversin_on_c_str (&encode_terminal_buf,
                                        &encode_terminal_bufsize,
                                        nchars, nbytes, coding);
       nchars = coding->produced_char;
@@ -981,11 +991,13 @@ write_glyphs (string, len)
       conversion_buffer = encode_terminal_code (string, n, coding);
       if (coding->produced > 0)
        {
+         BLOCK_INPUT;
          fwrite (conversion_buffer, 1, coding->produced, stdout);
          if (ferror (stdout))
            clearerr (stdout);
          if (termscript)
            fwrite (conversion_buffer, 1, coding->produced, termscript);
+         UNBLOCK_INPUT;
        }
       len -= n;
       string += n;
@@ -1080,11 +1092,13 @@ insert_glyphs (start, len)
 
       if (coding->produced > 0)
        {
+         BLOCK_INPUT;
          fwrite (conversion_buffer, 1, coding->produced, stdout);
          if (ferror (stdout))
            clearerr (stdout);
          if (termscript)
            fwrite (conversion_buffer, 1, coding->produced, termscript);
+         UNBLOCK_INPUT;
        }
 
       OUTPUT1_IF (TS_pad_inserted_char);
@@ -1625,15 +1639,21 @@ term_get_fkeys_1 ()
                       Character Display Information
  ***********************************************************************/
 
+/* Avoid name clash with functions defined in xterm.c */
+#ifdef static
+#define append_glyph append_glyph_term
+#define produce_stretch_glyph produce_stretch_glyph_term
+#endif
+
 static void append_glyph P_ ((struct it *));
 static void produce_stretch_glyph P_ ((struct it *));
 
 
 /* Append glyphs to IT's glyph_row.  Called from produce_glyphs for
-   terminal frames if IT->glyph_row != NULL.  IT->c is the character
-   for which to produce glyphs; IT->face_id contains the character's
-   face.  Padding glyphs are appended if IT->c has a IT->pixel_width >
-   1.  */
+   terminal frames if IT->glyph_row != NULL.  IT->char_to_display is
+   the character for which to produce glyphs; IT->face_id contains the
+   character's face.  Padding glyphs are appended if IT->c has a
+   IT->pixel_width > 1.  */
 
 static void
 append_glyph (it)
@@ -1653,7 +1673,7 @@ append_glyph (it)
     {
       glyph->type = CHAR_GLYPH;
       glyph->pixel_width = 1;
-      glyph->u.ch = it->c;
+      glyph->u.ch = it->char_to_display;
       glyph->face_id = it->face_id;
       glyph->padding_p = i > 0;
       glyph->charpos = CHARPOS (it->position);
@@ -1704,6 +1724,9 @@ produce_glyphs (it)
   xassert (it->what == IT_CHARACTER
           || it->what == IT_COMPOSITION);
 
+  /* Maybe translate single-byte characters to multibyte.  */
+  it->char_to_display = it->c;
+
   if (it->c >= 040 && it->c < 0177)
     {
       it->pixel_width = it->nglyphs = 1;
@@ -1733,13 +1756,11 @@ produce_glyphs (it)
        {
          int n = nspaces;
 
-         it->c = ' ';
+         it->char_to_display = ' ';
          it->pixel_width = it->len = 1;
 
          while (n--)
            append_glyph (it);
-
-         it->c = '\t';
        }
 
       it->pixel_width = nspaces;
@@ -1747,14 +1768,30 @@ produce_glyphs (it)
     }
   else if (SINGLE_BYTE_CHAR_P (it->c))
     {
-      /* Coming here means that it->c is from display table, thus we
-        must send the code as is to the terminal.  Although there's
-        no way to know how many columns it occupies on a screen, it
-        is a good assumption that a single byte code has 1-column
-        width.  */
-      it->pixel_width = it->nglyphs = 1;
-      if (it->glyph_row)
-       append_glyph (it);
+      if (unibyte_display_via_language_environment
+         && (it->c >= 0240
+             || !NILP (Vnonascii_translation_table)))
+       {
+         int charset;
+
+         it->char_to_display = unibyte_char_to_multibyte (it->c);
+         charset = CHAR_CHARSET (it->char_to_display);
+         it->pixel_width = CHARSET_WIDTH (charset);
+         it->nglyphs = it->pixel_width;
+         if (it->glyph_row)
+           append_glyph (it);
+       }
+      else
+       {
+         /* Coming here means that it->c is from display table, thus we
+            must send the code as is to the terminal.  Although there's
+            no way to know how many columns it occupies on a screen, it
+            is a good assumption that a single byte code has 1-column
+            width.  */
+         it->pixel_width = it->nglyphs = 1;
+         if (it->glyph_row)
+           append_glyph (it);
+       }
     }
   else
     {
@@ -1819,7 +1856,7 @@ produce_stretch_glyph (it)
           && calc_pixel_width_or_height (&tem, it, prop, 0, 1, &align_to))
     {
       if (it->glyph_row == NULL || !it->glyph_row->mode_line_p)
-       align_to = (align_to < 0 
+       align_to = (align_to < 0
                    ? 0
                    : align_to - window_box_left_offset (it->w, TEXT_AREA));
       else if (align_to < 0)
@@ -1839,17 +1876,15 @@ produce_stretch_glyph (it)
       Lisp_Object o_object = it->object;
       Lisp_Object object = it->stack[it->sp - 1].string;
       int n = width;
-      int c = it->c;
 
       if (!STRINGP (object))
        object = it->w->buffer;
       it->object = object;
-      it->c = ' ';
+      it->char_to_display = ' ';
       it->pixel_width = it->len = 1;
       while (n--)
        append_glyph (it);
       it->object = o_object;
-      it->c = c;
     }
   it->pixel_width = width;
   it->nglyphs = width;
@@ -2134,15 +2169,22 @@ DEFUN ("tty-display-color-cells", Ftty_display_color_cells,
 
 #ifndef WINDOWSNT
 
+/* Declare here rather than in the function, as in the rest of Emacs,
+   to work around an HPUX compiler bug (?). See
+   http://lists.gnu.org/archive/html/emacs-devel/2007-08/msg00410.html  */
+static int default_max_colors;
+static int default_max_pairs;
+static int default_no_color_video;
+static char *default_orig_pair;
+static char *default_set_foreground;
+static char *default_set_background;
+
 /* Save or restore the default color-related capabilities of this
    terminal.  */
 static void
 tty_default_color_capabilities (save)
      int save;
 {
-  static char
-    *default_orig_pair, *default_set_foreground, *default_set_background;
-  static int default_max_colors, default_max_pairs, default_no_color_video;
 
   if (save)
     {
@@ -2690,13 +2732,12 @@ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
 
 /* VARARGS 1 */
 void
-fatal (const char *str, ...)
+fatal (str, arg1, arg2)
+     char *str, *arg1, *arg2;
 {
-  va_list ap;
-  va_start (ap, str);
   fprintf (stderr, "emacs: ");
-  vfprintf (stderr, str, ap);
-  va_end (ap);
+  fprintf (stderr, str, arg1, arg2);
+  fprintf (stderr, "\n");
   fflush (stderr);
   exit (1);
 }
@@ -2728,9 +2769,18 @@ This variable can be used by terminal emulator packages.  */);
 The function should accept no arguments.  */);
   Vring_bell_function = Qnil;
 
+  DEFVAR_BOOL ("visible-cursor", &visible_cursor,
+              doc: /* Non-nil means to make the cursor very visible.
+This only has an effect when running in a text terminal.
+What means \"very visible\" is up to your terminal.  It may make the cursor
+bigger, or it may make it blink, or it may do nothing at all.  */);
+  visible_cursor = 1;
+
   defsubr (&Stty_display_color_p);
   defsubr (&Stty_display_color_cells);
   defsubr (&Stty_no_underline);
+
+  fullscreen_hook = NULL;
 }
 
 /* arch-tag: 498e7449-6f2e-45e2-91dd-b7d4ca488193