From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id moK7J0GqJF+nLwAA0tVLHw (envelope-from ) for ; Fri, 31 Jul 2020 23:33:21 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id yCEWI0GqJF+OcwAA1q6Kng (envelope-from ) for ; Fri, 31 Jul 2020 23:33:21 +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 E0FD294051F for ; Fri, 31 Jul 2020 23:33:20 +0000 (UTC) Received: from localhost ([::1]:44306 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k1eWd-0007gn-Cm for larch@yhetil.org; Fri, 31 Jul 2020 19:33:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37016) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1eWI-0007ga-7k for emacs-orgmode@gnu.org; Fri, 31 Jul 2020 19:32:58 -0400 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]:39189) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k1eWG-0001pl-5E for emacs-orgmode@gnu.org; Fri, 31 Jul 2020 19:32:57 -0400 Received: by mail-pf1-x441.google.com with SMTP id z188so7355132pfc.6 for ; Fri, 31 Jul 2020 16:32:55 -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=Lz2UR3N9NKYpvsLWdC3thQHIIuhjHM4SI43UlJ1OT5E=; b=p9aAJT65AYq2D2jDTKdyIk2s2Bg2rccIH8DhD0ZUHeH41ficTYj+JYz17hxa/ZmUV4 Zsaw4JoQsQUgaqfnynODAIou0XxgtczVn0QBCYTEFex0SumkqzW8UkceGqLi96CTyKpm qvUMKlvWWk2LQoLL5nczQaGRJpwL7tISrg3BX66a7KJvFbtt4LjwFk0PVPEA9epE10/0 Lq7TsYNiudrnfAEfRw4EI1gurxqqN2ASRHCJRc3l2D43wmx+vSH+eQWOur5AQJmdO+mP D33IwHxbxVYNLd9+827asIqKFPrzAaV7XivMAa2hUcpeyNw1XsUPtRsDWJON6y9njHiD YOUQ== 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=Lz2UR3N9NKYpvsLWdC3thQHIIuhjHM4SI43UlJ1OT5E=; b=WmqyMKHd+lEhfoAsr/yx37siMyBfBfztjK8zNx6fskzxFJezZDTAEwV6WLkalP87tO 2FTI+R4LDygIEPGZ0SbwY6JB1fSymqN7aif3RVbJCWb8W0wpOt4+pD5zdaK3j12Hbt4j rdJ1PPtGDr/uhMvp/wNNKnbkS8t3A/GRjW+D6PohUs+8vQcHnL9b0PaBbEHwppUvjJ/q SY+7LG3fOibh47EYEX1+GHKAC9wTJwfQM7yvlep9JMHS2u79A1IlkQvUe4LcVNmIw0Kw zZv3ocEMHg80d0vMmdpGKy691fqhMZ4md2AnKgl1GVCAA5tC2h+ipuhmkury9yI6XIl/ y89g== X-Gm-Message-State: AOAM531WJUp6Ft5IQcsL1f5KI2ZeEqtAHHvkg5Z0ZC5WZXIweN18a8un bYEa4Y7cF63YUJzgjZmb3Us= X-Google-Smtp-Source: ABdhPJwadjoG4nPF9rzU2lwO175fmgfRyX8YC9JmrdgFdQkzCdsOFhvLVBmQ9eyjNNzC99sECYomHw== X-Received: by 2002:a63:9246:: with SMTP id s6mr5584745pgn.22.1596238374020; Fri, 31 Jul 2020 16:32:54 -0700 (PDT) Received: from localhost ([101.99.64.65]) by smtp.gmail.com with ESMTPSA id 199sm12593654pgc.79.2020.07.31.16.32.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2020 16:32:52 -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: <87k0yjoaw7.fsf@gmail.com> References: <87eeos3w7v.fsf@localhost> <87k0yjoaw7.fsf@gmail.com> Date: Sat, 01 Aug 2020 07:32:11 +0800 Message-ID: <877dujz2f8.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::441; envelope-from=yantar92@gmail.com; helo=mail-pf1-x441.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=p9aAJT65; 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: 353YlPh79rPA > 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 us= ing the > =E2=80=98output-dir=E2=80=99 header arguments. If =E2=80=98output-di= r=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-fi= le-path-type) " |\n" > "| (expand-file-name default-directory) | " (expand-fil= e-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 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-buffer= )) 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/yanta= r92/.emacs.d/straight/build/org/) > > > -- > Mvh John --=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