changeset 110000:757182d1d4cb

Merge from mainline.
author Katsumi Yamaoka <yamaoka@jpl.org>
date Thu, 19 Aug 2010 22:47:51 +0000
parents 6e14b22d0a49 (current diff) 29102470d546 (diff)
children 87dd0fd298be
files
diffstat 26 files changed, 1489 insertions(+), 386 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Aug 19 00:35:46 2010 +0000
+++ b/ChangeLog	Thu Aug 19 22:47:51 2010 +0000
@@ -139,6 +139,21 @@
 
 	* Makefile.in (install-arch-indep): Delete any old info .gz files first.
 
+2010-06-12 Joakim Verona <joakim@verona.se>
+
+        * image.c: Add support for ImageMagick. When HAVE_IMAGEMAGICK is
+        defined:
+        (imagemagick_image_p): New function to test for ImageMagic img.
+        (imagemagick_load): New function to load ImageMagick img.
+        (imagemagick_load_image): New function, helper for imagemagick_load
+        (imagemagick-types): New function.
+        (Qimagemagick): New Lisp_object.
+	(imagemagick-render-type): New var, decides which renderer to use
+        * image.el:
+        (imagemagick-types-inhibit): New var.
+        (imagemagick-register-types): New function.
+        * config.in, Makefile.in, configure.in
+
 2010-06-11  Glenn Morris  <rgm@gnu.org>
 
 	* configure.in (--without-compress-info): New option.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README.imagemagick	Thu Aug 19 22:47:51 2010 +0000
@@ -0,0 +1,151 @@
+* README for the ImageMagick Emacs branch
+
+This is the imagemagick branch of Emacs. Imagemagick can now be used
+to load many new image formats, and also do useful transforms like
+scaling and rotation.
+
+This file will attempt to contain draft NEWS, Changelog and manual
+entries for the new functionality. 
+
+You might need to regenerate the configure scripts:
+aclocal
+automake
+autoheader
+autoconf
+./configure --with-imagemagick
+
+
+* TODO  image-type-header-regexps priorities the jpeg loader over the
+imagemagick one. This is not wrong, but how should a user go about
+prefering the imagemagick loader? The user might like zooming etc in
+jpegs. 
+
+try (setq image-type-header-regexps nil) for a quick hack to prefer
+imagemagick over the jpg loader.
+
+* TODO  For some reason its unbearably slow to look at a page in a large
+  image bundle using the :index feature. The imagemagick "display"
+  command is also a bit slow, but nowhere near as slow as the emacs
+  code. It seems imagemagick tries to unpack every page when loading
+  the bundle. This feature is not the primary usecase for the
+  imagemagick patch though.
+
+  ImageMagick 6.6.2-9 introduced a bugfix for single page djvu load.
+  It is now way faster to use the :index feature, but its still not
+  very fast.
+
+** DONE optimize number of pages calculation for bundles as suggested by
+  imagemagick forum: "set the density to something low like 2 and use
+  MagickPingImage()"
+  
+** TODO try to cache the num pages calculation. it can take a while to
+  calculate the number of pages, and if you need to do it for each
+  page view, page-flipping becomes uselessly slow.
+
+* TODO integrate with image-dired
+
+* TODO integrate with docview. 
+  
+* TODO integrate with image-mode
+Some work has been done, M-x image-transform-fit-to-height will fit
+the image to the height of the Emacs window for instance.
+
+* TODO look for optimizations for handling images with low depth
+Currently the code seems to default to 24 bit RGB which is costly for
+images with lower bit depth.
+
+* TODO complete documentation drafts below
+
+* DONE fix inconsistencys with spelling of imagemagick in the src
+* DONE report number of images in image bundle types somehow
+Works like for "gif" support. Thanks to Juri Linkov.
+* DONE probably add pdf to inhibited types
+* DONE inhibit types is defconst should probably be defcustom
+* TODO decide what to do with some uncommitted imagemagick support
+  functions for image size etc.
+* TODO Test with more systems
+Tested on Fedora 12, Fedora 14 so far, and the libmagick that ships with it.
+Ubuntu 8.04 was also tested, but it seems it ships a broken
+ImageMagick.
+
+I also tried using an imagemagick compiled from their SVN, in
+parallell with the one packaged by Fedora, it worked well.
+
+* DONE Also need some way to handle render methods that only work on newer ImageMagicks
+Is handled by configure now
+
+* Some nits from Stefan Monnier
+I just took a quick look at the code and I see the following nits to fix:
+
+** DONE obviously a merge will have to come with a good ChangeLog.
+** DONE also the merge will need to come with documentation.  Maybe not in the
+   Texinfo form yet, but at least in the etc/NEWS with enough info that
+   describes the `scale' and other such arguments that someone can start
+   using them.
+** DONE the README talks about naming inconsistencies, I think these should be
+  fixed before a first commit (should be straightforward).
+
+** DONE the "let" in image.el should not be followed by a line break and the while
+   should be replaced by a dolist.
+
+** DONE the prototype of imagemagick_load_image has some odd indentation in ([[2010.06.14]])
+   its args, not sure what happened.
+** DONE a few lines in the C code break the 80columns limit.
+** DONE please use ANSI style function declarations rather than K&R for new code. ([[2010.06.14]])
+** DONE you can get rid of the prototypes by reordering the code. ([[2010.06.14]])
+** DONE the docstrings in DEFUN should not be indented (they'll display ([[2010.06.14]])
+   weirdly otherwise in C-h f).
+** DONE Some "{" are at the end of a for/if rather than on their own line. ([[2010.06.14]])
+** DONE why use "*( imtypes + i)" rather than "imtypes[i]"? ([[2010.06.14]])
+** DONE some "," lack a space after them. ([[2010.06.14]])
+** DONE several "=" and "==" lack spaces around them. ([[2010.06.14]])
+  
+
+* NEWS entry
+** ImageMagick support
+It is now possible to use the Imagemagick library to load many new
+image formats in Emacs.
+
+To enable, use the following configure option:
+--with-imagemagick
+
+The new function (imagemagick-types) returns a list of image file
+extensions that your installation of imagemagick supports.
+
+The function (imagemagick-register-types) will enable the imagemagick
+support for the extensions in imagemagick-types minus the types listed
+in imagemagick-types-inhibit.
+
+imagemagick-types-inhibit has the value  '(C HTML HTM TXT PDF) by default.
+This means imagemagick will be used also to load jpeg files, if you
+have both jpeg and imagemagick libraries linked. Add 'JPG to
+imagemagick-types-inhibit if you do not want this.
+
+imagemagick-render-type is a new variable which can be set to choose
+between screen render methods.
+
+- 0 is a conservative metod which works with older ImageMagick
+  versions. It is a bit slow, but robust.
+
+- 1 utilizes a newer ImageMagick method   
+
+
+Images loaded with imagemagick will support a couple of new display
+specification behaviours:
+
+- if the :width and :height keywords are specified, these values are
+used for scaling the image. If only one of :width or :height is
+specified, the other one will be calculated so as to preserve the
+aspect ratio.If both :width and :height are specified, aspect ratio
+will not be preserved.
+
+- :rotation specifies a rotation angle in degrees.
+
+- :index specifies which image inside an image bundle file format, such
+as TIFF or DJVM, to view.
+
+The image-metadata function can be used to retrieve the total number
+of images in an image bundle. This is simmilar to how GIF files work.
+
+* Manual entry
+nothing yet, but the NEWS entry could be adapted.
--- a/configure	Thu Aug 19 00:35:46 2010 +0000
+++ b/configure	Thu Aug 19 22:47:51 2010 +0000
@@ -1,11 +1,11 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.66 for emacs 24.0.50.
+# Generated by GNU Autoconf 2.65 for emacs 24.0.50.
 #
 #
 # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
-# 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software
-# Foundation, Inc.
+# 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation,
+# Inc.
 #
 #
 # This configure script is free software; the Free Software Foundation
@@ -316,7 +316,7 @@
       test -d "$as_dir" && break
     done
     test -z "$as_dirs" || eval "mkdir $as_dirs"
-  } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir"
+  } || test -d "$as_dir" || as_fn_error "cannot create directory $as_dir"
 
 
 } # as_fn_mkdir_p
@@ -356,19 +356,19 @@
 fi # as_fn_arith
 
 
-# as_fn_error STATUS ERROR [LINENO LOG_FD]
-# ----------------------------------------
+# as_fn_error ERROR [LINENO LOG_FD]
+# ---------------------------------
 # Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are
 # provided, also output the error to LOG_FD, referencing LINENO. Then exit the
-# script with STATUS, using 1 if that was 0.
+# script with status $?, using 1 if that was 0.
 as_fn_error ()
 {
-  as_status=$1; test $as_status -eq 0 && as_status=1
-  if test "$4"; then
-    as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
-    $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4
-  fi
-  $as_echo "$as_me: error: $2" >&2
+  as_status=$?; test $as_status -eq 0 && as_status=1
+  if test "$3"; then
+    as_lineno=${as_lineno-"$2"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+    $as_echo "$as_me:${as_lineno-$LINENO}: error: $1" >&$3
+  fi
+  $as_echo "$as_me: error: $1" >&2
   as_fn_exit $as_status
 } # as_fn_error
 
@@ -530,7 +530,7 @@
 exec 6>&1
 
 # Name of the host.
-# hostname on some systems (SVR3.2, old GNU/Linux) returns a bogus exit status,
+# hostname on some systems (SVR3.2, Linux) returns a bogus exit status,
 # so uname gets run too.
 ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q`
 
@@ -688,6 +688,8 @@
 GTK_OBJ
 GTK_LIBS
 GTK_CFLAGS
+IMAGEMAGICK_LIBS
+IMAGEMAGICK_CFLAGS
 RSVG_LIBS
 RSVG_CFLAGS
 VMLIMIT_OBJ
@@ -805,6 +807,7 @@
 with_gif
 with_png
 with_rsvg
+with_imagemagick
 with_xft
 with_libotf
 with_m17n_flt
@@ -950,7 +953,7 @@
     ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'`
     # Reject names that are not valid shell variable names.
     expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
-      as_fn_error $? "invalid feature name: $ac_useropt"
+      as_fn_error "invalid feature name: $ac_useropt"
     ac_useropt_orig=$ac_useropt
     ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
     case $ac_user_opts in
@@ -976,7 +979,7 @@
     ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'`
     # Reject names that are not valid shell variable names.
     expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
-      as_fn_error $? "invalid feature name: $ac_useropt"
+      as_fn_error "invalid feature name: $ac_useropt"
     ac_useropt_orig=$ac_useropt
     ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
     case $ac_user_opts in
@@ -1180,7 +1183,7 @@
     ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'`
     # Reject names that are not valid shell variable names.
     expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
-      as_fn_error $? "invalid package name: $ac_useropt"
+      as_fn_error "invalid package name: $ac_useropt"
     ac_useropt_orig=$ac_useropt
     ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
     case $ac_user_opts in
@@ -1196,7 +1199,7 @@
     ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'`
     # Reject names that are not valid shell variable names.
     expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
-      as_fn_error $? "invalid package name: $ac_useropt"
+      as_fn_error "invalid package name: $ac_useropt"
     ac_useropt_orig=$ac_useropt
     ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
     case $ac_user_opts in
@@ -1226,8 +1229,8 @@
   | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*)
     x_libraries=$ac_optarg ;;
 
-  -*) as_fn_error $? "unrecognized option: \`$ac_option'
-Try \`$0 --help' for more information"
+  -*) as_fn_error "unrecognized option: \`$ac_option'
+Try \`$0 --help' for more information."
     ;;
 
   *=*)
@@ -1235,7 +1238,7 @@
     # Reject names that are not valid shell variable names.
     case $ac_envvar in #(
       '' | [0-9]* | *[!_$as_cr_alnum]* )
-      as_fn_error $? "invalid variable name: \`$ac_envvar'" ;;
+      as_fn_error "invalid variable name: \`$ac_envvar'" ;;
     esac
     eval $ac_envvar=\$ac_optarg
     export $ac_envvar ;;
@@ -1253,13 +1256,13 @@
 
 if test -n "$ac_prev"; then
   ac_option=--`echo $ac_prev | sed 's/_/-/g'`
-  as_fn_error $? "missing argument to $ac_option"
+  as_fn_error "missing argument to $ac_option"
 fi
 
 if test -n "$ac_unrecognized_opts"; then
   case $enable_option_checking in
     no) ;;
-    fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;;
+    fatal) as_fn_error "unrecognized options: $ac_unrecognized_opts" ;;
     *)     $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;;
   esac
 fi
@@ -1282,7 +1285,7 @@
     [\\/$]* | ?:[\\/]* )  continue;;
     NONE | '' ) case $ac_var in *prefix ) continue;; esac;;
   esac
-  as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val"
+  as_fn_error "expected an absolute directory name for --$ac_var: $ac_val"
 done
 
 # There might be people who depend on the old broken behavior: `$host'
@@ -1296,8 +1299,8 @@
 if test "x$host_alias" != x; then
   if test "x$build_alias" = x; then
     cross_compiling=maybe
-    $as_echo "$as_me: WARNING: if you wanted to set the --build type, don't use --host.
-    If a cross compiler is detected then cross compile mode will be used" >&2
+    $as_echo "$as_me: WARNING: If you wanted to set the --build type, don't use --host.
+    If a cross compiler is detected then cross compile mode will be used." >&2
   elif test "x$build_alias" != "x$host_alias"; then
     cross_compiling=yes
   fi
