From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id ECsJL5WZJV8aCgAA0tVLHw (envelope-from ) for ; Sat, 01 Aug 2020 16:34:29 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id cCThKpWZJV/6EgAAB5/wlQ (envelope-from ) for ; Sat, 01 Aug 2020 16:34:29 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 3961B9403D6 for ; Sat, 1 Aug 2020 16:34:29 +0000 (UTC) Received: from localhost ([::1]:52016 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k1uSp-00071H-EW for larch@yhetil.org; Sat, 01 Aug 2020 12:34:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48634) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1uST-000712-UL for emacs-orgmode@gnu.org; Sat, 01 Aug 2020 12:34:05 -0400 Received: from mail-lf1-x142.google.com ([2a00:1450:4864:20::142]:46559) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k1uSS-0003Hf-3u for emacs-orgmode@gnu.org; Sat, 01 Aug 2020 12:34:05 -0400 Received: by mail-lf1-x142.google.com with SMTP id i80so18380189lfi.13 for ; Sat, 01 Aug 2020 09:34:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=references:user-agent:from:to:cc:subject:in-reply-to:message-id :date:mime-version:content-transfer-encoding; bh=NNg3MbP51GDdk9t4/5/brmtkhquVKuOXkynvHd0eYqg=; b=F+eyAFzqBMPjotLLhioASfJtF5O0itkGdEJ9NMmECqJRsqtT+yazZqwOH0LbRVxxBu pJukHdDl/HeA0OKnSXiGIRRXqivdTwGVbKplX5HuhAZtDOhUZf6kOVA6krVhNyJIymiS pK5wfG5P1ElLweSz2e//yNZnfOULfNnyq3siLh8pXk5ioIegdj/k3SBSELbRlX/spYtn TH2vxLCfoxiigHabDQD8bCqVI2KesC/1gbo0sceBoWgrPe90J/QlOEzy0fR4MEqsfUWt +kb2vkevs2sjd4+vXqd0qgbZmyQw6ak4tbfWg6JPmyp8OPQtzgJpuXu+jjYimoXetxJR 9hvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:cc:subject :in-reply-to:message-id:date:mime-version:content-transfer-encoding; bh=NNg3MbP51GDdk9t4/5/brmtkhquVKuOXkynvHd0eYqg=; b=Svn2FPCAobvnfF20zM0IhuXC5byWW3D4lP5Xs27gkfyUUG40n3ORjItCCWDczNjy2K 6lRvhz71Fd9zilcRaeGGQ4d6PkNKEtgCxN4GJg5+NfLNjl8Wans4BqYAwc3NsXKJgd/f pYQ1lEbPfVKXD7/EkciTBDwy33siMUyVLgeZGZQhjLJ0lijU/BPsouSIxw8+HBr4NdRb bTP1nhtN0zg6yn+mHtx1/IdWkdJQ7AHiGdauNXRY8/Ya6BAI/So6fGtBfMl/YZWgM/EQ f7h67lslziIFuJT9uC315ZZNqRO3BgWQLPsWEphaOkxv2E/tHBBcL0IHhvMPeGwO9Ofu aDtw== X-Gm-Message-State: AOAM530yZ8vHsWcyEIoYrpGQN8HqtxjI/qxxnevuiKaSbuTFq87Dxk57 QQ5i0dozE6kxBKoq86CBj7vbGLrn X-Google-Smtp-Source: ABdhPJyiuSIxV+3rtRCw/S/R3tQ7bOGhLjndfI6605+mA2GSPl86oOpbWUdJj+o2+ZGB0wO4O/iOhg== X-Received: by 2002:a19:4f11:: with SMTP id d17mr4648183lfb.48.1596299641485; Sat, 01 Aug 2020 09:34:01 -0700 (PDT) Received: from arch ([98.128.186.110]) by smtp.gmail.com with ESMTPSA id p25sm460499ljn.58.2020.08.01.09.33.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Aug 2020 09:34:00 -0700 (PDT) References: <87eeos3w7v.fsf@localhost> <87k0yjoaw7.fsf@gmail.com> <877dujz2f8.fsf@localhost> User-agent: mu4e 1.4.10; emacs 26.3 From: John Herrlin To: Ihor Radchenko Subject: Re: Bug: [patch] Fix org-babel-result-to-file never expanding links when babel is evaluated in indirect buffer [9.3.7 (release_9.3.7-728-g1efc4e @ /home/yantar92/.emacs.d/straight/build/org/)] In-reply-to: <877dujz2f8.fsf@localhost> Message-ID: <87ime2xr4e.fsf@gmail.com> Date: Sat, 01 Aug 2020 18:33:54 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=2a00:1450:4864:20::142; envelope-from=jherrlin@gmail.com; helo=mail-lf1-x142.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: emacs-orgmode@gnu.org Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=F+eyAFzq; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Spam-Score: 3.29 X-TUID: szcy7lqgWQEv It's intended to change directory and dont clone base buffer values. I tried to accomplish "If the `default-directory' is different from the containing file's directory then expand relative links." As I understands it that's when it inserts a relative link, otherwise it just `result'. I was looking from the indirect buffers point of view and from there the relative link is off in this case. But from the base buffers point of view everything works fine. I guess that it was my use case that is strange. Looks good! Best regards John >> In my case the result is a relative link, but if I follow the link I end >> up in the wrong place. > > Do you mean that the generated script.sh ends up in your home dir? > It is expected since default-directory in your buffer is "~/": > >> (dired "~/") >> (make-indirect-buffer "tmp.org" "tmp-indirect") > > Note that you called make-indirect-buffer without third argument. > > According to manual: > >> (make-indirect-buffer BASE-BUFFER NAME &optional CLONE) >> CLONE nil means the indirect buffer's state is reset to default values. > >> Org first tries to generate the filename from the value of the >> =E2=80=98file=E2=80=99 header argument and the directory specified u= sing the >> =E2=80=98output-dir=E2=80=99 header arguments. If =E2=80=98output-d= ir=E2=80=99 is not specified, >> Org assumes it is the current directory. > > No surprise you got your file in the default-directory (~/). > > If you use (make-indirect-buffer "tmp.org" "tmp-indirect" t) instead, > the script.sh link will be relative, as expected. > > Let me know if I miss something. > > Best, > Ihor > > >> Hey Ihor, >> >> Could not get the patch to work. >> >> I used this use case. >> >> (with-current-buffer >> (find-file "/tmp/tmp.org") >> (insert "* A\n** b\n** c\n\n some text") >> (dired "~/") >> (make-indirect-buffer "tmp.org" "tmp-indirect") >> (switch-to-buffer "tmp-indirect") >> (goto-char (point-max)) >> (funcall 'org-mode) >> (insert (concat "\n\n| default-directory | " default-directory " |\n" >> "| org-link-file-path-type | " (symbol-name org-link-f= ile-path-type) " |\n" >> "| (expand-file-name default-directory) | " (expand-fi= le-name default-directory) " |\n" >> "| (buffer-file-name (buffer-base-buffer)) | " (buffer= -file-name (buffer-base-buffer)) " |\n")) >> (org-table-align) >> (insert "\n\n#+BEGIN_SRC shell :results file :file script.sh >> echo \"#!/bin/bash\" >> echo \"echo Hey\"\n#+END_SRC") >> (org-babel-execute-src-block)) >> >> In my case the result is a relative link, but if I follow the link I end >> up in the wrong place. >> >> src_emacs-lisp{emacs-version} {{{results(=3D26.3=3D)}}} >> src_emacs-lisp{org-version} {{{results(=3D9.3.7=3D)}}} >> >> Best regards >> John >> >> >> Ihor Radchenko writes: >> >>> Remember to cover the basics, that is, what you expected to happen and >>> what in fact did happen. You don't know how to make a good report? See >>> >>> https://orgmode.org/manual/Feedback.html#Feedback >>> >>> Your bug report will be posted to the Org mailing list. >>> ------------------------------------------------------------------------ >>> >>> I noticed that org-babel-result-to-file never expands file: links in >>> src block results when ran from indirect buffer and default-directory >>> is not same with base buffer file's directory. This is against the >>> docstring stating that >>> >>>> If the `default-directory' is different from the containing >>>> file's directory then expand relative links. >>> >>> The misbehavior happens because buffer-file-name variable is always >>> nil in indirect buffers. We need to call (file-name-directory >>> (buffer-file-name (buffer-base-buffer))) instead. >>> >>> The patch is attached. >>> >>> Best, >>> Ihor >>> >>> diff --git a/lisp/ob-core.el b/lisp/ob-core.el >>> index f86282f0f..d37eef5f9 100644 >>> --- a/lisp/ob-core.el >>> +++ b/lisp/ob-core.el >>> @@ -2561,16 +2561,16 @@ If the `default-directory' is different from th= e containing >>> file's directory then expand relative links." >>> (when (stringp result) >>> (let ((same-directory? >>> - (and buffer-file-name >>> + (and (buffer-file-name (buffer-base-buffer)) >>> (not (string=3D (expand-file-name default-directory) >>> - (expand-file-name >>> - (file-name-directory buffer-file-name))))))) >>> + (expand-file-name >>> + (file-name-directory (buffer-file-name (buffer-base-buffer))))= ))))) >>> (format "[[file:%s]%s]" >>> - (if (and default-directory buffer-file-name same-directory?) >>> + (if (and default-directory (buffer-file-name (buffer-base-buffe= r)) same-directory?) >>> (if (eq org-link-file-path-type 'adaptive) >>> (file-relative-name >>> (expand-file-name result default-directory) >>> - (file-name-directory (buffer-file-name))) >>> + (file-name-directory (buffer-file-name (buffer-base-buffer)))) >>> (expand-file-name result default-directory)) >>> result) >>> (if description (concat "[" description "]") ""))))) >>> >>> Emacs : GNU Emacs 28.0.50 (build 4, x86_64-pc-linux-gnu, GTK+ Version = 3.24.20, cairo version 1.16.0) >>> of 2020-07-27 >>> Package: Org mode version 9.3.7 (release_9.3.7-728-g1efc4e @ /home/yant= ar92/.emacs.d/straight/build/org/)