0
0
Fork 1
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-09-29 20:07:46 +00:00

Allow link abbreviations to be displayed as inline images

* lisp/org.el (org-display-inline-images): Also display link
  abbreviations when they point to a valid image file.

Reported-by: Fabrice Popineau <fabrice.popineau@gmail.com>
<http://lists.gnu.org/archive/html/emacs-orgmode/2017-08/msg00395.html>
This commit is contained in:
Nicolas Goaziou 2017-08-17 15:45:47 +02:00
parent 2fb129b5c7
commit 6ec148a263

View file

@ -19354,16 +19354,24 @@ 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)
(file-extension-re (image-file-name-regexp))
(link-abbrevs (append org-link-abbrev-alist-local
org-link-abbrev-alist))
;; Check absolute, relative file names and explicit "file:"
;; links. Also check link abbreviations since some might
;; expand to "file" links.
(file-types-re (format "[][]\\[\\(?:file\\|[./~]%s\\)"
(and link-abbrevs
(format "\\|\\(?:%s:\\)"
(regexp-opt link-abbrevs))))))
(while (re-search-forward file-types-re 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")
;; Check if we're at an inline image, i.e., an image file
;; link without a description (unless INCLUDE-LINKED is
;; non-nil).
(when (and (equal "file" (org-element-property :type link))
(or include-linked
(not (org-element-property :contents-begin link)))
(let ((parent (org-element-property :parent link)))
(or (not (eq (org-element-type parent) 'link))
(not (cdr (org-element-contents parent)))))
(null (org-element-contents link)))
(string-match-p file-extension-re
(org-element-property :path link)))
(let ((file (expand-file-name