changeset 108565:e53bb6f016b3

Merge from mainline.
author Katsumi Yamaoka <yamaoka@jpl.org>
date Fri, 14 May 2010 07:46:03 +0000
parents 255a042e399d (current diff) dea8b4d40a70 (diff)
children b7c1f69ad104
files
diffstat 16 files changed, 672 insertions(+), 260 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu May 13 22:43:33 2010 +0000
+++ b/ChangeLog	Fri May 14 07:46:03 2010 +0000
@@ -1,3 +1,14 @@
+2010-05-14  Glenn Morris  <rgm@gnu.org>
+
+	* configure.in (cpp_undefs): Add mktime, register, X11.
+
+	* configure.in (GPM_MOUSE_SUPPORT): Remove.
+	(MOUSE_SUPPORT, TOOLTIP_SUPPORT, WINDOW_SUPPORT): New output variables.
+	(HAVE_WINDOW_SYSTEM, HAVE_MOUSE): Move out of AC_BOTTOM.
+
+	* configure.in (NS_IMPL_GNUSTEP_INC): New output variable.
+	(GNUSTEP_MAKEFILES): Do not output.
+
 2010-05-13  Glenn Morris  <rgm@gnu.org>
 
 	* configure.in: Fix some paren typos.
--- a/admin/CPP-DEFINES	Thu May 13 22:43:33 2010 +0000
+++ b/admin/CPP-DEFINES	Fri May 14 07:46:03 2010 +0000
@@ -22,7 +22,6 @@
 NS_IMPL_COCOA	Compile support for Cocoa (Apple) implementation of NS GUI API.
 HAVE_X11	Compile support for the X11 GUI.
 HAVE_X_WINDOWS	Compile support for X Window system
-X11		??  Makefile.in suggests it's equivalent to HAVE_X11
 USE_LUCID	Use the Lucid toolkit for menus&scrollbars.  Requires HAVE_X11.
 USE_MOTIF	Use the Motif toolkit for menus&scrollbars.  Requires HAVE_X11.
 USE_GTK		Use the Gtk   toolkit for menus&scrollbars.  Requires HAVE_X11.
@@ -84,6 +83,9 @@
 BCOPY_UPWARD_SAFE
 BITS_PER_EMACS_INT
 BITS_PER_LONG
+BITS_PER_CHAR
+BITS_PER_SHORT
+BITS_PER_INT
 BROKEN_DATAGRAM_SOCKETS
 BROKEN_FIONREAD
 BROKEN_GET_CURRENT_DIR_NAME
@@ -98,7 +100,6 @@
 BSD4_3
 BSD_SYSTEM
 CLASH_DETECTION
-C_SWITCH_X_SYSTEM
 DATA_SEG_BITS
 DATA_START
 DBL_MIN_REPLACEMENT
@@ -114,7 +115,6 @@
 EMACS_CONFIG_OPTIONS
 EMACS_INT
 EMACS_UINT
-END_FILES_1
 FILE_SYSTEM_CASE
 FLOAT_CHECK_DOMAIN
 FSCALE
@@ -133,7 +133,6 @@
 HAVE_BCOPY
 HAVE_CBRT
 HAVE_CLOSEDIR
-HAVE_CRTIN
 HAVE_DUP2
 HAVE_EUIDACCESS
 HAVE_FMOD
@@ -154,9 +153,6 @@
 HAVE_INET_SOCKETS
 HAVE_INVERSE_HYPERBOLIC
 HAVE_LIBKSTAT
-HAVE_LIBNCURSES
-HAVE_LIBPTHREADS
-HAVE_LIBXMU
 HAVE_LIMITS_H
 HAVE_LINUX_VERSION_H
 HAVE_LOGB
@@ -266,8 +262,6 @@
 SIGTRAP
 SIGTYPE
 SOLARIS2
-START_FILES
-START_FILES_1
 STDC_HEADERS
 SYMS_SYSTEM
 SYSTEM_PURESIZE_EXTRA
--- a/configure	Thu May 13 22:43:33 2010 +0000
+++ b/configure	Fri May 14 07:46:03 2010 +0000
@@ -717,6 +717,7 @@
 XMKMF
 LD_SWITCH_X_SITE_AUX
 LD_SWITCH_X_SITE_AUX_RPATH
+NS_IMPL_GNUSTEP_INC
 NS_OBJ
 NS_SUPPORT
 LIB_STANDARD
@@ -751,7 +752,6 @@
 LIBTIFF
 LIBGIF
 LIBGPM
-GPM_MOUSE_SUPPORT
 LIBXSM
 ALLOCA
 liblockfile
@@ -796,7 +796,6 @@
 ns_appbindir
 ns_appresdir
 ns_appsrc
-GNUSTEP_MAKEFILES
 GNUSTEP_SYSTEM_HEADERS
 GNUSTEP_SYSTEM_LIBRARIES
 GNU_OBJC_CFLAGS
@@ -815,6 +814,9 @@
 LD_SWITCH_SYSTEM_TEMACS
 LD_SWITCH_SYSTEM_EXTRA
 LIB_GCC
+MOUSE_SUPPORT
+TOOLTIP_SUPPORT
+WINDOW_SUPPORT
 LTLIBOBJS'
 ac_subst_files=''
 ac_user_opts='
@@ -9929,6 +9931,7 @@
 HAVE_NS=no
 NS_IMPL_COCOA=no
 NS_IMPL_GNUSTEP=no
+NS_IMPL_GNUSTEP_INC=
 tmp_CPPFLAGS="$CPPFLAGS"
 tmp_CFLAGS="$CFLAGS"
 CPPFLAGS="$CPPFLAGS -x objective-c"
@@ -9949,6 +9952,13 @@
           GNUSTEP_MAKEFILES="$(. $GNUSTEP_CONFIG_FILE; echo $GNUSTEP_MAKEFILES)"
      GNUSTEP_SYSTEM_HEADERS="$(. $GNUSTEP_CONFIG_FILE; echo $GNUSTEP_SYSTEM_HEADERS)"
      GNUSTEP_SYSTEM_LIBRARIES="$(. $GNUSTEP_CONFIG_FILE; echo $GNUSTEP_SYSTEM_LIBRARIES)"
+     ## Pull in stuff from GNUstep-make.
+     NS_IMPL_GNUSTEP_INC="FOUNDATION_LIB=gnu
+GUI_LIB=gnu
+include $GNUSTEP_MAKEFILES/Additional/base.make
+include $GNUSTEP_MAKEFILES/Additional/gui.make
+shared=no
+"
      CPPFLAGS="$CPPFLAGS -I${GNUSTEP_SYSTEM_HEADERS}"
      CFLAGS="$CFLAGS -I${GNUSTEP_SYSTEM_HEADERS}"
      REAL_CFLAGS="$REAL_CFLAGS -I${GNUSTEP_SYSTEM_HEADERS}"
@@ -10141,6 +10151,7 @@
   fi
 fi
 
+
 NS_OBJ=
 NS_SUPPORT=
 if test "${HAVE_NS}" = yes; then
@@ -15991,7 +16002,7 @@
 ### Use -lgpm if available, unless `--with-gpm=no'.
 HAVE_GPM=no
 LIBGPM=
