From 6ec148a26390f830165791acb32f311d1b174276 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Thu, 17 Aug 2017 15:45:47 +0200 Subject: [PATCH] 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 --- lisp/org.el | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index d96da8623..03a8acf17 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -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