Nicolas Goaziou <m...@nicolasgoaziou.fr> writes:

>>      ;; I tried to add this, but failed. because `coderef` is executed in 
>> `org-edit-src-code` which invokes `org-src--edit-element`, it create a 
>> dedicated buffer which does not have `buffer-file-name`. I don't know how to 
>> archive what I want now.
>>         ;; ((eq org-link-file-path-type 'adaptive)
>
> In "org-src.el", we create local variables to store information from
> original buffer. See, e.g., `org-src--src-type' or `org-src--tab-width'.
> Anyway, see my first question.

Thanks for this hint, I added a new entry in org-src--babel-info list to
pass the original parent file path.

>From 6e8469545185a41d22b8046ebb367c3c742f0ff4 Mon Sep 17 00:00:00 2001
From: stardiviner <numbch...@gmail.com>
Date: Wed, 24 Oct 2018 10:45:40 +0800
Subject: [PATCH] org.el: fix org-coderef does not support adaptive file path
 link type.

* org.el (org-insert-link): support option org-link-file-path-type
  'adaptive value.
* ob-core.el (org-babel-get-src-block-info): add an new entry into src
  block info list to pass parent file path.
---
 lisp/ob-core.el | 5 +++--
 lisp/org.el     | 9 ++++++---
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 42360d618..73117f1a7 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -578,7 +578,7 @@ object instead.
 Return nil if point is not on a source block.  Otherwise, return
 a list with the following pattern:
 
-  (language body arguments switches name start coderef)"
+  (language body arguments switches name start coderef parent-file-path)"
   (let* ((datum (or datum (org-element-context)))
 	 (type (org-element-type datum))
 	 (inline (eq type 'inline-src-block)))
@@ -609,7 +609,8 @@ a list with the following pattern:
 	       name
 	       (org-element-property (if inline :begin :post-affiliated)
 				     datum)
-	       (and (not inline) (org-src-coderef-format datum)))))
+	       (and (not inline) (org-src-coderef-format datum))
+	       buffer-file-name)))
 	(unless light
 	  (setf (nth 2 info) (org-babel-process-params (nth 2 info))))
 	(setf (nth 2 info) (org-babel-generate-file-param name (nth 2 info)))
diff --git a/lisp/org.el b/lisp/org.el
index 0b5e8d739..37524bce0 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -9249,13 +9249,14 @@ non-nil."
 		(interactive?
 		 (let ((label (read-string "Code line label: ")))
 		   (end-of-line)
-		   (setq link (format coderef-format label))
 		   (let ((gc (- 79 (length link))))
 		     (if (< (current-column) gc)
 			 (org-move-to-column gc t)
 		       (insert " ")))
-		   (insert link)
-		   (setq link (concat "(" label ")"))
+		   (insert (format coderef-format label))
+		   (setq link (format "file:%s::%s"
+				      (car (last org-src--babel-info))
+				      (concat "(" label ")")))
 		   (setq desc nil)))
 		(t (setq link nil)))))
 
@@ -9852,6 +9853,8 @@ Use TAB to complete link prefixes, then RET for type-specific completion support
 	    (setq path (expand-file-name path)))
 	   ((eq org-link-file-path-type 'relative)
 	    (setq path (file-relative-name path)))
+	   ((eq org-link-file-path-type 'adaptive)
+	    (setq path (file-relative-name path)))
 	   (t
 	    (save-match-data
 	      (if (string-match (concat "^" (regexp-quote
-- 
2.19.1

--
[ stardiviner ]
       I try to make every word tell the meaning what I want to express.
       Blog: https://stardiviner.github.io/
       IRC(freenode): stardiviner
       GPG: F09F650D7D674819892591401B5DF1C95AE89AC3

Reply via email to