emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [org-contacts] How to show avatar image on org headings?
@ 2018-05-07  2:00 stardiviner
  2018-05-08  2:57 ` John Kitchin
  0 siblings, 1 reply; 5+ messages in thread
From: stardiviner @ 2018-05-07  2:00 UTC (permalink / raw)
  To: org-mode

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?

--
[ stardiviner ] don't need to convince with trends.
       Blog: https://stardiviner.github.io/
       IRC(freenode): stardiviner
       GPG: F09F650D7D674819892591401B5DF1C95AE89AC3

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [org-contacts] How to show avatar image on org headings?
  2018-05-07  2:00 [org-contacts] How to show avatar image on org headings? stardiviner
@ 2018-05-08  2:57 ` John Kitchin
  2018-05-09 13:31   ` stardiviner
  2018-05-09 14:03   ` John Kitchin
  0 siblings, 2 replies; 5+ messages in thread
From: John Kitchin @ 2018-05-08  2:57 UTC (permalink / raw)
  To: numbchild; +Cc: org-mode

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [org-contacts] How to show avatar image on org headings?
  2018-05-08  2:57 ` John Kitchin
@ 2018-05-09 13:31   ` stardiviner
  2018-05-09 14:03   ` John Kitchin
  1 sibling, 0 replies; 5+ messages in thread
From: stardiviner @ 2018-05-09 13:31 UTC (permalink / raw)
  To: John Kitchin; +Cc: org-mode

Hi, Kitchin, thanks for your sharing. Following your code example, I did
small modification to use on my case.

Here is my code:

#+begin_src emacs-lisp
(defvar image-overlay-re (concat
                          ":ICON:"
                          "\\(?3:'\\|\"\\)\\(?1:.*\\."
                          (regexp-opt '("png" "PNG"
                                        "jpg" "jpeg" "JPG" "JPEG"
                                        "gif" "GIF"
                                        "eps" "EPS"))
                          "\\)\\(?:\\3\\)")
  "Regexp to match image filenames in quotes")

(defun org-contacts-icon-property-image-overlay (&optional limit)
  (when (re-search-forward image-overlay-re limit t)
    (let ((beg (match-beginning 0))
          (end (match-end 0))
          (image-file (match-string 1)))
      (when (file-exists-p image-file)
        (setq org-contacts-icon-property-iimage (create-image (expand-file-name image-file)
                                                              'imagemagick nil :width 300))
        (setq org-contacts-icon-property-image-overlay (make-overlay beg end))
        (overlay-put org-contacts-icon-property-image-overlay 'display image)
        (overlay-put org-contacts-icon-property-image-overlay 'face 'default)
        (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

But when I evaluate upper code, and re-enable org-mode on Contacts.org
file. The :ICON: property value "John.png" is not displayed as image. Is
there something wrong?

I choose to use overlay to auto display image when open org-contacts
file.

--
[ stardiviner ] don't need to convince with trends.
       Blog: https://stardiviner.github.io/
       IRC(freenode): stardiviner
       GPG: F09F650D7D674819892591401B5DF1C95AE89AC3

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [org-contacts] How to show avatar image on org headings?
  2018-05-08  2:57 ` John Kitchin
  2018-05-09 13:31   ` stardiviner
@ 2018-05-09 14:03   ` John Kitchin
  2018-05-10  1:20     ` stardiviner
  1 sibling, 1 reply; 5+ messages in thread
From: John Kitchin @ 2018-05-09 14:03 UTC (permalink / raw)
  To: stardiviner; +Cc: org-mode

[-- Attachment #1: Type: text/plain, Size: 2494 bytes --]

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 <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 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
>

[-- Attachment #2: Type: text/html, Size: 4054 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [org-contacts] How to show avatar image on org headings?
  2018-05-09 14:03   ` John Kitchin
@ 2018-05-10  1:20     ` stardiviner
  0 siblings, 0 replies; 5+ messages in thread
From: stardiviner @ 2018-05-10  1:20 UTC (permalink / raw)
  To: John Kitchin; +Cc: org-mode

Thanks, Kitchin!

I tried code in Emacs minimal config. But the image is
not shown. I tried to toggle Edebug on function
`org-contacts-icon-property-image-overlay`. But it is not triggered.
Don't understand why. Because `(font-lock-add-keywords ..)` not correct?
I tried to change `nil` into `'org-mode`. But still does not work.

Possible reasons:

- In your code, seems don't need KEYWORDS for`font-lock-add-keywords`.
- font-lock can't enabled on org-property because it is already
  font-locked? (don't know this neither)

I'm considering might can change a thinking direction (This is an
optional solution). Because Org-mode support inline image display for
file link:

,----
| [[file:image.png]]
`----

So I tried to use this in Org property like this:

,----
| * Name
| :PROPERTY:
| :ICON: [[file:image.png]]
| :END:
`----

But Org inline image can't display on property value. (Because inline
image require a single line, invalid in org property value position?)

WDYT?

--
[ stardiviner ] don't need to convince with trends.
       Blog: https://stardiviner.github.io/
       IRC(freenode): stardiviner
       GPG: F09F650D7D674819892591401B5DF1C95AE89AC3

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-05-10  1:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-07  2:00 [org-contacts] How to show avatar image on org headings? stardiviner
2018-05-08  2:57 ` John Kitchin
2018-05-09 13:31   ` stardiviner
2018-05-09 14:03   ` John Kitchin
2018-05-10  1:20     ` stardiviner

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).