From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: Re: [org-contacts] How to show avatar image on org headings? Date: Wed, 9 May 2018 07:03:25 -0700 Message-ID: References: <87fu342pj7.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="001a11444b02e4abe1056bc65dcc" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:44265) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGPgs-0002qV-BB for emacs-orgmode@gnu.org; Wed, 09 May 2018 10:03:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGPgm-00065b-CJ for emacs-orgmode@gnu.org; Wed, 09 May 2018 10:03:34 -0400 Received: from mail-wm0-x235.google.com ([2a00:1450:400c:c09::235]:53642) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fGPgm-00063N-2E for emacs-orgmode@gnu.org; Wed, 09 May 2018 10:03:28 -0400 Received: by mail-wm0-x235.google.com with SMTP id a67so24870183wmf.3 for ; Wed, 09 May 2018 07:03:27 -0700 (PDT) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: stardiviner Cc: org-mode --001a11444b02e4abe1056bc65dcc Content-Type: text/plain; charset="UTF-8" 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 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 > --001a11444b02e4abe1056bc65dcc Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
there are a couple of typos in your code, and the regexp d= oesn't seem to match the property you want for some reason.=C2=A0
<= br>
This seems to do what you want.

#+begi= n_src emacs-lisp
(defun org-contacts-icon-property-image-overlay = (&optional limit)
=C2=A0 (when (re-search-forward org-heading= -regexp limit t)
=C2=A0 =C2=A0 (let ((beg (match-beginning 0))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (end (match-end 0))
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (image-file (org-entry-get nil "ICO= N"))
=C2=A0 org-cont= acts-icon-property-image
= =C2=A0 org-contacts-icon-property-image-overlay)
=C2=A0 =C2=A0 = =C2=A0 (when (and (not (ov-at beg)) (file-exists-p image-file))
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 (setq org-contacts-icon-property-image (create-= image (expand-file-name image-file)
=C2=A0 =C2=A0 =C2=A0'imagemagick nil :width 100))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (setq org-contacts-icon-property-image-ov= erlay (make-overlay beg (+ 1 beg)))
(overlay-put org-contacts-icon-property-image-overlay 'befor= e-string (propertize " "
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 'display org-contacts-icon-pr= operty-image))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (overlay-put org-conta= cts-icon-property-image-overlay 'org-image-overlay t)
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 (overlay-put org-contacts-icon-property-image-overlay = 'modification-hooks
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(list 'org-display-inline-remove-ove= rlay))))))

(font-lock-add-keywords
=C2= =A0nil
=C2=A0'((org-contacts-icon-property-image-overlay (0 &= #39;font-lock-keyword-face t)))
=C2=A0t)
#+END_SRC=C2= =A0

John

-----------------------------------Professor John Kitchin=C2=A0
Doherty Hall A207F
Department of Chemi= cal Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
41= 2-268-7803

On Mon, May 7, 2018 at 7:57 PM, John Kitchin= <jkitchin@andrew.cmu.edu> 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 ite= rate
> 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

--001a11444b02e4abe1056bc65dcc--