Browse Source

Match also image paths relative to home

Baoqui Cui writes:

> "robut@iinet.net.au" <robut@iinet.net.au> writes:
>
> I very much like the idea of native inline image display in Org-mode but  can't
> seem to make it work.
>
> Given a 6.36 snapshot or 6.36 release and these org file contents
>
> * Test image
> Test image
> [[Screenshot.png]]
>
>
> I hoped org would display that image after C-c C-x C-v. Rather Org-mode returns
> "No images to display inline".
>
> I've tried different ways of linking that image, different image formats,
> relative vs complete paths, and my regular .emacs vs  a near empty one and
> always the same result. If I toggle iimage-mode the image displays fine per se
> but does not affect how Org-mode works.
>
> Seems clear I am missing something simple. What?
>
> I like the idea of inline image display too, but hit the similar
> problems.  After reading the code in org.el, I found that the inline
> image file link has to start with either "file:" or "./".
>
> For example, the following two links are OK:
>
>   [[file:~/images/myImage.png]]
>   [[./figures/org-mode-unicorn.svg]]
>
> but the following two are not:
>
>   [[Screenshot.png]]
>   [[~/images/myImage.png]]
>
> Here is a small patch that seems to work well for me, but I'd like
> Carsten to check whether it may break anything
Carsten Dominik 15 years ago
parent
commit
33fba09ddb
2 changed files with 4 additions and 2 deletions
  1. 1 0
      lisp/ChangeLog
  2. 3 2
      lisp/org.el

+ 1 - 0
lisp/ChangeLog

@@ -2,6 +2,7 @@
 
 	* org.el (org-display-inline-images): Do the entire buffer,
 	not just the narrowed region.  Clear the cache.
+	(org-display-inline-images): Match mode file paths.
 
 2010-05-10  Carsten Dominik  <carsten.dominik@gmail.com>
 

+ 3 - 2
lisp/org.el

@@ -15513,14 +15513,15 @@ BEG and END default to the buffer boundaries."
       (widen)
       (setq beg (or beg (point-min)) end (or end (point-max)))
       (goto-char (point-min))
-      (let ((re (concat "\\[\\[\\(file:\\|\\./\\)\\(~?" "[-+./_0-9a-zA-Z]+"
+      (let ((re (concat "\\[\\[\\(\\(file:\\)\\|\\([./~]\\)\\)\\([-+~./_0-9a-zA-Z]+"
 			(substring (org-image-file-name-regexp) 0 -2)
 			"\\)\\]" (if include-linked "" "\\]")))
 	    file ov img)
 	(while (re-search-forward re end t)
 	  (setq old (get-char-property-and-overlay (match-beginning 1)
 						   'org-image-overlay))
-	  (setq file (expand-file-name (match-string 2)))
+	  (setq file (expand-file-name
+		      (concat (or (match-string 3) "") (match-string 4))))
 	  (when (file-exists-p file)
 	    (if (and (car-safe old) refresh)
 		(image-refresh (overlay-get (cdr old) 'display))