From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:8:6d80::]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 4PdeCoucdWDPvAAAgWs5BA (envelope-from ) for ; Tue, 13 Apr 2021 15:28:43 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id 8J5EBIucdWC8MgAAB5/wlQ (envelope-from ) for ; Tue, 13 Apr 2021 13:28:43 +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 DA2F919FCB for ; Tue, 13 Apr 2021 15:28:42 +0200 (CEST) Received: from localhost ([::1]:44764 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lWJ5s-0002IC-AE for larch@yhetil.org; Tue, 13 Apr 2021 09:28:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45450) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lWJ2C-00007k-4u for emacs-orgmode@gnu.org; Tue, 13 Apr 2021 09:24:52 -0400 Received: from mail-oi1-x22e.google.com ([2607:f8b0:4864:20::22e]:39556) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lWJ26-0005r6-Cc for emacs-orgmode@gnu.org; Tue, 13 Apr 2021 09:24:51 -0400 Received: by mail-oi1-x22e.google.com with SMTP id i81so16960836oif.6 for ; Tue, 13 Apr 2021 06:24:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ddoherty.net; s=google; h=references:user-agent:from:to:cc:subject:date:in-reply-to :message-id:mime-version; bh=sE5uwM4ReFj0d4biy8WePKB4tjNAPTDG3SiyiolBDms=; b=SjI5fgSMxT3SaS9Yswv0Ez5TIVx4BrikyTL+PxT+7ICAzxo0FNcH2PK6jG0NsQRXrH Pna6mmqr2uB119lPMdxBz8RoGz/1EriEH6E5EhH3cCaTQUaEEJhMEV8wFZNwNXg+FR0X SLoNcpMXXu1sfhWv+hTtCfreT9tJfsypZHiZw= 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:date :in-reply-to:message-id:mime-version; bh=sE5uwM4ReFj0d4biy8WePKB4tjNAPTDG3SiyiolBDms=; b=OMuqNFDG1uFlHEh8GbjlfxB2CfOYSAsGu0SrId6U8yTGZCx9OJBgXZbXIBUm3LQdHL Dzc2phHfprbp84JPIefQiURP6CDZwae4gSAJ5IDwyjHpp1htHIHNN3dVyjmJftxdC0ve aIldMU+uNYg7tFE3Swj4Y4srrx8W0EOl21Cbu6+LmH6KEAFXG1fVvhPy/WsXg7m/9GZl v05vqwNDqa7OKhgogU2DP05o8NZlj9Aq3GmC1iXFy/4FgNDdak51KWC74DKO/X4DzmGS /X/BzIQxapW+zDo/JGeixUsxK4H2+G5il0TAlVtegU3YgKocG3xwywKX+rXo3eRgdyIJ wnGw== X-Gm-Message-State: AOAM530TbzvK2L9yhChEVJ9kNbfkbZDI8w2CKjoIlzcWfiIwtKucSlCG 6JksL9T70i6FFq4L6vzMIotK5BNM3R/Dgg== X-Google-Smtp-Source: ABdhPJxVc2u3pQzhSPzgwD+Uy92dg2OtFWxnKXHZ5e8F9J7pD18vEpJvUTo6wO9gBH02wuTZaCX3+w== X-Received: by 2002:a54:4196:: with SMTP id 22mr30598oiy.34.1618320284007; Tue, 13 Apr 2021 06:24:44 -0700 (PDT) Received: from saturn.ddoherty.net ([2605:a601:ac43:6d00:3009:8dda:9d8b:b623]) by smtp.gmail.com with ESMTPSA id 128sm2782903oog.37.2021.04.13.06.24.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Apr 2021 06:24:43 -0700 (PDT) References: <8735w3kshh.fsf@ddoherty.net> <87blaq6glc.fsf@alphaville.usersys.redhat.com> <87k0pdj7p0.fsf@ddoherty.net> <87tuodoo6d.fsf@kyleam.com> User-agent: mu4e 1.5.8; emacs 28.0.50 From: "Daniel E. Doherty" To: Kyle Meyer Subject: Re: Bug: Display Inline Images from Subdirectory [9.4.4 (9.4.4-33-g5450d6-elpaplus @ /home/ded/.emacs.d/elpa/org-plus-contrib-20210322/)] Date: Tue, 13 Apr 2021 08:21:40 -0500 In-reply-to: <87tuodoo6d.fsf@kyleam.com> X-Keywords: Org-Mode Message-ID: <87eefejp0m.fsf@ddoherty.net> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2607:f8b0:4864:20::22e; envelope-from=ded@ddoherty.net; helo=mail-oi1-x22e.google.com 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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-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-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -4.00 Authentication-Results: aspmx1.migadu.com; none X-Migadu-Queue-Id: DA2F919FCB X-Spam-Score: -4.00 X-Migadu-Scanner: scn0.migadu.com X-TUID: uLDinUVfhKtf Kyle, Thanks for the excellent sleuthing. Nailed it. I took your second suggestion, and ended up with the following (for those interested), which works like a charm: ================================= (setq org-startup-with-inline-images t) (require 'subr-x) (defun ded:org-babel-inline-display-subtree () "Redisplay inline images in subtree if cursor in source block with :result graphics." (when (org-in-src-block-p) (let (beg end (default-directory (if-let ((fname (buffer-file-name))) (file-name-directory fname) default-directory))) (save-mark-and-excursion (org-mark-subtree) (setq beg (point)) (setq end (mark))) (when-let ((info (org-babel-get-src-block-info t)) (params (org-babel-process-params (nth 2 info))) (result-params (cdr (assq :result-params params))) ((member "graphics" result-params))) (org-display-inline-images nil nil beg end))))) (add-hook 'org-babel-after-execute-hook #'ded:org-babel-inline-display-subtree) ======================== On Sat, Apr 10 2021, Kyle Meyer wrote: > Daniel E. Doherty writes: > >> Nick, >> >> Thanks for trying this out. I tried this again using emacs -Q with both >> emacs27 and emacs28, and I still get the same result, i.e., it produces >> the link but does not display it inline. Both versions supported >> display of SVG graphics files. > > Hmm, I see the same behavior you're describing: your custom function > doesn't trigger the inline display when :dir is used. > > Let's look at the custom function... > >> | (defun ded:org-babel-inline-display-subtree () >> | "Redisplay inline images in subtree if cursor in source block with >> :result graphics." >> | >> | (when (org-in-src-block-p) >> | (let (beg end) >> | (save-mark-and-excursion >> | (org-mark-subtree) >> | (setq beg (point)) >> | (setq end (mark))) >> | (when-let ((info (org-babel-get-src-block-info t)) >> | (params (org-babel-process-params (nth 2 info))) >> | (result-params (cdr (assq :result-params params))) >> | ((member "graphics" result-params))) >> | (org-display-inline-images nil nil beg end))))) >> | >> | (add-hook 'org-babel-after-execute-hook >> #'ded:org-babel-inline-display-subtree) > > So, org-display-inline-images is probably the place to start debugging. > You can step through its execution [1] and compare the "no :dir" vs > ":dir" cases. When I did that, I noticed that a > > (expand-file-name "dot/lehman.svg") > > leads to a non-existent "/path/to/dot/dot/lehman.svg" (note the > repeating "dot/"). That's because :dir temporarily changes the > directory, and org-babel-after-execute-hook executes in that context. > > To work around that, you could avoid using org-babel-after-execute-hook > and instead advise org-babel-execute-src-block so that your function is > called afterward. Another approach would be to let-bind the > default-directory in your function: > > (when (org-in-src-block-p) > (let ((default-directory (if-let ((fname (buffer-file-name))) > (file-name-directory fname) > default-directory)) > ...) > ...)) > > > [1] (info "(elisp)Instrumenting") -- ==================================================== Daniel E. Doherty Law Offices of Daniel E. Doherty 7300 W. 110th Street, Suite 930 Overland Park, KS 66210 913.338.7182 (Phone) 913.338.7164 (FAX) ded@ddoherty.net