emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: display word wrapping


From: Juanma Barranquero
Subject: Re: display word wrapping
Date: Fri, 04 Jun 2004 03:39:04 +0200

OK, there goes the complete patch (minus docs, which I'll write when the
issue is ready to commit) implementing all your proposed changes.

It works really well.  The only thing that I would add is calling
`init-image-libraries' from startup, just after loading .emacs.el.  The
reason is that, without this, image-types contains on startup just xbm
and pbm, because the other libraries haven't been yet loaded (unless the
user calls init-image-libraries explicitly on his .emacs.el), even if
image-library-alist is correctly set up and the DLLs are available.

> > It's already implemented.  With my current patch (not included) you can
> > change image-library-alist and call init-image-libraries and it only
> > loads (and adds to Vimage_types, etc.) the newly loaded libraries (if
> > any).
> 
> Good.

In my patch, both w32_dynaload and define_image_type check whether the
image type is already supported (the check in define_image_type is not
strictly necessary, but I prefer to be safe). They do that by searching
on Vimage_types, so the user could "cheat" by modifying this variable,
in which case it'd be posible to force a reload.  I consider this a
clear "Don't Do That" situation: if the user really insists, he gets
what he asked for.

> Because we prefer to define things in Lisp whenever possible.

OK. `image-library-alist' is now defined in lisp/image.el.  Its value is
initializated on term/w32-win.el; other ports wanting to support dynamic
loading of image libraries should do the same in their respective
term/*.el files.

> IMHO, using an explicit parameter is cleaner than an implicit global variable.

I agree, of course, except in cases where the parameter has to be
shoe-horned into already chock-full arglists.  Fortunately this is not
the case (just the init_xxx_functions and w32_dynaload need to be
changed).

Last question (for now). As init-image-libraries needs to return
something, I've done it return Vimage_types instead of Qnil, so the
caller can see at once whether the list of supported image types has
changed. If OK'ed, I'll add this tiny bit of info to the function's
docstring.

                                                           /L/e/k/t/u



Index: lisp/image.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/image.el,v
retrieving revision 1.40
diff -u -2 -r1.40 image.el
--- lisp/image.el       26 Apr 2004 22:11:36 -0000      1.40
+++ lisp/image.el       4 Jun 2004 00:37:28 -0000
@@ -49,4 +49,17 @@
 a non-nil value, TYPE is the image's type.")
 
+;;;###autoload
+(defvar image-library-alist nil
+  "Alist of image-types vs external libraries needed to display them.
+
+Each element is a list (IMAGE-TYPE LIBRARY...), where the car is a symbol
+representing a supported image type, and the rest are strings giving
+alternate filenames for the corresponding external libraries to load.
+They are tried in the order they appear on the list; if none of them can
+be loaded, the running session of Emacs won't display the image type.
+No entries are needed for pbm and xbm images; they're always supported.
+
+This variable is reset to nil each time its entries are processed.")
+;;;###autoload (put 'image-library-alist 'risky-local-variable t)
 
 (defun image-jpeg-p (data)
@@ -112,6 +125,8 @@
   "Value is non-nil if image type TYPE is available.
 Image types are symbols like `xbm' or `jpeg'."
+  (when image-library-alist
+    (init-image-libraries image-library-alist)
+    (setq image-library-alist nil))
   (and (boundp 'image-types) (not (null (memq type image-types)))))
-
 
 ;;;###autoload
Index: lisp/term/w32-win.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/term/w32-win.el,v
retrieving revision 1.62
diff -u -2 -r1.62 w32-win.el
--- lisp/term/w32-win.el        9 May 2004 15:01:17 -0000       1.62
+++ lisp/term/w32-win.el        4 Jun 2004 00:15:48 -0000
@@ -1,5 +1,5 @@
 ;;; w32-win.el --- parse switches controlling interface with W32 window system
 
-;; Copyright (C) 1993, 1994, 2003 Free Software Foundation, Inc.
+;; Copyright (C) 1993, 1994, 2003, 2004 Free Software Foundation, Inc.
 
 ;; Author: Kevin Gallo
@@ -1261,4 +1261,12 @@
        (if (null font)
            (error "Font not found")))))
+
+;;; Set default known names for image libraries
+(setq image-library-alist
+      '((xpm "libXpm-nox4.dll" "libxpm.dll")
+        (png "libpng13d.dll" "libpng13.dll" "libpng12d.dll" "libpng12.dll" 
"libpng.dll")
+        (jpeg "jpeg62.dll" "libjpeg.dll" "jpeg-62.dll" "jpeg.dll")
+        (tiff "libtiff3.dll" "libtiff.dll")
+        (gif "libungif.dll")))
 
 ;;; arch-tag: 69fb1701-28c2-4890-b351-3d1fe4b4f166
Index: src/image.c
===================================================================
RCS file: /cvsroot/emacs/emacs/src/image.c,v
retrieving revision 1.12
diff -u -2 -r1.12 image.c
--- src/image.c 2 Jun 2004 00:50:09 -0000       1.12
+++ src/image.c 4 Jun 2004 01:09:36 -0000
@@ -646,11 +646,15 @@
      struct image_type *type;
 {
-  /* Make a copy of TYPE to avoid a bus error in a dumped Emacs.
-     The initialized data segment is read-only.  */
-  struct image_type *p = (struct image_type *) xmalloc (sizeof *p);
-  bcopy (type, p, sizeof *p);
-  p->next = image_types;
-  image_types = p;
-  Vimage_types = Fcons (*p->type, Vimage_types);
+  /* Protect against accidental redefinion.  */
+  if (NILP (Fmemq (*type->type, Vimage_types)))
+    {
+      /* Make a copy of TYPE to avoid a bus error in a dumped Emacs.
+         The initialized data segment is read-only.  */
+      struct image_type *p = (struct image_type *) xmalloc (sizeof *p);
+      bcopy (type, p, sizeof *p);
+      p->next = image_types;
+      image_types = p;
+      Vimage_types = Fcons (*p->type, Vimage_types);
+    }
 }
 