@@ -1312,9 +1315,9 @@
 ac_pwd=`pwd` && test -n "$ac_pwd" &&
 ac_ls_di=`ls -di .` &&
 ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` ||
-  as_fn_error $? "working directory cannot be determined"
+  as_fn_error "working directory cannot be determined"
 test "X$ac_ls_di" = "X$ac_pwd_ls_di" ||
-  as_fn_error $? "pwd does not report name of working directory"
+  as_fn_error "pwd does not report name of working directory"
 
 
 # Find the source files, if location was not specified.
@@ -1353,11 +1356,11 @@
 fi
 if test ! -r "$srcdir/$ac_unique_file"; then
   test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .."
-  as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir"
+  as_fn_error "cannot find sources ($ac_unique_file) in $srcdir"
 fi
 ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work"
 ac_abs_confdir=`(
-	cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg"
+	cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error "$ac_msg"
 	pwd)`
 # When building in place, set srcdir=.
 if test "$ac_abs_confdir" = "$ac_pwd"; then
@@ -1397,7 +1400,7 @@
       --help=short        display options specific to this package
       --help=recursive    display the short help of all the included packages
   -V, --version           display version information and exit
-  -q, --quiet, --silent   do not print \`checking ...' messages
+  -q, --quiet, --silent   do not print \`checking...' messages
       --cache-file=FILE   cache test results in FILE [disabled]
   -C, --config-cache      alias for \`--cache-file=config.cache'
   -n, --no-create         do not create output files
@@ -1511,6 +1514,7 @@
   --without-gif           don't compile with GIF image support
   --without-png           don't compile with PNG image support
   --without-rsvg          don't compile with SVG image support
+  --with-imagemagick      compile with ImageMagick image support
   --without-xft           don't use XFT for anti aliased fonts
   --without-libotf        don't use libotf for OpenType font support
   --without-m17n-flt      don't use m17n-flt for text shaping
@@ -1613,9 +1617,9 @@
 if $ac_init_version; then
   cat <<\_ACEOF
 emacs configure 24.0.50
-generated by GNU Autoconf 2.66
-
-Copyright (C) 2010 Free Software Foundation, Inc.
+generated by GNU Autoconf 2.65
+
+Copyright (C) 2009 Free Software Foundation, Inc.
 This configure script is free software; the Free Software Foundation
 gives unlimited permission to copy, distribute and modify it.
 _ACEOF
@@ -1755,10 +1759,10 @@
 ac_fn_c_check_header_mongrel ()
 {
   as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
-  if eval "test \"\${$3+set}\"" = set; then :
+  if { as_var=$3; eval "test \"\${$as_var+set}\" = set"; }; then :
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
 $as_echo_n "checking for $2... " >&6; }
-if eval "test \"\${$3+set}\"" = set; then :
+if { as_var=$3; eval "test \"\${$as_var+set}\" = set"; }; then :
   $as_echo_n "(cached) " >&6
 fi
 eval ac_res=\$$3
@@ -1821,7 +1825,7 @@
 esac
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
 $as_echo_n "checking for $2... " >&6; }
-if eval "test \"\${$3+set}\"" = set; then :
+if { as_var=$3; eval "test \"\${$as_var+set}\" = set"; }; then :
   $as_echo_n "(cached) " >&6
 else
   eval "$3=\$ac_header_compiler"
@@ -1885,7 +1889,7 @@
   as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
 $as_echo_n "checking for $2... " >&6; }
-if eval "test \"\${$3+set}\"" = set; then :
+if { as_var=$3; eval "test \"\${$as_var+set}\" = set"; }; then :
   $as_echo_n "(cached) " >&6
 else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
@@ -1907,18 +1911,15 @@
 
 } # ac_fn_c_check_header_compile
 
-# ac_fn_c_check_decl LINENO SYMBOL VAR INCLUDES
-# ---------------------------------------------
-# Tests whether SYMBOL is declared in INCLUDES, setting cache variable VAR
-# accordingly.
+# ac_fn_c_check_decl LINENO SYMBOL VAR
+# ------------------------------------
+# Tests whether SYMBOL is declared, setting cache variable VAR accordingly.
 ac_fn_c_check_decl ()
 {
   as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
-  as_decl_name=`echo $2|sed 's/ *(.*//'`
-  as_decl_use=`echo $2|sed -e 's/(/((/' -e 's/)/) 0&/' -e 's/,/) 0& (/g'`
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $as_decl_name is declared" >&5
-$as_echo_n "checking whether $as_decl_name is declared... " >&6; }
-if eval "test \"\${$3+set}\"" = set; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $2 is declared" >&5
+$as_echo_n "checking whether $2 is declared... " >&6; }
+if { as_var=$3; eval "test \"\${$as_var+set}\" = set"; }; then :
   $as_echo_n "(cached) " >&6
 else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
@@ -1927,12 +1928,8 @@
 int
 main ()
 {
-#ifndef $as_decl_name
-#ifdef __cplusplus
-  (void) $as_decl_use;
-#else
-  (void) $as_decl_name;
-#endif
+#ifndef $2
+  (void) $2;
 #endif
 
   ;
@@ -1961,7 +1958,7 @@
   as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
 $as_echo_n "checking for $2... " >&6; }
-if eval "test \"\${$3+set}\"" = set; then :
+if { as_var=$3; eval "test \"\${$as_var+set}\" = set"; }; then :
   $as_echo_n "(cached) " >&6
 else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
@@ -1991,7 +1988,7 @@
   as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2.$3" >&5
 $as_echo_n "checking for $2.$3... " >&6; }
-if eval "test \"\${$4+set}\"" = set; then :
+if { as_var=$4; eval "test \"\${$as_var+set}\" = set"; }; then :
   $as_echo_n "(cached) " >&6
 else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
@@ -2047,7 +2044,7 @@
   as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
 $as_echo_n "checking for $2... " >&6; }
-if eval "test \"\${$3+set}\"" = set; then :
+if { as_var=$3; eval "test \"\${$as_var+set}\" = set"; }; then :
   $as_echo_n "(cached) " >&6
 else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
@@ -2115,7 +2112,7 @@
   as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
 $as_echo_n "checking for $2... " >&6; }
-if eval "test \"\${$3+set}\"" = set; then :
+if { as_var=$3; eval "test \"\${$as_var+set}\" = set"; }; then :
   $as_echo_n "(cached) " >&6
 else
   eval "$3=no"
@@ -2164,7 +2161,7 @@
 running configure, to aid debugging if configure makes a mistake.
 
 It was created by emacs $as_me 24.0.50, which was
-generated by GNU Autoconf 2.66.  Invocation command line was
+generated by GNU Autoconf 2.65.  Invocation command line was
 
   $ $0 $@
 
@@ -2274,9 +2271,11 @@
   {
     echo
 
-    $as_echo "## ---------------- ##
+    cat <<\_ASBOX
+## ---------------- ##
 ## Cache variables. ##
-## ---------------- ##"
+## ---------------- ##
+_ASBOX
     echo
     # The following way of writing the cache mishandles newlines in values,
 (
@@ -2310,9 +2309,11 @@
 )
     echo
 
-    $as_echo "## ----------------- ##
+    cat <<\_ASBOX
+## ----------------- ##
 ## Output variables. ##
-## ----------------- ##"
+## ----------------- ##
+_ASBOX
     echo
     for ac_var in $ac_subst_vars
     do
@@ -2325,9 +2326,11 @@
     echo
 
     if test -n "$ac_subst_files"; then
-      $as_echo "## ------------------- ##
+      cat <<\_ASBOX
+## ------------------- ##
 ## File substitutions. ##
-## ------------------- ##"
+## ------------------- ##
+_ASBOX
       echo
       for ac_var in $ac_subst_files
       do
@@ -2341,9 +2344,11 @@
     fi
 
     if test -s confdefs.h; then
-      $as_echo "## ----------- ##
+      cat <<\_ASBOX
+## ----------- ##
 ## confdefs.h. ##
-## ----------- ##"
+## ----------- ##
+_ASBOX
       echo
       cat confdefs.h
       echo
@@ -2398,12 +2403,7 @@
 ac_site_file1=NONE
 ac_site_file2=NONE
 if test -n "$CONFIG_SITE"; then
-  # We do not want a PATH search for config.site.
-  case $CONFIG_SITE in #((
-    -*)  ac_site_file1=./$CONFIG_SITE;;
-    */*) ac_site_file1=$CONFIG_SITE;;
-    *)   ac_site_file1=./$CONFIG_SITE;;
-  esac
+  ac_site_file1=$CONFIG_SITE
 elif test "x$prefix" != xNONE; then
   ac_site_file1=$prefix/share/config.site
   ac_site_file2=$prefix/etc/config.site
@@ -2418,11 +2418,7 @@
     { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5
 $as_echo "$as_me: loading site script $ac_site_file" >&6;}
     sed 's/^/| /' "$ac_site_file" >&5
-    . "$ac_site_file" \
-      || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "failed to load site script $ac_site_file
-See \`config.log' for more details" "$LINENO" 5; }
+    . "$ac_site_file"
   fi
 done
 
@@ -2446,6 +2442,7 @@
 as_fn_append ac_header_list " stdlib.h"
 as_fn_append ac_header_list " unistd.h"
 as_fn_append ac_header_list " sys/param.h"
+as_fn_append ac_func_list " MagickExportImagePixels"
 as_fn_append ac_header_list " sys/time.h"
 as_fn_append ac_func_list " alarm"
 # Check that the precious variables saved in the cache have kept the same
@@ -2503,7 +2500,7 @@
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
   { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5
 $as_echo "$as_me: error: changes in the environment can compromise the build" >&2;}
-  as_fn_error $? "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5
+  as_fn_error "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5
 fi
 ## -------------------- ##
 ## Main body of script. ##
@@ -2677,7 +2674,7 @@
 	    g | gt | gtk  )	val=gtk ;;
 	    gtk3  )	val=gtk3 ;;
 	    * )
-as_fn_error $? "\`--with-x-toolkit=$withval' is invalid;
+as_fn_error "\`--with-x-toolkit=$withval' is invalid;
 this option's value should be \`yes', \`no', \`lucid', \`athena', \`motif', \`gtk' or
 \`gtk3'.  \`yes' and \`gtk' are synonyms. \`athena' and \`lucid' are synonyms." "$LINENO" 5
 	    ;;
@@ -2736,6 +2733,14 @@
 fi
 
 
+# Check whether --with-imagemagick was given.
+if test "${with_imagemagick+set}" = set; then :
+  withval=$with_imagemagick;
+else
+      with_imagemagick=no
+fi
+
+
 
 # Check whether --with-xft was given.
 if test "${with_xft+set}" = set; then :
@@ -2956,7 +2961,7 @@
 	stringfreelist) ac_gc_check_string_free_list=1 ;;
 	xmallocoverrun)	ac_xmalloc_overrun=1 ;;
 	conslist)	ac_gc_check_cons_list=1 ;;
-	*)	as_fn_error $? "unknown check category $check" "$LINENO" 5 ;;
+	*)	as_fn_error "unknown check category $check" "$LINENO" 5 ;;
 	esac
 done
 IFS="$ac_save_IFS"
@@ -3074,22 +3079,16 @@
 
 ac_aux_dir=
 for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do
-  if test -f "$ac_dir/install-sh"; then
-    ac_aux_dir=$ac_dir
-    ac_install_sh="$ac_aux_dir/install-sh -c"
-    break
-  elif test -f "$ac_dir/install.sh"; then
-    ac_aux_dir=$ac_dir
-    ac_install_sh="$ac_aux_dir/install.sh -c"
-    break
-  elif test -f "$ac_dir/shtool"; then
-    ac_aux_dir=$ac_dir
-    ac_install_sh="$ac_aux_dir/shtool install -c"
-    break
-  fi
+  for ac_t in install-sh install.sh shtool; do
+    if test -f "$ac_dir/$ac_t"; then
+      ac_aux_dir=$ac_dir
+      ac_install_sh="$ac_aux_dir/$ac_t -c"
+      break 2
+    fi
+  done
 done
 if test -z "$ac_aux_dir"; then
-  as_fn_error $? "cannot find install-sh, install.sh, or shtool in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" "$LINENO" 5
+  as_fn_error "cannot find install-sh, install.sh, or shtool in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" "$LINENO" 5
 fi
 
 # These three variables are undocumented and unsupported,
@@ -3103,7 +3102,7 @@
 
 # Make sure we can run config.sub.
 $SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 ||
-  as_fn_error $? "cannot run $SHELL $ac_aux_dir/config.sub" "$LINENO" 5
+  as_fn_error "cannot run $SHELL $ac_aux_dir/config.sub" "$LINENO" 5
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking build system type" >&5
 $as_echo_n "checking build system type... " >&6; }
@@ -3114,16 +3113,16 @@
 test "x$ac_build_alias" = x &&
   ac_build_alias=`$SHELL "$ac_aux_dir/config.guess"`
 test "x$ac_build_alias" = x &&
-  as_fn_error $? "cannot guess build type; you must specify one" "$LINENO" 5
+  as_fn_error "cannot guess build type; you must specify one" "$LINENO" 5
 ac_cv_build=`$SHELL "$ac_aux_dir/config.sub" $ac_build_alias` ||
-  as_fn_error $? "$SHELL $ac_aux_dir/config.sub $ac_build_alias failed" "$LINENO" 5
+  as_fn_error "$SHELL $ac_aux_dir/config.sub $ac_build_alias failed" "$LINENO" 5
 
 fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_build" >&5
 $as_echo "$ac_cv_build" >&6; }
 case $ac_cv_build in
 *-*-*) ;;
-*) as_fn_error $? "invalid value of canonical build" "$LINENO" 5;;
+*) as_fn_error "invalid value of canonical build" "$LINENO" 5;;
 esac
 build=$ac_cv_build
 ac_save_IFS=$IFS; IFS='-'
@@ -3148,7 +3147,7 @@
   ac_cv_host=$ac_cv_build
 else
   ac_cv_host=`$SHELL "$ac_aux_dir/config.sub" $host_alias` ||
-    as_fn_error $? "$SHELL $ac_aux_dir/config.sub $host_alias failed" "$LINENO" 5
+    as_fn_error "$SHELL $ac_aux_dir/config.sub $host_alias failed" "$LINENO" 5
 fi
 
 fi
@@ -3156,7 +3155,7 @@
 $as_echo "$ac_cv_host" >&6; }
 case $ac_cv_host in
 *-*-*) ;;
-*) as_fn_error $? "invalid value of canonical host" "$LINENO" 5;;
+*) as_fn_error "invalid value of canonical host" "$LINENO" 5;;
 esac
 host=$ac_cv_host
 ac_save_IFS=$IFS; IFS='-'
@@ -3450,7 +3449,7 @@
 
 
 if test $unported = yes; then
-  as_fn_error $? "Emacs hasn't been ported to \`${canonical}' systems.
+  as_fn_error "Emacs hasn't been ported to \`${canonical}' systems.
 Check \`etc/MACHINES' for recognized configuration names." "$LINENO" 5
 fi
 
@@ -3764,8 +3763,8 @@
 
 test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "no acceptable C compiler found in \$PATH
-See \`config.log' for more details" "$LINENO" 5; }
+as_fn_error "no acceptable C compiler found in \$PATH
+See \`config.log' for more details." "$LINENO" 5; }
 
 # Provide some information about the compiler.
 $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5
@@ -3879,8 +3878,9 @@
 
 { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error 77 "C compiler cannot create executables
-See \`config.log' for more details" "$LINENO" 5; }
+{ as_fn_set_status 77
+as_fn_error "C compiler cannot create executables
+See \`config.log' for more details." "$LINENO" 5; }; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
 $as_echo "yes" >&6; }
@@ -3922,8 +3922,8 @@
 else
   { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "cannot compute suffix of executables: cannot compile and link
-See \`config.log' for more details" "$LINENO" 5; }
+as_fn_error "cannot compute suffix of executables: cannot compile and link
+See \`config.log' for more details." "$LINENO" 5; }
 fi
 rm -f conftest conftest$ac_cv_exeext
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5
@@ -3980,9 +3980,9 @@
     else
 	{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "cannot run C compiled programs.
+as_fn_error "cannot run C compiled programs.
 If you meant to cross compile, use \`--host'.
-See \`config.log' for more details" "$LINENO" 5; }
+See \`config.log' for more details." "$LINENO" 5; }
     fi
   fi
 fi
@@ -4033,8 +4033,8 @@
 
 { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "cannot compute suffix of object files: cannot compile
-See \`config.log' for more details" "$LINENO" 5; }
+as_fn_error "cannot compute suffix of object files: cannot compile
+See \`config.log' for more details." "$LINENO" 5; }
 fi
 rm -f conftest.$ac_cv_objext conftest.$ac_ext
 fi
@@ -4451,8 +4451,8 @@
 else
   { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "C preprocessor \"$CPP\" fails sanity check
-See \`config.log' for more details" "$LINENO" 5; }
+as_fn_error "C preprocessor \"$CPP\" fails sanity check
+See \`config.log' for more details." "$LINENO" 5; }
 fi
 
 ac_ext=c
@@ -4513,7 +4513,7 @@
   done
 IFS=$as_save_IFS
   if test -z "$ac_cv_path_GREP"; then
-    as_fn_error $? "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
+    as_fn_error "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
   fi
 else
   ac_cv_path_GREP=$GREP
@@ -4579,7 +4579,7 @@
   done
 IFS=$as_save_IFS
   if test -z "$ac_cv_path_EGREP"; then
-    as_fn_error $? "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
+    as_fn_error "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
   fi
 else
   ac_cv_path_EGREP=$EGREP
@@ -4711,7 +4711,8 @@
   as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
 ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default
 "
-if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :
+eval as_val=\$$as_ac_Header
+   if test "x$as_val" = x""yes; then :
   cat >>confdefs.h <<_ACEOF
 #define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
 _ACEOF
@@ -5040,8 +5041,8 @@
 else
   { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "C preprocessor \"$CPP\" fails sanity check
-See \`config.log' for more details" "$LINENO" 5; }
+as_fn_error "C preprocessor \"$CPP\" fails sanity check
+See \`config.log' for more details." "$LINENO" 5; }
 fi
 
 ac_ext=c
@@ -5478,7 +5479,7 @@
   if test "x${with_makeinfo}" = "xno"; then
     MAKEINFO=off
   elif test ! -e $srcdir/info/emacs; then
-    as_fn_error $? "You do not seem to have makeinfo >= 4.6, and your
+    as_fn_error "You do not seem to have makeinfo >= 4.6, and your
 source tree does not seem to have pre-built manuals in the \`info' directory.
 Either install a suitable version of makeinfo, or re-run configure
 with the \`--without-makeinfo' option to build without the manuals. " "$LINENO" 5
@@ -5632,7 +5633,7 @@
     if test "x$GCC" = "xyes"; then
       C_SWITCH_MACHINE="-fno-common"
     else
-      as_fn_error $? "What gives?  Fix me if DEC Unix supports ELF now." "$LINENO" 5
+      as_fn_error "What gives?  Fix me if DEC Unix supports ELF now." "$LINENO" 5
     fi
   else
     UNEXEC_OBJ=unexalpha.o
@@ -5910,7 +5911,7 @@
   ## Some platforms don't use any of these files, so it is not
   ## appropriate to put this test outside the if block.
   test -e $CRT_DIR/crtn.o || test -e $CRT_DIR/crt0.o || \
-    as_fn_error $? "crt*.o not found in specified location." "$LINENO" 5
+    as_fn_error "crt*.o not found in specified location." "$LINENO" 5
 
 fi
 
@@ -5965,7 +5966,8 @@
 do :
   as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
 ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
-if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :
+eval as_val=\$$as_ac_Header
+   if test "x$as_val" = x""yes; then :
   cat >>confdefs.h <<_ACEOF
 #define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
 _ACEOF
@@ -6156,7 +6158,7 @@
 fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
       if test "$emacs_alsa_subdir" != yes; then
-        as_fn_error $? "pkg-config found alsa, but it does not compile.  See config.log for error messages." "$LINENO" 5
+        as_fn_error "pkg-config found alsa, but it does not compile.  See config.log for error messages." "$LINENO" 5
       fi
       ALSA_CFLAGS="$ALSA_CFLAGS -DALSA_SUBDIR_INCLUDE"
     fi
@@ -6191,7 +6193,8 @@
 do :
   as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
 ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
-if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :
+eval as_val=\$$as_ac_Header
+   if test "x$as_val" = x""yes; then :
   cat >>confdefs.h <<_ACEOF
 #define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
 _ACEOF
@@ -7246,7 +7249,7 @@
 
      ;; #(
    *)
-     as_fn_error $? "unknown endianness
+     as_fn_error "unknown endianness
  presetting ac_cv_c_bigendian=no (or yes) will help" "$LINENO" 5 ;;
  esac
 
@@ -7255,7 +7258,7 @@
 $as_echo_n "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; }
 set x ${MAKE-make}
 ac_make=`$as_echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'`
