there are a couple of typos in your code, and the regexp doesn't seem to
match the property you want for some reason.
This seems to do what you want.
#+begin_src emacs-lisp
(defun org-contacts-icon-property-image-overlay (&optional limit)
(when (re-search-forward org-heading-regexp limit t)
(let ((beg (match-beginning 0))
(end (match-end 0))
(image-file (org-entry-get nil "ICON"))
org-contacts-icon-property-image
org-contacts-icon-property-image-overlay)
(when (and (not (ov-at beg)) (file-exists-p image-file))
(setq org-contacts-icon-property-image (create-image
(expand-file-name image-file)
'imagemagick nil :width 100))
(setq org-contacts-icon-property-image-overlay (make-overlay beg (+
1 beg)))
(overlay-put org-contacts-icon-property-image-overlay 'before-string
(propertize " "
'display org-contacts-icon-property-image))
(overlay-put org-contacts-icon-property-image-overlay
'org-image-overlay t)
(overlay-put org-contacts-icon-property-image-overlay
'modification-hooks
(list 'org-display-inline-remove-overlay))))))
(font-lock-add-keywords
nil
'((org-contacts-icon-property-image-overlay (0 'font-lock-keyword-face t)))
t)
#+END_SRC
John
-----------------------------------
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu
On Mon, May 7, 2018 at 7:57 PM, John Kitchin <[email protected]>
wrote:
> you might find this
> http://kitchingroup.cheme.cmu.edu/blog/2016/03/21/
> Displaying-image-overlays-on-image-filenames-in-Emacs/
> potentially useful for what you want.
>
> stardiviner writes:
>
> > I want to show org-contacts avatar image on org-headings.
> > Use overlay, or there is other better methods?
> >
> > A sample org-contacts snippet looks like this:
> >
> > * [] John KK
> > :PROPERTIES:
> > :AVATAR: john kk.jpg []
> > :END:
> >
> > I want to display the image at [] on heading, or replace "john kk.jpg"
> > with [] image.
> >
> > BTW, another question, how to get property's value? and how to iterate
> > on all heading elements then auto display image when open Contacts.org
> > file?
>
>
> --
> Professor John Kitchin
> Doherty Hall A207F
> Department of Chemical Engineering
> Carnegie Mellon University
> Pittsburgh, PA 15213
> 412-268-7803
> @johnkitchin
> http://kitchingroup.cheme.cmu.edu
>