cleanup in s/darwin.h, define DARWIN_OS and use it instead of DARWIN and/or MAC_OSX...
[bpt/emacs.git] / src / nsterm.m
index c12e342..fd3757b 100644 (file)
@@ -140,10 +140,9 @@ Lisp_Object ns_input_color, ns_input_text, ns_working_text;
 Lisp_Object ns_input_spi_name, ns_input_spi_arg;
 Lisp_Object Vx_toolkit_scroll_bars;
 static Lisp_Object Qmodifier_value;
-/*PENDING: unsure why these defined in term files, anyway we need in keymap.c */
+/* TODO: unsure why these defined in term files, anyway we need in keymap.c */
 Lisp_Object Qalt, Qcontrol, Qhyper, Qmeta, Qsuper;
 extern Lisp_Object Qcursor_color, Qcursor_type, Qns;
-extern int lisp_to_mod (Lisp_Object lmod);
 
 
 EmacsPrefsController *prefsController;
@@ -181,7 +180,7 @@ Lisp_Object ns_cursor_blink_mode;
 Lisp_Object ns_expand_space;
 
 /* Control via default 'GSFontAntiAlias' on OS X and GNUstep. */
-int ns_antialias_text;
+Lisp_Object ns_antialias_text;
 
 /* On OS X picks up the default NSGlobalDomain AppleAntiAliasingThreshold,
    the maximum font size to NOT antialias.  On GNUstep there is currently
@@ -190,17 +189,17 @@ float ns_antialias_threshold;
 
 /* Controls use of an undocumented CG function to do Quickdraw-style font
    smoothing (less heavy) instead of regular Quartz smoothing. */
-int ns_use_qd_smoothing;
+Lisp_Object ns_use_qd_smoothing;
 
 /* Used to pick up AppleHighlightColor on OS X */
-int ns_use_system_highlight_color;
+Lisp_Object ns_use_system_highlight_color;
 NSString *ns_selection_color;
 
 
 NSArray *ns_send_types =0, *ns_return_types =0, *ns_drag_types =0;
 
 /* Display variables */
-struct ns_display_info *ns_display_list; /* Chain of existing displays */
+struct ns_display_info *x_display_list; /* Chain of existing displays */
 Lisp_Object ns_display_name_list;
 long context_menu_value = 0;
 
@@ -216,8 +215,8 @@ static int ns_window_num =0;
 static NSRect uRect;
 static BOOL gsaved = NO;
 BOOL ns_in_resize = NO;
-int ns_tmp_flags; /*PENDING */
-struct nsfont_info *ns_tmp_font; /*PENDING */
+int ns_tmp_flags; /* FIXME */
+struct nsfont_info *ns_tmp_font; /* FIXME */
 /*static int debug_lock = 0; */
 
 #ifdef NS_IMPL_COCOA
@@ -255,15 +254,15 @@ static BOOL inNsSelect = 0;
     ((([e modifierFlags] & NSHelpKeyMask) ?           \
            hyper_modifier : 0)                        \
      | (([e modifierFlags] & NSAlternateKeyMask) ?    \
-           lisp_to_mod (ns_alternate_modifier) : 0)   \
+           parse_solitary_modifier (ns_alternate_modifier) : 0)   \
      | (([e modifierFlags] & NSShiftKeyMask) ?        \
            shift_modifier : 0)                        \
      | (([e modifierFlags] & NSControlKeyMask) ?      \
-           lisp_to_mod (ns_control_modifier) : 0)     \
+           parse_solitary_modifier (ns_control_modifier) : 0)     \
      | (([e modifierFlags] & NS_FUNCTION_KEY_MASK) ?  \
-           lisp_to_mod (ns_function_modifier) : 0)    \
+           parse_solitary_modifier (ns_function_modifier) : 0)    \
      | (([e modifierFlags] & NSCommandKeyMask) ?      \
-           lisp_to_mod (ns_command_modifier):0))
+           parse_solitary_modifier (ns_command_modifier):0))
 
 #define EV_UDMODIFIERS(e)                                      \
     ((([e type] == NSLeftMouseDown) ? down_modifier : 0)       \
@@ -298,13 +297,13 @@ static BOOL inNsSelect = 0;
   ns_send_appdefined (-1);                                    \
   }
 
-/*PENDING: get rid of need for these forward declarations */
+/* TODO: get rid of need for these forward declarations */
 static void ns_condemn_scroll_bars (struct frame *f),
             ns_judge_scroll_bars (struct frame *f);
 
 /* unused variables needed for compatibility reasons */
 int x_use_underline_position_properties, x_underline_at_descent_line;
-/* PENDING: figure out what to do with underline_minimum_offset. */
+/* FIXME: figure out what to do with underline_minimum_offset. */
 
 
 /* ==========================================================================
@@ -368,10 +367,10 @@ ns_init_paths ()
             if (isDir)
               {
                 if ([resourcePaths length] > 0)
-                  resourcePaths =
-                    [resourcePaths stringByAppendingString: pathSeparator];
-                resourcePaths =
-                  [resourcePaths stringByAppendingString: resourcePath];
+                  resourcePaths
+                   = [resourcePaths stringByAppendingString: pathSeparator];
+                resourcePaths
+                 = [resourcePaths stringByAppendingString: resourcePath];
               }
         }
       if ([resourcePaths length] > 0)
@@ -392,10 +391,10 @@ ns_init_paths ()
             if (isDir)
               {
                 if ([resourcePaths length] > 0)
-                  resourcePaths =
-                    [resourcePaths stringByAppendingString: pathSeparator];
-                resourcePaths =
-                  [resourcePaths stringByAppendingString: resourcePath];
+                  resourcePaths
+                   = [resourcePaths stringByAppendingString: pathSeparator];
+                resourcePaths
+                 = [resourcePaths stringByAppendingString: resourcePath];
               }
         }
       if ([resourcePaths length] > 0)
@@ -414,7 +413,6 @@ ns_init_paths ()
         }
     }
 
-  /*PENDING: append to INFOPATH... */
   if (!getenv ("INFOPATH"))
     {
       resourcePath = [resourceDir stringByAppendingPathComponent: @"info"];
@@ -787,7 +785,7 @@ ns_unfocus (struct frame *f)
 
 
 static void
-ns_clip_to_row (struct window *w, struct glyph_row *row, int area, GC gc)
+ns_clip_to_row (struct window *w, struct glyph_row *row, int area, BOOL gc)
 /* --------------------------------------------------------------------------
      23: Internal (but parallels other terms): Focus drawing on given row
    -------------------------------------------------------------------------- */
@@ -848,7 +846,7 @@ ns_ring_bell ()
           r.origin.y += (r.size.height - dim.y) / 2;
           r.size.width = dim.x;
           r.size.height = dim.y;
-          /* PENDING: cacheImageInRect under GNUSTEP does not account for
+          /* XXX: cacheImageInRect under GNUSTEP does not account for
              offset in x_set_window_size, so overestimate (4 fine on Cocoa) */
           surr = NSInsetRect (r, -10, -10);
           ns_focus (frame, &surr, 1);
@@ -945,26 +943,26 @@ ns_frame_rehighlight (struct frame *frame)
    -------------------------------------------------------------------------- */
 {
   struct ns_display_info *dpyinfo = FRAME_NS_DISPLAY_INFO (frame);
-  struct frame *old_highlight = dpyinfo->ns_highlight_frame;
+  struct frame *old_highlight = dpyinfo->x_highlight_frame;
 
   NSTRACE (ns_frame_rehighlight);
-  if (dpyinfo->ns_focus_frame)
+  if (dpyinfo->x_focus_frame)
     {
-      dpyinfo->ns_highlight_frame =
-        (FRAMEP (FRAME_FOCUS_FRAME (dpyinfo->ns_focus_frame))
-           ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo->ns_focus_frame))
-           : dpyinfo->ns_focus_frame);
-      if (!FRAME_LIVE_P (dpyinfo->ns_highlight_frame))
+      dpyinfo->x_highlight_frame
+       = (FRAMEP (FRAME_FOCUS_FRAME (dpyinfo->x_focus_frame))
+           ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo->x_focus_frame))
+           : dpyinfo->x_focus_frame);
+      if (!FRAME_LIVE_P (dpyinfo->x_highlight_frame))
         {
-          FRAME_FOCUS_FRAME (dpyinfo->ns_focus_frame) = Qnil;
-          dpyinfo->ns_highlight_frame = dpyinfo->ns_focus_frame;
+          FRAME_FOCUS_FRAME (dpyinfo->x_focus_frame) = Qnil;
+          dpyinfo->x_highlight_frame = dpyinfo->x_focus_frame;
         }
     }
   else
-      dpyinfo->ns_highlight_frame = 0;
+      dpyinfo->x_highlight_frame = 0;
 
-  if (dpyinfo->ns_highlight_frame &&
-         dpyinfo->ns_highlight_frame != old_highlight)
+  if (dpyinfo->x_highlight_frame &&
+         dpyinfo->x_highlight_frame != old_highlight)
     {
       /* as of 20080602 the lower and raise are superfluous */
       if (old_highlight)
@@ -972,10 +970,10 @@ ns_frame_rehighlight (struct frame *frame)
           /*ns_lower_frame (old_highlight); */
           x_update_cursor (old_highlight, 1);
         }
-      if (dpyinfo->ns_highlight_frame)
+      if (dpyinfo->x_highlight_frame)
         {
-          /*ns_raise_frame (dpyinfo->ns_highlight_frame); */
-          x_update_cursor (dpyinfo->ns_highlight_frame, 1);
+          /*ns_raise_frame (dpyinfo->x_highlight_frame); */
+          x_update_cursor (dpyinfo->x_highlight_frame, 1);
         }
     }
 }
