emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Display inline images for shortcuts links
@ 2017-08-17 12:20 Fabrice Popineau
  2017-08-17 13:59 ` Nicolas Goaziou
  0 siblings, 1 reply; 5+ messages in thread
From: Fabrice Popineau @ 2017-08-17 12:20 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

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

Would it be possible to enable inline images for shortcuts links ?
Currently, the function `org-display-inline-images' checks for a hard coded
file: link.
In the case of :


#+LINK: temp file:c:/temp/%h

[[file:cover.jpg]]

[[temp:cover.jpg]]

The first link will be matched, but not the second one.
(Unless I missed something?)

A small patch like the one attached enables to display inline images for
all links.
But maybe relying on the org-element API is not the smarter move here.

( I voluntarily kept the old lines commented in the patch. )

Regards,

Fabrice

diff --git a/lisp/org.el b/lisp/org.el
index b05eac57e..0b45ecec2 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -19398,9 +19398,12 @@ boundaries."
     (org-with-wide-buffer
      (goto-char (or beg (point-min)))
      (let ((case-fold-search t)
-          (file-extension-re (image-file-name-regexp)))
-       (while (re-search-forward "[][]\\[\\(?:file\\|[./~]\\)" end t)
-        (let ((link (save-match-data (org-element-context))))
+          (file-extension-re (image-file-name-regexp))
+           (parse-tree (org-element-parse-buffer)))
+       (org-element-map parse-tree 'link
+         (lambda (link)
+           ;; (while (re-search-forward "[][]\\[\\(?:file\\|[./~]\\)" end
t)
+           ;;  (let ((link (save-match-data (org-element-context))))))
            ;; Check if we're at an inline image.
            (when (and (equal (org-element-property :type link) "file")
                       (or include-linked

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

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

* Re: Display inline images for shortcuts links
  2017-08-17 12:20 Display inline images for shortcuts links Fabrice Popineau
@ 2017-08-17 13:59 ` Nicolas Goaziou
  2017-08-17 20:05   ` Fabrice Popineau
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolas Goaziou @ 2017-08-17 13:59 UTC (permalink / raw)
  To: Fabrice Popineau; +Cc: emacs-orgmode@gnu.org

Hello,

Fabrice Popineau <fabrice.popineau@gmail.com> writes:

> Would it be possible to enable inline images for shortcuts links ?
> Currently, the function `org-display-inline-images' checks for a hard coded
> file: link.
> In the case of :
>
> #+LINK: temp file:c:/temp/%h
>
> [[file:cover.jpg]]
>
> [[temp:cover.jpg]]
>
> The first link will be matched, but not the second one.
> (Unless I missed something?)

Fixed, in master.

> A small patch like the one attached enables to display inline images for
> all links.
> But maybe relying on the org-element API is not the smarter move here.

org-element API is already used in the function (e.g.,
`org-element-property' ...). However `org-element-parse-buffer' is a bit
heavy for the task, in particular in the supposedly common case where
inline image are not the most common link type throughout the buffer.

I simply extended the link search to all link abbrevs, discarding those
that do not ultimately match a file.

Does it solve your issue?

Regards,

-- 
Nicolas Goaziou

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

* Re: Display inline images for shortcuts links
  2017-08-17 13:59 ` Nicolas Goaziou
@ 2017-08-17 20:05   ` Fabrice Popineau
  2017-08-18 10:06     ` Fabrice Popineau
  0 siblings, 1 reply; 5+ messages in thread
From: Fabrice Popineau @ 2017-08-17 20:05 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode@gnu.org

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

2017-08-17 15:59 GMT+02:00 Nicolas Goaziou <mail@nicolasgoaziou.fr>:

> Hello,
>
> I simply extended the link search to all link abbrevs, discarding those
> that do not ultimately match a file.
>
> Does it solve your issue?
>
>
Yes thanks. Much lighter.

I like link abbreviations, because they allow to change the reference point
where the files are stored (if needed some day)

Regards,

Fabrice

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

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

* Re: Display inline images for shortcuts links
  2017-08-17 20:05   ` Fabrice Popineau
@ 2017-08-18 10:06     ` Fabrice Popineau
  2017-08-18 10:27       ` Nicolas Goaziou
  0 siblings, 1 reply; 5+ messages in thread
From: Fabrice Popineau @ 2017-08-18 10:06 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode@gnu.org

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

While we are at it, would it be possible to display an inline image when
the image is in the contents part of the link?

The rationale is that something like:

[[file:book.pdf][file:cover.jpg]]

is exported to html as:

<a href="book.pdf"><img src="cover.jpg" alt="cover.jpg" /></a>

The result would be a clickable image in the Org buffer the same way it is
in HTML.

Is there any drawback in doing this ?

Fabrice

2017-08-17 22:05 GMT+02:00 Fabrice Popineau <fabrice.popineau@gmail.com>:

>
>
> 2017-08-17 15:59 GMT+02:00 Nicolas Goaziou <mail@nicolasgoaziou.fr>:
>
>> Hello,
>>
>> I simply extended the link search to all link abbrevs, discarding those
>> that do not ultimately match a file.
>>
>> Does it solve your issue?
>>
>>
> Yes thanks. Much lighter.
>
> I like link abbreviations, because they allow to change the reference
> point where the files are stored (if needed some day)
>
> Regards,
>
> Fabrice
>
>

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

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

* Re: Display inline images for shortcuts links
  2017-08-18 10:06     ` Fabrice Popineau
@ 2017-08-18 10:27       ` Nicolas Goaziou
  0 siblings, 0 replies; 5+ messages in thread
From: Nicolas Goaziou @ 2017-08-18 10:27 UTC (permalink / raw)
  To: Fabrice Popineau; +Cc: emacs-orgmode@gnu.org

Hello,

Fabrice Popineau <fabrice.popineau@gmail.com> writes:

> While we are at it, would it be possible to display an inline image when
> the image is in the contents part of the link?
>
> The rationale is that something like:
>
> [[file:book.pdf][file:cover.jpg]]
>
> is exported to html as:
>
> <a href="book.pdf"><img src="cover.jpg" alt="cover.jpg" /></a>
>
> The result would be a clickable image in the Org buffer the same way it is
> in HTML.
>
> Is there any drawback in doing this ?

Yes there is. Org syntax doesn't support nested links. Most export
back-ends do not either. I introduced `org-export-insert-image-links'
a few ago to let other export back-ends have nested links. See its
docstring for details.

Display would not be on par with underlying syntax. I find this
inconvenient. More inconvenient than not displaying the clickable image,
that is.

Regards,

-- 
Nicolas Goaziou                                                0x80A93738

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

end of thread, other threads:[~2017-08-18 10:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-17 12:20 Display inline images for shortcuts links Fabrice Popineau
2017-08-17 13:59 ` Nicolas Goaziou
2017-08-17 20:05   ` Fabrice Popineau
2017-08-18 10:06     ` Fabrice Popineau
2017-08-18 10:27       ` Nicolas Goaziou

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