From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/62276 Path: news.gmane.org!not-for-mail From: Bill Wohler Newsgroups: gmane.mail.mh-e.devel,gmane.emacs.gnus.general Subject: gmm-image-load-path-for-library redux (was: New GNOME icons) Date: Wed, 15 Mar 2006 17:41:46 -0800 Organization: Newt Software Message-ID: <9172.1142473306@olgas.newt.com> References: <20403.1141690692@olgas.newt.com> <3861.1142268982@olgas.newt.com> <22907.1142318606@olgas.newt.com> <1183.1142359136@olgas.newt.com> NNTP-Posting-Host: main.gmane.org X-Trace: sea.gmane.org 1142473348 20760 80.91.229.2 (16 Mar 2006 01:42:28 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 16 Mar 2006 01:42:28 +0000 (UTC) Cc: ding@gnus.org, mh-e-devel@lists.sourceforge.net Original-X-From: mh-e-devel-admin@lists.sourceforge.net Thu Mar 16 02:42:21 2006 Return-path: Envelope-to: gmmd-mh-e-devel@m.gmane.org Original-Received: from lists-outbound.sourceforge.net ([66.35.250.225]) by ciao.gmane.org with esmtp (Exim 4.43) id 1FJhVG-0001Vt-Cu for gmmd-mh-e-devel@m.gmane.org; Thu, 16 Mar 2006 02:42:14 +0100 Original-Received: from sc8-sf-list1-b.sourceforge.net (sc8-sf-list1-b.sourceforge.net [10.3.1.7]) by sc8-sf-spam1.sourceforge.net (Postfix) with ESMTP id A16DA89587; Wed, 15 Mar 2006 17:42:13 -0800 (PST) Original-Received: from sc8-sf-mx2-b.sourceforge.net ([10.3.1.92] helo=mail.sourceforge.net) by sc8-sf-list1.sourceforge.net with esmtp (Exim 4.30) id 1FJhUs-0007rX-Gz for mh-e-devel@lists.sourceforge.net; Wed, 15 Mar 2006 17:41:50 -0800 Original-Received: from pop-cowbird.atl.sa.earthlink.net ([207.69.195.68]) by mail.sourceforge.net with esmtp (Exim 4.44) id 1FJhUs-0003tI-5l for mh-e-devel@lists.sourceforge.net; Wed, 15 Mar 2006 17:41:50 -0800 Original-Received: from h-68-165-5-58.snvacaid.dynamic.covad.net ([68.165.5.58] helo=olgas.newt.com) by pop-cowbird.atl.sa.earthlink.net with esmtp (Exim 3.36 #10) id 1FJhUo-0005Lb-00; Wed, 15 Mar 2006 20:41:46 -0500 Original-Received: by olgas.newt.com (Postfix, from userid 1000) id 1E9801707E; Wed, 15 Mar 2006 17:41:46 -0800 (PST) Original-Received: from olgas.newt.com (localhost [127.0.0.1]) by olgas.newt.com (Postfix) with ESMTP id 1C18816FB0; Wed, 15 Mar 2006 17:41:46 -0800 (PST) Original-To: Katsumi Yamaoka In-reply-to: Comments: In-reply-to Katsumi Yamaoka message dated "Wed, 15 Mar 2006 16:34:40 +0900." X-Mailer: MH-E 7.93+cvs; nmh 1.1; GNU Emacs 22.0.50.14 X-Image-URL: http://www.newt.com/wohler/images/bill-diving.png Mail-Followup-To: mh-e-devel@lists.sourceforge.net, ding@gnus.org X-Spam-Score: 1.0 (+) X-Spam-Report: Spam Filtering performed by sourceforge.net. See http://spamassassin.org/tag/ for more details. Report problems to http://sf.net/tracker/?func=add&group_id=1&atid=200001 1.0 FORGED_RCVD_HELO Received: contains a forged HELO Original-Sender: mh-e-devel-admin@lists.sourceforge.net Errors-To: mh-e-devel-admin@lists.sourceforge.net X-BeenThere: mh-e-devel@lists.sourceforge.net X-Mailman-Version: 2.0.9-sf.net Precedence: bulk List-Unsubscribe: , List-Id: Forum for the MH-E developers List-Post: List-Help: List-Subscribe: , List-Archive: X-Original-Date: Wed, 15 Mar 2006 17:41:46 -0800 Xref: news.gmane.org gmane.mail.mh-e.devel:12000 gmane.emacs.gnus.general:62276 Archived-At: Katsumi Yamaoka wrote: > >>>>> In Katsumi Yamaoka wrote: > > > It suggests there's no way that she uses her favorite images instead > > of the ones Emacs provides. > > An alternative plan is here: > > * gmm-utils.el (gmm-image-load-path-for-library): Look for the > most preferred directory which may be specified in image-load-path > by a user. Rats, that's why we had the mh-image-directory variable... > ;; Check for another directory that is specified in > ;; image-load-path and preferred than image-directory. > ((and image-directory > (boundp 'image-load-path)) > (let ((image-load-path > (butlast > (symbol-value 'image-load-path) > (length (member (file-name-as-directory image-directory) > (mapcar > (lambda (dir) > (if (stringp dir) > (file-name-as-directory dir) > dir)) > (symbol-value 'image-load-path))))))) > (setq dir (image-search-load-path image)))) > Oh boy, that took me about an hour to figure out ;-). Assuming I've understood correctly, I think I see a couple of problems. I don't see how (butlast) can be right. That code is stripping away the directory found in .../etc/images *plus* all of the directories that follow it which could include the user's directory. Most likely .../etc/images won't be in image-load-path at all, so the last directory in image-load-path will be stripped (which could be the user's directory if they preferred to use the system images but provided images as a fall-back). I'm not quite sure of the whole point of that exercise anyway. Why not just call (image-search-load-path image)? But still, this isn't correct. If the user does *not* have a preferred version, and you're running an external package, you'd prefer the .../etc/images version over the one already in image-load-path. But this code would give you the directory already in image-load-path. A minor point, but why use (symbol-value 'image-load-path)? Why not just the simpler and clearer image-load-path? What I think might work is that we call (image-search-load-path image) and use it instead of .../etc/images if and only if it isn't the system image directory. The system image directory is (concat data-directory "images"), right? Here is a reworked function that seems to do what everybody wants (and hopefully doesn't take an hour to understand ;-). What do you think? (defun 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'. Then this function returns a list of directories which contains first the directory in which IMAGE was found, followed by the value of `load-path'. If PATH is given, it is used instead of `load-path'. If NO-ERROR is non-nil and a suitable path can't be found, don't signal an error. Instead, return a list of directories as before, except that nil appears in place of the image directory. Here is an example that uses a common idiom to provide compatibility with versions of Emacs that lack the variable `image-load-path': ;; Shush compiler. (defvar image-load-path) (let* ((load-path (image-load-path-for-library \"mh-e\" \"mh-logo.xpm\")) (image-load-path (cons (car load-path) (when (boundp 'image-load-path) image-load-path)))) (mh-tool-bar-folder-buttons-init))" (unless library (error "No library specified")) (unless image (error "No image specified")) (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. (image-search-load-path image) ;; 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. (setq library-name (locate-library library)) (if (not library-name) (error "Cannot find library %s in load-path" library)) ;; And then set image-directory relative to that. (setq ;; Go down 2 levels. d2ei (file-name-as-directory (expand-file-name (concat (file-name-directory library-name) "../../etc/images"))) ;; Go down 1 level. 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))))) (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 (error "Could not find image %s for library %s" image library))) ;; Return an augmented `path' or `load-path'. (nconc (list image-directory) (delete image-directory (copy-sequence (or path load-path)))))) -- Bill Wohler http://www.newt.com/wohler/ GnuPG ID:610BD9AD Maintainer of comp.mail.mh FAQ and MH-E. Vote Libertarian! If you're passed on the right, you're in the wrong lane. ------------------------------------------------------- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642