-if eval "test \"\${ac_cv_prog_make_${ac_make}_set+set}\"" = set; then :
+if { as_var=ac_cv_prog_make_${ac_make}_set; eval "test \"\${$as_var+set}\" = set"; }; then :
   $as_echo_n "(cached) " >&6
 else
   cat >conftest.make <<\_ACEOF
@@ -7263,7 +7266,7 @@
 all:
 	@echo '@@@%%%=$(MAKE)=@@@%%%'
 _ACEOF
-# GNU make sometimes prints "make[1]: Entering ...", which would confuse us.
+# GNU make sometimes prints "make[1]: Entering...", which would confuse us.
 case `${MAKE-make} -f conftest.make 2>/dev/null` in
   *@@@%%%=?*=@@@%%%*)
     eval ac_cv_prog_make_${ac_make}_set=yes;;
@@ -7399,7 +7402,7 @@
   have_x=disabled
 else
   case $x_includes,$x_libraries in #(
-    *\'*) as_fn_error $? "cannot use X directory names containing '" "$LINENO" 5;; #(
+    *\'*) as_fn_error "cannot use X directory names containing '" "$LINENO" 5;; #(
     *,NONE | NONE,*) if test "${ac_cv_have_x+set}" = set; then :
   $as_echo_n "(cached) " >&6
 else
@@ -7417,7 +7420,7 @@
 	@echo libdir='${LIBDIR}'
 _ACEOF
   if (export CC; ${XMKMF-xmkmf}) >/dev/null 2>/dev/null && test -f Makefile; then
-    # GNU make sometimes prints "make[1]: Entering ...", which would confuse us.
+    # GNU make sometimes prints "make[1]: Entering...", which would confuse us.
     for ac_var in incroot usrlibdir libdir; do
       eval "ac_im_$ac_var=\`\${MAKE-make} $ac_var 2>/dev/null | sed -n 's/^$ac_var=//p'\`"
     done
@@ -7686,7 +7689,7 @@
 if test "x$ac_cv_header_AppKit_AppKit_h" = x""yes; then :
   HAVE_NS=yes
 else
-  as_fn_error $? "\`--with-ns' was specified, but the include
+  as_fn_error "\`--with-ns' was specified, but the include
   files are missing or cannot be compiled." "$LINENO" 5
 fi
 
@@ -7802,7 +7805,7 @@
    if test "$HAVE_XSERVER" = true ||
       test -n "$DISPLAY" ||
       test "`echo /usr/lib/libX11.*`" != "/usr/lib/libX11.*"; then
-        as_fn_error $? "You seem to be running X, but no X development libraries
+        as_fn_error "You seem to be running X, but no X development libraries
 were found.  You should install the relevant development files for X
 and for the toolkit you want, such as Gtk+, Lesstif or Motif.  Also make
 sure you have development files for image handling, i.e.
@@ -7925,7 +7928,8 @@
   as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
 ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default
 "
-if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :
+eval as_val=\$$as_ac_Header
+   if test "x$as_val" = x""yes; then :
   cat >>confdefs.h <<_ACEOF
 #define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
 _ACEOF
@@ -8432,7 +8436,8 @@
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
-if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
+eval as_val=\$$as_ac_var
+   if test "x$as_val" = x""yes; then :
   cat >>confdefs.h <<_ACEOF
 #define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
 _ACEOF
@@ -8611,6 +8616,140 @@
   fi
 fi
 
