summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2017-08-17 15:45:47 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2017-08-17 15:45:47 +0200
commit6ec148a26390f830165791acb32f311d1b174276 (patch)
treee71805ede5d0e6d95d984d39716279ee04b62699
parent2fb129b5c7d8da924f02217f83be1254d86720eb (diff)
downloadorg-mode-6ec148a26390f830165791acb32f311d1b174276.tar.gz
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>
-rw-r--r--lisp/org.el24
1 files changed, 16 insertions, 8 deletions
diff --git a/lisp/org.el b/lisp/org.el
index d96da86..03a8acf 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