* mml2015.el (mml2015-epg-sign): Ask user whether to skip or abort if
[gnus] / lisp / gmm-utils.el
index ad05ffb..18b1a52 100644 (file)
 
 ;;; Code:
 
+(require 'wid-edit)
+
 (defgroup gmm nil
   "Utility functions for Gnus, Message and MML"
   :prefix "gmm-"
-  :version "23.0" ;; No Gnus
+  :version "22.1" ;; Gnus 5.10.9
   :group 'lisp)
 
 ;; Helper functions from `gnus-utils.el': gmm-verbose, gmm-message, gmm-error
@@ -201,8 +203,8 @@ This is copy of the `lazy' widget in Emacs 22.1 provided for compatibility."
       'gnome
     'retro)
   "Prefered tool bar style."
-  :type '(choice (const :tag "GNOME style" 'gnome)
-                (const :tag "Retro look"  'retro))
+  :type '(choice (const :tag "GNOME style" gnome)
+                (const :tag "Retro look"  retro))
   :group 'gmm)
 
 (defvar tool-bar-map)
@@ -277,11 +279,7 @@ DEFAULT-MAP specifies the default key map for ICON-LIST."
            icon-list))
     tool-bar-map))
 
-;; WARNING: The following is subject to change.  Don't rely on it yet.
-
-;; From MH-E without modifications:
-
-(defmacro gmm-defun-compat (name function arg-list &rest body)
+(defmacro defun-gmm (name function arg-list &rest body)
   "Create function NAME.
 If FUNCTION exists, then NAME becomes an alias for FUNCTION.
 Otherwise, create function NAME with ARG-LIST and BODY."
@@ -290,24 +288,23 @@ Otherwise, create function NAME with ARG-LIST and BODY."
         `(defalias ',name ',function)
       `(defun ,name ,arg-list ,@body))))
 
-(gmm-defun-compat gmm-image-search-load-path
+(defun-gmm gmm-image-search-load-path
   image-search-load-path (file &optional path)
   "Emacs 21 and XEmacs don't have `image-search-load-path'.
 This function returns nil on those systems."
   nil)
 
-;; From MH-E with modifications:
+;; Cf. `mh-image-load-path-for-library' in `mh-compat.el'.
 
-;; Don't use `gmm-defun-compat' until API changes in
-;; `image-load-path-for-library' in Emacs CVS are completed.
+(defun-gmm gmm-image-load-path-for-library
+  image-load-path-for-library (library image &optional path no-error)
+  "Return a suitable search path for images used by LIBRARY.
 
-(defun gmm-image-load-path-for-library (library image &optional path no-error)
-  "Return a suitable search path for images relative to LIBRARY.
-
-First it searches for IMAGE in a path suitable for LIBRARY, which
-includes \"../../etc/images\" and \"../etc/images\" relative to
-the library file itself, followed by `image-load-path' and
-`load-path'.
+It searches for IMAGE in `image-load-path' (excluding
+\"`data-directory'/images\") and `load-path', followed by a path
+suitable for LIBRARY, which includes \"../../etc/images\" and
+\"../etc/images\" relative to the library file itself, and then
+in \"`data-directory'/images\".
 
 Then this function returns a list of directories which contains
 first the directory in which IMAGE was found, followed by the
@@ -332,8 +329,36 @@ compatibility with versions of Emacs that lack the variable
       (mh-tool-bar-folder-buttons-init))"
   (unless library (error "No library specified"))
   (unless image   (error "No image specified"))
-  (let ((image-directory))
+  (let (image-directory image-directory-load-path)
+    ;; Check for images in image-load-path or load-path.
+    (let ((img image)
+          (dir (or
+                ;; Images in image-load-path.
+                (gmm-image-search-load-path image) ;; "gmm-" prefix!
+                ;; Images in load-path.
+                (locate-library image)))
+          parent)
+      ;; Since the image might be in a nested directory (for
+      ;; example, mail/attach.pbm), adjust `image-directory'
+      ;; accordingly.
+      (when dir
+        (setq dir (file-name-directory dir))
+        (while (setq parent (file-name-directory img))
+          (setq img (directory-file-name parent)
+                dir (expand-file-name "../" dir))))
+      (setq image-directory-load-path dir))
+
+    ;; If `image-directory-load-path' isn't Emacs' image directory,
+    ;; it's probably a user preference, so use it. Then use a
+    ;; relative setting if possible; otherwise, use
+    ;; `image-directory-load-path'.
     (cond
+     ;; User-modified image-load-path?
+     ((and image-directory-load-path
+           (not (equal image-directory-load-path
+                       (file-name-as-directory
+                        (expand-file-name "images" data-directory)))))
+      (setq image-directory image-directory-load-path))
      ;; Try relative setting.
      ((let (library-name d1ei d2ei)
         ;; First, find library in the load-path.
@@ -343,33 +368,20 @@ compatibility with versions of Emacs that lack the variable
         ;; And then set image-directory relative to that.
         (setq
          ;; Go down 2 levels.
-         d2ei (expand-file-name
-               (concat (file-name-directory library-name) "../../etc/images"))
+         d2ei (file-name-as-directory
+               (expand-file-name
+                (concat (file-name-directory library-name) "../../etc/images")))
          ;; Go down 1 level.
-         d1ei (expand-file-name
-               (concat (file-name-directory library-name) "../etc/images")))
+         d1ei (file-name-as-directory
+               (expand-file-name
+                (concat (file-name-directory library-name) "../etc/images"))))
         (setq image-directory
               ;; Set it to nil if image is not found.
               (cond ((file-exists-p (expand-file-name image d2ei)) d2ei)
                     ((file-exists-p (expand-file-name image d1ei)) d1ei)))))
-     ;; Check for images in image-load-path or load-path.
-     ((let ((img image)
-            (dir (or
-                  ;; Images in image-load-path.
-                  (gmm-image-search-load-path image) ;; "gmm-" prefix!
-                  ;; Images in load-path.
-                  (locate-library image)))
-            parent)
-        ;; Since the image might be in a nested directory (for
-        ;; example, mail/attach.pbm), adjust `image-directory'
-        ;; accordingly.
-        (and dir
-             (setq dir (file-name-directory dir))
-             (progn
-               (while (setq parent (file-name-directory img))
-                 (setq img (directory-file-name parent)
-                       dir (expand-file-name "../" dir)))
-               (setq image-directory dir)))))
+     ;; Use Emacs' image directory.
+     (image-directory-load-path
+      (setq image-directory image-directory-load-path))
      (no-error
       (message "Could not find image %s for library %s" image library))
      (t
@@ -389,6 +401,21 @@ If mode is nil, use `major-mode' of the curent buffer."
                 (string-match "^\\(.+\\)-mode$" mode)
                 (match-string 1 mode))))))
 
+(defun gmm-write-region (start end filename &optional append visit
+                              lockname mustbenew)
+  "Compatibility function for `write-region'.
+
+In XEmacs, the seventh argument of `write-region' specifies the
+coding-system."
+  (if (and mustbenew
+          (or (featurep 'xemacs)
+              (= emacs-major-version 20)))
+      (if (file-exists-p filename)
+         (signal 'file-already-exists
+                 (list "File exists" filename))
+       (write-region start end filename append visit lockname))
+    (write-region start end filename append visit lockname mustbenew)))
+
 (provide 'gmm-utils)
 
 ;; arch-tag: e0b60920-2ce6-40c1-bfc0-cadbbe26b602