+HAVE_IMAGEMAGICK=no
+if test "${with_imagemagick}" != "no"; then
+  IMAGEMAGICK_MODULE="Wand"
+
+  succeeded=no
+
+  # Extract the first word of "pkg-config", so it can be a program name with args.
+set dummy pkg-config; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_path_PKG_CONFIG+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $PKG_CONFIG in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_PKG_CONFIG="$PKG_CONFIG" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_path_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  test -z "$ac_cv_path_PKG_CONFIG" && ac_cv_path_PKG_CONFIG="no"
+  ;;
+esac
+fi
+PKG_CONFIG=$ac_cv_path_PKG_CONFIG
+if test -n "$PKG_CONFIG"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PKG_CONFIG" >&5
+$as_echo "$PKG_CONFIG" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+
+  if test "$PKG_CONFIG" = "no" ; then
+     :
+  else
+     PKG_CONFIG_MIN_VERSION=0.9.0
+     if $PKG_CONFIG --atleast-pkgconfig-version $PKG_CONFIG_MIN_VERSION; then
+        { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $IMAGEMAGICK_MODULE" >&5
+$as_echo_n "checking for $IMAGEMAGICK_MODULE... " >&6; }
+
+        if $PKG_CONFIG --exists "$IMAGEMAGICK_MODULE" 2>&5; then
+            { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+            succeeded=yes
+
+            { $as_echo "$as_me:${as_lineno-$LINENO}: checking IMAGEMAGICK_CFLAGS" >&5
+$as_echo_n "checking IMAGEMAGICK_CFLAGS... " >&6; }
+            IMAGEMAGICK_CFLAGS=`$PKG_CONFIG --cflags "$IMAGEMAGICK_MODULE"|sed -e 's,///*,/,g'`
+            { $as_echo "$as_me:${as_lineno-$LINENO}: result: $IMAGEMAGICK_CFLAGS" >&5
+$as_echo "$IMAGEMAGICK_CFLAGS" >&6; }
+
+            { $as_echo "$as_me:${as_lineno-$LINENO}: checking IMAGEMAGICK_LIBS" >&5
+$as_echo_n "checking IMAGEMAGICK_LIBS... " >&6; }
+            IMAGEMAGICK_LIBS=`$PKG_CONFIG --libs "$IMAGEMAGICK_MODULE"|sed -e 's,///*,/,g'`
+            { $as_echo "$as_me:${as_lineno-$LINENO}: result: $IMAGEMAGICK_LIBS" >&5
+$as_echo "$IMAGEMAGICK_LIBS" >&6; }
+        else
+            { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+            IMAGEMAGICK_CFLAGS=""
+            IMAGEMAGICK_LIBS=""
+            ## If we have a custom action on failure, don't print errors, but
+            ## do set a variable so people can do so.
+            IMAGEMAGICK_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "$IMAGEMAGICK_MODULE"`
+
+        fi
+
+
+
+     else
+        echo "*** Your version of pkg-config is too old. You need version $PKG_CONFIG_MIN_VERSION or newer."
+        echo "*** See http://www.freedesktop.org/software/pkgconfig"
+     fi
+  fi
+
+  if test $succeeded = yes; then
+     :
+  else
+     :
+  fi
+
+
+
+
+  if test ".${IMAGEMAGICK_CFLAGS}" != "."; then
+    HAVE_IMAGEMAGICK=yes
+
+$as_echo "#define HAVE_IMAGEMAGICK 1" >>confdefs.h
+
+    CFLAGS="$CFLAGS $IMAGEMAGICK_CFLAGS"
+    LIBS="$IMAGEMAGICK_LIBS $LIBS"
+  fi
+
+
+$as_echo "#define HAVE_MAGICKEXPORTIMAGEPIXELS 1" >>confdefs.h
+
+
+
+
+  for ac_func in $ac_func_list
+do :
+  as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
+ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
+eval as_val=\$$as_ac_var
+   if test "x$as_val" = x""yes; then :
+  cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+done
+
+
+
+
+
+fi
+
 
 HAVE_GTK=no
 if test "${with_gtk3}" = "yes"; then
@@ -8713,7 +8852,7 @@
   fi
 
   if test "$pkg_check_gtk" = "no" && test "$USE_X_TOOLKIT" != "maybe"; then
-     as_fn_error $? "$GTK_PKG_ERRORS" "$LINENO" 5
+     as_fn_error "$GTK_PKG_ERRORS" "$LINENO" 5
   fi
 fi
 
@@ -8819,7 +8958,7 @@
   fi
 
   if test "$pkg_check_gtk" = "no" && test "$USE_X_TOOLKIT" != "maybe"; then
-     as_fn_error $? "$GTK_PKG_ERRORS" "$LINENO" 5
+     as_fn_error "$GTK_PKG_ERRORS" "$LINENO" 5
   fi
 fi
 fi
@@ -8846,7 +8985,7 @@
 
   if test "${GTK_COMPILES}" != "yes"; then
     if test "$USE_X_TOOLKIT" != "maybe"; then
-      as_fn_error $? "Gtk+ wanted, but it does not compile, see config.log.  Maybe some x11-devel files missing?" "$LINENO" 5;
+      as_fn_error "Gtk+ wanted, but it does not compile, see config.log.  Maybe some x11-devel files missing?" "$LINENO" 5;
     fi
   else
     HAVE_GTK=yes
@@ -8976,7 +9115,8 @@
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
-if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
+eval as_val=\$$as_ac_var
+   if test "x$as_val" = x""yes; then :
   cat >>confdefs.h <<_ACEOF
 #define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
 _ACEOF
@@ -9341,7 +9481,7 @@
       USE_X_TOOLKIT=LUCID
       LUCID_LIBW=-lXaw
     elif test x"${USE_X_TOOLKIT}" = xLUCID; then
-      as_fn_error $? "Lucid toolkit requires X11/Xaw include files" "$LINENO" 5
+      as_fn_error "Lucid toolkit requires X11/Xaw include files" "$LINENO" 5
     else
       { $as_echo "$as_me:${as_lineno-$LINENO}: result: no; do not use toolkit by default" >&5
 $as_echo "no; do not use toolkit by default" >&6; }
@@ -10518,7 +10658,8 @@
 do :
   as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
 ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
-if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :
+eval as_val=\$$as_ac_Header
+   if test "x$as_val" = x""yes; then :
   cat >>confdefs.h <<_ACEOF
 #define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
 _ACEOF
@@ -10770,7 +10911,7 @@
     MISSING="$MISSING libtiff" && WITH_NO="$WITH_NO --with-tiff=no"
 
   if test "X${MISSING}" != X; then
-    as_fn_error $? "The following required libraries were not found:
+    as_fn_error "The following required libraries were not found:
     $MISSING
 Maybe some development libraries/packages are missing?
 If you don't want to link with them give
@@ -11105,7 +11246,8 @@
   for ac_func in _getb67 GETB67 getb67; do
     as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
-if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
+eval as_val=\$$as_ac_var
+   if test "x$as_val" = x""yes; then :
 
 cat >>confdefs.h <<_ACEOF
 #define CRAY_STACKSEG_END $ac_func
@@ -11169,7 +11311,7 @@
 
 
 if test x"$ac_cv_func_alloca_works" != xyes; then
-   as_fn_error $? "a system implementation of alloca is required " "$LINENO" 5
+   as_fn_error "a system implementation of alloca is required " "$LINENO" 5
 fi
 
 # fmod, logb, and frexp are found in -lm on most systems.
@@ -11365,7 +11507,7 @@
 
 
   if test $ac_cv_prog_liblockfile = yes; then
-    as_fn_error $? "Shared liblockfile found but can't link against it.
+    as_fn_error "Shared liblockfile found but can't link against it.
 This probably means that movemail could lose mail.
 There may be a \`development' package to install containing liblockfile." "$LINENO" 5
   fi
@@ -11454,7 +11596,8 @@
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
-if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
+eval as_val=\$$as_ac_var
+   if test "x$as_val" = x""yes; then :
   cat >>confdefs.h <<_ACEOF
 #define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
 _ACEOF
@@ -11481,21 +11624,6 @@
 
 
 
-  for ac_func in $ac_func_list
-do :
-  as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
-ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
-if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
-  cat >>confdefs.h <<_ACEOF
-#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
-_ACEOF
-
-fi
-done
-
-
-
-
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for working mktime" >&5
 $as_echo_n "checking for working mktime... " >&6; }
@@ -11537,8 +11665,8 @@
 static time_t time_t_min;
 
 /* Values we'll use to set the TZ environment variable.  */
-static const char *tz_strings[] = {
-  (const char *) 0, "TZ=GMT0", "TZ=JST-9",
+static char *tz_strings[] = {
+  (char *) 0, "TZ=GMT0", "TZ=JST-9",
   "TZ=EST+3EDT+2,M10.1.0/00:00:00,M2.3.0/00:00:00"
 };
 #define N_STRINGS (sizeof (tz_strings) / sizeof (tz_strings[0]))
@@ -11555,7 +11683,7 @@
      instead of "TZ=America/Vancouver" in order to detect the bug even
      on systems that don't support the Olson extension, or don't have the
      full zoneinfo tables installed.  */
-  putenv ((char*) "TZ=PST8PDT,M4.1.0,M10.5.0");
+  putenv ("TZ=PST8PDT,M4.1.0,M10.5.0");
 
   tm.tm_year = 98;
   tm.tm_mon = 3;
@@ -11568,14 +11696,16 @@
 }
 
 static int
-mktime_test1 (time_t now)
+mktime_test1 (now)
+     time_t now;
 {
   struct tm *lt;
   return ! (lt = localtime (&now)) || mktime (lt) == now;
 }
 
 static int
-mktime_test (time_t now)
+mktime_test (now)
+     time_t now;
 {
   return (mktime_test1 (now)
 	  && mktime_test1 ((time_t) (time_t_max - now))
@@ -11599,7 +11729,8 @@
 }
 
 static int
-bigtime_test (int j)
+bigtime_test (j)
+     int j;
 {
   struct tm tm;
   time_t now;
@@ -11643,7 +11774,7 @@
      instead of "TZ=America/Vancouver" in order to detect the bug even
      on systems that don't support the Olson extension, or don't have the
      full zoneinfo tables installed.  */
-  putenv ((char*) "TZ=PST8PDT,M4.1.0,M10.5.0");
+  putenv ("TZ=PST8PDT,M4.1.0,M10.5.0");
 
   t = mktime (&tm);
 
@@ -11678,7 +11809,7 @@
   for (i = 0; i < N_STRINGS; i++)
     {
       if (tz_strings[i])
-	putenv ((char*) tz_strings[i]);
+	putenv (tz_strings[i]);
 
       for (t = 0; t <= time_t_max - delta; t += delta)
 	if (! mktime_test (t))
@@ -11730,7 +11861,7 @@
 
 # Make sure getloadavg.c is where it belongs, at configure-time.
 test -f "$srcdir/$ac_config_libobj_dir/getloadavg.c" ||
-  as_fn_error $? "$srcdir/$ac_config_libobj_dir/getloadavg.c is missing" "$LINENO" 5
+  as_fn_error "$srcdir/$ac_config_libobj_dir/getloadavg.c is missing" "$LINENO" 5
 
 ac_save_LIBS=$LIBS
 
@@ -12599,7 +12730,7 @@
 fi
 
 if test "$have_tputs_et_al" != true; then
-  as_fn_error $? "I couldn't find termcap functions (tputs and friends).
+  as_fn_error "I couldn't find termcap functions (tputs and friends).
 Maybe some development libraries/packages are missing?  Try installing
 libncurses-dev(el), libterminfo-dev(el) or similar." "$LINENO" 5
 fi
@@ -13746,7 +13877,8 @@
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
-if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
+eval as_val=\$$as_ac_var
+   if test "x$as_val" = x""yes; then :
   cat >>confdefs.h <<_ACEOF
 #define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
 _ACEOF
@@ -14120,14 +14252,14 @@
    && test x"`$CC --version 2> /dev/null | grep 'gcc.* 4.5.0'`" != x \
    && test x"`echo $CFLAGS | grep '\-O[23]'`" != x \
    && test x"`echo $CFLAGS | grep '\-fno-optimize-sibling-calls'`" = x; then
-   as_fn_error $? "GCC 4.5.0 has problems compiling Emacs; see etc/PROBLEMS'." "$LINENO" 5
+   as_fn_error "GCC 4.5.0 has problems compiling Emacs; see etc/PROBLEMS'." "$LINENO" 5
 fi
 
 #### Find out which version of Emacs this is.
 version=`grep 'const char emacs_version' ${srcdir}/src/emacs.c \
 	 | sed -e 's/^[^"]*"\([^"]*\)".*$/\1/'`
 if test x"${version}" = x; then
-  as_fn_error $? "can't find current emacs version in \`${srcdir}/src/emacs.c'." "$LINENO" 5
+  as_fn_error "can't find current emacs version in \`${srcdir}/src/emacs.c'." "$LINENO" 5
 fi
 if test x"${version}" != x"$PACKAGE_VERSION"; then
   { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: version mismatch between \`${srcdir}/configure.in' and \`${srcdir}/src/emacs.c'." >&5
@@ -14551,6 +14683,7 @@
 echo "  Does Emacs use a gif library?                           ${HAVE_GIF} $LIBGIF"
 echo "  Does Emacs use -lpng?                                   ${HAVE_PNG}"
 echo "  Does Emacs use -lrsvg-2?                                ${HAVE_RSVG}"
+echo "  Does Emacs use imagemagick?                             ${HAVE_IMAGEMAGICK}"
 echo "  Does Emacs use -lgpm?                                   ${HAVE_GPM}"
 echo "  Does Emacs use -ldbus?                                  ${HAVE_DBUS}"
 echo "  Does Emacs use -lgconf?                                 ${HAVE_GCONF}"
@@ -14685,7 +14818,6 @@
 
 ac_libobjs=
 ac_ltlibobjs=
-U=
 for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue
   # 1. Remove the extension, and $U if already installed.
   ac_script='s/\$U\././;s/\.o$//;s/\.obj$//'
@@ -14848,19 +14980,19 @@
 (unset CDPATH) >/dev/null 2>&1 && unset CDPATH
 
 
-# as_fn_error STATUS ERROR [LINENO LOG_FD]
-# ----------------------------------------
+# as_fn_error ERROR [LINENO LOG_FD]
+# ---------------------------------
 # Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are
 # provided, also output the error to LOG_FD, referencing LINENO. Then exit the
-# script with STATUS, using 1 if that was 0.
+# script with status $?, using 1 if that was 0.
 as_fn_error ()
 {
-  as_status=$1; test $as_status -eq 0 && as_status=1
-  if test "$4"; then
-    as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
-    $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4
-  fi
-  $as_echo "$as_me: error: $2" >&2
+  as_status=$?; test $as_status -eq 0 && as_status=1
+  if test "$3"; then
+    as_lineno=${as_lineno-"$2"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+    $as_echo "$as_me:${as_lineno-$LINENO}: error: $1" >&$3
+  fi
+  $as_echo "$as_me: error: $1" >&2
   as_fn_exit $as_status
 } # as_fn_error
 
@@ -15056,7 +15188,7 @@
       test -d "$as_dir" && break
     done
     test -z "$as_dirs" || eval "mkdir $as_dirs"
-  } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir"
+  } || test -d "$as_dir" || as_fn_error "cannot create directory $as_dir"
 
 
 } # as_fn_mkdir_p
@@ -15110,7 +15242,7 @@
 # values after options handling.
 ac_log="
 This file was extended by emacs $as_me 24.0.50, which was
-generated by GNU Autoconf 2.66.  Invocation command line was
+generated by GNU Autoconf 2.65.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
   CONFIG_HEADERS  = $CONFIG_HEADERS
@@ -15176,10 +15308,10 @@
 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
 ac_cs_version="\\
 emacs config.status 24.0.50
-configured by $0, generated by GNU Autoconf 2.66,
+configured by $0, generated by GNU Autoconf 2.65,
   with options \\"\$ac_cs_config\\"
 
-Copyright (C) 2010 Free Software Foundation, Inc.
+Copyright (C) 2009 Free Software Foundation, Inc.
 This config.status script is free software; the Free Software Foundation
 gives unlimited permission to copy, distribute and modify it."
 
@@ -15233,7 +15365,7 @@
     ac_need_defaults=false;;
   --he | --h)
     # Conflict between --help and --header
-    as_fn_error $? "ambiguous option: \`$1'
+    as_fn_error "ambiguous option: \`$1'
 Try \`$0 --help' for more information.";;
   --help | --hel | -h )
     $as_echo "$ac_cs_usage"; exit ;;
@@ -15242,7 +15374,7 @@
     ac_cs_silent=: ;;
 
   # This is an error.
-  -*) as_fn_error $? "unrecognized option: \`$1'
+  -*) as_fn_error "unrecognized option: \`$1'
 Try \`$0 --help' for more information." ;;
 
   *) as_fn_append ac_config_targets " $1"
@@ -15310,7 +15442,7 @@
     "leim/Makefile") CONFIG_FILES="$CONFIG_FILES leim/Makefile" ;;
     "default") CONFIG_COMMANDS="$CONFIG_COMMANDS default" ;;
 
-  *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
+  *) as_fn_error "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
   esac
 done
 
@@ -15348,7 +15480,7 @@
 {
   tmp=./conf$$-$RANDOM
   (umask 077 && mkdir "$tmp")
-} || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5
+} || as_fn_error "cannot create a temporary directory in ." "$LINENO" 5
 
 # Set up the scripts for CONFIG_FILES section.
 # No need to generate them if there are no CONFIG_FILES.
@@ -15382,7 +15514,7 @@
 fi
 ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' </dev/null 2>/dev/null`
 if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then
-  ac_cs_awk_cr='\\r'
+  ac_cs_awk_cr='\r'
 else
   ac_cs_awk_cr=$ac_cr
 fi
@@ -15399,7 +15531,7 @@
   echo "_ACEOF"
 } >conf$$files.sh &&
 . ./conf$$files.sh ||
-  as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5
+  as_fn_error "could not make $CONFIG_STATUS" "$LINENO" 5
 rm -f conf$$files.sh
 
 {
@@ -15407,18 +15539,18 @@
   echo "$ac_subst_vars" | sed 's/.*/&!$&$ac_delim/' &&
   echo "_ACEOF"
 } >conf$$subs.sh ||
-  as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5
-ac_delim_num=`echo "$ac_subst_vars" | grep -c '^'`
+  as_fn_error "could not make $CONFIG_STATUS" "$LINENO" 5
+ac_delim_num=`echo "$ac_subst_vars" | grep -c '$'`
 ac_delim='%!_!# '
 for ac_last_try in false false false false false :; do
   . ./conf$$subs.sh ||
-    as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5
+    as_fn_error "could not make $CONFIG_STATUS" "$LINENO" 5
 
   ac_delim_n=`sed -n "s/.*$ac_delim\$/X/p" conf$$subs.awk | grep -c X`
   if test $ac_delim_n = $ac_delim_num; then
     break
   elif $ac_last_try; then
-    as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5
+    as_fn_error "could not make $CONFIG_STATUS" "$LINENO" 5
   else
     ac_delim="$ac_delim!$ac_delim _$ac_delim!! "
   fi
@@ -15513,28 +15645,20 @@
 else
   cat
 fi < "$tmp/subs1.awk" > "$tmp/subs.awk" \
-  || as_fn_error $? "could not setup config files machinery" "$LINENO" 5
-_ACEOF
-
-# VPATH may cause trouble with some makes, so we remove sole $(srcdir),
-# ${srcdir} and @srcdir@ entries from VPATH if srcdir is ".", strip leading and
+  || as_fn_error "could not setup config files machinery" "$LINENO" 5
+_ACEOF
+
+# VPATH may cause trouble with some makes, so we remove $(srcdir),
+# ${srcdir} and @srcdir@ from VPATH if srcdir is ".", strip leading and
 # trailing colons and then remove the whole line if VPATH becomes empty
 # (actually we leave an empty line to preserve line numbers).
 if test "x$srcdir" = x.; then
-  ac_vpsub='/^[	 ]*VPATH[	 ]*=[	 ]*/{
-h
-s///
-s/^/:/
-s/[	 ]*$/:/
-s/:\$(srcdir):/:/g
-s/:\${srcdir}:/:/g
-s/:@srcdir@:/:/g
-s/^:*//
+  ac_vpsub='/^[	 ]*VPATH[	 ]*=/{
+s/:*\$(srcdir):*/:/
+s/:*\${srcdir}:*/:/
+s/:*@srcdir@:*/:/
+s/^\([^=]*=[	 ]*\):*/\1/
 s/:*$//
-x
-s/\(=[	 ]*\).*/\1/
-G
-s/\n//
 s/^[^=]*=[	 ]*$//
 }'
 fi
@@ -15562,7 +15686,7 @@
   if test -z "$ac_t"; then
     break
   elif $ac_last_try; then
-    as_fn_error $? "could not make $CONFIG_HEADERS" "$LINENO" 5
+    as_fn_error "could not make $CONFIG_HEADERS" "$LINENO" 5
   else
     ac_delim="$ac_delim!$ac_delim _$ac_delim!! "
   fi
@@ -15647,7 +15771,7 @@
 _ACAWK
 _ACEOF
 cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
-  as_fn_error $? "could not setup config headers machinery" "$LINENO" 5
+  as_fn_error "could not setup config headers machinery" "$LINENO" 5
 fi # test -n "$CONFIG_HEADERS"
 
 
@@ -15660,7 +15784,7 @@
   esac
   case $ac_mode$ac_tag in
   :[FHL]*:*);;
-  :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5;;
+  :L* | :C*:*) as_fn_error "invalid tag \`$ac_tag'" "$LINENO" 5;;
   :[FH]-) ac_tag=-:-;;
   :[FH]*) ac_tag=$ac_tag:$ac_tag.in;;
   esac
@@ -15688,7 +15812,7 @@
 	   [\\/$]*) false;;
 	   *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";;
 	   esac ||
-	   as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;;
+	   as_fn_error "cannot find input file: \`$ac_f'" "$LINENO" 5;;
       esac
       case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac
       as_fn_append ac_file_inputs " '$ac_f'"
@@ -15715,7 +15839,7 @@
 
     case $ac_tag in
     *:-:* | *:-) cat >"$tmp/stdin" \
-      || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;;
+      || as_fn_error "could not create $ac_file" "$LINENO" 5 ;;
     esac
     ;;
   esac
@@ -15851,22 +15975,22 @@
 else
   $AWK -f "$tmp/subs.awk" | $SHELL
 fi >$tmp/out \
-  || as_fn_error $? "could not create $ac_file" "$LINENO" 5
+  || as_fn_error "could not create $ac_file" "$LINENO" 5
 
 test -z "$ac_datarootdir_hack$ac_datarootdir_seen" &&
   { ac_out=`sed -n '/\${datarootdir}/p' "$tmp/out"`; test -n "$ac_out"; } &&
   { ac_out=`sed -n '/^[	 ]*datarootdir[	 ]*:*=/p' "$tmp/out"`; test -z "$ac_out"; } &&
   { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir'
-which seems to be undefined.  Please make sure it is defined" >&5
+which seems to be undefined.  Please make sure it is defined." >&5
 $as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir'
-which seems to be undefined.  Please make sure it is defined" >&2;}
+which seems to be undefined.  Please make sure it is defined." >&2;}
 
   rm -f "$tmp/stdin"
   case $ac_file in
   -) cat "$tmp/out" && rm -f "$tmp/out";;
   *) rm -f "$ac_file" && mv "$tmp/out" "$ac_file";;
   esac \
-  || as_fn_error $? "could not create $ac_file" "$LINENO" 5
+  || as_fn_error "could not create $ac_file" "$LINENO" 5
  ;;
   :H)
   #
@@ -15877,19 +16001,19 @@
       $as_echo "/* $configure_input  */" \
       && eval '$AWK -f "$tmp/defines.awk"' "$ac_file_inputs"
     } >"$tmp/config.h" \
-      || as_fn_error $? "could not create $ac_file" "$LINENO" 5
+      || as_fn_error "could not create $ac_file" "$LINENO" 5
     if diff "$ac_file" "$tmp/config.h" >/dev/null 2>&1; then
       { $as_echo "$as_me:${as_lineno-$LINENO}: $ac_file is unchanged" >&5
 $as_echo "$as_me: $ac_file is unchanged" >&6;}
     else
       rm -f "$ac_file"
       mv "$tmp/config.h" "$ac_file" \
-	|| as_fn_error $? "could not create $ac_file" "$LINENO" 5
+	|| as_fn_error "could not create $ac_file" "$LINENO" 5
     fi
   else
     $as_echo "/* $configure_input  */" \
       && eval '$AWK -f "$tmp/defines.awk"' "$ac_file_inputs" \
