From mboxrd@z Thu Jan 1 00:00:00 1970 From: stardiviner Subject: Re: coderef does not provide file path for org-insert-link when not in original buffre Date: Wed, 24 Oct 2018 10:51:47 +0800 Message-ID: <875zxst5to.fsf@gmail.com> References: <87po1zvw9n.fsf@gmail.com> <87bmc1tb4s.fsf@nicolasgoaziou.fr> <87va6wk3ea.fsf@gmail.com> <875zysr0bb.fsf@nicolasgoaziou.fr> Reply-To: numbchild@gmail.com Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:56646) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gF9H1-0004eZ-7i for emacs-orgmode@gnu.org; Tue, 23 Oct 2018 22:51:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gF9Gw-0008Rl-OO for emacs-orgmode@gnu.org; Tue, 23 Oct 2018 22:51:55 -0400 Received: from [61.175.244.13] (port=51989 helo=dark.localdomain) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gF9Gv-0008Pi-Tq for emacs-orgmode@gnu.org; Tue, 23 Oct 2018 22:51:50 -0400 In-reply-to: <875zysr0bb.fsf@nicolasgoaziou.fr> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Nicolas Goaziou Cc: org-mode --=-=-= Content-Type: text/plain Nicolas Goaziou 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. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-org.el-fix-org-coderef-does-not-support-adaptive-fil.patch >From 6e8469545185a41d22b8046ebb367c3c742f0ff4 Mon Sep 17 00:00:00 2001 From: stardiviner 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 --=-=-= Content-Type: text/plain -- [ 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 --=-=-=--