-GPM_MOUSE_SUPPORT=
+MOUSE_SUPPORT=
 if test "${with_gpm}" != "no"; then
   if test "${ac_cv_header_gpm_h+set}" = set; then
   { $as_echo "$as_me:$LINENO: checking for gpm.h" >&5
@@ -16201,10 +16212,10 @@
 _ACEOF
 
     LIBGPM=-lgpm
-    GPM_MOUSE_SUPPORT="\${lispsource}mouse.elc"
-  fi
-fi
-
+    ## May be reset below.
+    MOUSE_SUPPORT="\$(GPM_MOUSE_SUPPORT)"
+  fi
+fi
 
 
 if test "${ac_cv_header_malloc_malloc_h+set}" = set; then
@@ -26357,7 +26368,6 @@
 
 
 
-
 cat >>confdefs.h <<_ACEOF
 #define EMACS_CONFIGURATION "${canonical}"
 _ACEOF
@@ -26589,6 +26599,33 @@
 fi
 
 
+TOOLTIP_SUPPORT=
+WINDOW_SUPPORT=
+## If we're using X11/GNUstep, define some consequences.
+if test "$HAVE_X_WINDOWS" = "yes" || test "$HAVE_NS" = "yes"; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_WINDOW_SYSTEM 1
+_ACEOF
+
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_MOUSE 1
+_ACEOF
+
+  MOUSE_SUPPORT="\$(REAL_MOUSE_SUPPORT)"
+  TOOLTIP_SUPPORT="\${lispsource}mouse.elc"
+
+  WINDOW_SUPPORT="\$(BASE_WINDOW_SUPPORT)"
+  test "$HAVE_X_WINDOWS" = "yes" && \
+    WINDOW_SUPPORT="$WINDOW_SUPPORT \$(X_WINDOW_SUPPORT)"
+
+fi
+
+
+
+
+
 
 
 
@@ -26685,7 +26722,7 @@
 # the C preprocessor to some helpful value like 1, or maybe the empty
 # string.  Needless to say consequent macro substitutions are less
 # than conducive to the makefile finding the correct directory.
-cpp_undefs="`echo $srcdir $configuration $canonical unix |
+cpp_undefs="`echo $srcdir $configuration $canonical unix mktime register X11 |
   sed -e 's/[^a-zA-Z0-9_]/ /g' -e 's/^/ /' -e 's/  *$//' \
   -e 's/  */ -U/g' -e 's/-U[0-9][^ ]*//g'`"
 
--- a/configure.in	Thu May 13 22:43:33 2010 +0000
+++ b/configure.in	Fri May 14 07:46:03 2010 +0000
@@ -1452,6 +1452,7 @@
 HAVE_NS=no
 NS_IMPL_COCOA=no
 NS_IMPL_GNUSTEP=no
+NS_IMPL_GNUSTEP_INC=
 tmp_CPPFLAGS="$CPPFLAGS"
 tmp_CFLAGS="$CFLAGS"
 CPPFLAGS="$CPPFLAGS -x objective-c"
@@ -1473,6 +1474,13 @@
      GNUSTEP_MAKEFILES="$(. $GNUSTEP_CONFIG_FILE; echo $GNUSTEP_MAKEFILES)"
      GNUSTEP_SYSTEM_HEADERS="$(. $GNUSTEP_CONFIG_FILE; echo $GNUSTEP_SYSTEM_HEADERS)"
      GNUSTEP_SYSTEM_LIBRARIES="$(. $GNUSTEP_CONFIG_FILE; echo $GNUSTEP_SYSTEM_LIBRARIES)"
+     ## Pull in stuff from GNUstep-make.
+     NS_IMPL_GNUSTEP_INC="FOUNDATION_LIB=gnu
+GUI_LIB=gnu
+include $GNUSTEP_MAKEFILES/Additional/base.make
+include $GNUSTEP_MAKEFILES/Additional/gui.make
+shared=no
+"
      CPPFLAGS="$CPPFLAGS -I${GNUSTEP_SYSTEM_HEADERS}"
      CFLAGS="$CFLAGS -I${GNUSTEP_SYSTEM_HEADERS}"
      REAL_CFLAGS="$REAL_CFLAGS -I${GNUSTEP_SYSTEM_HEADERS}"
@@ -1491,6 +1499,7 @@
     NS_HAVE_NSINTEGER=no
   fi
 fi
+AC_SUBST(NS_IMPL_GNUSTEP_INC)
 
 NS_OBJ=
 NS_SUPPORT=
@@ -2391,7 +2400,7 @@
 ### Use -lgpm if available, unless `--with-gpm=no'.
 HAVE_GPM=no
 LIBGPM=
-GPM_MOUSE_SUPPORT=
+MOUSE_SUPPORT=
 if test "${with_gpm}" != "no"; then
   AC_CHECK_HEADER(gpm.h,
     [AC_CHECK_LIB(gpm, Gpm_Open, HAVE_GPM=yes)])
@@ -2399,11 +2408,11 @@
   if test "${HAVE_GPM}" = "yes"; then
     AC_DEFINE(HAVE_GPM, 1, [Define to 1 if you have the gpm library (-lgpm).])
     LIBGPM=-lgpm
-    GPM_MOUSE_SUPPORT="\${lispsource}mouse.elc"
+    ## May be reset below.
+    MOUSE_SUPPORT="\$(GPM_MOUSE_SUPPORT)"
   fi
 fi
 AC_SUBST(LIBGPM)
-AC_SUBST(GPM_MOUSE_SUPPORT)
 
 dnl Check for malloc/malloc.h on darwin
 AC_CHECK_HEADER(malloc/malloc.h, [AC_DEFINE(HAVE_MALLOC_MALLOC_H, 1, [Define to 1 if you have the <malloc/malloc.h> header file.])])
@@ -3050,7 +3059,6 @@
 AC_SUBST(ns_appbindir)
 AC_SUBST(ns_appresdir)
 AC_SUBST(ns_appsrc)
-AC_SUBST(GNUSTEP_MAKEFILES)
 AC_SUBST(GNUSTEP_SYSTEM_HEADERS)
 AC_SUBST(GNUSTEP_SYSTEM_LIBRARIES)
 AC_SUBST(GNU_OBJC_CFLAGS)
@@ -3254,6 +3262,25 @@
 AC_SUBST(LIB_GCC)
 
 
+TOOLTIP_SUPPORT=
+WINDOW_SUPPORT=
+## If we're using X11/GNUstep, define some consequences.
+if test "$HAVE_X_WINDOWS" = "yes" || test "$HAVE_NS" = "yes"; then
+  AC_DEFINE(HAVE_WINDOW_SYSTEM, 1, [Define if you have a window system.])
+  AC_DEFINE(HAVE_MOUSE, 1, [Define if you have mouse support.])
+  MOUSE_SUPPORT="\$(REAL_MOUSE_SUPPORT)"
+  TOOLTIP_SUPPORT="\${lispsource}mouse.elc"
+
+  WINDOW_SUPPORT="\$(BASE_WINDOW_SUPPORT)"
+  test "$HAVE_X_WINDOWS" = "yes" && \
+    WINDOW_SUPPORT="$WINDOW_SUPPORT \$(X_WINDOW_SUPPORT)"
+
+fi
+AC_SUBST(MOUSE_SUPPORT)
+AC_SUBST(TOOLTIP_SUPPORT)
+AC_SUBST(WINDOW_SUPPORT)
+
+
 AH_TOP([/* GNU Emacs site configuration template file.
    Copyright (C) 1988, 1993, 1994, 1999, 2000, 2001, 2002, 2004, 2005,
      2006, 2007, 2008, 2009, 2010  Free Software Foundation, Inc.
@@ -3282,12 +3309,6 @@
 ])dnl
 
 AH_BOTTOM([
-/* If we're using X11/Carbon/GNUstep, define some consequences.  */
-#if defined(HAVE_X_WINDOWS) || defined(HAVE_NS)
-#define HAVE_WINDOW_SYSTEM
-#define HAVE_MOUSE
-#endif
-
 /* Define AMPERSAND_FULL_NAME if you use the convention
    that & in the full name stands for the login id.  */
 /* Turned on June 1996 supposing nobody will mind it.  */
@@ -3312,7 +3333,7 @@
 #endif
 #endif /* __FreeBSD__ || __NetBSD__ || __linux__  */
 
-/* If using GNU, then support inline function declarations. */
+/* If using GNU, then support inline function declarations.  */
 /* Don't try to switch on inline handling as detected by AC_C_INLINE
    generally, because even if non-gcc compilers accept `inline', they
    may reject `extern inline'.  */
@@ -3337,7 +3358,7 @@
 /* Set up some defines, C and LD flags for NeXTstep interface on GNUstep.
   (There is probably a better place to do this, but right now the Cocoa
    side does this in s/darwin.h and we cannot
-   parallel this exactly since GNUstep is multi-OS. */
+   parallel this exactly since GNUstep is multi-OS.  */
 #ifdef HAVE_NS
 # ifdef NS_IMPL_GNUSTEP
 /* GNUstep needs a bit more pure memory.  Of the existing knobs,
@@ -3434,7 +3455,7 @@
 #include "string.h"
 #endif
 #ifdef HAVE_STRINGS_H
-#include "strings.h"  /* May be needed for bcopy & al. */
+#include "strings.h"  /* May be needed for bcopy & al.  */
 #endif
 #ifdef HAVE_STDLIB_H
 #include <stdlib.h>
@@ -3601,7 +3622,10 @@
 # the C preprocessor to some helpful value like 1, or maybe the empty
 # string.  Needless to say consequent macro substitutions are less
 # than conducive to the makefile finding the correct directory.
-[cpp_undefs="`echo $srcdir $configuration $canonical unix |
+# src/Makefile.in used to treat X11 as equivalent to HAVE_X11.
+# But nothing in Emacs defines X11, and everywhere else uses HAVE_X11,
+# so that cannot have been doing anything.
+[cpp_undefs="`echo $srcdir $configuration $canonical unix mktime register X11 |
   sed -e 's/[^a-zA-Z0-9_]/ /g' -e 's/^/ /' -e 's/  *$//' \
   -e 's/  */ -U/g' -e 's/-U[0-9][^ ]*//g'`"]
 
--- a/msdos/ChangeLog	Thu May 13 22:43:33 2010 +0000
+++ b/msdos/ChangeLog	Fri May 14 07:46:03 2010 +0000
@@ -1,3 +1,21 @@
+2010-05-14  Glenn Morris  <rgm@gnu.org>
+
+	* sed1v2.inp (ns_appdir, ns_appbindir, ns_appsrc): Edit to empty.
+
+	* sed1v2.inp (MSDOS_OBJ): Edit to dosfns.o msdos.o.
+	(MSDOS_SUPPORT): Edit to $(MSDOS_SUPPORT_REAL).
+	* sed1x.inp (MSDOS_X_OBJ): Edit to w16select.o termcap.o.
+
+	* sed2x.inp (HAVE_WINDOW_SYSTEM): Define.
+	* sed1x.inp (TOOLTIP_SUPPORT): Edit to ${lispsource}tooltip.elc.
+	(WINDOW_SUPPORT): Edit to $(BASE_WINDOW_SUPPORT) $(X_WINDOW_SUPPORT).
+	* sed1v2.inp (MOUSE_SUPPORT): Edit to $(REAL_MOUSE_SUPPORT).
+	(TOOLTIP_SUPPORT, WINDOW_SUPPORT): Edit to empty.
+
+	* sed1v2.inp (FONT_OBJ): Use the plain X version (no XFT, Freetype).
+
+	* sed1v2.inp (@NS_IMPL_GNUSTEP_INC@): Edit to nil.
+
 2010-05-13  Glenn Morris  <rgm@gnu.org>
 
 	* sed1x.inp (OLDXMENU): Edit to ${oldXMenudir}libXMenu11.a.
--- a/msdos/sed1v2.inp	Thu May 13 22:43:33 2010 +0000
+++ b/msdos/sed1v2.inp	Fri May 14 07:46:03 2010 +0000
@@ -89,6 +89,11 @@
 /^RSVG_CFLAGS *=/s/@RSVG_CFLAGS@//
 /^WIDGET_OBJ *=/s/@WIDGET_OBJ@//
 /^CYGWIN_OBJ *=/s/@CYGWIN_OBJ@//
+/^MSDOS_OBJ *=/s/= */= dosfns.o msdos.o/
+/^MSDOS_SUPPORT *=/s/= */= $(MSDOS_SUPPORT_REAL)/
+/^ns_appdir *=/s/@ns_appdir@//
+/^ns_appbindir *=/s/@ns_appbindir@//
+/^ns_appsrc *=/s/@ns_appsrc@//
 /^NS_OBJ *=/s/@NS_OBJ@//
 /^NS_SUPPORT *=/s/@NS_SUPPORT@//
 /^GNU_OBJC_CFLAGS*=/s/@GNU_OBJC_CFLAGS@//
@@ -99,7 +104,10 @@
 /^START_FILES *=/s/@START_FILES@//
 /^OTHER_FILES *=/s/@OTHER_FILES@//
 /^XMENU_OBJ *=/s/@XMENU_OBJ@/xmenu.o/
-/^FONT_OBJ *=/s/@FONT_OBJ@/xfont.o ftfont.o xftfont.o ftxfont.o/
+/^FONT_OBJ *=/s/@FONT_OBJ@/xfont.o/
+/^MOUSE_SUPPORT *=/s/@MOUSE_SUPPORT@/$(REAL_MOUSE_SUPPORT)/
+/^TOOLTIP_SUPPORT *=/s/@TOOLTIP_SUPPORT@//
+/^WINDOW_SUPPORT *=/s/@WINDOW_SUPPORT@//
 /^LIBGPM *=/s/@LIBGPM@//
 /^EXEEXT *=/s/@EXEEXT@/.exe/
 /^PRE_ALLOC_OBJ *=/s/@PRE_ALLOC_OBJ@/lastfile.o/
@@ -109,6 +117,7 @@
 /^M_FILE *=/s!@[^@\n]*@!m/intel386.h!
 /^S_FILE *=/s!@[^@\n]*@!s/msdos.h!
 /^@SET_MAKE@$/s/@SET_MAKE@//
+/^@NS_IMPL_GNUSTEP_INC@/s/@NS_IMPL_GNUSTEP_INC@//
 /^.\${libsrc}make-docfile.*>/s!make-docfile!make-docfile -o ../etc/DOC!
 /^.\${libsrc}make-doc/s!>.*$!!
 /^[ 	]*$/d
--- a/msdos/sed1x.inp	Thu May 13 22:43:33 2010 +0000
+++ b/msdos/sed1x.inp	Fri May 14 07:46:03 2010 +0000
@@ -8,6 +8,9 @@
 /^LIBXMENU *=/s!@LIBXMENU@!${OLDXMENU}!
 /^LIBX_OTHER *=/s!@LIBX_OTHER@!${LIBXT} ${LIBX_EXTRA}!
 /^LIBS_SYSTEM *=/s!= *!= -lxext -lsys!
+/^MSDOS_X_OBJ *=/s!= *!= w16select.o termcap.o!
+/^TOOLTIP_SUPPORT *=/s!= *!= ${lispsource}tooltip.elc!
+/^WINDOW_SUPPORT *=/s!= *!= $(BASE_WINDOW_SUPPORT) $(X_WINDOW_SUPPORT)!
 /^temacs *:/s!OLDXMENU!LIBXMENU!
 
 # arch-tag: 3e8a78f2-3dec-44f3-81f6-3785a562da19
--- a/msdos/sed2x.inp	Thu May 13 22:43:33 2010 +0000
+++ b/msdos/sed2x.inp	Fri May 14 07:46:03 2010 +0000
@@ -2,8 +2,8 @@
 # Extra configuration script for src/config.h for DesqView/X
 # ----------------------------------------------------------------------
 #
-# Copyright (C) 1994, 2001, 2002, 2003, 2004, 2005,
-#   2006, 2007, 2008, 2009, 2010  Free Software Foundation, Inc.
+# Copyright (C) 1994, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
+#   2009, 2010  Free Software Foundation, Inc.
 #
 # This file is part of GNU Emacs.
 #
@@ -17,6 +17,7 @@
 #
 # ----------------------------------------------------------------------
 /^#undef HAVE_X_WINDOWS *$/s/undef/define/
+/^#undef HAVE_WINDOW_SYSTEM *$/s/undef/define/
 /^#undef HAVE_X11 *$/s/undef/define/
 /^#undef HAVE_X_MENU *$/s/undef/define/
 /^#undef HAVE_XSCREENNUMBEROFSCREEN *$/s/undef/define/
--- a/src/ChangeLog	Thu May 13 22:43:33 2010 +0000
+++ b/src/ChangeLog	Fri May 14 07:46:03 2010 +0000
@@ -1,3 +1,52 @@
+2010-05-14  Kenichi Handa  <handa@m17n.org>
+
+	* dispextern.h (struct composition_it): New member reversed_p.
+
+	* composite.c (composition_compute_stop_pos): Search backward if
+	ENDPOS < CHARPOS.
+	(composition_reseat_it): Handle the case that ENDPOS < CHARPOS.
+	Set CMP_IT->reversed_p.
+	(composition_update_it): Pay attention ot CMP_IT->reversed_p.
+
+	* xdisp.c (set_iterator_to_next): Call
+	composition_compute_stop_pos with negative ENDPOS if we are
+	scanning backward.  Call composition_compute_stop_pos if scan
+	direction is changed.
+	(next_element_from_buffer): Call composition_compute_stop_pos with
+	negative ENDPOS if we are scanning backward.
+	(next_element_from_composition): Pay attention to
+	IT->cmp_it.reversed_p.
+
+2010-05-14  Kenichi Handa  <handa@m17n.org>
+
+	* font.c (font_range): Return the range for the font found at
+	first.
+
+2010-05-14  Glenn Morris  <rgm@gnu.org>
+
+	* Makefile.in (ns_appdir, ns_appbindir, ns_appsrc): Always define.
+
+	* Makefile.in (mktime, X11, register): Move undefs to configure.
+
+	* Makefile.in (MSDOS_OBJ): Default to empty, let msdos scripts set it.
+	(MSDOS_X_OBJ): New variable.
+	(MSDOS_SUPPORT_REAL): New constant.
+	(MSDOS_SUPPORT): Set as a variable, not with cpp.
+	(obj): Use MSDOS_X_OBJ.
+	(lisp): Use MSDOS_SUPPORT as a variable.
+
+	* Makefile.in (REAL_MOUSE_SUPPORT): New constant.
+	(GPM_MOUSE_SUPPORT): Now it's a constant.
+	(MOUSE_SUPPORT, TOOLTIP_SUPPORT, WINDOW_SUPPORT): Set with configure,
+	not cpp.
+
+	* Makefile.in (@NS_IMPL_GNUSTEP_INC@): Use in place of #ifdef.
+	(ns_appresdir): Remove, unused.
+
+	* Makefile.in (SHELL): Move outside cpp section.
+
+	* s/netbsd.h (AMPERSAND_FULL_NAME): Remove (defined in AH_BOTTOM).
+
 2010-05-13  Glenn Morris  <rgm@gnu.org>
 
 	* Makefile.in (FONT_DRIVERS): Place with other HAVE_X_WINDOWS stuff.
@@ -53,6 +102,7 @@
 	* xdisp.c (init_iterator): Don't turn on bidi reordering in
 	unibyte buffers.  See
 	http://lists.gnu.org/archive/html/emacs-devel/2010-05/msg00263.html.
+>>>>>>> MERGE-SOURCE
 
 2010-05-10  Glenn Morris  <rgm@gnu.org>
 
--- a/src/Makefile.in	Thu May 13 22:43:33 2010 +0000
+++ b/src/Makefile.in	Fri May 14 07:46:03 2010 +0000
@@ -30,6 +30,7 @@
 # Some of the conditionals might be dead now.  Finding them and
 # deleting them would be fine.
 
+SHELL = /bin/sh
 
 # Here are the things that we expect ../configure to edit.
 # We use $(srcdir) explicitly in dependencies so as not to depend on VPATH.
@@ -183,6 +184,19 @@
 ## sheap.o if CYGWIN, otherwise empty.
 CYGWIN_OBJ=@CYGWIN_OBJ@
 
+## dosfns.o msdos.o if MSDOS.
+MSDOS_OBJ =
+## w16select.o termcap.o if MSDOS && HAVE_X_WINDOWS.
+MSDOS_X_OBJ =
+MSDOS_SUPPORT_REAL = ${lispsource}ls-lisp.elc ${lispsource}disp-table.elc \
+ ${lispsource}dos-fns.elc ${lispsource}dos-w32.elc ${lispsource}dos-vars.elc \
+ ${lispsource}term/internal.elc ${lispsource}term/pc-win.elc
+## $MSDOS_SUPPORT_REAL if MSDOS.
+MSDOS_SUPPORT = 
+
+ns_appdir=@ns_appdir@/
+ns_appbindir=@ns_appbindir@/
+ns_appsrc=@ns_appsrc@
 NS_OBJ=@NS_OBJ@
 NS_SUPPORT=@NS_SUPPORT@
 ## Next two only set if NS_IMPL_GNUSTEP.
@@ -192,10 +206,17 @@
 ## Only used if HAVE_X_WINDOWS.
 FONT_OBJ=@FONT_OBJ@
 
-## ${lispsource}mouse.elc if HAVE_GPM, otherwise empty.
-## Not used if HAVE_MOUSE.
-GPM_MOUSE_SUPPORT=@GPM_MOUSE_SUPPORT@
+## Used if HAVE_MOUSE.
+REAL_MOUSE_SUPPORT=${lispsource}mouse.elc ${lispsource}select.elc \
+  ${lispsource}scroll-bar.elc
+## Used if HAVE_GPM && !HAVE_MOUSE
+GPM_MOUSE_SUPPORT=${lispsource}mouse.elc
 LIBGPM = @LIBGPM@
+## Either of the two preceding options, or empty.
+MOUSE_SUPPORT=@MOUSE_SUPPORT@
+
+## ${lispsource}tooltip.elc if HAVE_WINDOW_SYSTEM, else empty.
+TOOLTIP_SUPPORT=@TOOLTIP_SUPPORT@
 
 BASE_WINDOW_SUPPORT=${lispsource}fringe.elc ${lispsource}image.elc \
   ${lispsource}international/fontset.elc ${lispsource}dnd.elc \
@@ -204,6 +225,10 @@
 X_WINDOW_SUPPORT=${lispsource}x-dnd.elc ${lispsource}term/common-win.elc \
   ${lispsource}term/x-win.elc ${lispsource}dynamic-setting.elc
 
+## If HAVE_X_WINDOWS, both the above
+## else if HAVE_WINDOW_SYSTEM (ie, HAVE_NS) just the former; else empty.
+WINDOW_SUPPORT=@WINDOW_SUPPORT@
+
 ## -lresolv, or empty.
 LIBRESOLV = @LIBRESOLV@
 
@@ -222,9 +247,6 @@
 # ========================== start of cpp stuff =======================
 /* From here on, comments must be done in C syntax.  */
 
-/* just to be sure the sh is used */
-SHELL=/bin/sh
-
 #define NOT_C_CODE
 #include "config.h"
 
@@ -232,37 +254,13 @@
 DEPFLAGS = -MMD -MF deps/$*.d
 #endif
 
-/* Do not let the file name mktime.c get messed up.  */
-#ifdef mktime
-#undef mktime
-#endif
-
-/* Use HAVE_X11 as an alias for X11 in this file
-   to avoid problems with X11 as a subdirectory name
-   in -I and other such options which pass through this file. */
-
-#ifdef X11
-#define HAVE_X11
-#undef X11
-#endif
-
-/* On some machines #define register is done in config;
-   do not let it interfere with this file.  */
-#undef register
-
-#ifdef NS_IMPL_GNUSTEP
-/* Pull in stuff from GNUstep-make. */
-FOUNDATION_LIB=gnu
-GUI_LIB=gnu
-include @GNUSTEP_MAKEFILES@/Additional/base.make
-include @GNUSTEP_MAKEFILES@/Additional/gui.make
-shared=no
-#endif
+/* If NS_IMPL_GNUSTEP, some definitions and includes are expanded here.  */
+@NS_IMPL_GNUSTEP_INC@
 
 /* DO NOT use -R.  There is a special hack described in lastfile.c
    which is used instead.  Some initialized data areas are modified
    at initial startup, then labeled as part of the text area when
-   Emacs is dumped for the first time, and never changed again. */
+   Emacs is dumped for the first time, and never changed again.  */
 
 /* -Demacs is needed to make some files produce the correct version
    for use in Emacs.
@@ -338,24 +336,8 @@
 
 #endif /* not ORDINARY_LINK */
 
-
-#ifdef MSDOS
-#ifdef HAVE_X_WINDOWS
-MSDOS_OBJ = dosfns.o msdos.o
-#else
-MSDOS_OBJ = dosfns.o msdos.o w16select.o termcap.o
-#endif
-#endif
-
-#ifdef HAVE_NS
-ns_appdir=@ns_appdir@/
-ns_appbindir=@ns_appbindir@/
-ns_appresdir=@ns_appresdir@/
-ns_appsrc=@ns_appsrc@
-#endif  /* HAVE_NS */
-
-/* lastfile must follow all files
-   whose initialized data areas should be dumped as pure by dump-emacs.  */
+/* lastfile must follow all files whose initialized data areas should
+   be dumped as pure by dump-emacs.  */
 obj=    dispnew.o frame.o scroll.o xdisp.o menu.o $(XMENU_OBJ) window.o \
 	charset.o coding.o category.o ccl.o character.o chartab.o bidi.o \
 	cm.o term.o terminal.o xfaces.o $(XOBJ) $(GTK_OBJ) $(DBUS_OBJ) \
@@ -369,11 +351,10 @@
 	process.o callproc.o \
 	region-cache.o sound.o atimer.o \
 	doprnt.o strftime.o intervals.o textprop.o composite.o md5.o \
-	$(MSDOS_OBJ) $(NS_OBJ) $(CYGWIN_OBJ) $(FONT_DRIVERS)
+	$(MSDOS_OBJ) $(MSDOS_X_OBJ) $(NS_OBJ) $(CYGWIN_OBJ) $(FONT_DRIVERS)
 
 /* Object files used on some machine or other.
-   These go in the DOC file on all machines
-   in case they are needed there.  */
+   These go in the DOC file on all machines in case they are needed.  */
 SOME_MACHINE_OBJECTS = dosfns.o msdos.o \
   xterm.o xfns.o xmenu.o xselect.o xrdb.o xsmfns.o fringe.o image.o \
   fontset.o dbusbind.o \
@@ -405,34 +386,6 @@
 otherobj= $(TERMCAP_OBJ) $(PRE_ALLOC_OBJ) $(gmallocobj) $(rallocobj) \
   $(POST_ALLOC_OBJ) $(WIDGET_OBJ) $(LIBOBJS)
 
-#ifdef HAVE_MOUSE
-#define MOUSE_SUPPORT ${lispsource}mouse.elc \
-  ${lispsource}select.elc ${lispsource}scroll-bar.elc
-#else
-#define MOUSE_SUPPORT $(GPM_MOUSE_SUPPORT)
-#endif
-
-#ifdef MSDOS
-#define MSDOS_SUPPORT ${lispsource}ls-lisp.elc ${lispsource}disp-table.elc \
- ${lispsource}dos-fns.elc ${lispsource}dos-w32.elc ${lispsource}dos-vars.elc \
- ${lispsource}term/internal.elc ${lispsource}term/pc-win.elc
-
-#else
-#define MSDOS_SUPPORT
-#endif
-
-#ifdef HAVE_WINDOW_SYSTEM
-#define TOOLTIP_SUPPORT ${lispsource}tooltip.elc
-#ifdef HAVE_X_WINDOWS
-#define WINDOW_SUPPORT $(BASE_WINDOW_SUPPORT) $(X_WINDOW_SUPPORT)
-#else
-#define WINDOW_SUPPORT $(BASE_WINDOW_SUPPORT)
-#endif /* HAVE_X_WINDOWS */
-#else
-#define TOOLTIP_SUPPORT
-#define WINDOW_SUPPORT
-#endif /* HAVE_WINDOW_SYSTEM */
-
 /* This is the platform-specific list of Lisp files loaded into the
    dumped Emacs.  It is arranged like this because it is easier to generate
    it semi-mechanically from loadup.el this way.
@@ -466,7 +419,7 @@
 	${lispsource}files.elc \
 	${lispsource}format.elc \
 	${lispsource}facemenu.elc \
-	MOUSE_SUPPORT \
+	${MOUSE_SUPPORT} \
 	${lispsource}emacs-lisp/float-sup.elc \
 	${lispsource}frame.elc \
 	${lispsource}help.elc \
@@ -529,9 +482,9 @@
 	${lispsource}vc-hooks.elc \
 	${lispsource}ediff-hook.elc \
 	${lispsource}epa-hook.elc \
-	TOOLTIP_SUPPORT \
-	MSDOS_SUPPORT \
-	WINDOW_SUPPORT \
+	${TOOLTIP_SUPPORT} \
+	${MSDOS_SUPPORT} \
+	${WINDOW_SUPPORT} \
 	${NS_SUPPORT} \
 	${lispsource}widget.elc \
 	${lispsource}window.elc \
@@ -713,9 +666,8 @@
 
 #if defined (HAVE_X_WINDOWS) && defined (HAVE_X11) && defined (HAVE_MENUS) && ! defined (USE_GTK)
 
-/* We use stamp-xmenu with these two deps
-   to both ensure that lwlib gets remade based on its dependencies
-   in its own makefile,
+/* We use stamp-xmenu with these two deps to both ensure that lwlib
+   gets remade based on its dependencies in its own makefile,
    and remake temacs if lwlib gets changed by this.  */
 stamp-oldxmenu: ${OLDXMENU} ../src/$(OLDXMENU)
 	touch stamp-oldxmenu
@@ -769,6 +721,8 @@
 Eg callproc.c only depends on w32.h for WINDOWSNT builds.
 One way to fix this would be to replace w32.h (etc) by $(W32_H),
 a variable set by configure.  Does not seem worth the trouble.
+Since the w32 build does not even use this file, you might ask
+why these dependencies are here at all...
 
 nsgui.h: In fact, every .o file depends directly or indirectly on
 dispextern.h and hence nsgui.h under NS.  But the ones that actually
@@ -978,8 +932,8 @@
 xsettings.o: xterm.h xsettings.h lisp.h frame.h termhooks.h $(config_h) \
   dispextern.h keyboard.h systime.h coding.h composite.h blockinput.h atimer.h \
   termopts.h
-/* The files of Lisp proper */
 
+/* The files of Lisp proper.  */
 alloc.o: alloc.c process.h frame.h window.h buffer.h  puresize.h syssignal.h \
  keyboard.h blockinput.h atimer.h systime.h character.h lisp.h $(config_h) \
  $(INTERVALS_H) termhooks.h
@@ -1001,7 +955,7 @@
  charset.h lisp.h $(config_h) $(INTERVALS_H) termhooks.h coding.h msdos.h \
  systime.h frame.h blockinput.h atimer.h
 
-/* Text properties support */
+/* Text properties support.  */
 composite.o: composite.c buffer.h character.h coding.h font.h ccl.h \
 	 frame.h termhooks.h $(INTERVALS_H) window.h lisp.h $(config_h)
 intervals.o: intervals.c buffer.h $(INTERVALS_H) keyboard.h puresize.h \
@@ -1012,8 +966,7 @@
 #endif /* ! AUTO_DEPEND */
 
 /* System-specific programs to be made.
-   OTHER_FILES
-   select which of these should be compiled.  */
+   OTHER_FILES select which of these should be compiled.  */
 
 #ifdef HAVE_NS
 ${ns_appdir}: ${ns_appsrc}
--- a/src/composite.c	Thu May 13 22:43:33 2010 +0000
+++ b/src/composite.c	Fri May 14 07:46:03 2010 +0000
@@ -1018,12 +1018,29 @@
   return unbind_to (count, Qnil);
 }
 
+static Lisp_Object _work_val;
+static int _work_char;
+
+/* 1 iff the character C is composable.  */
+#define CHAR_COMPOSABLE_P(C)						\
+  ((C) == 0x200C || (C) == 0x200D					\
+   || (_work_val = CHAR_TABLE_REF (Vunicode_category_table, (C)),	\
+       (SYMBOLP (_work_val)						\
+	&& (_work_char = SDATA (SYMBOL_NAME (_work_val))[0]) != 'C'	\
+	&& _work_char != 'Z')))
 
 /* Update cmp_it->stop_pos to the next position after CHARPOS (and
    BYTEPOS) where character composition may happen.  If BYTEPOS is
-   negative, compute it.  If it is a static composition, set
-   cmp_it->ch to -1.  Otherwise, set cmp_it->ch to the character that
-   triggers a automatic composition.  */
+   negative, compute it.  ENDPOS is a limit of searching.  If it is
+   less than CHARPOS, search backward to ENDPOS+1 assuming that
+   set_iterator_to_next works in reverse order.  In this case, if a
+   composition closest to CHARPOS is found, set cmp_it->stop_pos to
+   the last character of the composition.
+
+   If no composition is found, set cmp_it->ch to -2.  If a static
+   composition is found, set cmp_it->ch to -1.  Otherwise, set
+   cmp_it->ch to the character that triggers the automatic
+   composition.  */
 
 void
 composition_compute_stop_pos (cmp_it, charpos, bytepos, endpos, string)
@@ -1036,60 +1053,200 @@
   /* This is from forward_to_next_line_start in xdisp.c.  */
   const int MAX_NEWLINE_DISTANCE = 500;
 
-  if (endpos > charpos + MAX_NEWLINE_DISTANCE)
-    endpos = charpos + MAX_NEWLINE_DISTANCE;
-  cmp_it->stop_pos = endpos;
+  if (charpos < endpos)
+    {
+      if (endpos > charpos + MAX_NEWLINE_DISTANCE)
+	endpos = charpos + MAX_NEWLINE_DISTANCE;
+    }
+  else if (endpos < charpos)
+    {
+      /* We search backward for a position to check composition.  */
+      if (endpos < 0)
+	{
+	  /* But we don't know where to stop the searching.  */
+	  endpos = NILP (string) ? BEGV - 1 : -1;
+	  /* Usually we don't reach ENDPOS because we stop searching
+	     at an uncomposable character (NL, LRE, etc).  */
+	}
+    }
   cmp_it->id = -1;
   cmp_it->ch = -2;
-  if (find_composition (charpos, endpos, &start, &end, &prop, string)
+  cmp_it->reversed_p = 0;
+  cmp_it->stop_pos = endpos;
+  if (charpos == endpos)
+    return;
+  /* FIXME: Bidi is not yet handled well in static composition.  */
+  if (charpos < endpos
+      && find_composition (charpos, endpos, &start, &end, &prop, string)
       && COMPOSITION_VALID_P (start, end, prop))
     {
       cmp_it->stop_pos = endpos = start;
       cmp_it->ch = -1;
     }
-  if (NILP (string) && PT > charpos && PT < endpos)
-    cmp_it->stop_pos = PT;
+  if (NILP (string))
+    {
+      /* A composition never strides over PT.  */
+      if (PT > charpos)
+	{
+	  if (PT < endpos)
+	    cmp_it->stop_pos = endpos = PT;
+	}
+      else if (PT < charpos && PT > endpos)
+	{
+	  cmp_it->stop_pos = endpos = PT - 1;
+	}
+    }
   if (NILP (current_buffer->enable_multibyte_characters)
       || NILP (Vauto_composition_mode))
     return;
   if (bytepos < 0)
     {
-      if (STRINGP (string))
+      if (NILP (string))
+	bytepos = CHAR_TO_BYTE (charpos);
+      else
 	bytepos = string_char_to_byte (string, charpos);
-      else
-	bytepos = CHAR_TO_BYTE (charpos);
     }
 
   start = charpos;
-  while (charpos < endpos)
+  if (charpos < endpos)
     {
-      if (STRINGP (string))
-	FETCH_STRING_CHAR_ADVANCE (c, string, charpos, bytepos);
+      /* Forward search.  */
+      while (charpos < endpos)
+	{
+	  if (STRINGP (string))
+	    FETCH_STRING_CHAR_ADVANCE (c, string, charpos, bytepos);
+	  else
+	    FETCH_CHAR_ADVANCE (c, charpos, bytepos);
+	  if (c == '\n')
+	    {
+	      cmp_it->ch = -2;
+	      break;
+	    }
+	  val = CHAR_TABLE_REF (Vcomposition_function_table, c);
+	  if (! NILP (val))
+	    {
+	      Lisp_Object elt;
+
+	      for (; CONSP (val); val = XCDR (val))
+		{
+		  elt = XCAR (val);
+		  if (VECTORP (elt) && ASIZE (elt) == 3
+		      && NATNUMP (AREF (elt, 1))
+		      && charpos - 1 - XFASTINT (AREF (elt, 1)) >= start)
+		    break;
+		}
+	      if (CONSP (val))
+		{
+		  cmp_it->lookback = XFASTINT (AREF (elt, 1));
+		  cmp_it->stop_pos = charpos - 1 - cmp_it->lookback;
+		  cmp_it->ch = c;
+		  return;
+		}
+	    }
+	}
+    }
+  else
+    {
+      /* Search backward for a pattern that may be composed and the
+	 position of (possibly) the last character of the match is
+	 closest to (but not after) START.  The reason for the last
+	 character is that set_iterator_to_next works in reverse order
+	 and, thus we must stop at the last character for composition
+	 check.  */
+      unsigned char *p;
+      int len;
+      /* limit byte position used in fast_looking_at.  This is the
+	 byte position of the next character of START. */
+      EMACS_INT limit;
+
+      if (NILP (string))
+	p = BYTE_POS_ADDR (bytepos);
       else
-	FETCH_CHAR_ADVANCE (c, charpos, bytepos);
-      if (c == '\n')
-	{
-	  cmp_it->ch = -2;
-	  break;
-	}
-      val = CHAR_TABLE_REF (Vcomposition_function_table, c);
-      if (! NILP (val))
+	p = SDATA (string) + bytepos;
+      c = STRING_CHAR_AND_LENGTH (p, len);
+      limit = bytepos + len;
+      while (CHAR_COMPOSABLE_P (c))
 	{
-	  Lisp_Object elt;
-
-	  for (; CONSP (val); val = XCDR (val))
+	  for (val = CHAR_TABLE_REF (Vcomposition_function_table, c);
+	       CONSP (val); val = XCDR (val))
 	    {
-	      elt = XCAR (val);
-	      if (VECTORP (elt) && ASIZE (elt) == 3 && NATNUMP (AREF (elt, 1))
-		  && charpos - 1 - XFASTINT (AREF (elt, 1)) >= start)
-		break;
+	      Lisp_Object elt = XCAR (val);
+	      int back, len;
+
+	      if (VECTORP (elt) && ASIZE (elt) == 3
+		  && NATNUMP (AREF (elt, 1))
+		  && charpos - (back = XFASTINT (AREF (elt, 1))) > endpos)
+		{
+		  EMACS_INT cpos = charpos - back, bpos;
+
+		  if (back == 0)
+		    bpos = bytepos;
+		  else
+		    bpos = (NILP (string) ? CHAR_TO_BYTE (cpos)
+			    : string_char_to_byte (string, cpos));
+		  if (STRINGP (AREF (elt, 0)))
+		    len = fast_looking_at (AREF (elt, 0), cpos, bpos,
+					   start + 1, limit, string);
+		  else
+		    len = 1;
+		  if (len > 0)
+		    {
+		      /* Make CPOS points the last character of match.
+			 Note that LEN is byte-length.  */
+		      bpos += len;
+		      if (NILP (string))
+			cpos = BYTE_TO_CHAR (bpos) - 1;
+		      else
+			cpos = string_byte_to_char (string, bpos) - 1;
+		      back = cpos - (charpos - back);
+		      if (cmp_it->stop_pos < cpos
+			  || (cmp_it->stop_pos == cpos
+			      && cmp_it->lookback < back))
+			{
+			  cmp_it->stop_pos = cpos;
+			  cmp_it->ch = c;
+			  cmp_it->lookback = back;
+			}
+		    }
+		}
 	    }
-	  if (CONSP (val))
+	  if (charpos - 1 == endpos)
+	    break;
+	  if (STRINGP (string))
+	    {
+	      p--, bytepos--;
+	      while (! CHAR_HEAD_P (*p))
+		p--, bytepos--;
+	      charpos--;
+	    }
+	  else
 	    {
-	      cmp_it->lookback = XFASTINT (AREF (elt, 1));
-	      cmp_it->stop_pos = charpos - 1 - cmp_it->lookback;
-	      cmp_it->ch = c;
-	      return;
+	      DEC_BOTH (charpos, bytepos);
+	      p = BYTE_POS_ADDR (bytepos);
+	    }
+	  c = STRING_CHAR (p);
+	}
+      if (cmp_it->ch >= 0)
+	/* We found a position to check.  */
+	return;
+      /* Skip all uncomposable characters.  */
+      if (NILP (string))
+	{
+	  while (charpos - 1 > endpos && ! CHAR_COMPOSABLE_P (c))
+	    {
+	      DEC_BOTH (charpos, bytepos);
+	      c = FETCH_MULTIBYTE_CHAR (bytepos);
+	    }
+	}
+      else
+	{
+	  while (charpos - 1 > endpos && ! CHAR_COMPOSABLE_P (c))
+	    {
+	      p--;
+	      while (! CHAR_HEAD_P (*p))
+		p--;
+	      charpos--;
+	      c = STRING_CHAR (p);
 	    }
 	}
     }
@@ -1104,8 +1261,8 @@
    string.  In that case, FACE must not be NULL.
 
    If the character is composed, setup members of CMP_IT (id, nglyphs,
-   and from), and return 1.  Otherwise, update CMP_IT->stop_pos, and
-   return 0.  */
+   from, to, reversed_p), and return 1.  Otherwise, update
+   CMP_IT->stop_pos, and return 0.  */
 
 int
 composition_reseat_it (cmp_it, charpos, bytepos, endpos, w, face, string)
@@ -1115,13 +1272,29 @@
      struct face *face;
      Lisp_Object string;
 {
-  if (NILP (string) && charpos < PT && PT < endpos)
-    endpos = PT;
+  if (endpos <= charpos)
+    {
+      if (NILP (string))
+	{
+	  if (endpos < 0)
+	    endpos = BEGV;
+	  if (endpos < PT && PT < charpos) 
+	    endpos = PT;
+	}
+      else if (endpos < 0)
+	endpos = 0;
+    }
+  else
+    {
+      if (NILP (string) && charpos < PT && PT < endpos)
+	endpos = PT;
+    }
 
   if (cmp_it->ch == -2)
     {
       composition_compute_stop_pos (cmp_it, charpos, bytepos, endpos, string);
-      if (cmp_it->ch == -2)
+      if (cmp_it->stop_pos != charpos)
+	/* The current position is not composed.  */
 	return 0;
     }
 
@@ -1145,18 +1318,46 @@
       int i;
 
       val = CHAR_TABLE_REF (Vcomposition_function_table, cmp_it->ch);
-      for (; CONSP (val); val = XCDR (val))
+      if (charpos < endpos)
 	{
-	  elt = XCAR (val);
-	  if (cmp_it->lookback == XFASTINT (AREF (elt, 1)))
-	    break;
+	  for (; CONSP (val); val = XCDR (val))
+	    {
+	      elt = XCAR (val);
+	      if (cmp_it->lookback == XFASTINT (AREF (elt, 1)))
+		break;
+	    }
+	  if (NILP (val))
+	    goto no_composition;
+
+	  val = autocmp_chars (val, charpos, bytepos, endpos, w, face, string);
+	  if (! composition_gstring_p (val))
+	    goto no_composition;
+	  cmp_it->reversed_p = 0;
 	}
-      if (NILP (val))
-	goto no_composition;
+      else
+	{
+	  EMACS_INT saved_charpos = charpos, saved_bytepos = bytepos;
 
-      val = autocmp_chars (val, charpos, bytepos, endpos, w, face, string);
-      if (! composition_gstring_p (val))
-	goto no_composition;
+	  if (cmp_it->lookback > 0)
+	    {
+	      charpos -= cmp_it->lookback;
+	      if (charpos < endpos)
+		goto no_composition;
+	      if (STRINGP (string))
+		bytepos = string_char_to_byte (string, charpos);
+	      else
+		bytepos = CHAR_TO_BYTE (charpos);
+	    }
+	  val = autocmp_chars (val, charpos, bytepos, saved_charpos + 1,
+			       w, face, string);
+	  if (! composition_gstring_p (val)
+	      || charpos + LGSTRING_CHAR_LEN (val) <= saved_charpos)
+	    {
+	      charpos = saved_charpos, bytepos = saved_bytepos;
+	      goto no_composition;
+	    }
+	  cmp_it->reversed_p = 1;
+	}
       if (NILP (LGSTRING_ID (val)))
 	val = composition_gstring_put_cache (val, -1);
       cmp_it->id = XINT (LGSTRING_ID (val));
@@ -1164,22 +1365,40 @@
 	if (NILP (LGSTRING_GLYPH (val, i)))
 	  break;
       cmp_it->nglyphs = i;
+      cmp_it->from = 0;
+      cmp_it->to = i;
     }
   else
     goto no_composition;
-  cmp_it->from = 0;
   return 1;
 
  no_composition:
-  charpos++;
-  if (STRINGP (string))
-    bytepos += MULTIBYTE_LENGTH_NO_CHECK (SDATA (string) + bytepos);
+  if (charpos == endpos)
+    return 0;
+  if (charpos < endpos)
+    {
+      charpos++;
+      if (STRINGP (string))
+	bytepos += MULTIBYTE_LENGTH_NO_CHECK (SDATA (string) + bytepos);
+      else
+	INC_POS (bytepos);
+    }
   else
-    INC_POS (bytepos);
+    {
+      charpos--;
+      /* BYTEPOS is calculated in composition_compute_stop_pos */
+      bytepos = -1;
+    }
   composition_compute_stop_pos (cmp_it, charpos, bytepos, endpos, string);
   return 0;
 }
 
+/* Update nchars, nbytes, and width of the current grapheme cluster
+   which is identified by CMP_IT->from (if the composition is static
+   or automatic in l2r context) or CMPT_IT->to (if the composition is
+   automatic in r2l context).  In addition, in the former case, update
+   CMP_IT->to, and in the latter case, update CMP_IT->from.  */
+
 int
 composition_update_it (cmp_it, charpos, bytepos, string)
      struct composition_it *cmp_it;
@@ -1215,7 +1434,7 @@
 	  cmp_it->nchars = LGSTRING_CHAR_LEN (gstring);
 	  cmp_it->width = 0;
 	}
-      else
+      else if (! cmp_it->reversed_p)
 	{
 	  Lisp_Object glyph = LGSTRING_GLYPH (gstring, cmp_it->from);
 	  int from = LGLYPH_FROM (glyph);
@@ -1234,6 +1453,33 @@
 		cmp_it->width += CHAR_WIDTH (LGLYPH_CHAR (glyph));
 	    }
 	}
+      else
+	{
+	  int from_idx = cmp_it->to - 1;
+	  Lisp_Object glyph = LGSTRING_GLYPH (gstring, from_idx);
+	  int from = LGLYPH_FROM (glyph);
+
+	  c = XINT (LGSTRING_CHAR (gstring, from));
+	  cmp_it->nchars = LGLYPH_TO (glyph) - from + 1;
+	  cmp_it->width = (LGLYPH_WIDTH (glyph) > 0
+			   ? CHAR_WIDTH (LGLYPH_CHAR (glyph)) : 0);
+	  for (from_idx--; from_idx >= 0; from_idx--)
+	    {
+	      glyph = LGSTRING_GLYPH (gstring, from_idx);
+	      if (LGLYPH_FROM (glyph) != from)
+		break;
+	      if (LGLYPH_WIDTH (glyph) > 0)
+		cmp_it->width += CHAR_WIDTH (LGLYPH_CHAR (glyph));
+	    }
+	  cmp_it->from = from_idx + 1;
+	  charpos -= cmp_it->nchars - 1;
+	  bytepos += CHAR_BYTES (c);
+	  if (STRINGP (string))
+	    cmp_it->nbytes = bytepos - string_char_to_byte (string, charpos);
+	  else
+	    cmp_it->nbytes = bytepos - CHAR_TO_BYTE (charpos);
+	  return c;
+	}
     }
 
   charpos += cmp_it->nchars;
@@ -1279,17 +1525,6 @@
     (POSITION).pos--;				\
   } while (0)
 
-static Lisp_Object _work_val;
-static int _work_char;
-
-/* 1 iff the character C is composable.  */
-#define CHAR_COMPOSABLE_P(C)						\
-  ((C) == 0x200C || (C) == 0x200D					\
-   || (_work_val = CHAR_TABLE_REF (Vunicode_category_table, (C)),	\
-       (SYMBOLP (_work_val)						\
-	&& (_work_char = SDATA (SYMBOL_NAME (_work_val))[0]) != 'C'	\
-	&& _work_char != 'Z')))
-
 /* This is like find_composition, but find an automatic composition
    instead.  If found, set *GSTRING to the glyph-string representing
    the composition, and return 1.  Otherwise, return 0.  */
--- a/src/config.in	Thu May 13 22:43:33 2010 +0000
+++ b/src/config.in	Fri May 14 07:46:03 2010 +0000
@@ -482,6 +482,9 @@
 /* Define to 1 if you have a working `mmap' system call. */
 #undef HAVE_MMAP
 
+/* Define if you have mouse support. */
+#undef HAVE_MOUSE
+
 /* Define to 1 if you have the `mremap' function. */
 #undef HAVE_MREMAP
 
@@ -737,6 +740,9 @@
 /* Define to 1 if you have the <vfork.h> header file. */
 #undef HAVE_VFORK_H
 
+/* Define if you have a window system. */
+#undef HAVE_WINDOW_SYSTEM
+
 /* Define to 1 if `fork' works. */
 #undef HAVE_WORKING_FORK
 
@@ -1004,12 +1010,6 @@
 #undef volatile
 
 
-/* If we're using X11/Carbon/GNUstep, define some consequences.  */
-#if defined(HAVE_X_WINDOWS) || defined(HAVE_NS)
-#define HAVE_WINDOW_SYSTEM
-#define HAVE_MOUSE
-#endif
-
 /* Define AMPERSAND_FULL_NAME if you use the convention
    that & in the full name stands for the login id.  */
 /* Turned on June 1996 supposing nobody will mind it.  */
@@ -1034,7 +1034,7 @@
 #endif
 #endif /* __FreeBSD__ || __NetBSD__ || __linux__  */
 
-/* If using GNU, then support inline function declarations. */
+/* If using GNU, then support inline function declarations.  */
 /* Don't try to switch on inline handling as detected by AC_C_INLINE
    generally, because even if non-gcc compilers accept `inline', they
    may reject `extern inline'.  */
@@ -1059,7 +1059,7 @@
 /* Set up some defines, C and LD flags for NeXTstep interface on GNUstep.
   (There is probably a better place to do this, but right now the Cocoa
    side does this in s/darwin.h and we cannot
-   parallel this exactly since GNUstep is multi-OS. */
+   parallel this exactly since GNUstep is multi-OS.  */
 #ifdef HAVE_NS
 # ifdef NS_IMPL_GNUSTEP
 /* GNUstep needs a bit more pure memory.  Of the existing knobs,
@@ -1156,7 +1156,7 @@
 #include "string.h"
 #endif
 #ifdef HAVE_STRINGS_H
-#include "strings.h"  /* May be needed for bcopy & al. */
+#include "strings.h"  /* May be needed for bcopy & al.  */
 #endif
 #ifdef HAVE_STDLIB_H
 #include <stdlib.h>
--- a/src/dispextern.h	Thu May 13 22:43:33 2010 +0000
+++ b/src/dispextern.h	Fri May 14 07:46:03 2010 +0000
@@ -1987,6 +1987,10 @@
      graphic display and in units of canonical characters on a
      terminal display.  */
   int width;
+  /* Nonzero iff the composition is created while buffer is scanned in
+     reverse order, and thus the grapheme clusters must be rendered
+     from the last to the first.  */
+  int reversed_p;
 };
 
 struct it
--- a/src/font.c	Thu May 13 22:43:33 2010 +0000
+++ b/src/font.c	Fri May 14 07:46:03 2010 +0000
@@ -3961,7 +3961,7 @@
      struct face *face;
      Lisp_Object string;
 {
-  EMACS_INT pos_byte, ignore, start, start_byte;
+  EMACS_INT pos_byte, ignore;
   int c;
   Lisp_Object font_object = Qnil;
 
@@ -3983,7 +3983,6 @@
       pos_byte = string_char_to_byte (string, pos);
     }
 
-  start = pos, start_byte = pos_byte;
   while (pos < *limit)
     {
       Lisp_Object category;
@@ -3992,6 +3991,10 @@
 	FETCH_CHAR_ADVANCE_NO_CHECK (c, pos, pos_byte);
       else
 	FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c, string, pos, pos_byte);
+      category = CHAR_TABLE_REF (Vunicode_category_table, c);
+      if (EQ (category, QCf)
+	  || CHAR_VARIATION_SELECTOR_P (c))
+	continue;
       if (NILP (font_object))
 	{
 	  font_object = font_for_char (face, c, pos - 1, string);
@@ -3999,40 +4002,8 @@
 	    return Qnil;
 	  continue;
 	}
-
-      category = CHAR_TABLE_REF (Vunicode_category_table, c);
-      if (! EQ (category, QCf)
-	  && ! CHAR_VARIATION_SELECTOR_P (c)
-	  && font_encode_char (font_object, c) == FONT_INVALID_CODE)
-	{
-	  Lisp_Object f = font_for_char (face, c, pos - 1, string);
-	  EMACS_INT i, i_byte;
-
-
-	  if (NILP (f))
-	    {
-	      *limit = pos - 1;
-	      return font_object;
-	    }
-	  i = start, i_byte = start_byte;
-	  while (i < pos - 1)
-	    {
-
-	      if (NILP (string))
-		FETCH_CHAR_ADVANCE_NO_CHECK (c, i, i_byte);
-	      else
-		FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c, string, i, i_byte);
-	      category = CHAR_TABLE_REF (Vunicode_category_table, c);
-	      if (! EQ (category, QCf)
-		  && ! CHAR_VARIATION_SELECTOR_P (c)
-		  && font_encode_char (f, c) == FONT_INVALID_CODE)
-		{
-		  *limit = pos - 1;
-		  return font_object;
-		}
-	    }
-	  font_object = f;
-	}
+      if (font_encode_char (font_object, c) == FONT_INVALID_CODE)
+	*limit = pos - 1;
     }
   return font_object;
 }
--- a/src/s/netbsd.h	Thu May 13 22:43:33 2010 +0000
+++ b/src/s/netbsd.h	Fri May 14 07:46:03 2010 +0000
@@ -26,8 +26,6 @@
 
 #define PENDING_OUTPUT_COUNT(FILE) ((FILE)->_p - (FILE)->_bf._base)
 
-#define AMPERSAND_FULL_NAME
-
 /* On post 1.3 releases of NetBSD, gcc -nostdlib also clears
    the library search parth, i.e. it won't search /usr/lib
    for libc and friends.  Using -nostartfiles instead avoids
--- a/src/xdisp.c	Thu May 13 22:43:33 2010 +0000
+++ b/src/xdisp.c	Fri May 14 07:46:03 2010 +0000
@@ -6285,25 +6285,96 @@
 	reseat_at_next_visible_line_start (it, 0);
       else if (it->cmp_it.id >= 0)
 	{
-	  IT_CHARPOS (*it) += it->cmp_it.nchars;
-	  IT_BYTEPOS (*it) += it->cmp_it.nbytes;
-	  if (it->bidi_p)
-	    {
-	      if (it->bidi_it.new_paragraph)
-		bidi_paragraph_init (it->paragraph_embedding, &it->bidi_it);
-	      /* Resync the bidi iterator with IT's new position.
-		 FIXME: this doesn't support bidirectional text.  */
-	      while (it->bidi_it.charpos < IT_CHARPOS (*it))
+	  /* We are currently getting glyphs from a composition.  */
+	  int i;
+
+	  if (! it->bidi_p)
+	    {
+	      IT_CHARPOS (*it) += it->cmp_it.nchars;
+	      IT_BYTEPOS (*it) += it->cmp_it.nbytes;
+	      if (it->cmp_it.to < it->cmp_it.nglyphs)
+		{
+		  it->cmp_it.from = it->cmp_it.to;
+		}
+	      else
+		{
+		  it->cmp_it.id = -1;
+		  composition_compute_stop_pos (&it->cmp_it, IT_CHARPOS (*it),
+						IT_BYTEPOS (*it),
+						it->stop_charpos, Qnil);
+		}
+	    }
+	  else if (! it->cmp_it.reversed_p)
+	    {
+	      /* Composition created while scanning forward.  */
+	      /* Update IT's char/byte positions to point the first
+		 character of the next grapheme cluster, or to the
+		 character visually after the current composition.  */
+#if 0
+	      /* Is it ok to do this directly? */
+	      IT_CHARPOS (*it) += it->cmp_it.nchars;
+	      IT_BYTEPOS (*it) += it->cmp_it.nbytes;
+#else
+	      /* Or do we have to call bidi_get_next_char_visually
+		 repeatedly (perhaps not to confuse some internal
+		 state of bidi_it)?  At least we must do this if we
+		 have consumed all grapheme clusters in the current
+		 composition because the next character will be in the
+		 different bidi level.  */
+	      for (i = 0; i < it->cmp_it.nchars; i++)
 		bidi_get_next_char_visually (&it->bidi_it);
-	    }
-	  if (it->cmp_it.to < it->cmp_it.nglyphs)
-	    it->cmp_it.from = it->cmp_it.to;
-	  else
-	    {
-	      it->cmp_it.id = -1;
-	      composition_compute_stop_pos (&it->cmp_it, IT_CHARPOS (*it),
-					    IT_BYTEPOS (*it), it->stop_charpos,
-					    Qnil);
+	      /* BTW, it seems that the name
+		 bidi_get_next_char_visually is confusing because
+		 it sounds like not advancing character position.
+		 How about bidi_set_iterator_to_next? */
+	      IT_BYTEPOS (*it) = it->bidi_it.bytepos;
+	      IT_CHARPOS (*it) = it->bidi_it.charpos;
+#endif
+	      if (it->cmp_it.to < it->cmp_it.nglyphs)
+		{
+		  /* Proceed to the next grapheme cluster.  */
+		  it->cmp_it.from = it->cmp_it.to;
+		}
+	      else
+		{
+		  /* No more grapheme cluster in this composition.
+		     Find the next stop position.  */
+		  EMACS_INT stop = it->stop_charpos;
+		  if (it->bidi_it.scan_dir < 0)
+		    /* Now we are scanning backward and don't know
+		       where to stop.  */
+		    stop = -1;
+		  composition_compute_stop_pos (&it->cmp_it, IT_CHARPOS (*it),
+						IT_BYTEPOS (*it), stop, Qnil);
+		}
+	    }
+	  else
+	    {
+	      /* Composition created while scanning backward.  */
+	      /* Update IT's char/byte positions to point the last
+		 character of the previous grapheme cluster, or the
+		 character visually after the current composition.  */
+	      bidi_get_next_char_visually (&it->bidi_it);
+	      IT_BYTEPOS (*it) = it->bidi_it.bytepos;
+	      IT_CHARPOS (*it) = it->bidi_it.charpos;
+
+	      if (it->cmp_it.from > 0)
+		{
+		  /* Proceed to the previous grapheme cluster.  */
+		  it->cmp_it.to = it->cmp_it.from;
+		}
+	      else
+		{
+		  /* No more grapheme cluster in this composition.
+		     Find the next stop position.  */
+		  EMACS_INT stop = it->stop_charpos;
+		  if (it->bidi_it.scan_dir < 0)
+		    /* Now we are scanning backward and don't know
+		       where to stop.  */
+		    stop = -1;
+		  composition_compute_stop_pos (&it->cmp_it, IT_CHARPOS (*it),
+						IT_BYTEPOS (*it), stop, Qnil);
+		}
 	    }
 	}
       else
