diff options
| author | Bill Wohler | 2006-03-10 22:52:26 +0000 |
|---|---|---|
| committer | Bill Wohler | 2006-03-10 22:52:26 +0000 |
| commit | 7c565097d15d61cef15fe7474da44a2bc9e87725 (patch) | |
| tree | 7ce0e30b0890be673c925f35af6492fcf37a3983 | |
| parent | a2c7d24fafbfb091fc9f74afa1e1c77d51047768 (diff) | |
| download | emacs-7c565097d15d61cef15fe7474da44a2bc9e87725.tar.gz emacs-7c565097d15d61cef15fe7474da44a2bc9e87725.zip | |
(image-load-path-for-library): Merge at least three functions from
Gnus and MH-E into this one function that can now be shared.
| -rw-r--r-- | lisp/ChangeLog | 6 | ||||
| -rw-r--r-- | lisp/image.el | 74 |
2 files changed, 80 insertions, 0 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 000011e2de3..7892a9b6d22 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2006-03-10 Bill Wohler <wohler@newt.com> | ||
| 2 | |||
| 3 | * image.el (image-load-path-for-library): Merge at least three | ||
| 4 | functions from Gnus and MH-E into this one function that can now | ||
| 5 | be shared. | ||
| 6 | |||
| 1 | 2006-03-11 Nick Roberts <nickrob@snap.net.nz> | 7 | 2006-03-11 Nick Roberts <nickrob@snap.net.nz> |
| 2 | 8 | ||
| 3 | * progmodes/gdb-ui.el (gdb-remove-text-properties): Rename from | 9 | * progmodes/gdb-ui.el (gdb-remove-text-properties): Rename from |
diff --git a/lisp/image.el b/lisp/image.el index 316896cabce..4acff8d251b 100644 --- a/lisp/image.el +++ b/lisp/image.el | |||
| @@ -77,6 +77,80 @@ value is used as a list of directories to search.") | |||
| 77 | (list (file-name-as-directory (expand-file-name "images" data-directory)) | 77 | (list (file-name-as-directory (expand-file-name "images" data-directory)) |
| 78 | 'data-directory 'load-path))) | 78 | 'data-directory 'load-path))) |
| 79 | 79 | ||
| 80 | (defun image-load-path-for-library (library image &optional path) | ||
| 81 | "Return a suitable search path for images relative to LIBRARY. | ||
| 82 | |||
| 83 | Images for LIBRARY are searched for in \"../../etc/images\" and | ||
| 84 | \"../etc/images\" relative to the files in \"lisp/LIBRARY\" as | ||
| 85 | well as in `image-load-path' and `load-path'. | ||
| 86 | |||
| 87 | This function returns the value of `load-path' augmented with the | ||
| 88 | path to IMAGE. If PATH is given, it is used instead of | ||
| 89 | `load-path'. | ||
| 90 | |||
| 91 | Here is an example that uses a common idiom to provide | ||
| 92 | compatibility with versions of Emacs that lack the variable | ||
| 93 | `image-load-path': | ||
| 94 | |||
| 95 | (let ((load-path | ||
| 96 | (image-load-path-for-library \"mh-e\" \"mh-logo.xpm\")) | ||
| 97 | (image-load-path | ||
| 98 | (image-load-path-for-library \"mh-e\" \"mh-logo.xpm\" 'image-load-path))) | ||
| 99 | (mh-tool-bar-folder-buttons-init))" | ||
| 100 | (unless library (error "No library specified")) | ||
| 101 | (unless image (error "No image specified")) | ||
| 102 | (let ((image-directory)) | ||
| 103 | (cond | ||
| 104 | ;; Try relative setting. | ||
| 105 | ((let (library-name d1ei d2ei) | ||
| 106 | ;; First, find library in the load-path. | ||
| 107 | (setq library-name (locate-library library)) | ||
| 108 | (if (not library-name) | ||
| 109 | (error "Cannot find library %s in load-path" library)) | ||
| 110 | ;; And then set image-directory relative to that. | ||
| 111 | (setq | ||
| 112 | ;; Go down 2 levels. | ||
| 113 | d2ei (expand-file-name | ||
| 114 | (concat (file-name-directory library-name) "../../etc/images")) | ||
| 115 | ;; Go down 1 level. | ||
| 116 | d1ei (expand-file-name | ||
| 117 | (concat (file-name-directory library-name) "../etc/images"))) | ||
| 118 | (setq image-directory | ||
| 119 | ;; Set it to nil if image is not found. | ||
| 120 | (cond ((file-exists-p (expand-file-name image d2ei)) d2ei) | ||
| 121 | ((file-exists-p (expand-file-name image d1ei)) d1ei))))) | ||
| 122 | ;; Check for images in image-load-path or load-path. | ||
| 123 | ((let ((img image) | ||
| 124 | (dir (or | ||
| 125 | ;; Images in image-load-path. | ||
| 126 | (image-search-load-path image) | ||
| 127 | ;; Images in load-path. | ||
| 128 | (locate-library image))) | ||
| 129 | parent) | ||
| 130 | ;; Since the image might be in a nested directory (for | ||
| 131 | ;; example, mail/attach.pbm), adjust `image-directory' | ||
| 132 | ;; accordingly. | ||
| 133 | (and dir | ||
| 134 | (setq dir (file-name-directory dir)) | ||
| 135 | (progn | ||
| 136 | (while (setq parent (file-name-directory img)) | ||
| 137 | (setq img (directory-file-name parent) | ||
| 138 | dir (expand-file-name "../" dir))) | ||
| 139 | (setq image-directory dir))))) | ||
| 140 | (t | ||
| 141 | (error "Could not find image %s for library %s" image library))) | ||
| 142 | |||
| 143 | ;; Return augmented `image-load-path' or `load-path'. | ||
| 144 | (cond ((and path (symbolp path)) | ||
| 145 | (nconc (list image-directory) | ||
| 146 | (delete image-directory | ||
| 147 | (if (boundp path) | ||
| 148 | (copy-sequence (symbol-value path)) | ||
| 149 | nil)))) | ||
| 150 | (t | ||
| 151 | (nconc (list image-directory) | ||
| 152 | (delete image-directory (copy-sequence load-path))))))) | ||
| 153 | |||
| 80 | (defun image-jpeg-p (data) | 154 | (defun image-jpeg-p (data) |
| 81 | "Value is non-nil if DATA, a string, consists of JFIF image data. | 155 | "Value is non-nil if DATA, a string, consists of JFIF image data. |
| 82 | We accept the tag Exif because that is the same format." | 156 | We accept the tag Exif because that is the same format." |