From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id APsUDvUSJ1+KYQAA0tVLHw (envelope-from ) for ; Sun, 02 Aug 2020 19:24:37 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id MCK9CfUSJ18yJwAAbx9fmQ (envelope-from ) for ; Sun, 02 Aug 2020 19:24:37 +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 8A4669403CB for ; Sun, 2 Aug 2020 19:24:36 +0000 (UTC) Received: from localhost ([::1]:41030 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k2Jb1-0008Mu-IW for larch@yhetil.org; Sun, 02 Aug 2020 15:24:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56420) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k2Jag-0008Ml-58 for emacs-orgmode@gnu.org; Sun, 02 Aug 2020 15:24:14 -0400 Received: from mail-lf1-x144.google.com ([2a00:1450:4864:20::144]:46937) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k2Jad-00018b-K6 for emacs-orgmode@gnu.org; Sun, 02 Aug 2020 15:24:13 -0400 Received: by mail-lf1-x144.google.com with SMTP id i80so19345071lfi.13 for ; Sun, 02 Aug 2020 12:24:11 -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=nIKT7WITTZpY951KIjLo3WB/h/FtPGKfOcDcck/PvyY=; b=djTaRvDaM5CrgPxyxKKBM9rwQYKzyqBCQDhNZG2mkLsjgWZ/9rzezVykDtC/Te92Zb bObUQkGpPWCvRY/Y6bPG9q1FgBa9Xl8YCdoRQba2OWaTKvoFNsPXf6TJhTFPxpwHxA3U 5F3ZTjmma/MRH+MncenymxRhsQnsIqkG7DP0HVppKWHI0b/NJQljtu1KzDlcwq6oZlNo UdGkkV/3yTo/CI//lZvaj2ctwMSmJsglOVhkFOJ40YZiWXSvK73NB58L7T+PjZsNntoA SjZzRIkA0gkpCXfOw649C6X2+fwraEeUV7hLuEWDYUuDSLxZDzu7fzyUA+TSQeIutnIk pcRA== 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=nIKT7WITTZpY951KIjLo3WB/h/FtPGKfOcDcck/PvyY=; b=FyeYvhRnIxFs3v2sHYX7iPQ9SB2eB9cNZ6sU+p/QXQAmCa/5uIeJAofNDJsS9y9Yly 92BxY6eaSVTgZMlbmV9t/36s/jKxSOyu+5syMJJvhUACCn9Dqo+fQ5HJx9PBVMs5iB2P UReX634bwlMjQZ6JR1KCt1xmf1kpUIDp8fo3qIFdVnL2FOVt9cExCKmyBfcQWh6HiGg1 CEZp26GTCXd3/yoN4P1COqkmUqSB8LbEwJH4UdW2TribT5FBzvgsn8iOKmUfzfnELT4N dfbYEzZDeYXyk8d42GTMKdkcQWgjs6OI2PKjsmUjA/Ut+Tcsn7sxHqntxcVwbbwOAfgC l7rg== X-Gm-Message-State: AOAM5315KAQjiL8Z7mDl+31GIQTViBTPItJTp6GZgaa4QYN4MmrYH5eJ qgioyf9Ck75axCqu9HWzlRWa1R2+ X-Google-Smtp-Source: ABdhPJybDDV8vzUgPag/CS108rTg2Iq76ubm3Z99h5ncRp150QKy7l/viWmbMlCTVkmJ+S3Ao3P09w== X-Received: by 2002:a19:9149:: with SMTP id y9mr6909999lfj.81.1596396248890; Sun, 02 Aug 2020 12:24:08 -0700 (PDT) Received: from arch ([98.128.186.72]) by smtp.gmail.com with ESMTPSA id f24sm3908407ljc.99.2020.08.02.12.24.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Aug 2020 12:24:08 -0700 (PDT) References: <87eeos3w7v.fsf@localhost> <87k0yjoaw7.fsf@gmail.com> <877dujz2f8.fsf@localhost> <87ime2xr4e.fsf@gmail.com> <87lfix1x6n.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: <87lfix1x6n.fsf@localhost> Message-ID: <877duglulm.fsf@gmail.com> Date: Sun, 02 Aug 2020 21:24:06 +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::144; envelope-from=jherrlin@gmail.com; helo=mail-lf1-x144.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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=ham 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=djTaRvDa; 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: -1.71 X-TUID: nvyVVRMjGLRW Ihor Radchenko writes: >> 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." > > Not sure if I understand your use-case. Can you explain why you need to > achieve such behaviour? There might be an easier way to get what you > want. I don't have a real world scenario, just the one I made up below. I used that to play around with the function. Best regards John > > Best, > Ihor > > > John Herrlin writes: > >> 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 e= nd >>>> 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= using the >>>> =E2=80=98output-dir=E2=80=99 header arguments. If =E2=80=98output= -dir=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= -file-path-type) " |\n" >>>> "| (expand-file-name default-directory) | " (expand-= file-name default-directory) " |\n" >>>> "| (buffer-file-name (buffer-base-buffer)) | " (buff= er-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 e= nd >>>> 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 = the 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-buf= fer)) 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+ Versio= n 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/ya= ntar92/.emacs.d/straight/build/org/)