I think I followed the example literally, but it doesn’t work. If I use defimage macro, the image descriptor isn’t created, but when I use create-image will all the same arguments it does. Below is what I tried:
(defimage test ((:type png :file "/home/wvxvw/Projects/haxe-mode/trunk/ede/etc/images/interface.png")))
test ; nil
(defimage test (:type png :file "/home/wvxvw/Projects/haxe-mode/trunk/ede/etc/images/interface.png"))
test ; nil
(insert-image test) ; error
(setq test (create-image "/home/wvxvw/Projects/haxe-mode/trunk/ede/etc/images/interface.png" 'png nil))
(image :type png :file "/home/wvxvw/Projects/haxe-mode/trunk/ede/etc/images/interface.png")
(insert-image test) ; shows image
Any hints?
EDIT:
While the code above should illustrate the problem, the actual code that I’m trying to run is a bit more involved. Posting it just in case:
(require 'cl)
(defvar haxe-images-dir
(concat (file-name-directory load-file-name) "etc/images/"))
(defmacro haxe-define-images (images)
(append
'(progn)
(loop for image in images
collect
`(defimage ,(intern (concat "haxe-" image "-icon"))
((:type png :file
(concat haxe-images-dir ,(concat image ".png"))))))))
(haxe-define-images
("private" "public" "static" "instance" "inline"
"volatile" "variable" "class" "interface" "macro"
"enum" "deftype" "function"))
EDIT2:
This is how it finally works. Perhaps I had some parts of the code compiled and thus loaded from a different place or some such mystery…
(require 'cl)
(require 'haxe-project)
(defmacro haxe-define-images (images)
(append
`(progn)
(loop for image in images
with images-root = (concat haxe-install-dir "etc/images/")
collect
`(defimage ,(intern (concat "haxe-" image "-icon"))
((:type png :file
,(concat images-root image ".png")))))))
(haxe-define-images
("private" "public" "static" "instance" "inline"
"volatile" "variable" "class" "interface" "macro"
"enum" "deftype" "function"))
It’s a feature of
defimageand otherdef-forms that they only set the variable if it is not already set. From the documentation fordefvar:So I presume that you already have assigned something to
test, so thedefimageform does nothing. If you are in the process of editing the code, you can force adef-form to be evaluated by putting point on the form, and using the commandeval-defun(C-M-x).Note that you should use
defimageonly for declaring a global variable. For other cases (where you are going to be using the image locally), usefind-imageinstead.In your updated code, your macro
haxe-define-imagesfails to evaluate the expression(concat haxe-images-dir ...). You can see this by expanding the macro:This won’t work because the
concatis insidequoteand so is not evaluated. You need to write something like this instead:(If you actually intend to delay evaluation of
haxe-images-dirthen the macro will need to be more complex than this, but I’m sure you can figure it out from here.)