@@ -988,7 +986,7 @@ x_make_frame_visible (struct frame *f)
    -------------------------------------------------------------------------- */
 {
   NSTRACE (x_make_frame_visible);
-  /* PENDING: at some points in past this was not needed, as the only place that
+  /* XXX: at some points in past this was not needed, as the only place that
      called this (frame.c:Fraise_frame ()) also called raise_lower;
      if this ends up the case again, comment this out again. */
   if (!FRAME_VISIBLE_P (f))
@@ -1020,8 +1018,8 @@ x_iconify_frame (struct frame *f)
   NSTRACE (x_iconify_frame);
   check_ns ();
 
-  if (dpyinfo->ns_highlight_frame == f)
-    dpyinfo->ns_highlight_frame = 0;
+  if (dpyinfo->x_highlight_frame == f)
+    dpyinfo->x_highlight_frame = 0;
 
   if ([[view window] windowNumber] <= 0)
     {
@@ -1059,10 +1057,10 @@ x_destroy_window (struct frame *f)
   if (FRAME_FACE_CACHE (f))
     free_frame_faces (f);
 
-  if (f == dpyinfo->ns_focus_frame)
-    dpyinfo->ns_focus_frame = 0;
-  if (f == dpyinfo->ns_highlight_frame)
-    dpyinfo->ns_highlight_frame = 0;
+  if (f == dpyinfo->x_focus_frame)
+    dpyinfo->x_focus_frame = 0;
+  if (f == dpyinfo->x_highlight_frame)
+    dpyinfo->x_highlight_frame = 0;
   if (f == dpyinfo->mouse_face_mouse_frame)
     {
       dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1;
@@ -1159,13 +1157,13 @@ x_set_window_size (struct frame *f, int change_grav, int cols, int rows)
   
   /* If we have a change in toolbar display, calculate height */
   if (tb)
-    /* PENDING: GNUstep has not yet implemented the first method below, added
-                in Panther, however the second is incorrect under Cocoa. */
+    /* XXX: GNUstep has not yet implemented the first method below, added
+           in Panther, however the second is incorrect under Cocoa. */
 #ifdef NS_IMPL_GNUSTEP
-    FRAME_NS_TOOLBAR_HEIGHT (f) =
-      NSHeight ([NSWindow frameRectForContentRect: NSMakeRect (0, 0, 0, 0)
-                                       styleMask: [window styleMask]])
-          - FRAME_NS_TITLEBAR_HEIGHT (f);
+    FRAME_NS_TOOLBAR_HEIGHT (f)
+      NSHeight ([NSWindow frameRectForContentRect: NSMakeRect (0, 0, 0, 0)
+                           styleMask: [window styleMask]])
+        - FRAME_NS_TITLEBAR_HEIGHT (f);
 #else
     FRAME_NS_TOOLBAR_HEIGHT (f) = 32;
       /* actually get wrong result here if toolbar not yet displayed
@@ -1261,8 +1259,8 @@ ns_index_color (NSColor *color, struct frame *f)
     {
       color_table->size = NS_COLOR_CAPACITY;
       color_table->avail = 1; /* skip idx=0 as marker */
-      color_table->colors =
-        (NSColor **)xmalloc (color_table->size * sizeof (NSColor *));
+      color_table->colors
+       = (NSColor **)xmalloc (color_table->size * sizeof (NSColor *));
       color_table->empty_indices = [[NSMutableSet alloc] init];
     }
 
@@ -1290,9 +1288,9 @@ ns_index_color (NSColor *color, struct frame *f)
       if (color_table->avail == color_table->size)
         {
           color_table->size += NS_COLOR_CAPACITY;
-          color_table->colors = 
-            (NSColor **)xrealloc (color_table->colors,
-                                  color_table->size * sizeof (NSColor *));
+          color_table->colors
+           = (NSColor **)xrealloc (color_table->colors,
+                                   color_table->size * sizeof (NSColor *));
         }
       idx = color_table->avail++;
       index = [NSNumber numberWithUnsignedInt: idx];
@@ -1329,7 +1327,8 @@ ns_get_color (const char *name, NSColor **col)
    of colors found in the file Emacs.clr. Color formats include:
    - #rrggbb or RGBrrggbb where rr, gg, bb specify red, green and blue in hex
    - ARGBaarrggbb is similar, with aa being the alpha channel (FF = opaque)
-   - HSVhhssvv and AHSVaahhssvv are similar for hue, saturation, value
+   - HSVhhssvv and AHSVaahhssvv (or HSB/AHSB) are similar for hue, saturation,
+     value;
    - CMYKccmmyykk is similar for cyan, magenta, yellow, black. */
 {
   NSColor * new = nil;
@@ -1359,9 +1358,9 @@ ns_get_color (const char *name, NSColor **col)
       return 0;
     }
 
-  /* 23: PENDING: emacs seems to downcase everything before passing it here,
-     which we can work around, except for GRAY, since gray##, where ## is
-     decimal between 0 and 99, is also an X11 colorname. */
+  /* 23: FIXME: emacs seems to downcase everything before passing it here,
+      which we can work around, except for GRAY, since gray##, where ## is
+      decimal between 0 and 99, is also an X11 colorname. */
   if (name[0] == '#')             /* X11 format */
     {
       hex = name + 1;
@@ -1377,12 +1376,14 @@ ns_get_color (const char *name, NSColor **col)
       hex = name + 4;
       color_space = argb;
     }
-  else if (!memcmp (name, "HSV", 3) || !memcmp (name, "hsv", 3))
+  else if (!memcmp (name, "HSV", 3) || !memcmp (name, "hsv", 3) || 
+           !memcmp (name, "HSB", 3) || !memcmp (name, "hsb", 3))
     {
       hex = name + 3;
       color_space = hsv;
     }
-  else if (!memcmp (name, "AHSV", 4) || !memcmp (name, "ahsv", 4))
+  else if (!memcmp (name, "AHSV", 4) || !memcmp (name, "ahsv", 4) ||
+           !memcmp (name, "AHSB", 4) || !memcmp (name, "ahsb", 4))
     {
       hex = name + 4;
       color_space = ahsv;
@@ -1457,17 +1458,13 @@ ns_get_color (const char *name, NSColor **col)
     NSEnumerator *lenum, *cenum;
     NSString *name;
     NSColorList *clist;
+
 #ifdef NS_IMPL_GNUSTEP
-    /* PENDING: who is wrong, the requestor or the implementation? */
+    /* XXX: who is wrong, the requestor or the implementation? */
     if ([nsname compare: @"Highlight" options: NSCaseInsensitiveSearch]
         == NSOrderedSame)
       nsname = @"highlightColor";
 #endif
-    if ([nsname compare: @"dark blue" options: NSCaseInsensitiveSearch]
-        == NSOrderedSame
-      || [nsname compare: @"darkblue" options: NSCaseInsensitiveSearch]
-        == NSOrderedSame)
-      nsname = @"navy blue";
 
     lenum = [[NSColorList availableColorLists] objectEnumerator];
     while ( (clist = [lenum nextObject]) && new == nil)
@@ -1513,10 +1510,10 @@ ns_lisp_to_color (Lisp_Object color, NSColor **col)
    -------------------------------------------------------------------------- */
 {
   NSTRACE (ns_lisp_to_color);
-  if (XTYPE (color) == Lisp_String)
-    return ns_get_color (XSTRING (color)->data, col);
-  else if (XTYPE (color) == Lisp_Symbol)
-    return ns_get_color (XSTRING (XSYMBOL (color)->xname)->data, col);
+  if (STRINGP (color))
+    return ns_get_color (SDATA (color), col);
+  else if (SYMBOLP (color))
+    return ns_get_color (SDATA (SYMBOL_NAME (color)), col);
   return 1;
 }
 
@@ -1583,7 +1580,7 @@ ns_defined_color (struct frame *f, char *name, XColor *color_def, int alloc,
     return 0;
 
   if (makeIndex && alloc)
-      color_def->pixel = ns_index_color(temp, f);//[temp retain];
+      color_def->pixel = ns_index_color(temp, f); /* [temp retain]; */
 
   [temp getRed: &r green: &g blue: &b alpha: &a];
   color_def->red   = r * 256;
@@ -1591,9 +1588,9 @@ ns_defined_color (struct frame *f, char *name, XColor *color_def, int alloc,
   color_def->blue  = b * 256;
 
   if (!makeIndex)
-    color_def->pixel =
-      ARGB_TO_ULONG((int)(a*256),
-                    color_def->red, color_def->green, color_def->blue);
+    color_def->pixel
+      ARGB_TO_ULONG((int)(a*256),
+                     color_def->red, color_def->green, color_def->blue);
 
   return 1;
 }
@@ -1636,7 +1633,7 @@ x_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y)
   NSTRACE (x_set_mouse_pixel_position);
   ns_raise_frame (f);
 #if 0
-  /*PENDING: this does not work, and what about GNUstep? */
+  /* FIXME: this does not work, and what about GNUstep? */
 #ifdef NS_IMPL_COCOA
   [FRAME_NS_VIEW (f) lockFocus];
   PSsetmouse ((float)pix_x, (float)pix_y);
@@ -1730,8 +1727,8 @@ ns_mouse_position (struct frame **fp, int insist, Lisp_Object *bar_window,
 
   if (last_mouse_scroll_bar != nil && insist == 0)
     {
-      /* PENDING: we do not use this path at the moment because drag events will
-         go directly to the EmacsScroller.  Leaving code in for now. */
+      /* TODO: we do not use this path at the moment because drag events will
+           go directly to the EmacsScroller.  Leaving code in for now. */
       [last_mouse_scroll_bar getMouseMotionPart: (int *)part window: bar_window
                                               x: x y: y];
       if (time) *time = last_mouse_movement_time;
@@ -1749,10 +1746,10 @@ ns_mouse_position (struct frame **fp, int insist, Lisp_Object *bar_window,
       if (last_mouse_frame && FRAME_LIVE_P (last_mouse_frame))
         f = last_mouse_frame;
       else
-        f = dpyinfo->ns_focus_frame ? dpyinfo->ns_focus_frame
+        f = dpyinfo->x_focus_frame ? dpyinfo->x_focus_frame
                                     : SELECTED_FRAME ();
 
-      if (f && f->output_data.ns)  /*PENDING: 2nd check no longer needed? */
+      if (f && f->output_data.ns)  /* TODO: 2nd check no longer needed? */
         {
           view = FRAME_NS_VIEW (*fp);
 
@@ -1946,8 +1943,8 @@ ns_clear_frame_area (struct frame *f, int x, int y, int width, int height)
   {
     /* clip out the resize handle */
     NSWindow *window = [FRAME_NS_VIEW (f) window];
-    NSRect ir =
-      [view convertRect: ns_resize_handle_rect (window) fromView: nil];
+    NSRect ir
+      [view convertRect: ns_resize_handle_rect (window) fromView: nil];
 
     ir = NSIntersectionRect (r, ir);
     if (NSIsEmptyRect (ir))
@@ -2138,8 +2135,9 @@ ns_compute_glyph_string_overhangs (struct glyph_string *s)
 
       font->driver->text_extents (font, codes, 2, &metrics);
       s->left_overhang = -metrics.lbearing;
-      s->right_overhang =
-        metrics.rbearing > metrics.width ? metrics.rbearing - metrics.width : 0;
+      s->right_overhang
+       = metrics.rbearing > metrics.width
+       ? metrics.rbearing - metrics.width : 0;
     }
   else
     {
@@ -2174,11 +2172,11 @@ ns_draw_fringe_bitmap (struct window *w, struct glyph_row *row,
   /* NS-specific: move internal border inside fringe */
   int x = p->bx < 0 ? p->x : p->bx;
   int wd = p->bx < 0 ? p->wd : p->nx;
-  BOOL fringeOnVeryLeft =
-      x - WINDOW_LEFT_SCROLL_BAR_COLS (w) * WINDOW_FRAME_COLUMN_WIDTH (w)
+  BOOL fringeOnVeryLeft
+    = x - WINDOW_LEFT_SCROLL_BAR_COLS (w) * WINDOW_FRAME_COLUMN_WIDTH (w)
       - FRAME_INTERNAL_BORDER_WIDTH (f) < 10;
-  BOOL fringeOnVeryRight =
-      FRAME_PIXEL_WIDTH (f) - x - wd - FRAME_INTERNAL_BORDER_WIDTH (f)
+  BOOL fringeOnVeryRight
+    = FRAME_PIXEL_WIDTH (f) - x - wd - FRAME_INTERNAL_BORDER_WIDTH (f)
       - WINDOW_RIGHT_SCROLL_BAR_COLS (w) * WINDOW_FRAME_COLUMN_WIDTH (w) < 10;
   int xAdjust = FRAME_INTERNAL_BORDER_WIDTH (f) *
     (fringeOnVeryLeft ? -1 : (fringeOnVeryRight ? 1 : 0));
@@ -2186,8 +2184,8 @@ ns_draw_fringe_bitmap (struct window *w, struct glyph_row *row,
   /* grow bimgs if needed */
   if (nBimgs < max_used_fringe_bitmap)
     {
-      EmacsImage **newBimgs =
-        xmalloc (max_used_fringe_bitmap * sizeof (EmacsImage *));
+      EmacsImage **newBimgs
+       = xmalloc (max_used_fringe_bitmap * sizeof (EmacsImage *));
       bzero (newBimgs, max_used_fringe_bitmap * sizeof (EmacsImage *));
 
       if (nBimgs)
@@ -2210,7 +2208,7 @@ ns_draw_fringe_bitmap (struct window *w, struct glyph_row *row,
       int oldVH = row->visible_height;
       row->visible_height = p->h;
       row->y -= rowY - p->y;
-      ns_clip_to_row (w, row, -1, NULL);
+      ns_clip_to_row (w, row, -1, NO);
       row->y = oldY;
       row->visible_height = oldVH;
     }
@@ -2311,7 +2309,7 @@ ns_draw_window_cursor (struct window *w, struct glyph_row *glyph_row,
   r.size.height = h;
   r.size.width = w->phys_cursor_width;
 
-  /* PENDING: if we overwrite the internal border area, it does not get erased;
+  /* FIXME: if we overwrite the internal border area, it does not get erased;
      fix by truncating cursor, but better would be to erase properly */
   overspill = r.origin.x + r.size.width -
     WINDOW_TEXT_TO_FRAME_PIXEL_X (w, WINDOW_BOX_RIGHT_EDGE_X (w) 
@@ -2319,15 +2317,15 @@ ns_draw_window_cursor (struct window *w, struct glyph_row *glyph_row,
   if (overspill > 0)
     r.size.width -= overspill;
 
-  /* PENDING: 23: use emacs stored f->cursor_type instead of ns-specific */
+  /* TODO: 23: use emacs stored f->cursor_type instead of ns-specific */
   oldCursorType = FRAME_CURSOR (f);
   cursorType = FRAME_CURSOR (f) = FRAME_NEW_CURSOR (f);
-  f->output_data.ns->current_cursor_color =
-     f->output_data.ns->desired_cursor_color;
+  f->output_data.ns->current_cursor_color
+    = f->output_data.ns->desired_cursor_color;
 
-  /* PENDING: only needed in rare cases with last-resort font in HELLO..
+  /* TODO: only needed in rare cases with last-resort font in HELLO..
      should we do this more efficiently? */
-  ns_clip_to_row (w, glyph_row, -1, NULL);
+  ns_clip_to_row (w, glyph_row, -1, NO);
 /*  ns_focus (f, &r, 1); */
 
   if (FRAME_LAST_INACTIVE (f))
@@ -2419,7 +2417,7 @@ show_hourglass (struct atimer *timer)
 
   BLOCK_INPUT;
 
-  /*PENDING: add NSProgressIndicator to selected frame (see macfns.c) */
+  /* TODO: add NSProgressIndicator to selected frame (see macfns.c) */
 
   hourglass_shown_p = 1;
   UNBLOCK_INPUT;
@@ -2432,7 +2430,9 @@ hide_hourglass ()
   if (!hourglass_shown_p)
     return;
 
-  /*PENDING: remove NSProgressIndicator from all frames */
+  BLOCK_INPUT;
+
+  /* TODO: remove NSProgressIndicator from all frames */
 
   hourglass_shown_p = 0;
   UNBLOCK_INPUT;
@@ -2560,7 +2560,7 @@ ns_draw_relief (NSRect r, int thickness, char raised_p,
   if (newBaseCol == nil)
     newBaseCol = [NSColor grayColor];
 
-  if (newBaseCol != baseCol)  /* PENDING: better check */
+  if (newBaseCol != baseCol)  /* TODO: better check */
     {
       [baseCol release];
       baseCol = [newBaseCol retain];
@@ -2692,7 +2692,7 @@ ns_maybe_dumpglyphs_background (struct glyph_string *s, char force_p)
           else
             face = FACE_FROM_ID (s->f, s->first_glyph->face_id);
           if (!face->stipple)
-            [(NS_FACE_BACKGROUND (face) != nil
+            [(NS_FACE_BACKGROUND (face) != 0
               ? ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), s->f)
               : FRAME_BACKGROUND_COLOR (s->f)) set];
           else
@@ -2840,7 +2840,7 @@ ns_draw_glyph_string (struct glyph_string *s)
       External (RIF): Main draw-text call.
    -------------------------------------------------------------------------- */
 {
-  /*PENDING (optimize): focus for box and contents draw */
+  /* TODO (optimize): focus for box and contents draw */
   NSRect r[2];
   int n;
   char box_drawn_p = 0;
@@ -2891,11 +2891,11 @@ ns_draw_glyph_string (struct glyph_string *s)
                                     - WINDOW_RIGHT_FRINGE_WIDTH (s->w)));
               r[0].size.width -= overrun;
 
-              /* PENDING: Try to work between problem where a stretch glyph on
-                 a partially-visible bottom row will clear part of the
-                 modeline, and another where list-buffers headers and similar
-                 rows erroneously have visible_height set to 0.  Not sure
-                 where this is coming from as other terms seem not to show. */
+              /* XXX: Try to work between problem where a stretch glyph on
+                  a partially-visible bottom row will clear part of the
+                  modeline, and another where list-buffers headers and similar
+                  rows erroneously have visible_height set to 0.  Not sure
+                  where this is coming from as other terms seem not to show. */
               r[0].size.height = min (s->height, s->row->visible_height);
             }
 
@@ -2939,8 +2939,8 @@ ns_draw_glyph_string (struct glyph_string *s)
                      (s->for_overlaps ? NS_DUMPGLYPH_FOREGROUND :
                       NS_DUMPGLYPH_NORMAL));
       ns_tmp_font = (struct nsfont_info *)s->face->font;
-      if (ns_tmp_font == ~0 || ns_tmp_font == NULL)
-          ns_tmp_font = FRAME_FONT (s->f);
+      if (ns_tmp_font == NULL)
+          ns_tmp_font = (struct nsfont_info *)FRAME_FONT (s->f);
 
       ns_tmp_font->font.driver->draw
         (s, 0, s->nchars, s->x, s->y,
@@ -3074,8 +3074,9 @@ ns_read_socket (struct terminal *terminal, int expected,
     }
   /* Deal with pending service requests. */
   else if (ns_pending_service_names && [ns_pending_service_names count] != 0
-    && [NSApp fulfillService: [ns_pending_service_names objectAtIndex: 0]
-                     withArg: [ns_pending_service_args objectAtIndex: 0]])
+    && [(EmacsApp *)
+         NSApp fulfillService: [ns_pending_service_names objectAtIndex: 0]
+                      withArg: [ns_pending_service_args objectAtIndex: 0]])
     {
       [ns_pending_service_names removeObjectAtIndex: 0];
       [ns_pending_service_args removeObjectAtIndex: 0];
@@ -3086,7 +3087,7 @@ ns_read_socket (struct terminal *terminal, int expected,
          to ourself, otherwise [NXApp run] will never exit.  */
       send_appdefined = YES;
 
-      /*PENDING: from termhooks.h: */
+      /* TODO: from termhooks.h: */
       /* XXX Please note that a non-zero value of EXPECTED only means that
      there is available input on at least one of the currently opened
      terminal devices -- but not necessarily on this device.
@@ -3187,16 +3188,16 @@ ns_select (int nfds, fd_set *readfds, fd_set *writefds,
     {
       if (NUMBERP (ns_cursor_blink_rate))
           ns_cursor_blink_rate = Qnil;
-      struct ns_display_info *dpyinfo = ns_display_list; /* HACK */
+      struct ns_display_info *dpyinfo = x_display_list; /* HACK */
       [cursor_blink_entry invalidate];
       [cursor_blink_entry release];
       cursor_blink_entry = 0;
-      if (dpyinfo->ns_highlight_frame)
+      if (dpyinfo->x_highlight_frame)
         {
-          Lisp_Object tem = 
-            get_frame_param (dpyinfo->ns_highlight_frame, Qcursor_type);
-          dpyinfo->ns_highlight_frame->output_data.ns->desired_cursor =
-            ns_lisp_to_cursor_type (tem);
+          Lisp_Object tem
+           = get_frame_param (dpyinfo->x_highlight_frame, Qcursor_type);
+          dpyinfo->x_highlight_frame->output_data.ns->desired_cursor
+           = ns_lisp_to_cursor_type (tem);
         }
     }
 
@@ -3433,7 +3434,7 @@ x_wm_set_icon_position (struct frame *f, int icon_x, int icon_y)
 
    ========================================================================== */
 
-static Lisp_Object ns_string_to_lispmod (char *s)
+static Lisp_Object ns_string_to_lispmod (const char *s)
 /* --------------------------------------------------------------------------
      Convert modifier name to lisp symbol
    -------------------------------------------------------------------------- */
@@ -3488,10 +3489,10 @@ ns_set_default_prefs ()
   ns_cursor_blink_rate = Qnil;
   ns_cursor_blink_mode = Qnil;
   ns_expand_space = make_float (0.0);
-  ns_antialias_text = YES;
-  ns_antialias_threshold = 10.0;
-  ns_use_qd_smoothing = NO;
-  ns_use_system_highlight_color = YES;
+  ns_antialias_text = Qt;
+  ns_antialias_threshold = 10.0; /* not exposed to lisp side */
+  ns_use_qd_smoothing = Qnil;
+  ns_use_system_highlight_color = Qt;
 }
 
 
@@ -3544,8 +3545,8 @@ ns_initialize_display_info (struct ns_display_info *dpyinfo)
                                                  NSColorSpaceFromDepth (depth)];
     dpyinfo->n_planes = NSBitsPerPixelFromDepth (depth);
     dpyinfo->image_cache = make_image_cache ();
-    dpyinfo->color_table =
-      (struct ns_color_table *)xmalloc (sizeof (struct ns_color_table));
+    dpyinfo->color_table
+      (struct ns_color_table *)xmalloc (sizeof (struct ns_color_table));
     dpyinfo->color_table->colors = NULL;
     dpyinfo->root_window = 42; /* a placeholder.. */
 
@@ -3560,7 +3561,7 @@ ns_initialize_display_info (struct ns_display_info *dpyinfo)
     dpyinfo->mouse_face_mouse_x = dpyinfo->mouse_face_mouse_y = 0;
     dpyinfo->mouse_face_defer = 0;
 
-    dpyinfo->ns_highlight_frame = dpyinfo->ns_focus_frame = NULL;
+    dpyinfo->x_highlight_frame = dpyinfo->x_focus_frame = NULL;
 
     dpyinfo->n_fonts = 0;
     dpyinfo->smallest_font_height = 1;
@@ -3593,7 +3594,7 @@ static struct redisplay_interface ns_redisplay_interface =
   x_get_glyph_overhangs, /*23: generic OK */
   x_fix_overlapping_area, /*generic OK */
   ns_draw_fringe_bitmap, /*23 */
-  0, /* define_fringe_bitmap */ /*PENDING: simplify ns_draw_fringe_bitmap? */
+  0, /* define_fringe_bitmap */ /* FIXME: simplify ns_draw_fringe_bitmap */
   0, /* destroy_fringe_bitmap */
   ns_compute_glyph_string_overhangs, /*23 */
   ns_draw_glyph_string, /*23: interface to nsfont.m */
@@ -3608,7 +3609,7 @@ static struct redisplay_interface ns_redisplay_interface =
 static void
 ns_delete_display (struct ns_display_info *dpyinfo)
 {
-  /*PENDING... */
+  /* TODO... */
 }
 
 
@@ -3714,7 +3715,7 @@ ns_term_init (Lisp_Object display_name)
   /* count object allocs (About, click icon); on OS X use ObjectAlloc tool */
   /*GSDebugAllocationActive (YES); */
   BLOCK_INPUT;
-handling_signal = 0;
+  handling_signal = 0;
 
   if (!ns_initialized)
     {
@@ -3757,8 +3758,8 @@ handling_signal = 0;
     current_kboard = terminal->kboard;
   terminal->kboard->reference_count++;
 
-  dpyinfo->next = ns_display_list;
-  ns_display_list = dpyinfo;
+  dpyinfo->next = x_display_list;
+  x_display_list = dpyinfo;
 
   /* Put it on ns_display_name_list */
   ns_display_name_list = Fcons (Fcons (display_name, Qnil),
@@ -3800,16 +3801,16 @@ handling_signal = 0;
   ns_default ("ExpandSpace", &ns_expand_space,
              make_float (0.5), make_float (0.0), YES, NO);
   ns_default ("GSFontAntiAlias", &ns_antialias_text,
-             YES, NO, NO, NO);
+             Qt, Qnil, NO, NO);
   tmp = Qnil;
   ns_default ("AppleAntiAliasingThreshold", &tmp,
              make_float (10.0), make_float (6.0), YES, NO);
   ns_antialias_threshold = NILP (tmp) ? 10.0 : XFLOATINT (tmp);
   ns_default ("UseQuickdrawSmoothing", &ns_use_qd_smoothing,
-             YES, NO, NO, NO);
+             Qt, Qnil, NO, NO);
   ns_default ("UseSystemHighlightColor", &ns_use_system_highlight_color,
-             YES, NO, NO, NO);
-  if (ns_use_system_highlight_color == YES)
+             Qt, Qnil, NO, NO);
+  if (EQ (ns_use_system_highlight_color, Qt))
     {
       ns_selection_color = [[NSUserDefaults standardUserDefaults]
                                stringForKey: @"AppleHighlightColor"];
@@ -3820,37 +3821,37 @@ handling_signal = 0;
     ns_selection_color = NS_SELECTION_COLOR_DEFAULT;
 
   {
-    id cl;
-    Lisp_Object tem, tem1;
-    extern Lisp_Object Vsource_directory;
-
-    cl = [NSColorList colorListNamed: @"Emacs"];
+    NSColorList *cl = [NSColorList colorListNamed: @"Emacs"];
 
     if ( cl == nil )
       {
-        /* first try data_dir, then invocation-dir
-           and finally source-directory/etc */
-        tem1 = tem =
-          Fexpand_file_name (build_string ("Emacs.clr"), Vdata_directory);
-        if (NILP (Ffile_exists_p (tem)))
+        Lisp_Object color_file, color_map, color;
+        int r,g,b;
+        unsigned long c;
+        char *name;
+
+        color_file = Fexpand_file_name (build_string ("rgb.txt"),
+                         Fsymbol_value (intern ("data-directory")));
+        if (NILP (Ffile_readable_p (color_file)))
+          fatal ("Could not find %s.\n", SDATA (color_file));
+
+        color_map = Fx_load_color_file (color_file);
+        if (NILP (color_map))
+          fatal ("Could not read %s.\n", SDATA (color_file));
+
+        cl = [[NSColorList alloc] initWithName: @"Emacs"];
+        for ( ; CONSP (color_map); color_map = XCDR (color_map))
           {
-            tem = Fexpand_file_name (build_string ("Emacs.clr"),
-                                     Vinvocation_directory);
-            if (NILP (Ffile_exists_p (tem)))
-              {
-                Lisp_Object newdir =
-                  Fexpand_file_name (build_string ("etc/"),
-                                     Vsource_directory);
-                tem = Fexpand_file_name (build_string ("Emacs.clr"),
-                                         newdir);
-              }
+            color = XCAR (color_map);
+            name = SDATA (XCAR (color));
+            c = XINT (XCDR (color));
+            [cl setColor:
+                  [NSColor colorWithCalibratedRed: RED_FROM_ULONG (c) / 255.0
+                                            green: GREEN_FROM_ULONG (c) / 255.0
+                                             blue: BLUE_FROM_ULONG (c) / 255.0
+                                            alpha: 1.0]
+                  forKey: [NSString stringWithUTF8String: name]];
           }
-
-        cl = [[NSColorList alloc]
-               initWithName: @"Emacs"
-                   fromFile: [NSString stringWithCString: XSTRING (tem)->data]];
-        if (cl ==nil)
-          fatal ("Could not find %s.\n", XSTRING (tem1)->data);
         [cl writeToFile: nil];
       }
   }
@@ -3872,7 +3873,7 @@ handling_signal = 0;
 #ifdef NS_IMPL_COCOA
   {
     NSMenu *appMenu;
-    id<NSMenuItem> item;
+    NSMenuItem *item;
     /* set up the application menu */
     svcsMenu = [[EmacsMenu alloc] initWithTitle: @"Services"];
     [svcsMenu setAutoenablesItems: NO];
@@ -3938,159 +3939,13 @@ ns_term_shutdown (int sig)
 {
   /* code not reached in emacs.c after this is called by shut_down_emacs: */
   if (STRINGP (Vauto_save_list_file_name))
-    unlink (XSTRING (Vauto_save_list_file_name)->data);
+    unlink (SDATA (Vauto_save_list_file_name));
 
   ns_shutdown_properly = YES;
   [NSApp terminate: NSApp];
 }
 
 
-void
-syms_of_nsterm ()
-{
-  NSTRACE (syms_of_nsterm);
-  DEFVAR_LISP ("ns-input-file", &ns_input_file,
-              "The file specified in the last NS event.");
-  ns_input_file =Qnil;
-
-  DEFVAR_LISP ("ns-input-text", &ns_input_text,
-              "The data received in the last NS text drag event.");
-  ns_input_text =Qnil;
-
-  DEFVAR_LISP ("ns-working-text", &ns_working_text,
-              "String for visualizing working composition sequence.");
-  ns_working_text =Qnil;
-
-  DEFVAR_LISP ("ns-input-font", &ns_input_font,
-              "The font specified in the last NS event.");
-  ns_input_font =Qnil;
-
-  DEFVAR_LISP ("ns-input-fontsize", &ns_input_fontsize,
-              "The fontsize specified in the last NS event.");
-  ns_input_fontsize =Qnil;
-
-  DEFVAR_LISP ("ns-input-line", &ns_input_line,
-               "The line specified in the last NS event.");
-  ns_input_line =Qnil;
-
-  DEFVAR_LISP ("ns-input-color", &ns_input_color,
-               "The color specified in the last NS event.");
-  ns_input_color =Qnil;
-
-  DEFVAR_LISP ("ns-input-spi-name", &ns_input_spi_name,
-               "The service name specified in the last NS event.");
-  ns_input_spi_name =Qnil;
-
-  DEFVAR_LISP ("ns-input-spi-arg", &ns_input_spi_arg,
-               "The service argument specified in the last NS event.");
-  ns_input_spi_arg =Qnil;
-
-  DEFVAR_LISP ("ns-alternate-modifier", &ns_alternate_modifier,
-               "This variable describes the behavior of the alternate or option key.\n\
-Set to control, meta, alt, super, or hyper means it is taken to be that key.\n\
-Set to none means that the alternate / option key is not interpreted by Emacs\n\
-at all, allowing it to be used at a lower level for accented character entry.");
-
-  DEFVAR_LISP ("ns-command-modifier", &ns_command_modifier,
-               "This variable describes the behavior of the command key.\n\
-Set to control, meta, alt, super, or hyper means it is taken to be that key.");
-
-  DEFVAR_LISP ("ns-control-modifier", &ns_control_modifier,
-               "This variable describes the behavior of the control key.\n\
-Set to control, meta, alt, super, or hyper means it is taken to be that key.");
-
-  DEFVAR_LISP ("ns-function-modifier", &ns_function_modifier,
-               "This variable describes the behavior of the function key (on laptops).\n\
-Set to control, meta, alt, super, or hyper means it is taken to be that key.\n\
-Set to none means that the function key is not interpreted by Emacs at all,\n\
-allowing it to be used at a lower level for accented character entry.");
-
-  DEFVAR_LISP ("ns-cursor-blink-rate", &ns_cursor_blink_rate,
-               "Rate at which the Emacs cursor blinks (in seconds).\n\
-Set to nil to disable blinking.");
-
-  DEFVAR_LISP ("ns-cursor-blink-mode", &ns_cursor_blink_mode,
-               "Internal variable -- use M-x blink-cursor-mode or preferences\n\
-panel to control this setting.");
-
-  DEFVAR_LISP ("ns-expand-space", &ns_expand_space,
-               "Amount by which spacing between lines is expanded (positive)\n\
-or shrunk (negative).  Zero (the default) means standard line height.\n\
-(This variable should only be read, never set.)");
-
-  DEFVAR_BOOL ("ns-antialias-text", &ns_antialias_text,
-               "Non-nil (the default) means to render text antialiased. Only has an effect on OS X Panther and above.");
-
-  DEFVAR_BOOL ("ns-use-qd-smoothing", &ns_use_qd_smoothing,
-               "Whether to render text using QuickDraw (less heavy) antialiasing. Only has an effect on OS X Panther and above.  Default is nil (use Quartz smoothing).");
-
-  DEFVAR_BOOL ("ns-use-system-highlight-color",
-               &ns_use_system_highlight_color,
-               "Whether to use the system default (on OS X only) for the highlight color.  Nil means to use standard emacs (prior to version 21) 'grey'.");
-
-  staticpro (&ns_display_name_list);
-  ns_display_name_list = Qnil;
-
-  staticpro (&last_mouse_motion_frame);
-  last_mouse_motion_frame = Qnil;
-
-/*23: now apparently we need to tell emacs what modifiers there are.. */
-  Qmodifier_value = intern ("modifier-value");
-  Qalt = intern ("alt");
-  Fput (Qalt, Qmodifier_value, make_number (alt_modifier));
-  Qhyper = intern ("hyper");
-  Fput (Qhyper, Qmodifier_value, make_number (hyper_modifier));
-  Qmeta = intern ("meta");
-  Fput (Qmeta, Qmodifier_value, make_number (meta_modifier));
-  Qsuper = intern ("super");
-  Fput (Qsuper, Qmodifier_value, make_number (super_modifier));
-  Qcontrol = intern ("control");
-  Fput (Qcontrol, Qmodifier_value, make_number (ctrl_modifier));
-
-  /*PENDING: move to common code */
-  DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars,
-              doc: /* If not nil, Emacs uses toolkit scroll bars.  */);
-#ifdef USE_TOOLKIT_SCROLL_BARS
-  Vx_toolkit_scroll_bars = Qt; 
-#else
-  Vx_toolkit_scroll_bars = Qnil;
-#endif
-
-  /* these are unsupported but we need the declarations to avoid whining
-     messages from cus-start.el */
-  DEFVAR_BOOL ("x-use-underline-position-properties",
-              &x_use_underline_position_properties,
-     doc: /* NOT SUPPORTED UNDER NS.
-*Non-nil means make use of UNDERLINE_POSITION font properties.
-A value of nil means ignore them.  If you encounter fonts with bogus
-UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
-to 4.1, set this to nil.
-
-NOTE: Not supported on Mac yet.  */);
-  x_use_underline_position_properties = 0;
-
-  DEFVAR_BOOL ("x-underline-at-descent-line",
-              &x_underline_at_descent_line,
-     doc: /* NOT SUPPORTED UNDER NS.
-*Non-nil means to draw the underline at the same place as the descent line.
-A value of nil means to draw the underline according to the value of the
-variable `x-use-underline-position-properties', which is usually at the
-baseline level.  The default value is nil.  */);
-  x_underline_at_descent_line = 0;
-
-  /* Tell emacs about this window system. */
-  Fprovide (intern ("ns-windowing"), Qnil);
-  /* PENDING: try to move this back into lisp (ns-win.el loaded too late
-              right now */
-  {
-    Lisp_Object args[3] = { intern ("ns-version-string"), build_string ("9.0"),
-                    build_string ("NS Window system port version number.") };
-    Fdefconst (Flist (3, args));
-  }
-}
-
-
-
 /* ==========================================================================
 
     EmacsApp implementation
@@ -4171,6 +4026,26 @@ baseline level.  The default value is nil.  */);
 }
 
 
+/* Open a file (used by below, after going into queue read by ns_read_socket) */
+- (BOOL) openFile: (NSString *)fileName
+{
+  struct frame *emacsframe = SELECTED_FRAME ();
+  NSEvent *theEvent = [NSApp currentEvent];
+
+  if (!emacs_event)
+    return NO;
+
+  emacs_event->kind = NON_ASCII_KEYSTROKE_EVENT;
+  emacs_event->code = KEY_NS_OPEN_FILE_LINE;
+  ns_input_file = append2 (ns_input_file, build_string ([fileName UTF8String]));
+  ns_input_line = Qnil; /* can be start or cons start,end */
+  emacs_event->modifiers =0;
+  EV_TRAILER (theEvent);
+
+  return YES;
+}
+
+
 /* **************************************************************************
 
       EmacsApp delegate implementation
@@ -4212,8 +4087,8 @@ baseline level.  The default value is nil.  */);
       Fcons (build_string ("Cancel"), Qnil),
       Fcons (build_string ("Save and Exit"), Qt));
   Lisp_Object res = ns_popup_dialog (Qt, contents, Qnil);
-fprintf (stderr, "res = %d\n", res ==Qt);
-  if (res == Qt)
+fprintf (stderr, "res = %d\n", EQ (res, Qt)); /* FIXME */
+  if (EQ (res, Qt))
     {
       Feval (Fcons (intern ("save-buffers-kill-emacs"), Qnil));
       return NSTerminateNow;
@@ -4222,26 +4097,6 @@ fprintf (stderr, "res = %d\n", res ==Qt);
 }
 
 
-/* Open a file (used by below, after going into queue read by ns_read_socket) */
--(BOOL) openFile: (NSString *)fileName
-{
-  struct frame *emacsframe = SELECTED_FRAME ();
-  NSEvent *theEvent = [NSApp currentEvent];
-
-  if (!emacs_event)
-    return NO;
-
-  emacs_event->kind = NON_ASCII_KEYSTROKE_EVENT;
-  emacs_event->code = KEY_NS_OPEN_FILE_LINE;
-  ns_input_file = append2 (ns_input_file, build_string ([fileName UTF8String]));
-  ns_input_line = Qnil; /* can be start or cons start,end */
-  emacs_event->modifiers =0;
-  EV_TRAILER (theEvent);
-
-  return YES;
-}
-
-
 /*   Notification from the Workspace to open a file */
 - (BOOL)application: sender openFile: (NSString *)file
 {
@@ -4273,10 +4128,16 @@ fprintf (stderr, "res = %d\n", res ==Qt);
   NSString *file;
   while ((file = [files nextObject]) != nil)
     [ns_pending_files addObject: file];
-  return YES;
+
+#ifdef NS_IMPL_GNUSTEP
+  [self replyToOpenOrPrint: 0];
+#else
+  [self replyToOpenOrPrint: NSApplicationDelegateReplySuccess];
+#endif /* NS_IMPL_GNUSTEP */
+
 }
 
-/*PENDING: these may help w/IO switching btwn terminal and NSApp */
+/* TODO: these may help w/IO switching btwn terminal and NSApp */
 - (void)applicationDidBecomeActive: (NSNotification *)notification
 {
 }
@@ -4310,8 +4171,8 @@ extern void update_window_cursor (struct window *w, int on);
      Flash the cursor
    -------------------------------------------------------------------------- */
 {
-  struct ns_display_info *dpyinfo = ns_display_list; /*HACK, but OK for now */
-  struct frame *f = dpyinfo->ns_highlight_frame;
+  struct ns_display_info *dpyinfo = x_display_list; /*HACK, but OK for now */
+  struct frame *f = dpyinfo->x_highlight_frame;
   NSTRACE (cursor_blink_handler);
 
   if (!f)
@@ -4440,11 +4301,7 @@ extern void update_window_cursor (struct window *w, int on);
       emacs_event->code = KEY_NS_CHANGE_FONT;
 
       size = [newFont pointSize];
-      /* PENDING: stick w/integer sizes for now. */
-/*        if (size == lrint (size)) */
-        ns_input_fontsize = make_number (lrint (size));
-/*          else
-            ns_input_fontsize = make_float (size); */
+      ns_input_fontsize = make_number (lrint (size));
       ns_input_font = build_string ([[newFont familyName] UTF8String]);
       EV_TRAILER (e);
     }
@@ -4495,21 +4352,19 @@ extern void update_window_cursor (struct window *w, int on);
   if (!emacs_event)
     return;
 
-/*#if defined (COCOA_EXPERIMENTAL_CTRL_G) */
  if (![[self window] isKeyWindow])
    {
-     /* PENDING: Using NO_SOCK_SIGIO like Carbon causes a condition in which,
-        when Emacs display updates a different frame from the current one,
-        and temporarily selects it, then processes some interrupt-driven
-        input (dispnew.c:3878), OS will send the event to the correct NSWindow,
-        but for some reason that window has its first responder set to the
-        NSView most recently updated (I guess), which is not the correct one.
-        UPDATE: After multi-TTY merge this happens even w/o NO_SOCK_SIGIO */
+     /* XXX: Using NO_SOCK_SIGIO like Carbon causes a condition in which,
+         when Emacs display updates a different frame from the current one,
+         and temporarily selects it, then processes some interrupt-driven
+         input (dispnew.c:3878), OS will send the event to the correct NSWindow,
+         but for some reason that window has its first responder set to the
+         NSView most recently updated (I guess), which is not the correct one.
+         UPDATE: After multi-TTY merge this happens even w/o NO_SOCK_SIGIO */
      if ([[theEvent window] isKindOfClass: [EmacsWindow class]])
-         [[(EmacsView *)[theEvent window] delegate] keyDown: theEvent];
+         [(EmacsView *)[[theEvent window] delegate] keyDown: theEvent];
      return;
    }
-/*#endif */
 
   if (nsEvArray == nil)
     nsEvArray = [[NSMutableArray alloc] initWithCapacity: 1];
@@ -4552,14 +4407,14 @@ extern void update_window_cursor (struct window *w, int on);
 
       if (flags & NSCommandKeyMask)
         {
-          emacs_event->modifiers |= lisp_to_mod (ns_command_modifier);
+          emacs_event->modifiers |= parse_solitary_modifier (ns_command_modifier);
           /* if super (default), take input manager's word so things like
              dvorak / qwerty layout work */
           if (EQ (ns_command_modifier, Qsuper)
               && !fnKeysym
               && [[theEvent characters] length] != 0)
             {
-              /* PENDING: the code we get will be unshifted, so if we have
+              /* XXX: the code we get will be unshifted, so if we have
                  a shift modifier, must convert ourselves */
               if (!(flags & NSShiftKeyMask))
                 code = [[theEvent characters] characterAtIndex: 0];
@@ -4586,10 +4441,10 @@ extern void update_window_cursor (struct window *w, int on);
         }
 
       if (flags & NSControlKeyMask)
-          emacs_event->modifiers |= lisp_to_mod (ns_control_modifier);
+          emacs_event->modifiers |= parse_solitary_modifier (ns_control_modifier);
 
       if (flags & NS_FUNCTION_KEY_MASK && !fnKeysym)
-          emacs_event->modifiers |= lisp_to_mod (ns_function_modifier);
+          emacs_event->modifiers |= parse_solitary_modifier (ns_function_modifier);
 
       if (flags & NSAlternateKeyMask) /* default = meta */
         {
@@ -4602,7 +4457,7 @@ extern void update_window_cursor (struct window *w, int on);
                 emacs_event->modifiers = 0;
             }
           else
-              emacs_event->modifiers |= lisp_to_mod (ns_alternate_modifier);
+              emacs_event->modifiers |= parse_solitary_modifier (ns_alternate_modifier);
         }
 
 /*fprintf (stderr,"code =%x\tfnKey =%x\tflags = %x\tmods = %x\n",code,fnKeysym,flags,emacs_event->modifiers); */
@@ -4668,12 +4523,12 @@ if (NS_KEYLOG) NSLog (@"insertText '%@'\tlen = %d", aString, len);
   for (i =0; i<len; i++)
     {
       code = [aString characterAtIndex: i];
-      /* PENDING: still need this? */
+      /* TODO: still need this? */
       if (code == 0x2DC)
         code = '~'; /* 0x7E */
       emacs_event->modifiers = 0;
-      emacs_event->kind =
-        code > 0xFF ? MULTIBYTE_CHAR_KEYSTROKE_EVENT : ASCII_KEYSTROKE_EVENT;
+      emacs_event->kind
+       = code > 0xFF ? MULTIBYTE_CHAR_KEYSTROKE_EVENT : ASCII_KEYSTROKE_EVENT;
       emacs_event->code = code;
       EV_TRAILER ((id)nil);
     }
@@ -4786,12 +4641,12 @@ if (NS_KEYLOG) NSLog (@"firstRectForCharRange request");
   return rect;
 }
 
-- (long)conversationIdentifier
+- (NSInteger)conversationIdentifier
 {
-  return (long)self;
+  return (NSInteger)self;
 }
 
-/*PENDING: below here not yet implemented correctly, but may not be needed */
+/* TODO: below here not yet implemented correctly, but may not be needed */
 
 - (void)doCommandBySelector: (SEL)aSelector
 {
@@ -4921,8 +4776,8 @@ if (NS_KEYLOG) NSLog (@"attributedSubstringFromRange request");
   NSTRACE (mouseMoved);
 
   last_mouse_movement_time = EV_TIMESTAMP (e);
-  last_mouse_motion_position =
-    [self convertPoint: [e locationInWindow] fromView: nil];
+  last_mouse_motion_position
+    [self convertPoint: [e locationInWindow] fromView: nil];
 
   /* update any mouse face */
   if (dpyinfo->mouse_face_hidden)
@@ -5087,7 +4942,13 @@ if (NS_KEYLOG) NSLog (@"attributedSubstringFromRange request");
     x_set_window_size (emacsframe, 0, cols, rows);
 
   ns_send_appdefined (-1);
+
+  /* The following line causes a crash on GNUstep.  Adrian Roberts
+     says he doesn't remember why he added this line, but removing it
+     doesn't seem to cause problems on OSX, either.  */
+#if 0
   [NSApp stopModal];
+#endif
 }
 
 
@@ -5095,12 +4956,12 @@ if (NS_KEYLOG) NSLog (@"attributedSubstringFromRange request");
 {
   int val = ns_lisp_to_cursor_type (get_frame_param (emacsframe, Qcursor_type));
   struct ns_display_info *dpyinfo = FRAME_NS_DISPLAY_INFO (emacsframe);
-  struct frame *old_focus = dpyinfo->ns_focus_frame;
+  struct frame *old_focus = dpyinfo->x_focus_frame;
 
   NSTRACE (windowDidBecomeKey);
 
   if (emacsframe != old_focus)
-    dpyinfo->ns_focus_frame = emacsframe;
+    dpyinfo->x_focus_frame = emacsframe;
   /*/last_mouse_frame = emacsframe;? */
 
   if (val >= 0)
@@ -5131,10 +4992,10 @@ if (NS_KEYLOG) NSLog (@"attributedSubstringFromRange request");
       FRAME_LAST_INACTIVE (emacsframe) = YES;
     }
 
-  if (dpyinfo->ns_highlight_frame == emacsframe)
-    dpyinfo->ns_highlight_frame = 0;
-  if (dpyinfo->ns_focus_frame == emacsframe)
-    dpyinfo->ns_focus_frame = 0;
+  if (dpyinfo->x_highlight_frame == emacsframe)
+    dpyinfo->x_highlight_frame = 0;
+  if (dpyinfo->x_focus_frame == emacsframe)
+    dpyinfo->x_focus_frame = 0;
 
   if (dpyinfo->mouse_face_mouse_frame == emacsframe)
     {
@@ -5223,7 +5084,7 @@ if (NS_KEYLOG) NSLog (@"attributedSubstringFromRange request");
 
   tem = f->name;
   name = [NSString stringWithUTF8String:
-                   NILP (tem) ? (unsigned char *)"Emacs" : XSTRING (tem)->data];
+                   NILP (tem) ? (unsigned char *)"Emacs" : SDATA (tem)];
   [win setTitle: name];
 
   /* toolbar support */
@@ -5242,7 +5103,7 @@ if (NS_KEYLOG) NSLog (@"attributedSubstringFromRange request");
   tem = f->icon_name;
   if (!NILP (tem))
     [win setMiniwindowTitle:
-           [NSString stringWithUTF8String: XSTRING (tem)->data]];
+           [NSString stringWithUTF8String: SDATA (tem)]];
 
   {
     NSScreen *screen = [win screen];
@@ -5362,8 +5223,8 @@ if (NS_KEYLOG) NSLog (@"attributedSubstringFromRange request");
 {
   NSPoint p = [self convertPoint: [theEvent locationInWindow] fromView: nil];
   NSRect r;
-  struct ns_display_info *dpyinfo =
-      emacsframe ? FRAME_NS_DISPLAY_INFO (emacsframe) : NULL;
+  struct ns_display_info *dpyinfo
+    = emacsframe ? FRAME_NS_DISPLAY_INFO (emacsframe) : NULL;
 
   NSTRACE (mouseExited);
 
@@ -5387,7 +5248,8 @@ if (NS_KEYLOG) NSLog (@"attributedSubstringFromRange request");
     context_menu_value = [sender tag];
   else
     find_and_call_menu_selection (emacsframe, emacsframe->menu_bar_items_used,
-                                  emacsframe->menu_bar_vector, [sender tag]);
+                                  emacsframe->menu_bar_vector,
+                                  (void *)[sender tag]);
   ns_send_appdefined (-1);
   return self;
 }
@@ -5726,8 +5588,8 @@ if (NS_KEYLOG) NSLog (@"attributedSubstringFromRange request");
 
 + (float) scrollerWidth
 {
-  /* PENDING: if we want to allow variable widths, this is the place to do it,
-     however neither GNUstep nor Cocoa support it very well */
+  /* TODO: if we want to allow variable widths, this is the place to do it,
+           however neither GNUstep nor Cocoa support it very well */
   return [NSScroller scrollerWidth];
 }
 
@@ -5870,8 +5732,8 @@ if (NS_KEYLOG) NSLog (@"attributedSubstringFromRange request");
   return self;
 }
 
-/* PENDING: unused at moment (see ns_mouse_position) at the moment because
-   drag events will go directly to the EmacsScroller.  Leaving in for now. */
+/* FIXME: unused at moment (see ns_mouse_position) at the moment because
+     drag events will go directly to the EmacsScroller.  Leaving in for now. */
 -(void)getMouseMotionPart: (int *)part window: (Lisp_Object *)window
                         x: (Lisp_Object *)x y: ( Lisp_Object *)y
 {
@@ -5925,14 +5787,14 @@ if (NS_KEYLOG) NSLog (@"attributedSubstringFromRange request");
         if (inKnob)
           return self;
 
-        scroll_repeat_entry =
-          [[NSTimer scheduledTimerWithTimeInterval:
-                      SCROLL_BAR_CONTINUOUS_DELAY
+        scroll_repeat_entry
+         = [[NSTimer scheduledTimerWithTimeInterval:
+                       SCROLL_BAR_CONTINUOUS_DELAY
                                             target: self
                                           selector: @selector (repeatScroll:)
                                           userInfo: 0
                                            repeats: YES]
-            retain];
+             retain];
     }
 
   [self sendScrollEventAtLoc: 0 fromEvent: e];
@@ -5976,13 +5838,13 @@ if (NS_KEYLOG) NSLog (@"attributedSubstringFromRange request");
       pos = 0;      /* ignored */
 
       /* set a timer to repeat, as we can't let superclass do this modally */
-      scroll_repeat_entry =
-        [[NSTimer scheduledTimerWithTimeInterval: 0.5
-                                          target: self
-                                        selector: @selector (repeatScroll:)
-                                        userInfo: 0
-                                         repeats: YES]
-          retain];
+      scroll_repeat_entry
+       = [[NSTimer scheduledTimerWithTimeInterval: 0.5
+                                            target: self
+                                          selector: @selector (repeatScroll:)
+                                          userInfo: 0
+                                           repeats: YES]
+           retain];
     }
   else
     {
@@ -6134,8 +5996,8 @@ static void selectItemWithTag (NSPopUpButton *popup, int tag)
 
 - (void) setPanelFromValues
 {
-  int cursorType =
-    ns_lisp_to_cursor_type (get_frame_param (frame, Qcursor_type));
+  int cursorType
+    ns_lisp_to_cursor_type (get_frame_param (frame, Qcursor_type));
   prevExpandSpace = XFLOATINT (ns_expand_space);
   prevBlinkRate = NILP (ns_cursor_blink_rate)
     ? 0 : XFLOATINT (ns_cursor_blink_rate);
@@ -6149,14 +6011,18 @@ static void selectItemWithTag (NSPopUpButton *popup, int tag)
   [cursorTypeMatrix selectCellWithTag: (cursorType == filled_box ? 1 :
                                         (cursorType == bar ? 2 :
                                          (cursorType == underscore ? 3 : 4)))];
-  selectItemWithTag (alternateModMenu, lisp_to_mod (ns_alternate_modifier));
-  selectItemWithTag (commandModMenu, lisp_to_mod (ns_command_modifier));
+  selectItemWithTag (alternateModMenu,
+                    parse_solitary_modifier (ns_alternate_modifier));
+  selectItemWithTag (commandModMenu,
+                    parse_solitary_modifier (ns_command_modifier));
 #ifdef NS_IMPL_COCOA
-  selectItemWithTag (controlModMenu, lisp_to_mod (ns_control_modifier));
-  selectItemWithTag (functionModMenu, lisp_to_mod (ns_function_modifier));
-  [smoothFontsCheck setState: ns_antialias_text ? YES : NO];
-  [useQuickdrawCheck setState: ns_use_qd_smoothing ? YES : NO];
-  [useSysHiliteCheck setState: prevUseHighlightColor ? YES : NO];
+  selectItemWithTag (controlModMenu,
+                    parse_solitary_modifier (ns_control_modifier));
+  selectItemWithTag (functionModMenu,
+                    parse_solitary_modifier (ns_function_modifier));
+  [smoothFontsCheck setState: (NILP (ns_antialias_text) ? NO : YES)];
+  [useQuickdrawCheck setState: (NILP (ns_use_qd_smoothing) ? NO : YES)];
+  [useSysHiliteCheck setState: (NILP (prevUseHighlightColor) ? NO : YES)];
 #endif
 }
 
@@ -6177,7 +6043,7 @@ static void selectItemWithTag (NSPopUpButton *popup, int tag)
   if (expandSpace != prevExpandSpace)
     {
       ns_expand_space = make_float (expandSpace);
-      /* PENDING: more needed: store needed metrics in nsfont_info, update
+      /* TODO: more needed: store needed metrics in nsfont_info, update
          frame default font max_bounds and fontp, recompute faces */
 /*         FRAME_LINE_HEIGHT (frame) *= (expandSpace / prevExpandSpace);
            x_set_window_size (frame, 0, frame->text_cols, frame->text_lines); */
@@ -6196,7 +6062,7 @@ static void selectItemWithTag (NSPopUpButton *popup, int tag)
           ns_cursor_blink_rate = make_float (blinkRate);
           ns_cursor_blink_mode = Qt;
         }
-      if (ns_cursor_blink_mode != old_cursor_blink_mode)
+      if (!EQ (ns_cursor_blink_mode, old_cursor_blink_mode))
           Feval (Fcons (intern ("blink-cursor-mode"), Qnil));
 
       if (blinkRate != 0.0 && prevBlinkRate != 0.0)
@@ -6205,20 +6071,20 @@ static void selectItemWithTag (NSPopUpButton *popup, int tag)
           [cursor_blink_entry invalidate];
           [cursor_blink_entry release];
           cursor_blink_entry = 0;
-          if (dpyinfo->ns_highlight_frame)
+          if (dpyinfo->x_highlight_frame)
             {
-              Lisp_Object tem =
-                get_frame_param (dpyinfo->ns_highlight_frame, Qcursor_type);
-              dpyinfo->ns_highlight_frame->output_data.ns->desired_cursor =
-                ns_lisp_to_cursor_type (tem);
+              Lisp_Object tem
+               = get_frame_param (dpyinfo->x_highlight_frame, Qcursor_type);
+              dpyinfo->x_highlight_frame->output_data.ns->desired_cursor
+               = ns_lisp_to_cursor_type (tem);
             }
         }
       prevBlinkRate = blinkRate;
     }
-  FRAME_NEW_CURSOR (frame) =
-                         (cursorTag == 1 ? filled_box :
-                          (cursorTag == 2 ? bar :
-                           (cursorTag == 3 ? underscore : hollow_box)));
+  FRAME_NEW_CURSOR (frame)
+    = (cursorTag == 1 ? filled_box
+       : cursorTag == 2 ? bar
+       : cursorTag == 3 ? underscore : hollow_box);
   store_frame_param (frame, Qcursor_type,
                     ns_cursor_type_to_lisp (FRAME_NEW_CURSOR (frame)));
   ns_alternate_modifier = ns_mod_to_lisp (altTag);
@@ -6226,13 +6092,13 @@ static void selectItemWithTag (NSPopUpButton *popup, int tag)
 #ifdef NS_IMPL_COCOA
   ns_control_modifier = ns_mod_to_lisp (ctrlTag);
   ns_function_modifier = ns_mod_to_lisp (fnTag);
-  ns_antialias_text = [smoothFontsCheck state];
-  ns_use_qd_smoothing = [useQuickdrawCheck state];
-  ns_use_system_highlight_color = [useSysHiliteCheck state];
-  if (ns_use_system_highlight_color != prevUseHighlightColor)
+  ns_antialias_text = [smoothFontsCheck state] ? Qt : Qnil;
+  ns_use_qd_smoothing = [useQuickdrawCheck state] ? Qt : Qnil;
+  ns_use_system_highlight_color = [useSysHiliteCheck state] ? Qt : Qnil;
+  if (! EQ (ns_use_system_highlight_color, prevUseHighlightColor))
     {
       prevUseHighlightColor = ns_use_system_highlight_color;
-      if (ns_use_system_highlight_color == YES)
+      if (EQ (ns_use_system_highlight_color, Qt))
         {
           ns_selection_color = [[NSUserDefaults standardUserDefaults]
                                  stringForKey: @"AppleHighlightColor"];
@@ -6300,6 +6166,7 @@ static void selectItemWithTag (NSPopUpButton *popup, int tag)
 /* ==========================================================================
 
    Font-related functions; these used to be in nsfaces.m
+   The XLFD functions (115 lines) are an abomination that should be removed.
 
    ========================================================================== */
 
@@ -6348,140 +6215,9 @@ x_new_font (struct frame *f, Lisp_Object font_object, int fontset)
 }
 
 
-Lisp_Object
-ns_list_fonts (FRAME_PTR f, Lisp_Object pattern, int size, int maxnames)
-/* --------------------------------------------------------------------------
-     This is used by the xfaces system.  It is expected to speak XLFD.
-   -------------------------------------------------------------------------- */
-{
-  Lisp_Object list = Qnil,
-    rpattern,
-    key,
-    tem,
-    args[2];
-  struct re_pattern_buffer *bufp;
-  id fm = [NSFontManager sharedFontManager];
-  NSEnumerator *fenum, *senum;
-  NSArray *membInfo;
-  NSString *fontname;
-  const char *xlfdName;
-  char *pattFam;
-  char *patt;
-  NSString *famName;
-
-  NSTRACE (ns_list_fonts);
-
-  CHECK_STRING (pattern);
-  patt = XSTRING (pattern)->data;
-
-#if 0
-/* temporary: for font_backend, we use fontsets, and when these are defined,
-   the old XLFD-based system is used; eventually this will be replaced by
-   backend code, but for now we allow specs that are just family names */
-      /* if pattern is not XLFD, panic now */
-      if (patt[0] != '-')
-        error ("ns_list_fonts: X font name (XLFD) expected.");
-
-      /* if unicode encoding not requested, also die */
-      if (!strstr (patt, "iso10646") && patt[strlen (patt)-3] != '*')
-        return Qnil;
-#endif /* 0 */
-
-  key = f ? Fcons (pattern, make_number (maxnames)) : Qnil;
-  tem = f ? XCDR (FRAME_NS_DISPLAY_INFO (f)->name_list_element) : Qnil;
-
-  /* See if we cached the result for this particular query.
-     The cache is an alist of the form:
-     ((((PATTERN . MAXNAMES) FONTNAME) ...) ...)
-  */
-  if (f && !NILP (list = Fassoc (key, tem)))
-    {
-      list = Fcdr_safe (list);
-      /* We have a cached list.  Don't have to get the list again.  */
-      if (!NILP (list))
-        return list;
-    }
-
-  if (patt[0] != '-')
-      pattFam = patt;
-  else
-      pattFam = ns_xlfd_to_fontname (patt);
-  /*PENDING: '*' at beginning matches literally.. */
-  if (pattFam[0] == '*')
-    pattFam[0] = '.';
-
-  /* must start w/family name, but can have other stuff afterwards
-    (usually bold and italic specifiers) */
-  args[0] = build_string ("^");
-  args[1] = build_string (pattFam);
-  rpattern = Fconcat (2, args);
-  bufp = compile_pattern (rpattern, 0, Vascii_canon_table, 0, 0);
-
-  list = Qnil;
-  fenum = [[fm availableFontFamilies] objectEnumerator];
-  while ( (famName = [fenum nextObject]) )
-    {
-      NSMutableString *tmp = [famName mutableCopy];
-      const char *fname;
-      NSRange r;
-
-      /* remove spaces, to look like postscript name */
-      while ((r = [tmp rangeOfString: @" "]).location != NSNotFound)
-        [tmp deleteCharactersInRange: r];
-
-      fname = [tmp UTF8String];
-      int len = strlen (fname);
-      BOOL foundItal;
-      const char *synthItalFont;
-
-      if (re_search (bufp, fname, len, 0, len, 0) >= 0)
-        {
-          /* Found a family.  Add all variants.  If we have no italic variant,
-             add a synthItal. */
-          senum =[[fm availableMembersOfFontFamily: famName] objectEnumerator];
-          foundItal = NO;
-          synthItalFont = NULL;
-          while (membInfo = [senum nextObject])
-            {
-              xlfdName =
-                ns_fontname_to_xlfd ([[membInfo objectAtIndex: 0] UTF8String]);
-              list = Fcons (build_string (xlfdName), list);
-              if (!synthItalFont)
-                {
-                  NSString *synthName =
-                    [[membInfo objectAtIndex: 0]
-                      stringByAppendingString: @"-synthItal"];
-                  synthItalFont = [synthName UTF8String];
-                }
-              else if ([[membInfo objectAtIndex: 3] intValue]
-                         & NSItalicFontMask)
-                foundItal = YES;
-            }
-          if (foundItal == NO)
-            {
-              xlfdName = ns_fontname_to_xlfd (synthItalFont);
-              list = Fcons (build_string (xlfdName), list);
-            }
-        }
-      [tmp release];
-    }
-
-  /* fallback */
-  if (XFASTINT (Flength (list)) == 0)
-      list = Fcons (build_string (ns_fontname_to_xlfd ("Monaco")), list);
-
-  /* store result in cache */
-  if (f != NULL)
-    XCDR_AS_LVALUE (FRAME_NS_DISPLAY_INFO (f)->name_list_element)
-      = Fcons (Fcons (key, list),
-               XCDR (FRAME_NS_DISPLAY_INFO (f)->name_list_element));
-  return list;
-}
-
-
 /* XLFD: -foundry-family-weight-slant-swidth-adstyle-pxlsz-ptSz-resx-resy-spc-avgWidth-rgstry-encoding */
 
-const char *
+static const char *
 ns_font_to_xlfd (NSFont *nsfont)
 /* --------------------------------------------------------------------------
     Convert an NS font name to an X font name (XLFD).
@@ -6490,7 +6226,7 @@ ns_font_to_xlfd (NSFont *nsfont)
 {
   NSFontManager *mgr = [NSFontManager sharedFontManager];
   NSString *sname = [nsfont /*familyName*/fontName];
-  char *famName = [sname UTF8String];
+  char *famName = (char *)[sname UTF8String];
   char *weightStr = [mgr fontNamed: sname hasTraits: NSBoldFontMask] ?
       "bold" : "medium";
   char *slantStr = [mgr fontNamed: sname hasTraits: NSItalicFontMask] ?
@@ -6501,7 +6237,7 @@ ns_font_to_xlfd (NSFont *nsfont)
   int i, len;
 
   /* change '-' to '$' to avoid messing w/XLFD separator */
-  for (len =strlen (famName), i =0; i<len; i++)
+  for (len = strlen (famName), i =0; i<len; i++)
     if (famName[i] == '-')
       {
         famName[i] = '\0';
@@ -6516,7 +6252,7 @@ ns_font_to_xlfd (NSFont *nsfont)
   return xlfd;
 }
 
-const char *
+static const char *
 ns_fontname_to_xlfd (const char *name)
 /* --------------------------------------------------------------------------
     Convert an NS font name to an X font name (XLFD).
@@ -6596,4 +6332,150 @@ ns_xlfd_to_fontname (const char *xlfd)
   return ret;
 }
 
+
+void
+syms_of_nsterm ()
+{
+  NSTRACE (syms_of_nsterm);
+  DEFVAR_LISP ("ns-input-file", &ns_input_file,
+              "The file specified in the last NS event.");
+  ns_input_file =Qnil;
+
+  DEFVAR_LISP ("ns-input-text", &ns_input_text,
+              "The data received in the last NS text drag event.");
+  ns_input_text =Qnil;
+
+  DEFVAR_LISP ("ns-working-text", &ns_working_text,
+              "String for visualizing working composition sequence.");
+  ns_working_text =Qnil;
+
+  DEFVAR_LISP ("ns-input-font", &ns_input_font,
+              "The font specified in the last NS event.");
+  ns_input_font =Qnil;
+
+  DEFVAR_LISP ("ns-input-fontsize", &ns_input_fontsize,
+              "The fontsize specified in the last NS event.");
+  ns_input_fontsize =Qnil;
+
+  DEFVAR_LISP ("ns-input-line", &ns_input_line,
+               "The line specified in the last NS event.");
+  ns_input_line =Qnil;
+
+  DEFVAR_LISP ("ns-input-color", &ns_input_color,
+               "The color specified in the last NS event.");
+  ns_input_color =Qnil;
+
+  DEFVAR_LISP ("ns-input-spi-name", &ns_input_spi_name,
+               "The service name specified in the last NS event.");
+  ns_input_spi_name =Qnil;
+
+  DEFVAR_LISP ("ns-input-spi-arg", &ns_input_spi_arg,
+               "The service argument specified in the last NS event.");
+  ns_input_spi_arg =Qnil;
+
+  DEFVAR_LISP ("ns-alternate-modifier", &ns_alternate_modifier,
+               "This variable describes the behavior of the alternate or option key.\n\
+Set to control, meta, alt, super, or hyper means it is taken to be that key.\n\
+Set to none means that the alternate / option key is not interpreted by Emacs\n\
+at all, allowing it to be used at a lower level for accented character entry.");
+
+  DEFVAR_LISP ("ns-command-modifier", &ns_command_modifier,
+               "This variable describes the behavior of the command key.\n\
+Set to control, meta, alt, super, or hyper means it is taken to be that key.");
+
+  DEFVAR_LISP ("ns-control-modifier", &ns_control_modifier,
+               "This variable describes the behavior of the control key.\n\
+Set to control, meta, alt, super, or hyper means it is taken to be that key.");
+
+  DEFVAR_LISP ("ns-function-modifier", &ns_function_modifier,
+               "This variable describes the behavior of the function key (on laptops).\n\
+Set to control, meta, alt, super, or hyper means it is taken to be that key.\n\
+Set to none means that the function key is not interpreted by Emacs at all,\n\
+allowing it to be used at a lower level for accented character entry.");
+
+  DEFVAR_LISP ("ns-cursor-blink-rate", &ns_cursor_blink_rate,
+               "Rate at which the Emacs cursor blinks (in seconds).\n\
+Set to nil to disable blinking.");
+
+  DEFVAR_LISP ("ns-cursor-blink-mode", &ns_cursor_blink_mode,
+               "Internal variable -- use M-x blink-cursor-mode or preferences\n\
+panel to control this setting.");
+
+  DEFVAR_LISP ("ns-expand-space", &ns_expand_space,
+               "Amount by which spacing between lines is expanded (positive)\n\
+or shrunk (negative).  Zero (the default) means standard line height.\n\
+(This variable should only be read, never set.)");
+
+  DEFVAR_LISP ("ns-antialias-text", &ns_antialias_text,
+               "Non-nil (the default) means to render text antialiased. Only has an effect on OS X Panther and above.");
+
+  DEFVAR_LISP ("ns-use-qd-smoothing", &ns_use_qd_smoothing,
+               "Whether to render text using QuickDraw (less heavy) antialiasing. Only has an effect on OS X Panther and above.  Default is nil (use Quartz smoothing).");
+
+  DEFVAR_LISP ("ns-use-system-highlight-color",
+               &ns_use_system_highlight_color,
+               "Whether to use the system default (on OS X only) for the highlight color.  Nil means to use standard emacs (prior to version 21) 'grey'.");
+
+  staticpro (&ns_display_name_list);
+  ns_display_name_list = Qnil;
+
+  staticpro (&last_mouse_motion_frame);
+  last_mouse_motion_frame = Qnil;
+
+  /*23: now apparently we need to tell emacs what modifiers there are.. */
+  Qmodifier_value = intern ("modifier-value");
+  Qalt = intern ("alt");
+  Fput (Qalt, Qmodifier_value, make_number (alt_modifier));
+  Qhyper = intern ("hyper");
+  Fput (Qhyper, Qmodifier_value, make_number (hyper_modifier));
+  Qmeta = intern ("meta");
+  Fput (Qmeta, Qmodifier_value, make_number (meta_modifier));
+  Qsuper = intern ("super");
+  Fput (Qsuper, Qmodifier_value, make_number (super_modifier));
+  Qcontrol = intern ("control");
+  Fput (Qcontrol, Qmodifier_value, make_number (ctrl_modifier));
+
+  /* TODO: move to common code */
+  DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars,
+              doc: /* If not nil, Emacs uses toolkit scroll bars.  */);
+#ifdef USE_TOOLKIT_SCROLL_BARS
+  Vx_toolkit_scroll_bars = Qt;
+#else
+  Vx_toolkit_scroll_bars = Qnil;
+#endif
+
+  /* these are unsupported but we need the declarations to avoid whining
+     messages from cus-start.el */
+  DEFVAR_BOOL ("x-use-underline-position-properties",
+              &x_use_underline_position_properties,
+     doc: /* NOT SUPPORTED UNDER NS.
+*Non-nil means make use of UNDERLINE_POSITION font properties.
+A value of nil means ignore them.  If you encounter fonts with bogus
+UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
+to 4.1, set this to nil.
+
+NOTE: Not supported on Mac yet.  */);
+  x_use_underline_position_properties = 0;
+
+  DEFVAR_BOOL ("x-underline-at-descent-line",
+              &x_underline_at_descent_line,
+     doc: /* NOT SUPPORTED UNDER NS.
+*Non-nil means to draw the underline at the same place as the descent line.
+A value of nil means to draw the underline according to the value of the
+variable `x-use-underline-position-properties', which is usually at the
+baseline level.  The default value is nil.  */);
+  x_underline_at_descent_line = 0;
+
+  /* Tell emacs about this window system. */
+  Fprovide (intern ("ns"), Qnil);
+  /* TODO: try to move this back into lisp,  ns-win.el loaded too late
+           right now */
+  {
+    Lisp_Object args[3] = { intern ("ns-version-string"), build_string ("9.0"),
+                    build_string ("NS Window system port version number.") };
+    Fdefconst (Flist (3, args));
+  }
+}
+
+
 // arch-tag: 6eaa8f7d-a69b-4e1c-b43d-ab31defbe0d2