@@ -1789,4 +1793,34 @@
   }
 
+/* Load a DLL implementing an image type.
+   The `image-library-alist' variable associates a symbol,
+   identifying  an image type, to a list of possible filenames.
+   The function returns NULL if no library could be loaded for
+   the given image type, or if the library was previously loaded;
+   else the handle of the DLL.  */
+static HMODULE
+w32_dynaload (Lisp_Object libraries, Lisp_Object library_id)
+{
+  HMODULE library = NULL;
+
+  if (NILP (Fmemq (library_id, Vimage_types)))
+    {
+      Lisp_Object dlls = Fassq (library_id, libraries);
+
+      if (CONSP (dlls))
+        for (dlls = XCDR (dlls); !NILP (dlls); dlls = XCDR (dlls))
+          {
+            Lisp_Object lib = XCAR (dlls);
+
+            if (!STRINGP (lib))
+              error ("Invalid entry in library alist");
+            else if (library = LoadLibrary (SDATA (lib)))
+              break;
+          }
+    }
+
+  return library;
+}
+
 #endif /* HAVE_NTGUI */
 
@@ -3489,11 +3522,10 @@
 DEF_IMGLIB_FN (XImageFree);
 
-
 static int
-init_xpm_functions (void)
+init_xpm_functions (Lisp_Object libraries)
 {
   HMODULE library;
 
-  if (!(library = LoadLibrary ("libXpm.dll")))
+  if (!(library = w32_dynaload (libraries, Qxpm)))
     return 0;
 
@@ -5589,19 +5621,10 @@
 
 static int
-init_png_functions (void)
+init_png_functions (Lisp_Object libraries)
 {
   HMODULE library;
 
-  /* Ensure zlib is loaded.  Try debug version first.  */
-  if (!LoadLibrary ("zlibd.dll")
-      && !LoadLibrary ("zlib.dll"))
-    return 0;
-
   /* Try loading libpng under probable names.  */
-  if (!(library = LoadLibrary ("libpng13d.dll"))
-      && !(library = LoadLibrary ("libpng13.dll"))
-      && !(library = LoadLibrary ("libpng12d.dll"))
-      && !(library = LoadLibrary ("libpng12.dll"))
-      && !(library = LoadLibrary ("libpng.dll")))
+  if (!(library = w32_dynaload (libraries, Qpng)))
     return 0;
 
@@ -6247,11 +6270,9 @@
 
 static int
-init_jpeg_functions (void)
+init_jpeg_functions (Lisp_Object libraries)
 {
   HMODULE library;
 
-  if (!(library = LoadLibrary ("libjpeg.dll"))
-      && !(library = LoadLibrary ("jpeg-62.dll"))
-      && !(library = LoadLibrary ("jpeg.dll")))
+  if (!(library = w32_dynaload (libraries, Qjpeg)))
     return 0;
 
@@ -6684,9 +6705,9 @@
 
 static int
-init_tiff_functions (void)
+init_tiff_functions (Lisp_Object libraries)
 {
   HMODULE library;
 
-  if (!(library = LoadLibrary ("libtiff.dll")))
+  if (!(library = w32_dynaload (libraries, Qtiff)))
     return 0;
 
@@ -7104,9 +7125,9 @@
 
 static int
-init_gif_functions (void)
+init_gif_functions (Lisp_Object libraries)
 {
   HMODULE library;
 
-  if (!(library = LoadLibrary ("libungif.dll")))
+  if (!(library = w32_dynaload (libraries, Qgif)))
     return 0;
 
@@ -7881,4 +7902,59 @@
  ***********************************************************************/
 
+#ifdef HAVE_NTGUI
+/* Image types that rely on external libraries are loaded dynamically
+   if the library is available.  */
+#define IF_LIB_AVAILABLE(init_lib_fn)  if (init_lib_fn (libraries))
+#else
+#define IF_LIB_AVAILABLE(init_func)    /* Load unconditionally */
+#endif /* HAVE_NTGUI */
+
+DEFUN ("init-image-libraries", Finit_image_libraries, Sinit_image_libraries, 
1, 1, 0,
+       doc: /* Initialize image libraries.
+Image types pbm and xbm are prebuilt; other types are loaded here.
+Which libraries are loaded depends on LIBRARIES (usually, the value
+of `image-library-alist'.  */)
+     (libraries)
+{
+#if defined (HAVE_XPM) || defined (MAC_OS)
+  IF_LIB_AVAILABLE(init_xpm_functions)
+    define_image_type (&xpm_type);
+#endif
+
+#if defined (HAVE_JPEG) || defined (MAC_OS)
+  IF_LIB_AVAILABLE(init_jpeg_functions)
+    define_image_type (&jpeg_type);
+#endif
+
+#if defined (HAVE_TIFF) || defined (MAC_OS)
+  IF_LIB_AVAILABLE(init_tiff_functions)
+    define_image_type (&tiff_type);
+#endif
+
+#if defined (HAVE_GIF) || defined (MAC_OS)
+  IF_LIB_AVAILABLE(init_gif_functions)
+    define_image_type (&gif_type);
+#endif
+
+#if defined (HAVE_PNG) || defined (MAC_OS)
+  IF_LIB_AVAILABLE(init_png_functions)
+    define_image_type (&png_type);
+#endif
+
+#ifdef HAVE_GHOSTSCRIPT
+  define_image_type (&gs_type);
+#endif
+
+#ifdef MAC_OS
+  /* Animated gifs use QuickTime Movie Toolbox.  So initialize it here. */
+  EnterMovies ();
+#ifdef MAC_OSX
+  init_image_func_pointer ();
+#endif
+#endif
+
+  return Vimage_types;
+}
+
 void
 syms_of_image ()
@@ -7958,4 +8034,5 @@
 #endif
 
+  defsubr (&Sinit_image_libraries);
   defsubr (&Sclear_image_cache);
   defsubr (&Simage_size);
@@ -7985,13 +8062,4 @@
 }
 
-
-#ifdef HAVE_NTGUI
-/* Image types that rely on external libraries are loaded dynamically
-   if the library is available.  */
-#define IF_LIB_AVAILABLE(init_lib_fn)  if (init_lib_fn())
-#else
-#define IF_LIB_AVAILABLE(init_func)    /* Load unconditionally */
-#endif /* HAVE_NTGUI */
-
 void
 init_image ()
@@ -8002,41 +8070,4 @@
   define_image_type (&xbm_type);
   define_image_type (&pbm_type);
-
-#if defined (HAVE_XPM) || defined (MAC_OS)
-  IF_LIB_AVAILABLE(init_xpm_functions)
-    define_image_type (&xpm_type);
-#endif
-
-#if defined (HAVE_JPEG) || defined (MAC_OS)
-  IF_LIB_AVAILABLE(init_jpeg_functions)
-    define_image_type (&jpeg_type);
-#endif
-
-#if defined (HAVE_TIFF) || defined (MAC_OS)
-  IF_LIB_AVAILABLE(init_tiff_functions)
-    define_image_type (&tiff_type);
-#endif
-
-#if defined (HAVE_GIF) || defined (MAC_OS)
-  IF_LIB_AVAILABLE(init_gif_functions)
-    define_image_type (&gif_type);
-#endif
-
-#if defined (HAVE_PNG) || defined (MAC_OS)
-  IF_LIB_AVAILABLE(init_png_functions)
-    define_image_type (&png_type);
-#endif
-
-#ifdef HAVE_GHOSTSCRIPT
-  define_image_type (&gs_type);
-#endif
-
-#ifdef MAC_OS
-  /* Animated gifs use QuickTime Movie Toolbox.  So initialize it here. */
-  EnterMovies ();
-#ifdef MAC_OSX
-  init_image_func_pointer ();
-#endif
-#endif
 }
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]