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 uGzCGIVDJ1/BDAAA0tVLHw (envelope-from ) for ; Sun, 02 Aug 2020 22:51:49 +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 YGCZFIVDJ187QwAAbx9fmQ (envelope-from ) for ; Sun, 02 Aug 2020 22:51:49 +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 9F09C9404CF for ; Sun, 2 Aug 2020 22:51:48 +0000 (UTC) Received: from localhost ([::1]:60658 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k2MpX-00014A-Ia for larch@yhetil.org; Sun, 02 Aug 2020 18:51:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37306) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k2MpB-000144-Ha for emacs-orgmode@gnu.org; Sun, 02 Aug 2020 18:51:25 -0400 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]:37963) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k2Mp9-0008TQ-9Z for emacs-orgmode@gnu.org; Sun, 02 Aug 2020 18:51:25 -0400 Received: by mail-pj1-x1036.google.com with SMTP id ep8so1069810pjb.3 for ; Sun, 02 Aug 2020 15:51:22 -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=PYOFCo/DH5n49h1fzhR1B9fAVwrItq2nNwhGHXq4UDw=; b=RFOQ5qaK+ZxGMDdYE2aN08Y2kVZgEol8/YJVkQJtepxiRDvMUX8dJ0bWa8nw9kGjax ni5UYQbVXx+IQ49kzdXIKm+D9b/3VftGZuDUrcXcnPqothUzRIbwYjLxgBSySLI4wf0l UPEntWf0qq4/f0S+AztobCTguGQoEp3Sorpbqsy2wtU8ml2gNUBxiwAIj+NmneQ9euNJ 9nLUf1gdgBZPWX78lkDtocS8G1g8+3s1HNrH21LYnIdO5Rx0+DVseQaqhrNMJDYDyULn NPVOdV5rp3LXTy2dCN9newjgHzRIkWzGm6ggltE8qA66qntU35/976+ZYztCyD0O6CfQ QtKA== 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=PYOFCo/DH5n49h1fzhR1B9fAVwrItq2nNwhGHXq4UDw=; b=JXkP0cVyPLou5M4ryH/pig/sBsGhFE4xl29ij7jLbhtsLr6CCAXE9uzmQrv9xuTbTt 9ozQGL/88wjRLGjcnQBZAS0E7omCer3faR4SH00AVrgJsKvg4DkY6tTWOWxSTcq6ZiPf pm+++uv40TjXqNcFls98eiLwsPLwZZ9wETLzQ4yWJhMW9S8rJ0ZLhvlSRcojX8Xilb30 VJ28TJ/mmbh/3bSTStepKHm3pKnatDIH6xBbF8ZFFgzJ1tOILTfL0FC5iHHJcJYMslhH isWNv2i9iLR2ntJfbY9sU+Tu+edCLnFHgnxg+QZlN8IkSG7EQrEgbAuqEEs/0CAlAYDZ qWwQ== X-Gm-Message-State: AOAM533vbyS08dKV5Cdis30fXbWIUcQ/Nq46r8UGJm4rQgEUDWlCqgoU 2sQkQ0XjYYFQRXcZ7DRvG6g= X-Google-Smtp-Source: ABdhPJx5Fgk3Wk+OraWJ2kDu2KDlCyb6J6dA0FPso0R806unqrusg9OTuQ9UnPuMyzmnPzpP+9R2bg== X-Received: by 2002:a17:90a:6e09:: with SMTP id b9mr4554359pjk.136.1596408681630; Sun, 02 Aug 2020 15:51:21 -0700 (PDT) Received: from localhost ([104.168.14.206]) by smtp.gmail.com with ESMTPSA id u29sm5105287pfl.180.2020.08.02.15.51.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Aug 2020 15:51:20 -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: <877duglulm.fsf@gmail.com> References: <87eeos3w7v.fsf@localhost> <87k0yjoaw7.fsf@gmail.com> <877dujz2f8.fsf@localhost> <87ime2xr4e.fsf@gmail.com> <87lfix1x6n.fsf@localhost> <877duglulm.fsf@gmail.com> Date: Mon, 03 Aug 2020 06:50:34 +0800 Message-ID: <87zh7cy85h.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::1036; envelope-from=yantar92@gmail.com; helo=mail-pj1-x1036.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=RFOQ5qaK; 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: uVYxZGeaAK7z > I don't have a real world scenario, just the one I made up below. I used > that to play around with the function. I see. FYI: I do change default-directory during src block execution in my config. The following code makes src blocks execute inside attachment folder by default: (define-advice org-babel-execute-src-block (:filter-args (&optional args) s= et-detault-dir-to-org-attach-path) "Set working directory to the current entry's attach directory." (if (eq major-mode 'org-mode) (let* ((directory (file-name-as-directory (org-attach-dir 'create-if-= none))) (arg (car args)) (info (cadr args)) (params (org-babel-merge-params (nth 2 info) (caddr args))) (dir-param (alist-get :dir params))) (unless (and dir-param (or (equal (f-full default-directory) (f-ful= l dir-param)) (f-absolute-p dir-param))) (setf (alist-get :dir params) (if dir-param (f-join directory (alist-get :dir params)) directory))) (list arg info params)) (list arg info params))) That's actually how I found the reported bug. Best, Ihor John Herrlin writes: > 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 = 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 value= s. >>>> >>>>> Org first tries to generate the filename from the value of the >>>>> =E2=80=98file=E2=80=99 header argument and the directory specifie= d using the >>>>> =E2=80=98output-dir=E2=80=99 header arguments. If =E2=80=98outpu= t-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-lin= k-file-path-type) " |\n" >>>>> "| (expand-file-name default-directory) | " (expand= -file-name default-directory) " |\n" >>>>> "| (buffer-file-name (buffer-base-buffer)) | " (buf= fer-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 a= nd >>>>>> 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-bu= ffer)) 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+ Versi= on 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/y= antar92/.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