@@ -6317,6 +6388,7 @@
 	    }
 	  else
 	    {
+	      int prev_scan_dir = it->bidi_it.scan_dir;
 	      /* If this is a new paragraph, determine its base
 		 direction (a.k.a. its base embedding level).  */
 	      if (it->bidi_it.new_paragraph)
@@ -6324,6 +6396,16 @@
 	      bidi_get_next_char_visually (&it->bidi_it);
 	      IT_BYTEPOS (*it) = it->bidi_it.bytepos;
 	      IT_CHARPOS (*it) = it->bidi_it.charpos;
+	      if (prev_scan_dir != it->bidi_it.scan_dir)
+		{
+		  /* As scan direction was changed, we must re-compute
+		     the stop position for composition.  */
+		  EMACS_INT stop = it->stop_charpos;
+		  if (it->bidi_it.scan_dir < 0)
+		    stop = -1;
+		  composition_compute_stop_pos (&it->cmp_it, IT_CHARPOS (*it),
+						IT_BYTEPOS (*it), stop, Qnil);
+		}
 	    }
 	  xassert (IT_BYTEPOS (*it) == CHAR_TO_BYTE (IT_CHARPOS (*it)));
 	}
@@ -6820,6 +6902,13 @@
       IT_CHARPOS (*it) = it->bidi_it.charpos;
       IT_BYTEPOS (*it) = it->bidi_it.bytepos;
       SET_TEXT_POS (it->position, IT_CHARPOS (*it), IT_BYTEPOS (*it));