-      || as_fn_error $? "could not create -" "$LINENO" 5
+      || as_fn_error "could not create -" "$LINENO" 5
   fi
  ;;
 
@@ -15926,7 +16050,7 @@
 ac_clean_files=$ac_clean_files_save
 
 test $ac_write_fail = 0 ||
-  as_fn_error $? "write failure creating $CONFIG_STATUS" "$LINENO" 5
+  as_fn_error "write failure creating $CONFIG_STATUS" "$LINENO" 5
 
 
 # configure is writing to config.log, and then calls config.status.
@@ -15947,7 +16071,7 @@
   exec 5>>config.log
   # Use ||, not &&, to avoid exiting from the if with $? = 1, which
   # would make configure fail if this is the last instruction.
-  $ac_cs_success || as_fn_exit 1
+  $ac_cs_success || as_fn_exit $?
 fi
 if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then
   { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5
--- a/configure.in	Thu Aug 19 00:35:46 2010 +0000
+++ b/configure.in	Thu Aug 19 22:47:51 2010 +0000
@@ -155,6 +155,7 @@
 OPTION_DEFAULT_ON([gif],[don't compile with GIF image support])
 OPTION_DEFAULT_ON([png],[don't compile with PNG image support])
 OPTION_DEFAULT_ON([rsvg],[don't compile with SVG image support])
+OPTION_DEFAULT_OFF([imagemagick],[compile with ImageMagick image support])
 
 OPTION_DEFAULT_ON([xft],[don't use XFT for anti aliased fonts])
 OPTION_DEFAULT_ON([libotf],[don't use libotf for OpenType font support])
@@ -1837,6 +1838,25 @@
   fi
 fi
 
+HAVE_IMAGEMAGICK=no
+if test "${with_imagemagick}" != "no"; then
+  IMAGEMAGICK_MODULE="Wand"
+  PKG_CHECK_MODULES(IMAGEMAGICK, $IMAGEMAGICK_MODULE, :, :)
+  AC_SUBST(IMAGEMAGICK_CFLAGS)
+  AC_SUBST(IMAGEMAGICK_LIBS)
+
+  if test ".${IMAGEMAGICK_CFLAGS}" != "."; then
+    HAVE_IMAGEMAGICK=yes
+    AC_DEFINE(HAVE_IMAGEMAGICK, 1, [Define to 1 if using imagemagick.])
+    CFLAGS="$CFLAGS $IMAGEMAGICK_CFLAGS"
+    LIBS="$IMAGEMAGICK_LIBS $LIBS"
+  fi
+
+  AC_DEFINE(HAVE_MAGICKEXPORTIMAGEPIXELS, 1, [Define to 1 if MagickExportImagePixels is defined.])
+  AC_CHECK_FUNCS_ONCE(MagickExportImagePixels)
+  
+fi
+
 
 HAVE_GTK=no
 if test "${with_gtk3}" = "yes"; then
@@ -3662,6 +3682,7 @@
 echo "  Does Emacs use a gif library?                           ${HAVE_GIF} $LIBGIF"
 echo "  Does Emacs use -lpng?                                   ${HAVE_PNG}"
 echo "  Does Emacs use -lrsvg-2?                                ${HAVE_RSVG}"
+echo "  Does Emacs use imagemagick?                             ${HAVE_IMAGEMAGICK}"
 echo "  Does Emacs use -lgpm?                                   ${HAVE_GPM}"
 echo "  Does Emacs use -ldbus?                                  ${HAVE_DBUS}"
 echo "  Does Emacs use -lgconf?                                 ${HAVE_GCONF}"
--- a/doc/lispref/display.texi	Thu Aug 19 00:35:46 2010 +0000
+++ b/doc/lispref/display.texi	Thu Aug 19 22:47:51 2010 +0000
@@ -4039,6 +4039,7 @@
 * GIF Images::          Special features for GIF format.
 * TIFF Images::         Special features for TIFF format.
 * PostScript Images::   Special features for PostScript format.
+* ImageMagick Images::  Special features available through ImageMagick.
 * Other Image Types::   Various other formats are supported.
 * Defining Images::     Convenient ways to define an image for later use.
 * Showing Images::      Convenient ways to display an image once it is defined.
@@ -4463,6 +4464,51 @@
 @end example
 @end table
 
+@node ImageMagick Images
+@subsection ImageMagick Images
+The Imagemagick library can be used to load many image formats in Emacs.
+
+The function (imagemagick-types) returns a list of image file
+extensions that your installation of imagemagick supports.
+
+The function (imagemagick-register-types) will enable the imagemagick
+support for the extensions in imagemagick-types minus the types listed
+in imagemagick-types-inhibit.
+
+imagemagick-types-inhibit has the value '(C HTML HTM TXT PDF) by
+default.  There can be overlap between image loaders in your Emacs
+installation. If you never want to use the ImageMagick loader to use
+Jpeg files, for instance, add 'JPG to imagemagick-types-inhibit. Which
+loader that will be used in practice depends on the priority of the
+loaders.
+
+imagemagick-render-type is a new variable which can be set to choose
+between screen render methods for the ImageMagick loader.
+
+- 0 is a conservative metod which works with older ImageMagick
+  versions. It is a bit slow, but robust.
+
+- 1 utilizes a newer ImageMagick method   
+
+
+Images loaded with imagemagick will support a couple of new display
+specification behaviours:
+
+- if the :width and :height keywords are specified, these values are
+used for scaling the image. If only one of :width or :height is
+specified, the other one will be calculated so as to preserve the
+aspect ratio.If both :width and :height are specified, aspect ratio
+will not be preserved.
+
+- :rotation specifies a rotation angle in degrees.
+
+- :index specifies which image inside an image bundle file format, such
+as TIFF or DJVM, to view.
+
+The image-metadata function can be used to retrieve the total number
+of images in an image bundle. This is simmilar to how GIF files work.
+
+
 @node Other Image Types
 @subsection Other Image Types
 @cindex PBM
--- a/etc/NEWS	Thu Aug 19 00:35:46 2010 +0000
+++ b/etc/NEWS	Thu Aug 19 22:47:51 2010 +0000
@@ -109,6 +109,22 @@
 top, left, right or bottom.  The Options => Show/Hide menu has entries
 for this.
 
+** ImageMagick support
+It is now possible to use the Imagemagick library to load many new
+image formats in Emacs.
+
+To enable, use the following configure option:
+--with-imagemagick
+
+The new function (imagemagick-types) returns a list of image file
+extensions that your installation of imagemagick supports.
+
+The function (imagemagick-register-types) will enable the imagemagick
+support for the extensions in imagemagick-types minus the types listed
+in imagemagick-types-inhibit.
+
+See the Emacs Manual for more information.
+
 ** The colors for selected text (the region face) are taken from the GTK
 theme when Emacs is built with GTK.
 
@@ -437,6 +453,8 @@
 
 * Lisp changes in Emacs 24.1
 
+** New hook post-self-insert-hook run at the end of self-insert-command.
+
 ** Syntax tables support a new "comment style c" additionally to style b.
 ** frame-local variables cannot be let-bound any more.
 ** prog-mode is a new major-mode meant to be the parent of programming mode.
--- a/lisp/ChangeLog	Thu Aug 19 00:35:46 2010 +0000
+++ b/lisp/ChangeLog	Thu Aug 19 22:47:51 2010 +0000
@@ -1,3 +1,15 @@
+2010-08-19  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+	* files.el (locate-file-completion-table): Only list the .el and .elc
+	extensions if there's no other choice (bug#5955).
+
+	* facemenu.el (facemenu-self-insert-data): New var.
+	(facemenu-post-self-insert-function, facemenu-set-self-insert-face):
+	New functions.
+	(facemenu-add-face): Use them.
+
+	* simple.el (blink-matching-open): Obey forward-sexp-function.
+
 2010-08-18  Stefan Monnier  <monnier@iro.umontreal.ca>
 
 	* simple.el (prog-mode-map): New var.
--- a/lisp/facemenu.el	Thu Aug 19 00:35:46 2010 +0000
+++ b/lisp/facemenu.el	Thu Aug 19 22:47:51 2010 +0000
@@ -699,6 +699,22 @@
   (cond ((equal a b) t)
 	((equal (color-values a) (color-values b)))))
 
+
+(defvar facemenu-self-insert-data nil)
+
+(defun facemenu-post-self-insert-function ()
+  (when (and (car facemenu-self-insert-data)
+             (eq last-command (cdr facemenu-self-insert-data)))
+    (put-text-property (1- (point)) (point)
+                       'face (car facemenu-self-insert-data))
+    (setq facemenu-self-insert-data nil))
+  (remove-hook 'post-self-insert-hook 'facemenu-post-self-insert-function))
+
+(defun facemenu-set-self-insert-face (face)
+  "Arrange for the next self-inserted char to have face `face'."
+  (setq facemenu-self-insert-data (cons face this-command))
+  (add-hook 'post-self-insert-hook 'facemenu-post-self-insert-function))
+
 (defun facemenu-add-face (face &optional start end)
   "Add FACE to text between START and END.
 If START is nil or START to END is empty, add FACE to next typed character
@@ -712,51 +728,52 @@
 text property.  Otherwise, selecting the default face would not have any
 effect.  See `facemenu-remove-face-function'."
   (interactive "*xFace: \nr")
-  (if (and (eq face 'default)
-	   (not (eq facemenu-remove-face-function t)))
-      (if facemenu-remove-face-function
-	  (funcall facemenu-remove-face-function start end)
-	(if (and start (< start end))
-	    (remove-text-properties start end '(face default))
-	  (setq self-insert-face 'default
-		self-insert-face-command this-command)))
-    (if facemenu-add-face-function
-	(save-excursion
-	  (if end (goto-char end))
-	  (save-excursion
-	    (if start (goto-char start))
-	    (insert-before-markers
-	     (funcall facemenu-add-face-function face end)))
-	  (if facemenu-end-add-face
-	      (insert (if (stringp facemenu-end-add-face)
-			  facemenu-end-add-face
-			(funcall facemenu-end-add-face face)))))
+  (cond
+   ((and (eq face 'default)
+         (not (eq facemenu-remove-face-function t)))
+    (if facemenu-remove-face-function
+        (funcall facemenu-remove-face-function start end)
       (if (and start (< start end))
-	  (let ((part-start start) part-end)
-	    (while (not (= part-start end))
-	      (setq part-end (next-single-property-change part-start 'face
-							  nil end))
-	      (let ((prev (get-text-property part-start 'face)))
-		(put-text-property part-start part-end 'face
-				   (if (null prev)
-				       face
-				     (facemenu-active-faces
-				      (cons face
-					    (if (listp prev)
-						prev
-					      (list prev)))
-				      ;; Specify the selected frame
-				      ;; because nil would mean to use
-				      ;; the new-frame default settings,
-				      ;; and those are usually nil.
-				      (selected-frame)))))
-	      (setq part-start part-end)))
-	(setq self-insert-face (if (eq last-command self-insert-face-command)
-				   (cons face (if (listp self-insert-face)
-						  self-insert-face
-						(list self-insert-face)))
-				 face)
-	      self-insert-face-command this-command))))
+          (remove-text-properties start end '(face default))
+        (facemenu-set-self-insert-face 'default))))
+   (facemenu-add-face-function
+    (save-excursion
+      (if end (goto-char end))
+      (save-excursion
+        (if start (goto-char start))
+        (insert-before-markers
+         (funcall facemenu-add-face-function face end)))
+      (if facemenu-end-add-face
+          (insert (if (stringp facemenu-end-add-face)
+                      facemenu-end-add-face
+                    (funcall facemenu-end-add-face face))))))
+   ((and start (< start end))
+    (let ((part-start start) part-end)
+      (while (not (= part-start end))
+        (setq part-end (next-single-property-change part-start 'face
+                                                    nil end))
+        (let ((prev (get-text-property part-start 'face)))
+          (put-text-property part-start part-end 'face
+                             (if (null prev)
+                                 face
+                               (facemenu-active-faces
+                                (cons face
+                                      (if (listp prev)
+                                          prev
+                                        (list prev)))
+                                ;; Specify the selected frame
+                                ;; because nil would mean to use
+                                ;; the new-frame default settings,
+                                ;; and those are usually nil.
+                                (selected-frame)))))
+        (setq part-start part-end))))
+   (t
+    (facemenu-set-self-insert-face
+     (if (eq last-command (cdr facemenu-self-insert-data))
+         (cons face (if (listp (car facemenu-self-insert-data))
+                        (car facemenu-self-insert-data)
+                      (list (car facemenu-self-insert-data))))
+       face))))
   (unless (facemenu-enable-faces-p)
     (message "Font-lock mode will override any faces you set in this buffer")))
 
--- a/lisp/files.el	Thu Aug 19 00:35:46 2010 +0000
+++ b/lisp/files.el	Thu Aug 19 22:47:51 2010 +0000
@@ -757,21 +757,44 @@
              (let ((x (file-name-directory suffix)))
                (if x (1- (length x)) (length suffix))))))
    (t
-    (let ((names nil)
+    (let ((names '())
+          ;; If we have files like "foo.el" and "foo.elc", we could load one of
+          ;; them with "foo.el", "foo.elc", or "foo", where just "foo" is the
+          ;; preferred way.  So if we list all 3, that gives a lot of redundant
+          ;; entries for the poor soul looking just for "foo".  OTOH, sometimes
+          ;; the user does want to pay attention to the extension.  We try to
+          ;; diffuse this tension by stripping the suffix, except when the
+          ;; result is a single element (i.e. usually we only list "foo" unless
+          ;; it's the only remaining element in the list, in which case we do
+          ;; list "foo", "foo.elc" and "foo.el").
+          (fullnames '())
 	  (suffix (concat (regexp-opt suffixes t) "\\'"))
 	  (string-dir (file-name-directory string))
           (string-file (file-name-nondirectory string)))
       (dolist (dir dirs)
-	(unless dir
-	  (setq dir default-directory))
-	(if string-dir (setq dir (expand-file-name string-dir dir)))
-	(when (file-directory-p dir)
-	  (dolist (file (file-name-all-completions
-			 string-file dir))
-	    (push file names)
-	    (when (string-match suffix file)
-	      (setq file (substring file 0 (match-beginning 0)))
-              (push file names)))))
+        (unless dir
+          (setq dir default-directory))
+        (if string-dir (setq dir (expand-file-name string-dir dir)))
+        (when (file-directory-p dir)
+          (dolist (file (file-name-all-completions
+                         string-file dir))
+            (if (not (string-match suffix file))
+                (push file names)
+              (push file fullnames)
+              (push (substring file 0 (match-beginning 0)) names)))))
+      ;; Switching from names to names+fullnames creates a non-monotonicity
+      ;; which can cause problems with things like partial-completion.
+      ;; To minimize the problem, filter out completion-regexp-list, so that
+      ;; M-x load-library RET t/x.e TAB finds some files.
+      (if completion-regexp-list
+          (setq names (all-completions "" names)))
+      ;; Remove duplicates of the first element, so that we can easily check
+      ;; if `names' really only contains a single element.
+      (when (cdr names) (setcdr names (delete (car names) (cdr names))))
+      (unless (cdr names)
+        ;; There's no more than one matching non-suffixed element, so expand
+        ;; the list by adding the suffixed elements as well.
+        (setq names (nconc names fullnames)))
       (completion-table-with-context
        string-dir names string-file pred action)))))
 
--- a/lisp/image-mode.el	Thu Aug 19 00:35:46 2010 +0000
+++ b/lisp/image-mode.el	Thu Aug 19 22:47:51 2010 +0000
@@ -493,7 +493,10 @@
 			    (buffer-substring-no-properties (point-min) (point-max)))
 			 filename))
 	 (type (image-type file-or-data nil data-p))
-	 (image (create-animated-image file-or-data type data-p))
+         (image0 (create-animated-image file-or-data type data-p))
+	 (image (append image0
+                        (image-transform-properties image0)
+                        ))
 	 (props
 	  `(display ,image
 		    intangible ,image
@@ -556,6 +559,84 @@
     (when (not (string= image-type (bookmark-prop-get bmk 'image-type)))
       (image-toggle-display))))
 
+
+(defvar image-transform-minor-mode-map
+  (let ((map (make-sparse-keymap)))
+;    (define-key map  [(control ?+)] 'image-scale-in)
+;    (define-key map  [(control ?-)] 'image-scale-out)
+;    (define-key map  [(control ?=)] 'image-scale-none)
+;;    (define-key map "c f h" 'image-scale-fit-height)
+;;    (define-key map "c ]" 'image-rotate-right)
+    map)
+  "Minor mode keymap for transforming the view of images Image mode.")
+
+(define-minor-mode image-transform-mode
+  "minor mode for scaleing and rotation"
+  nil "image-transform"
+  image-transform-minor-mode-map)
+
+(defvar image-transform-resize   nil
+  "The image resize operation. See the command
+  `image-transform-set-scale' for more information." )
+
+(defvar image-transform-rotation 0.0)
+
+
+(defun image-transform-properties (display)
+  "Calculate the display properties for transformations; scaling
+and rotation. "
+  (let*
+      ((size (image-size display t))
+       (height
+        (cond
+         ((and (numberp image-transform-resize) (eq 100 image-transform-resize))
+          nil)
+         ((numberp image-transform-resize)
+          (* image-transform-resize (cdr size)))
+         ((eq image-transform-resize 'fit-height)
+          (- (nth 3 (window-inside-pixel-edges)) (nth 1 (window-inside-pixel-edges))))
+         (t nil)))
+       (width (if (eq image-transform-resize 'fit-width)
+                  (- (nth 2 (window-inside-pixel-edges)) (nth 0 (window-inside-pixel-edges))))))
+
+    `(,@(if height (list :height height))
+      ,@(if width (list :width width))
+      ,@(if (not (equal 0.0 image-transform-rotation))
+            (list :rotation image-transform-rotation))
+      ;;TODO fit-to-* should consider the rotation angle
+      )))
+
+(defun image-transform-set-scale (scale)
+  "SCALE sets the scaling for images. "
+  (interactive "nscale:")
+  (image-transform-set-resize (float scale)))
+
+(defun image-transform-fit-to-height ()
+  "Fit image height to window height. "
+  (interactive)
+  (image-transform-set-resize 'fit-height))
+
+(defun image-transform-fit-to-width ()
+  "Fit image width to window width. "
+  (interactive)
+  (image-transform-set-resize 'fit-width))
+
+(defun image-transform-set-resize (resize)
+  "Set the resize mode for images. The RESIZE value can be the
+symbol fit-height which fits the image to the window height. The
+symbol fit-width fits the image to the window width.  A number
+indicates a scaling factor. nil indicates scale to 100%. "
+  (setq image-transform-resize resize)
+  (if (eq 'image-mode major-mode) (image-toggle-display-image)))
+
+(defun image-transform-set-rotation (rotation)
+  "Set the image ROTATION angle. "
+  (interactive "nrotation:")
+  ;;TODO 0 90 180 270 degrees are the only reasonable angles here
+  ;;otherwise combining with rescaling will get very awkward
+  (setq image-transform-rotation (float rotation))
+  (if (eq major-mode 'image-mode) (image-toggle-display-image)))
+
 (provide 'image-mode)
 
 ;; arch-tag: b5b2b7e6-26a7-4b79-96e3-1546b5c4c6cb
--- a/lisp/image.el	Thu Aug 19 00:35:46 2010 +0000
+++ b/lisp/image.el	Thu Aug 19 22:47:51 2010 +0000
@@ -694,6 +694,27 @@
 	(cons images tmo))))))
 
 
+(defcustom imagemagick-types-inhibit
+  '(C HTML HTM TXT PDF)
+  "Types the imagemagick loader should not try to handle.")
+
+;;;###autoload
+(defun imagemagick-register-types ()
+  "Register file types that imagemagick is able to handle."
+  (let ((im-types (imagemagick-types)))
+    (dolist (im-inhibit imagemagick-types-inhibit)
+      (setq im-types (remove im-inhibit im-types)))
+    (dolist (im-type im-types)
+      (let ((extension (downcase (symbol-name im-type))))
+	(push
+	 (cons  (concat "\\." extension "\\'") 'image-mode)
+	 auto-mode-alist)
+	(push
+	 (cons  (concat "\\." extension "\\'") 'imagemagick)
+	 image-type-file-name-regexps)))))
+
+
+
 (provide 'image)
 
 ;; arch-tag: 8e76a07b-eb48-4f3e-a7a0-1a7ba9f096b3
--- a/lisp/org/ChangeLog	Thu Aug 19 00:35:46 2010 +0000
+++ b/lisp/org/ChangeLog	Thu Aug 19 22:47:51 2010 +0000
@@ -1,3 +1,12 @@
+2010-08-19  Glenn Morris  <rgm@gnu.org>
+
+	* org.el (org-outline-overlay-data, org-set-outline-overlay-data)
+	(org-save-outline-visibility): Move to org-macs.
+	* org-macs.el (org-outline-overlay-data, org-set-outline-overlay-data)
+	(org-save-outline-visibility): Move here from org.el.
+	(show-all): Autoload it.
+	* ob.el: Don't require org when compiling.
+
 2010-08-18  Glenn Morris  <rgm@gnu.org>
 
 	* ob.el: Require org when compiling.
--- a/lisp/org/ob.el	Thu Aug 19 00:35:46 2010 +0000
+++ b/lisp/org/ob.el	Thu Aug 19 22:47:51 2010 +0000
@@ -30,8 +30,7 @@
 
 ;;; Code:
 (eval-when-compile
-  (require 'cl)
-  (require 'org))                  ; org-save-outline-visibility macro
+  (require 'cl))
 (require 'org-macs)
 
 (defvar org-babel-call-process-region-original)
--- a/lisp/org/org-macs.el	Thu Aug 19 00:35:46 2010 +0000
+++ b/lisp/org/org-macs.el	Thu Aug 19 22:47:51 2010 +0000
@@ -300,6 +300,66 @@
 	   (nstars (if org-odd-levels-only (1- (* limit-level 2)) limit-level)))
       (format "\\*\\{1,%d\\} " nstars))))
 
+
+;;; Saving and restoring visibility
+
+(defun org-outline-overlay-data (&optional use-markers)
+  "Return a list of the locations of all outline overlays.
+The are overlays with the `invisible' property value `outline'.
+The return values is a list of cons cells, with start and stop
+positions for each overlay.
+If USE-MARKERS is set, return the positions as markers."
+  (let (beg end)
+    (save-excursion
+      (save-restriction
+	(widen)
+	(delq nil
+	      (mapcar (lambda (o)
+			(when (eq (overlay-get o 'invisible) 'outline)
+			  (setq beg (overlay-start o)
+				end (overlay-end o))
+			  (and beg end (> end beg)
+			       (if use-markers
+				   (cons (move-marker (make-marker) beg)
+					 (move-marker (make-marker) end))
+				 (cons beg end)))))
+		      (overlays-in (point-min) (point-max))))))))
+
+(autoload 'show-all "outline" nil t)
+
+(defun org-set-outline-overlay-data (data)
+  "Create visibility overlays for all positions in DATA.
+DATA should have been made by `org-outline-overlay-data'."
+  (let (o)
+    (save-excursion
+      (save-restriction
+	(widen)
+	(show-all)
+	(mapc (lambda (c)
+		(setq o (make-overlay (car c) (cdr c)))
+		(overlay-put o 'invisible 'outline))
+	      data)))))
+
+(defmacro org-save-outline-visibility (use-markers &rest body)
+  "Save and restore outline visibility around BODY.
+If USE-MARKERS is non-nil, use markers for the positions.
+This means that the buffer may change while running BODY,
+but it also means that the buffer should stay alive
+during the operation, because otherwise all these markers will
+point nowhere."
+  (declare (indent 1))
+  `(let ((data (org-outline-overlay-data ,use-markers)))
+     (unwind-protect
+	 (progn
+	   ,@body
+	   (org-set-outline-overlay-data data))
+       (when ,use-markers
+	 (mapc (lambda (c)
+		 (and (markerp (car c)) (move-marker (car c) nil))
+		 (and (markerp (cdr c)) (move-marker (cdr c) nil)))
+	       data)))))
+
+
 (provide 'org-macs)
 
 ;; arch-tag: 7e6a73ce-aac9-4fc0-9b30-ce6f89dc6668
--- a/lisp/org/org.el	Thu Aug 19 00:35:46 2010 +0000
+++ b/lisp/org/org.el	Thu Aug 19 22:47:51 2010 +0000
@@ -6190,62 +6190,6 @@
     (beginning-of-line)
     (recenter (prefix-numeric-value N))))
 
-;;; Saving and restoring visibility
-
-(defun org-outline-overlay-data (&optional use-markers)
-  "Return a list of the locations of all outline overlays.
-The are overlays with the `invisible' property value `outline'.
-The return values is a list of cons cells, with start and stop
-positions for each overlay.
-If USE-MARKERS is set, return the positions as markers."
-  (let (beg end)
-    (save-excursion
-      (save-restriction
-	(widen)
-	(delq nil
-	      (mapcar (lambda (o)
-			(when (eq (overlay-get o 'invisible) 'outline)
-			  (setq beg (overlay-start o)
-				end (overlay-end o))
-			  (and beg end (> end beg)
-			       (if use-markers
-				   (cons (move-marker (make-marker) beg)
-					 (move-marker (make-marker) end))
-				 (cons beg end)))))
-		      (overlays-in (point-min) (point-max))))))))
-
-(defun org-set-outline-overlay-data (data)
-  "Create visibility overlays for all positions in DATA.
-DATA should have been made by `org-outline-overlay-data'."
-  (let (o)
-    (save-excursion
-      (save-restriction
-	(widen)
-	(show-all)
-	(mapc (lambda (c)
-		(setq o (make-overlay (car c) (cdr c)))
-		(overlay-put o 'invisible 'outline))
-	      data)))))
-
-(defmacro org-save-outline-visibility (use-markers &rest body)
-  "Save and restore outline visibility around BODY.
-If USE-MARKERS is non-nil, use markers for the positions.
-This means that the buffer may change while running BODY,
-but it also means that the buffer should stay alive
-during the operation, because otherwise all these markers will
-point nowhere."
-  (declare (indent 1))
-  `(let ((data (org-outline-overlay-data ,use-markers)))
-     (unwind-protect
-	 (progn
-	   ,@body
-	   (org-set-outline-overlay-data data))
-       (when ,use-markers
-	 (mapc (lambda (c)
-		 (and (markerp (car c)) (move-marker (car c) nil))
-		 (and (markerp (cdr c)) (move-marker (cdr c) nil)))
-	       data)))))
-
 
 ;;; Folding of blocks
 
--- a/lisp/simple.el	Thu Aug 19 00:35:46 2010 +0000
+++ b/lisp/simple.el	Thu Aug 19 22:47:51 2010 +0000
@@ -5495,7 +5495,9 @@
                        (and parse-sexp-ignore-comments
                             (not blink-matching-paren-dont-ignore-comments))))
                   (condition-case ()
-                      (scan-sexps oldpos -1)
+                      (progn
+                        (forward-sexp -1)
+                        (point))
                     (error nil))))))
 	   (matching-paren
             (and blinkpos
--- a/nt/ChangeLog	Thu Aug 19 00:35:46 2010 +0000
+++ b/nt/ChangeLog	Thu Aug 19 22:47:51 2010 +0000
@@ -1,3 +1,7 @@
+2010-08-19  Juanma Barranquero  <lekktu@gmail.com>
+
+	* addpm.c (add_registry): Create App Paths of type REG_EXPAND_SZ.
+
 2010-08-12  Jason Rumney  <jasonr@gnu.org>
 
 	* addpm.c (add_registry): Set path for runemacs.exe to use.
--- a/nt/addpm.c	Thu Aug 19 00:35:46 2010 +0000
+++ b/nt/addpm.c	Thu Aug 19 22:47:51 2010 +0000
@@ -113,7 +113,7 @@
       emacs_path = (char *) alloca (len);
       sprintf (emacs_path, "%s\\bin\\emacs.exe", path);
 
-      RegSetValueEx (hrootkey, NULL, 0, REG_SZ, emacs_path, len);
+      RegSetValueEx (hrootkey, NULL, 0, REG_EXPAND_SZ, emacs_path, len);
 
       /* Look for a GTK installation. If found, add it to the library search
          path for Emacs so that the image libraries it provides are available
@@ -135,7 +135,8 @@
                   len = strlen (path) + 5 + size;
                   dll_paths = (char *) alloca (size + strlen (path) + 1);
                   sprintf (dll_paths, "%s\\bin;%s", path, gtk_path);
-                  RegSetValueEx (hrootkey, "Path", 0, REG_SZ, dll_paths, len);
+                  RegSetValueEx (hrootkey, "Path", 0, REG_EXPAND_SZ,
+				 dll_paths, len);
 
 		  /* Set the same path for runemacs.exe, as the Explorer shell
 		     looks this up, so the above does not take effect when
@@ -145,7 +146,7 @@
 				      KEY_WRITE, NULL, &runemacs_key, NULL)
 		      == ERROR_SUCCESS)
 		    {
-		      RegSetValueEx (runemacs_key, "Path", 0, REG_SZ,
+		      RegSetValueEx (runemacs_key, "Path", 0, REG_EXPAND_SZ,
 				     dll_paths, len);
 
 		      RegCloseKey (runemacs_key);
--- a/src/ChangeLog	Thu Aug 19 00:35:46 2010 +0000
+++ b/src/ChangeLog	Thu Aug 19 22:47:51 2010 +0000
@@ -1,3 +1,21 @@
+2010-08-19  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+	* cmds.c (Vself_insert_face, Vself_insert_face_command): Remove.
+	(Qpost_self_insert_hook, Vpost_self_insert_hook): New vars.
+	(internal_self_insert): Run Qpost_self_insert_hook rather than handle
+	self-insert-face.
+	(syms_of_cmds): Initialize the new vars.
+
+2010-08-19  Jason Rumney  <jasonr@gnu.org>
+
+	* w32menu.c (set_frame_menubar): Remove call to undefined function.
+
+	* w32fns.c (w32_wnd_proc): Don't check context before initializing.
+
+2010-08-19  Jan Djärv  <jan.h.d@swipnet.se>
+
+	* nsselect.m (nxatoms_of_nsselect): Use "Selection" and "Secondary".
+
 2010-08-18  Eli Zaretskii  <eliz@gnu.org>
 
 	* xterm.c (x_draw_bar_cursor):
--- a/src/Makefile.in	Thu Aug 19 00:35:46 2010 +0000
+++ b/src/Makefile.in	Thu Aug 19 22:47:51 2010 +0000
@@ -1,3 +1,4 @@
+
 # Makefile for GNU Emacs.
 # Copyright (C) 1985, 1987, 1988, 1993, 1994, 1995, 1999, 2000, 2001, 2002,
 #   2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
@@ -222,6 +223,10 @@
 RSVG_LIBS= @RSVG_LIBS@
 RSVG_CFLAGS= @RSVG_CFLAGS@
 
+IMAGEMAGICK_LIBS= @IMAGEMAGICK_LIBS@
+IMAGEMAGICK_CFLAGS= @IMAGEMAGICK_CFLAGS@
+
+
 ## widget.o if USE_X_TOOLKIT, otherwise empty.
 WIDGET_OBJ=@WIDGET_OBJ@
 
@@ -315,7 +320,7 @@
 ## FIXME? MYCPPFLAGS only referenced in etc/DEBUG.
 ALL_CFLAGS=-Demacs -DHAVE_CONFIG_H $(MYCPPFLAGS) -I. -I${srcdir} \
   ${C_SWITCH_MACHINE} ${C_SWITCH_SYSTEM} ${C_SWITCH_X_SITE} \
-  ${C_SWITCH_X_SYSTEM} ${CFLAGS_SOUND} ${RSVG_CFLAGS} ${DBUS_CFLAGS} \
+  ${C_SWITCH_X_SYSTEM} ${CFLAGS_SOUND} ${RSVG_CFLAGS} ${IMAGEMAGICK_CFLAGS} ${DBUS_CFLAGS} \
   ${GCONF_CFLAGS} ${FREETYPE_CFLAGS} ${FONTCONFIG_CFLAGS} \
   ${LIBOTF_CFLAGS} ${M17N_FLT_CFLAGS} ${DEPFLAGS} ${PROFILING_CFLAGS} \
   ${C_WARNINGS_SWITCH} ${CFLAGS}
@@ -590,7 +595,7 @@
 ## duplicated symbols.  If the standard libraries were compiled
 ## with GCC, we might need LIB_GCC again after them.
 LIBES = $(LIBS) $(LIBX_BASE) $(LIBX_OTHER) $(LIBSOUND) \
-   $(RSVG_LIBS) $(DBUS_LIBS) $(LIBGPM) $(LIBRESOLV) $(LIBS_SYSTEM) \
+   $(RSVG_LIBS) ${IMAGEMAGICK_LIBS}  $(DBUS_LIBS) $(LIBGPM) $(LIBRESOLV) $(LIBS_SYSTEM) \
    $(LIBS_TERMCAP) $(GETLOADAVG_LIBS) ${GCONF_LIBS} ${LIBSELINUX_LIBS} \
    $(FREETYPE_LIBS) $(FONTCONFIG_LIBS) $(LIBOTF_LIBS) $(M17N_FLT_LIBS) \
    $(LIB_GCC) $(LIB_MATH) $(LIB_STANDARD) $(LIB_GCC)
--- a/src/cmds.c	Thu Aug 19 00:35:46 2010 +0000
+++ b/src/cmds.c	Thu Aug 19 22:47:51 2010 +0000
@@ -37,12 +37,6 @@
 /* A possible value for a buffer's overwrite-mode variable.  */
 Lisp_Object Qoverwrite_mode_binary;
 
-/* Non-nil means put this face on the next self-inserting character.  */
-Lisp_Object Vself_insert_face;
-
-/* This is the command that set up Vself_insert_face.  */
-Lisp_Object Vself_insert_face_command;
-
 static int internal_self_insert (int, int);
 
 DEFUN ("forward-point", Fforward_point, Sforward_point, 1, 1, 0,
@@ -346,6 +340,7 @@
    A value of 2 means this did things that call for an undo boundary.  */
 
 static Lisp_Object Qexpand_abbrev;
+static Lisp_Object Qpost_self_insert_hook, Vpost_self_insert_hook;
 
 static int
 internal_self_insert (int c, int noautofill)
@@ -451,10 +446,10 @@
       && synt != Sword
       && NILP (current_buffer->read_only)
       && PT > BEGV
-      && (!NILP (current_buffer->enable_multibyte_characters)
-	  ? SYNTAX (XFASTINT (Fprevious_char ())) == Sword
-	  : (SYNTAX (UNIBYTE_TO_CHAR (XFASTINT (Fprevious_char ())))
-	     == Sword)))
+      && (SYNTAX (!NILP (current_buffer->enable_multibyte_characters)
+		  ? XFASTINT (Fprevious_char ())
+		  : UNIBYTE_TO_CHAR (XFASTINT (Fprevious_char ())))
+	  == Sword))
     {
       int modiff = MODIFF;
       Lisp_Object sym;
@@ -514,15 +509,6 @@
 	hairy = 2;
     }
 
-  /* If previous command specified a face to use, use it.  */
-  if (!NILP (Vself_insert_face)
-      && EQ (current_kboard->Vlast_command, Vself_insert_face_command))
-    {
-      Fput_text_property (make_number (PT - 1), make_number (PT),
-			  Qface, Vself_insert_face, Qnil);
-      Vself_insert_face = Qnil;
-    }
-
   if ((synt == Sclose || synt == Smath)
       && !NILP (Vblink_paren_function) && INTERACTIVE
       && !noautofill)
@@ -530,6 +516,9 @@
       call0 (Vblink_paren_function);
       hairy = 2;
     }
+  /* Run hooks for electric keys.  */
+  call1 (Vrun_hooks, Qpost_self_insert_hook);
+
   return hairy;
 }
 
@@ -550,15 +539,13 @@
   Qexpand_abbrev = intern_c_string ("expand-abbrev");
   staticpro (&Qexpand_abbrev);
 
-  DEFVAR_LISP ("self-insert-face", &Vself_insert_face,
-	       doc: /* If non-nil, set the face of the next self-inserting character to this.
-See also `self-insert-face-command'.  */);
-  Vself_insert_face = Qnil;
+  Qpost_self_insert_hook = intern_c_string ("post-self-insert-hook");
+  staticpro (&Qpost_self_insert_hook);
 
-  DEFVAR_LISP ("self-insert-face-command", &Vself_insert_face_command,
-	       doc: /* This is the command that set up `self-insert-face'.
-If `last-command' does not equal this value, we ignore `self-insert-face'.  */);
-  Vself_insert_face_command = Qnil;
+  DEFVAR_LISP ("post-self-insert-hook", &Vpost_self_insert_hook,
+	       doc: /* Hook run at the end of `self-insert-command'.
+This run is run after inserting the charater.  */);
+  Vpost_self_insert_hook = Qnil;
 
   DEFVAR_LISP ("blink-paren-function", &Vblink_paren_function,
 	       doc: /* Function called, if non-nil, whenever a close parenthesis is inserted.
--- a/src/config.in	Thu Aug 19 00:35:46 2010 +0000
+++ b/src/config.in	Thu Aug 19 22:47:51 2010 +0000
@@ -294,6 +294,9 @@
 /* Define to 1 if netdb.h declares h_errno. */
 #undef HAVE_H_ERRNO
 
+/* Define to 1 if using imagemagick. */
+#undef HAVE_IMAGEMAGICK
+
 /* Define to 1 if you have inet sockets. */
 #undef HAVE_INET_SOCKETS
 
@@ -432,6 +435,9 @@
 /* Define to 1 if you have the <mach/mach.h> header file. */
 #undef HAVE_MACH_MACH_H
 
+/* Define to 1 if you have the `MagickExportImagePixels' function. */
+#undef HAVE_MAGICKEXPORTIMAGEPIXELS
+
 /* Define to 1 if you have the <maillock.h> header file. */
 #undef HAVE_MAILLOCK_H
 
--- a/src/image.c	Thu Aug 19 00:35:46 2010 +0000
+++ b/src/image.c	Thu Aug 19 22:47:51 2010 +0000
@@ -583,7 +583,7 @@
 
 Lisp_Object QCascent, QCmargin, QCrelief, Qcount, Qextension_data;
 Lisp_Object QCconversion, QCcolor_symbols, QCheuristic_mask;
-Lisp_Object QCindex, QCmatrix, QCcolor_adjustment, QCmask;
+Lisp_Object QCindex, QCmatrix, QCcolor_adjustment, QCmask, QCgeometry, QCcrop, QCrotation;
 
 /* Other symbols.  */
 
@@ -7342,6 +7342,519 @@
 #endif /* HAVE_GIF */
 
 
+/***********************************************************************
+				 imagemagick
+***********************************************************************/
+#if defined (HAVE_IMAGEMAGICK)
+Lisp_Object Vimagemagick_render_type;
+
+/* The symbol `imagemagick' identifying images of this type.  */
+
+Lisp_Object Qimagemagick;
+Lisp_Object Vimagemagick_render_type;
+
+/* Indices of image specification fields in imagemagick_format, below.  */
+
+enum imagemagick_keyword_index
+  {
+    IMAGEMAGICK_TYPE,
+    IMAGEMAGICK_DATA,
+    IMAGEMAGICK_FILE,
+    IMAGEMAGICK_ASCENT,
+    IMAGEMAGICK_MARGIN,
+    IMAGEMAGICK_RELIEF,
+    IMAGEMAGICK_ALGORITHM,
+    IMAGEMAGICK_HEURISTIC_MASK,
+    IMAGEMAGICK_MASK,
+    IMAGEMAGICK_BACKGROUND,
+    IMAGEMAGICK_HEIGHT,
+    IMAGEMAGICK_WIDTH,
+    IMAGEMAGICK_ROTATION,
+    IMAGEMAGICK_CROP,
+    IMAGEMAGICK_LAST
+  };
+
+/* Vector of image_keyword structures describing the format
+   of valid user-defined image specifications.  */
+
+static struct image_keyword imagemagick_format[IMAGEMAGICK_LAST] =
+  {
+    {":type",		IMAGE_SYMBOL_VALUE,			1},
+    {":data",		IMAGE_STRING_VALUE,			0},
+    {":file",		IMAGE_STRING_VALUE,			0},
+    {":ascent",		IMAGE_ASCENT_VALUE,			0},
+    {":margin",		IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR,	0},
+    {":relief",		IMAGE_INTEGER_VALUE,			0},
+    {":conversion",	IMAGE_DONT_CHECK_VALUE_TYPE,		0},
+    {":heuristic-mask",	IMAGE_DONT_CHECK_VALUE_TYPE,		0},
+    {":mask",		IMAGE_DONT_CHECK_VALUE_TYPE,		0},
+    {":background",	IMAGE_STRING_OR_NIL_VALUE,		0},
+    {":height",		IMAGE_INTEGER_VALUE,			0},    
+    {":width",		IMAGE_INTEGER_VALUE,			0},    
+    {":rotation",	IMAGE_NUMBER_VALUE,     		0},    
+    {":crop",		IMAGE_DONT_CHECK_VALUE_TYPE,		0}
+  };
+/* Free X resources of imagemagick image IMG which is used on frame F.  */
+
+static void
+imagemagick_clear_image (struct frame *f,
+                         struct image *img)
+{
+  printf("clearing imagemagick image\n");
+  x_clear_image (f, img);
+}
+
+
+
+/* Return non-zero if OBJECT is a valid IMAGEMAGICK image specification.  Do
+   this by calling parse_image_spec and supplying the keywords that
+   identify the IMAGEMAGICK format.   */
+
+static int
+imagemagick_image_p (Lisp_Object object)
+{
+  struct image_keyword fmt[IMAGEMAGICK_LAST];
+  bcopy (imagemagick_format, fmt, sizeof fmt);
+
+  if (!parse_image_spec (object, fmt, IMAGEMAGICK_LAST, Qimagemagick))
+    return 0;
+
+  /* Must specify either the :data or :file keyword.  */
+  return fmt[IMAGEMAGICK_FILE].count + fmt[IMAGEMAGICK_DATA].count == 1;
+}
+
+/* The GIF library also defines DrawRectangle, but its never used in Emacs.
+   Therefore rename the function so it doesnt collide with ImageMagick.  */
+#define DrawRectangle DrawRectangleGif
+#include <wand/MagickWand.h>
+
+/* imagemagick_load_image is a helper function for imagemagick_load,
+   which does the actual loading given contents and size, apart from
+   frame and image structures, passed from imagemagick_load.
+
+   Uses librimagemagick to do most of the image processing.
+
+   non-zero when successful.
+*/
+
+static int
+imagemagick_load_image (/* Pointer to emacs frame structure.  */
+                        struct frame *f,
+                        /* Pointer to emacs image structure.  */
+                        struct image *img, 
+                        /* String containing the IMAGEMAGICK data to
+                           be parsed.  */
+                        unsigned char *contents,
+                        /* Size of data in bytes.  */
+                        unsigned int size,
+                        /* Filename, either pass filename or
+                           contents/size.  */
+                        unsigned char *filename)
+{
+  size_t width;
+  size_t height;
+
+  MagickBooleanType
+    status;
+
+  XImagePtr ximg;
+  Lisp_Object specified_bg;
+  XColor background;
+  int x;
+  int y;
+
+  MagickWand  *image_wand;
+  MagickWand  *ping_wand;  
+  PixelIterator *iterator;
+  PixelWand  **pixels;
+  MagickPixelPacket  pixel;
+  Lisp_Object image;
+  Lisp_Object value;  
+  Lisp_Object crop, geometry;
+  long ino;
+  int desired_width, desired_height;
+  double rotation;
+  int imagemagick_rendermethod;
+  int pixelwidth; 
+  ImageInfo  *image_info;
+  ExceptionInfo *exception;
+  Image * im_image;
+
+  
+  /* Handle image index for image types who can contain more than one
+     image.  Interface :index is same as for GIF.  First we "ping" the
+     image to see how many sub-images it contains. Pinging is faster
+     than loading the image to find out things about it.  */
+  printf("im ping file %s\n", filename);
+  image = image_spec_value (img->spec, QCindex, NULL);
+  ino = INTEGERP (image) ? XFASTINT (image) : 0;
+  ping_wand=NewMagickWand();
+  MagickSetResolution(ping_wand, 2, 2);
+  if (filename != NULL)
+    {
+      status = MagickPingImage(ping_wand, filename);
+    }
+  else
+    {
+      status = MagickPingImageBlob(ping_wand, contents, size);
+    }
+  
+  if (ino >= MagickGetNumberImages(ping_wand)) 
+    { 
+      image_error ("Invalid image number `%s' in image `%s'", 
+         	   image, img->spec); 
+      UNGCPRO; 
+      return 0; 
+    } 
+
+  if (MagickGetNumberImages(ping_wand) > 1)
+    img->data.lisp_val =
+      Fcons (Qcount,
+             Fcons (make_number (MagickGetNumberImages(ping_wand)),
+                    img->data.lisp_val));
+
+  DestroyMagickWand (ping_wand);
+  /* Now, after pinging, we know how many images are inside the
+     file. If its not a bundle, just one.  */
+
+  if (filename != NULL)
+    {
+      printf("im read file %s\n", filename);
+      image_info=CloneImageInfo((ImageInfo *) NULL);
+      (void) strcpy(image_info->filename, filename);
+      image_info -> number_scenes = 1;
+      image_info -> scene = ino;
+      exception=AcquireExceptionInfo();
+
+      im_image = ReadImage (image_info, exception); 
+      CatchException(exception);
+
+      printf("im wand from image\n");   
+      image_wand = NewMagickWandFromImage(im_image);
+    }
+  else
+    {
+      image_wand = NewMagickWand();  
+      status = MagickReadImageBlob(image_wand, contents, size);
+    }
+  image_error ("im read failed", Qnil, Qnil);
+  if (status == MagickFalse) goto imagemagick_error;
+
+  /* If width and/or height is set in the display spec assume we want
+     to scale to those values.  if either h or w is unspecified, the
+     unspecified should be calculated from the specified to preserve
+     aspect ratio.  */
+
+  value = image_spec_value (img->spec, QCwidth, NULL);
+  desired_width = (INTEGERP (value)  ? XFASTINT (value) : -1);
+  value = image_spec_value (img->spec, QCheight, NULL);
+  desired_height = (INTEGERP (value) ? XFASTINT (value) : -1);
+
+  height = MagickGetImageHeight (image_wand);
+  width = MagickGetImageWidth (image_wand);
+
+  if(desired_width != -1 && desired_height == -1)
+    {
+      /* w known, calculate h.  */
+      desired_height = ( (double)desired_width / width  ) * height;
+    }
+  if(desired_width == -1 && desired_height != -1)
+    {
+      /* h known, calculate w.  */
+      desired_width = ( (double)desired_height / height  ) * width;
+    }  
+  if(desired_width != -1 && desired_height != -1)
+    {
+      printf("MagickScaleImage %d %d\n", desired_width, desired_height);
+      status = MagickScaleImage(image_wand, desired_width, desired_height);
+      if (status == MagickFalse) {
+        image_error ("Imagemagick scale failed", Qnil, Qnil);
+        goto imagemagick_error;
+      }
+    }
+
+
+  /* crop behaves similar to image slicing in Emacs but is more memory
+     efficient */
+  crop     = image_spec_value (img->spec, QCcrop, NULL);
+  
+  if(CONSP (crop))
+    {
+      /* 
+         after some testing, it seems MagickCropImage is the fastest
+         crop function in ImageMagick. This crop function seems to do
+         less copying than the alternatives, but it still reads the
+         entire image into memory before croping, which is aparently
+         difficult to avoid when using imagemagick. */
+      
+      int w,h,x,y;
+      w=XFASTINT(XCAR(crop));
+      h=XFASTINT(XCAR(XCDR(crop)));
+      x=XFASTINT(XCAR(XCDR(XCDR(crop))));
+      y=XFASTINT(XCAR(XCDR(XCDR(XCDR(crop)))));
+      printf("MagickCropImage(image_wand, %d,%d, %d,%d)\n", w, h, x, y);
+      MagickCropImage(image_wand, w,h, x,y);
+    }
+  
+  /* Furthermore :rotation. we need background color and angle for
+     rotation.  */
+  /*
+    TODO background handling for rotation specified_bg =
+    image_spec_value (img->spec, QCbackground, NULL); if (!STRINGP
+    (specified_bg).  */
+  value = image_spec_value (img->spec, QCrotation, NULL);
+  if (FLOATP (value))
+    {
+      PixelWand* background = NewPixelWand();
+      PixelSetColor (background, "#ffffff");/*TODO remove hardcode*/
+        
+      rotation = extract_float (value);
+      printf ("MagickRotateImage %f\n", rotation);
+        
+      status = MagickRotateImage (image_wand, background, rotation);
+      DestroyPixelWand (background);
+      if (status == MagickFalse)
+        {
+          image_error ("Imagemagick image rotate failed", Qnil, Qnil);
+          goto imagemagick_error;
+        }
+    }
+  
+  /* Finaly we are done manipulating the image, figure out resulting
+     width, height, and then transfer ownerwship to Emacs.  */
+  height = MagickGetImageHeight (image_wand);
+  width = MagickGetImageWidth (image_wand);
+  if (status == MagickFalse)
+    {
+      image_error ("Imagemagick image get size failed", Qnil, Qnil);  
+      goto imagemagick_error;
+    }
+    
+  if (! check_image_size (f, width, height))
+    {
+      image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil);
+      goto imagemagick_error;
+    }
+  
+  /* We can now get a valid pixel buffer from the imagemagick file, if all
+     went ok.  */
+
+  init_color_table ();
+  imagemagick_rendermethod = (INTEGERP (Vimagemagick_render_type)
+                              ? XFASTINT (Vimagemagick_render_type) : 0);
+  if (imagemagick_rendermethod == 0)
+    {
+      /* Try to create a x pixmap to hold the imagemagick pixmap.  */
+      if (!x_create_x_image_and_pixmap (f, width, height, 0,
+                                        &ximg, &img->pixmap))
+        {
+          image_error("Imagemagick X bitmap allocation failure", Qnil, Qnil);
+          goto imagemagick_error;
+        }
+    
+      /* Copy imagegmagick image to x with primitive yet robust pixel
+         pusher loop.  This has been tested a lot with many different
+         images.  */
+  
+      /* Copy pixels from the imagemagick image structure to the x image map. */
+      iterator = NewPixelIterator (image_wand);
+      if ((iterator == (PixelIterator *) NULL))
+        {
+          image_error ("Imagemagick pixel iterator creation failed",
+                       Qnil, Qnil);
+          goto imagemagick_error;
+        }
+
+      for (y = 0; y < (long) MagickGetImageHeight(image_wand); y++)
+        {
+          pixels = PixelGetNextIteratorRow (iterator, &width);
+          if ((pixels == (PixelWand **) NULL))
+            break;
+          for (x = 0; x < (long) width; x++)
+            {
+              PixelGetMagickColor (pixels[x], &pixel);
+              XPutPixel (ximg, x, y,
+                         lookup_rgb_color (f,
+                                           pixel.red,
+                                           pixel.green,
+                                           pixel.blue));
+            }
+        }
+      DestroyPixelIterator (iterator);
+    }
+
+  if (imagemagick_rendermethod == 1)
+    {
+      /* Magicexportimage is normaly faster than pixelpushing.  This
+         method is also well tested. Some aspects of this method are
+         ad-hoc and needs to be more researched. */
+      int imagedepth = 24;/*MagickGetImageDepth(image_wand);*/
+      char* exportdepth = imagedepth <= 8 ? "I" : "BGRP";/*"RGBP";*/
+      /* Try to create a x pixmap to hold the imagemagick pixmap.  */
+      printf("imagedepth:%d exportdepth:%s\n", imagedepth, exportdepth);
+      if (!x_create_x_image_and_pixmap (f, width, height, imagedepth,
+                                        &ximg, &img->pixmap)){
+        image_error("Imagemagick X bitmap allocation failure", Qnil, Qnil);
+        goto imagemagick_error;
+      }
+
+    
+      /* Oddly, the below code doesnt seem to work:*/
+      /* switch(ximg->bitmap_unit){ */
+      /* case 8: */
+      /*   pixelwidth=CharPixel; */
+      /*   break; */
+      /* case   16: */
+      /*   pixelwidth=ShortPixel; */
+      /*   break; */
+      /* case   32: */
+      /*   pixelwidth=LongPixel; */
+      /*   break; */
+      /* } */
+      /*
+        Here im just guessing the format of the bitmap.
+        happens to work fine for:
+        - bw djvu images
+        on rgb display.
+        seems about 3 times as fast as pixel pushing(not carefully measured)
+      */
+      pixelwidth = CharPixel;/*??? TODO figure out*/
+#ifdef HAVE_MAGICKEXPORTIMAGEPIXELS    
+      MagickExportImagePixels(image_wand,
+                              0, 0,
+                              width, height,
+                              exportdepth,
+                              pixelwidth, 
+                              /*&(img->pixmap));*/
+                              ximg->data);
+#else
+      image_error("You dont have MagickExportImagePixels, upgrade ImageMagick!",
+                  Qnil, Qnil);
+#endif    
+    }
+  
+
+#ifdef COLOR_TABLE_SUPPORT
+  /* Remember colors allocated for this image.  */
+  img->colors = colors_in_color_table (&img->ncolors);
+  free_color_table ();
+#endif /* COLOR_TABLE_SUPPORT */
+
+
+  img->width  = width;
+  img->height = height;
+
+  /* Put the image into the pixmap, then free the X image and its
+     buffer.  */
+  x_put_x_image (f, ximg, img->pixmap, width, height);
+  x_destroy_x_image (ximg);
+
+
+  /* Final cleanup. image_wand should be the only resource left. */
+  DestroyMagickWand (image_wand);
+
+  return 1;
+
+ imagemagick_error:
+  /* TODO more cleanup.  */
+  image_error ("Error parsing IMAGEMAGICK image `%s'", img->spec, Qnil);
+  printf("Imagemagick error, see *Messages*\n");
+  return 0;
+}
+
+
+/* Load IMAGEMAGICK image IMG for use on frame F.  Value is non-zero if
+   successful. this function will go into the imagemagick_type structure, and
+   the prototype thus needs to be compatible with that structure.  */
+
+static int
+imagemagick_load (struct frame *f,
+                  struct image *img)
+{
+  int success_p = 0;
+  Lisp_Object file_name;
+
+  /* If IMG->spec specifies a file name, create a non-file spec from it.  */
+  file_name = image_spec_value (img->spec, QCfile, NULL);
+  if (STRINGP (file_name))
+    {
+      Lisp_Object file;
+      unsigned char *contents;
+      int size;
+      struct gcpro gcpro1;
+
+      file = x_find_image_file (file_name);
+      GCPRO1 (file);
+      if (!STRINGP (file))
+	{
+	  image_error ("Cannot find image file `%s'", file_name, Qnil);
+	  UNGCPRO;
+	  return 0;
+	}
+      success_p = imagemagick_load_image (f, img, 0, 0, SDATA(file_name));
+      UNGCPRO;
+    }
+  /* Else its not a file, its a lisp object.  Load the image from a
+     lisp object rather than a file.  */
+  else
+    {
+      Lisp_Object data;
+
+      data = image_spec_value (img->spec, QCdata, NULL);
+      success_p = imagemagick_load_image (f, img, SDATA (data),
+                                          SBYTES (data), NULL);
+    }
+
+  return success_p;
+}
+
+/* Structure describing the image type `imagemagick'.  Its the same
+   type of structure defined for all image formats, handled by Emacs
+   image functions.  See struct image_type in dispextern.h.  */
+
+static struct image_type imagemagick_type =
+  {
+    /* An identifier showing that this is an image structure for the
+       IMAGEMAGICK format.  */
+    &Qimagemagick,
+    /* Handle to a function that can be used to identify a IMAGEMAGICK
+       file.  */
+    imagemagick_image_p,
+    /* Handle to function used to load a IMAGEMAGICK file.  */
+    imagemagick_load,
+    /* Handle to function to free resources for IMAGEMAGICK.  */
+    imagemagick_clear_image,
+    /* An internal field to link to the next image type in a list of
+       image types, will be filled in when registering the format.  */
+    NULL
+  };
+
+
+
+
+DEFUN ("imagemagick-types", Fimagemagick_types, Simagemagick_types, 0, 0, 0, 
+       doc: /* Return image file types supported by ImageMagick.
+               Since ImageMagick recognizes a lot of file-types that clash with Emacs,
+               such as .c, we want to be able to alter the list at the lisp level.  */)
+  (void)
+{
+  Lisp_Object typelist = Qnil;
+  size_t numf;
+  ExceptionInfo ex;
+  char** imtypes = GetMagickList ("*", &numf, &ex);
+  int i;
+  Lisp_Object Qimagemagicktype;
+  for (i = 0; i < numf; i++)
+    {
+      Qimagemagicktype = intern (imtypes[i]);
+      typelist = Fcons (Qimagemagicktype, typelist);
+    }
+  return typelist;
+}
+  
+#endif	/* defined (HAVE_IMAGEMAGICK) */
+
+
 
 /***********************************************************************
 				 SVG
@@ -8117,6 +8630,15 @@
     return CHECK_LIB_AVAILABLE (&svg_type, init_svg_functions, libraries);
 #endif
 
+#if defined (HAVE_IMAGEMAGICK)
+  if (EQ (type, Qimagemagick)){
+    /* MagickWandGenesis() initalizes the imagemagick library.  */
+    MagickWandGenesis(); 
+    return CHECK_LIB_AVAILABLE (&imagemagick_type, init_imagemagick_functions,
+                                libraries);
+  }
+#endif
+
 #ifdef HAVE_GHOSTSCRIPT
   if (EQ (type, Qpostscript))
     return CHECK_LIB_AVAILABLE (&gs_type, init_gs_functions, libraries);
@@ -8202,6 +8724,12 @@
   staticpro (&QCheuristic_mask);
   QCindex = intern_c_string (":index");
   staticpro (&QCindex);
+  QCgeometry = intern (":geometry");
+  staticpro (&QCgeometry);
+  QCcrop = intern (":crop");
+  staticpro (&QCcrop);
+  QCrotation = intern (":rotation");
+  staticpro (&QCrotation);
   QCmatrix = intern_c_string (":matrix");
   staticpro (&QCmatrix);
   QCcolor_adjustment = intern_c_string (":color-adjustment");
@@ -8262,6 +8790,12 @@
   ADD_IMAGE_TYPE (Qpng);
 #endif
 
+#if defined (HAVE_IMAGEMAGICK)
+  Qimagemagick = intern ("imagemagick");
+  staticpro (&Qimagemagick);
+  ADD_IMAGE_TYPE (Qimagemagick);
+#endif
+  
 #if defined (HAVE_RSVG)
   Qsvg = intern_c_string ("svg");
   staticpro (&Qsvg);
@@ -8278,6 +8812,9 @@
 #endif /* HAVE_RSVG  */
 
   defsubr (&Sinit_image_library);
+#ifdef HAVE_IMAGEMAGICK  
+  defsubr (&Simagemagick_types);
+#endif  
   defsubr (&Sclear_image_cache);
   defsubr (&Simage_flush);
   defsubr (&Simage_size);
@@ -8308,6 +8845,11 @@
 
 The function `clear-image-cache' disregards this variable.  */);
   Vimage_cache_eviction_delay = make_number (300);
+#ifdef HAVE_IMAGEMAGICK  
+  DEFVAR_LISP ("imagemagick-render-type", &Vimagemagick_render_type,
+               doc: /* Choose between ImageMagick render methods.  */);
+#endif    
+
 }
 
 void
--- a/src/nsselect.m	Thu Aug 19 00:35:46 2010 +0000
+++ b/src/nsselect.m	Thu Aug 19 22:47:51 2010 +0000
@@ -542,8 +542,8 @@
 void
 nxatoms_of_nsselect (void)
 {
-  NXPrimaryPboard = @"PrimarySelection";
-  NXSecondaryPboard = @"SecondarySelection";
+  NXPrimaryPboard = @"Selection";
+  NXSecondaryPboard = @"Secondary";
 }
 
 void
--- a/src/w32fns.c	Thu Aug 19 00:35:46 2010 +0000
+++ b/src/w32fns.c	Thu Aug 19 22:47:51 2010 +0000
@@ -3109,9 +3109,6 @@
 	  HIMC context;
 	  struct window *w;
 
-	  if (!context)
-	    break;
-
 	  f = x_window_to_frame (dpyinfo, hwnd);
 	  w = XWINDOW (FRAME_SELECTED_WINDOW (f));
 
@@ -3129,6 +3126,10 @@
 				- WINDOW_MODE_LINE_HEIGHT (w));
 
 	  context = get_ime_context_fn (hwnd);
+
+	  if (!context)
+	    break;
+
 	  set_ime_composition_window_fn (context, &form);
 	  release_ime_context_fn (hwnd, context);
 	}
--- a/src/w32menu.c	Thu Aug 19 00:35:46 2010 +0000
+++ b/src/w32menu.c	Thu Aug 19 22:47:51 2010 +0000
@@ -420,12 +420,8 @@
 
       set_buffer_internal_1 (XBUFFER (buffer));
 
-      /* Run the Lucid hook.  */
+      /* Run the hooks.  */
       safe_run_hooks (Qactivate_menubar_hook);
-      /* If it has changed current-menubar from previous value,
-	 really recompute the menubar from the value.  */
-      if (! NILP (Vlucid_menu_bar_dirty_flag))
-	call0 (Qrecompute_lucid_menubar);
       safe_run_hooks (Qmenu_bar_update_hook);
       FRAME_MENU_BAR_ITEMS (f) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f));