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 cDjTECRDJl+KQwAA0tVLHw (envelope-from ) for ; Sun, 02 Aug 2020 04:37:56 +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 YI2DDCRDJl+EIwAAbx9fmQ (envelope-from ) for ; Sun, 02 Aug 2020 04:37:56 +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 74F599403E7 for ; Sun, 2 Aug 2020 04:37:55 +0000 (UTC) Received: from localhost ([::1]:47898 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k25ku-0007BI-KH for larch@yhetil.org; Sun, 02 Aug 2020 00:37:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52194) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k25kP-0007B8-Cd for emacs-orgmode@gnu.org; Sun, 02 Aug 2020 00:37:21 -0400 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]:38518) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k25kN-0000Ce-At for emacs-orgmode@gnu.org; Sun, 02 Aug 2020 00:37:21 -0400 Received: by mail-pl1-x641.google.com with SMTP id m16so19165357pls.5 for ; Sat, 01 Aug 2020 21:37:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:in-reply-to:references:date:message-id :mime-version:content-transfer-encoding; bh=MMeKMlTnhIf9j5pD2ZIKxZS3yyEwysdiLvopNb3Fp2o=; b=H6SCg3doDHZL2//Rgn6TGfgMwOoEWs+yncR1Dmj9qE17VcRjc6Mco2ybZswdLHdt/S UXkQpkhqMrnlk5oLl1CZwFicKyuSc3JGTYy/Wgof/8m03Nbnzt94fCUnUg/F763Ci97r GpMZ4OETYiRlCH62zV/ke6cyN8EyvaOplHCGLfhm3KumdmfESX7WDD6IAMG+9D0XcVx8 yGSeeuLOB3NquLfwCBPjF86Ojcu3+m1+FZDBmejRhUQSsIPkcJJtZe524kiURV8irXNr Lldu9Eu+LPXN8310cYqF/75gpjuQyXES7IRLIDR41N3+RvrOn8u6wuLgFFmp+rso2WUx U6DQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version:content-transfer-encoding; bh=MMeKMlTnhIf9j5pD2ZIKxZS3yyEwysdiLvopNb3Fp2o=; b=T4cilf6YnF6cMFGl8/0QnGYx+5auSSsfzHGHryAqRXsF4qnYsBDOZS/dKf3pF/fLOm 1vNKXuzFimeJ7jTGAbBqojNlPq0rAM0allDzDuxfhmU2EuBbgFw82pawTXkKjwQz2nNG 5SuqEDAaRrRZr5H4KuoKoF2D2wDrIMPvuAHug5Rxc5thOCxmV0jHoaX0+OB0OwRDO7ie 377GSxZAomKseUwfmTXGad42iDnhDa7kgdPgfYMmZXF9/8X9XO5J9WK+3lzGygx42gmC fQIUPmhBMBuwhGJb1AbZtW+q3yRHdRDzCk1Nd0pInbuX9vSdLszHLtM5SQ2dCjeFNrQD HtFA== X-Gm-Message-State: AOAM531D0JJKsZBSxyiCQ4ql9tYQWPAWjXFzt4H/rwsgksYEfsoYgvhA cdH9tT1G3kL2FfaoEnnzzTA= X-Google-Smtp-Source: ABdhPJxt48AIEok0eQOXNxYkDCVXdDJGEXrrWeACfXFid0sriYG3ell+PnJtWEPjKaGIiPkvsCFAYw== X-Received: by 2002:a17:902:7244:: with SMTP id c4mr9775550pll.277.1596343037108; Sat, 01 Aug 2020 21:37:17 -0700 (PDT) Received: from localhost ([104.168.14.206]) by smtp.gmail.com with ESMTPSA id il10sm4066683pjb.54.2020.08.01.21.37.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Aug 2020 21:37:16 -0700 (PDT) From: Ihor Radchenko To: John Herrlin 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: <87ime2xr4e.fsf@gmail.com> References: <87eeos3w7v.fsf@localhost> <87k0yjoaw7.fsf@gmail.com> <877dujz2f8.fsf@localhost> <87ime2xr4e.fsf@gmail.com> Date: Sun, 02 Aug 2020 12:36:16 +0800 Message-ID: <87lfix1x6n.fsf@localhost> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=2607:f8b0:4864:20::641; envelope-from=yantar92@gmail.com; helo=mail-pl1-x641.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: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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_ENVFROM_END_DIGIT=0.25, 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=H6SCg3do; 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.21 X-TUID: 9QAbMRewhviW > 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. 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 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 = 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-f= ile-name default-directory) " |\n" >>> "| (buffer-file-name (buffer-base-buffer)) | " (buffe= r-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? S= ee >>>> >>>> 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 t= he 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-buff= er)) 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/yan= tar92/.emacs.d/straight/build/org/) --=20 Ihor Radchenko, PhD, Center for Advancing Materials Performance from the Nanoscale (CAMP-nano) State Key Laboratory for Mechanical Behavior of Materials, Xi'an Jiaotong U= niversity, Xi'an, China Email: yantar92@gmail.com, ihor_radchenko@alumni.sutd.edu.sg