+      {
+	EMACS_INT stop = it->stop_charpos;
+	if (it->bidi_it.scan_dir < 0)
+	  stop = -1;
+	composition_compute_stop_pos (&it->cmp_it, IT_CHARPOS (*it),
+				      IT_BYTEPOS (*it), stop, Qnil);
+      }
     }
 
   if (IT_CHARPOS (*it) >= it->stop_charpos)
@@ -6897,6 +6986,7 @@
       /* No face changes, overlays etc. in sight, so just return a
 	 character from current_buffer.  */
       unsigned char *p;
+      EMACS_INT stop;
 
       /* Maybe run the redisplay end trigger hook.  Performance note:
 	 This doesn't seem to cost measurable time.  */
@@ -6905,8 +6995,9 @@
 	  && IT_CHARPOS (*it) >= it->redisplay_end_trigger_charpos)
 	run_redisplay_end_trigger_hook (it);
 
+      stop = it->bidi_it.scan_dir < 0 ? -1 : it->end_charpos;
       if (CHAR_COMPOSED_P (it, IT_CHARPOS (*it), IT_BYTEPOS (*it),
-			   it->end_charpos)
+			   stop)
 	  && next_element_from_composition (it))
 	{
 	  return 1;
@@ -7032,6 +7123,19 @@
       it->object = it->w->buffer;
       it->c = composition_update_it (&it->cmp_it, IT_CHARPOS (*it),
 				     IT_BYTEPOS (*it), Qnil);
+      if (it->cmp_it.reversed_p)
+	{
+	  /* Now it->position points the last character of the current
+	     grapheme cluster.  Adjust it to point the first one.  We
+	     have to do it here so that append_composite_glyph sets
+	     correct (struct glyph)->charpos.  */
+	  int i;
+	  for (i = 0; i < it->cmp_it.nchars - 1; i++)
+	    bidi_get_next_char_visually (&it->bidi_it);
+	  IT_CHARPOS (*it) = it->bidi_it.charpos;
+	  IT_BYTEPOS (*it) = it->bidi_it.bytepos;
+	  it->position = it->current.pos;
+	}
     }
   return 1;
 }