comparison lisp/mh-e/mh-utils.el @ 69273:b52e0cc8af61

* mh-folder.el (mh-folder-mode): Rename mh-image-load-path to mh-image-load-path-for-library. * mh-letter.el (mh-letter-mode): Rename mh-image-load-path to mh-image-load-path-for-library. * mh-utils.el (mh-image-load-path): Rename to mh-image-load-path-for-library. Add example to docstring. Rename local variable mh-image-directory to image-directory. Move error checks to default case in cond and simplify.
author Bill Wohler <wohler@newt.com>
date Fri, 03 Mar 2006 20:50:50 +0000
parents f3bbf5f32462
children ade4a047af1b
comparison
equal deleted inserted replaced
69272:cc66ebd3f3a4 69273:b52e0cc8af61
80 (defun mh-delete-line (lines) 80 (defun mh-delete-line (lines)
81 "Delete the next LINES lines." 81 "Delete the next LINES lines."
82 (delete-region (point) (progn (forward-line lines) (point)))) 82 (delete-region (point) (progn (forward-line lines) (point))))
83 83
84 ;;;###mh-autoload 84 ;;;###mh-autoload
85 (defun mh-image-load-path (library image &optional path) 85 (defun mh-image-load-path-for-library (library image &optional path)
86 "Return a suitable search path for images of LIBRARY. 86 "Return a suitable search path for images of LIBRARY.
87 87
88 Images for LIBRARY are searched for in \"../../etc/images\" and 88 Images for LIBRARY are searched for in \"../../etc/images\" and
89 \"../etc/images\" relative to the files in \"lisp/LIBRARY\", in 89 \"../etc/images\" relative to the files in \"lisp/LIBRARY\", in
90 `image-load-path', or in `load-path'. 90 `image-load-path', or in `load-path'.
91 91
92 This function returns value of `load-path' augmented with the 92 This function returns value of `load-path' augmented with the
93 path to IMAGE. If PATH is given, it is used instead of 93 path to IMAGE. If PATH is given, it is used instead of
94 `load-path'." 94 `load-path'.
95
96 Here is an example that uses a common idiom to provide
97 compatibility with versions of Emacs that lack the variable
98 `image-load-path':
99
100 (let ((load-path
101 (image-load-path-for-library \"mh-e\" \"mh-logo.xpm\" 'load-path))
102 (image-load-path
103 (image-load-path-for-library \"mh-e\" \"mh-logo.xpm\" 'image-load-path)))
104 (mh-tool-bar-folder-buttons-init))"
95 (unless library (error "No library specified")) 105 (unless library (error "No library specified"))
96 (unless image (error "No image specified")) 106 (unless image (error "No image specified"))
97 (let ((mh-image-directory)) 107 (let ((image-directory))
98 (cond 108 (cond
99 ;; Try relative setting. 109 ;; Try relative setting.
100 ((let (mh-library-name d1ei d2ei) 110 ((let (library-name d1ei d2ei)
101 ;; First, find library in the load-path. 111 ;; First, find library in the load-path.
102 (setq mh-library-name (locate-library library)) 112 (setq library-name (locate-library library))
103 (if (not mh-library-name) 113 (if (not library-name)
104 (error "Cannot find library %s in load-path" library)) 114 (error "Cannot find library %s in load-path" library))
105 ;; And then set mh-image-directory relative to that. 115 ;; And then set image-directory relative to that.
106 (setq 116 (setq
107 ;; Go down 2 levels. 117 ;; Go down 2 levels.
108 d2ei (expand-file-name 118 d2ei (expand-file-name
109 (concat (file-name-directory mh-library-name) 119 (concat (file-name-directory library-name) "../../etc/images"))
110 "../../etc/images"))
111 ;; Go down 1 level. 120 ;; Go down 1 level.
112 d1ei (expand-file-name 121 d1ei (expand-file-name
113 (concat (file-name-directory mh-library-name) 122 (concat (file-name-directory library-name) "../etc/images")))
114 "../etc/images"))) 123 (setq image-directory
115 (setq mh-image-directory
116 ;; Set it to nil if image is not found. 124 ;; Set it to nil if image is not found.
117 (cond ((file-exists-p (expand-file-name image d2ei)) d2ei) 125 (cond ((file-exists-p (expand-file-name image d2ei)) d2ei)
118 ((file-exists-p (expand-file-name image d1ei)) d1ei))))) 126 ((file-exists-p (expand-file-name image d1ei)) d1ei)))))
119 ;; Check for images in image-load-path or load-path. 127 ;; Check for images in image-load-path or load-path.
120 ((let ((img image) 128 ((let ((img image)
122 ;; Images in image-load-path. 130 ;; Images in image-load-path.
123 (mh-image-search-load-path image) 131 (mh-image-search-load-path image)
124 ;; Images in load-path. 132 ;; Images in load-path.
125 (locate-library image))) 133 (locate-library image)))
126 parent) 134 parent)
127 ;; Since the image might be in a nested directory 135 ;; Since the image might be in a nested directory (for
128 ;; (for example, mail/attach.pbm), adjust `mh-image-directory' 136 ;; example, mail/attach.pbm), adjust `image-directory'
129 ;; accordingly. 137 ;; accordingly.
130 (and dir 138 (and dir
131 (setq dir (file-name-directory dir)) 139 (setq dir (file-name-directory dir))
132 (progn 140 (progn
133 (while (setq parent (file-name-directory img)) 141 (while (setq parent (file-name-directory img))
134 (setq img (directory-file-name parent) 142 (setq img (directory-file-name parent)
135 dir (expand-file-name "../" dir))) 143 dir (expand-file-name "../" dir)))
136 (setq mh-image-directory dir)))))) 144 (setq image-directory dir)))))
137 ;; 145 (t
138 (unless (file-exists-p mh-image-directory) 146 (error "Could not find image %s for library %s" image library)))
139 (error "Directory %s in mh-image-directory does not exist" 147
140 mh-image-directory))
141 (unless (file-exists-p (expand-file-name image mh-image-directory))
142 (error "Directory %s in mh-image-directory does not contain image %s"
143 mh-image-directory image))
144 ;; Return augmented `image-load-path' or `load-path'. 148 ;; Return augmented `image-load-path' or `load-path'.
145 (cond ((and path (symbolp path)) 149 (cond ((and path (symbolp path))
146 (nconc (list mh-image-directory) 150 (nconc (list image-directory)
147 (delete mh-image-directory 151 (delete image-directory
148 (if (boundp path) 152 (if (boundp path)
149 (copy-sequence (symbol-value path)) 153 (copy-sequence (symbol-value path))
150 nil)))) 154 nil))))
151 (t 155 (t
152 (nconc (list mh-image-directory) 156 (nconc (list image-directory)
153 (delete mh-image-directory 157 (delete image-directory (copy-sequence load-path)))))))
154 (copy-sequence load-path)))))))
155 158
156 ;;;###mh-autoload 159 ;;;###mh-autoload
157 (defun mh-make-local-vars (&rest pairs) 160 (defun mh-make-local-vars (&rest pairs)
158 "Initialize local variables according to the variable-value PAIRS." 161 "Initialize local variables according to the variable-value PAIRS."
159 (while pairs 162 (while pairs
201 204
202 ;;;###mh-autoload 205 ;;;###mh-autoload
203 (defun mh-logo-display () 206 (defun mh-logo-display ()
204 "Modify mode line to display MH-E logo." 207 "Modify mode line to display MH-E logo."
205 (mh-do-in-gnu-emacs 208 (mh-do-in-gnu-emacs
206 (let ((load-path 209 (let ((load-path (mh-image-load-path-for-library
207 (mh-image-load-path "mh-e" "mh-logo.xpm" 'load-path)) 210 "mh-e" "mh-logo.xpm" 'load-path))
208 (image-load-path 211 (image-load-path (mh-image-load-path-for-library
209 (mh-image-load-path "mh-e" "mh-logo.xpm" 'image-load-path))) 212 "mh-e" "mh-logo.xpm" 'image-load-path)))
210 (add-text-properties 213 (add-text-properties
211 0 2 214 0 2
212 `(display ,(or mh-logo-cache 215 `(display ,(or mh-logo-cache
213 (setq mh-logo-cache 216 (setq mh-logo-cache
214 (mh-funcall-if-exists 217 (mh-funcall-if-exists