From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id YKfjHpi6hmdbBgEAe85BDQ:P1 (envelope-from ) for ; Tue, 14 Jan 2025 19:27:20 +0000 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id YKfjHpi6hmdbBgEAe85BDQ (envelope-from ) for ; Tue, 14 Jan 2025 20:27:20 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=chen-becker.org header.s=google header.b=VgrmkpMs; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1736882840; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=gqzOvpBebxP674K0IphUdf6QIajeykQxor8J3KEkw3I=; b=WndENybNi05D6aFK3LyB8RaQ0CpS8MjkDJ6GSEUy7XKRyjNZGa+fs2sqmflDxxtRq4DRGL 7sFVMm6iaYGPiXgmISwyKdaLUVFvdv9kJhxZX8Ejw1hGYVaffjj5pmgv5tyJeo5G0oCDhb d9m2CRPudNKwXR66dzwDwCteTNhvXhGpjT0H4AJb0P1+jllHAO6512mi2UT9EzPCq3A1xa LTvtOn5KK9hyc50FRyZL4ejOSDhGzzYyF/WssnkFQUxNrhqzGS6SLUOT4i1MAQiqrlZYh9 P1KIEqYV+J41t8xGAIidfdL3fN1YMU5nXDmch0bmP2z/QCkWFsM6hBkeo13OgQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=chen-becker.org header.s=google header.b=VgrmkpMs; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=none ARC-Seal: i=1; s=key1; d=yhetil.org; t=1736882840; a=rsa-sha256; cv=none; b=uE1PDPJBSsyhyBS+H2Avc9xAE6AiFj6SMNcflp4I6Git9Oy3PstM/e+U0oQwf4mCXB0JfX Kp5IqdckrTI1LtDDbUfZyISriyCec96xIiUMgSRVow2xIRk15kUZ/7CN/u0+/RdijUiPCU LXGgTyWAVLrRqIcqLwutBkq0549iwLDM9uPpKeltS5mmhFKjSwEKOt9GJvzF4BJsbuCGAi yXL/Oir8xEeY0JhEe7heTK9EwV5gJ2u13Hmr4Pi+UZV0xbrxmIExKA33+GvtW0PbAg6oNG NLwsFs/+FIwJ76YgDYWPUANT5VPAc7JC+ewWsy/cQjBowNgqPXB31GNe1/NQRg== 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 8BF3B7045 for ; Tue, 14 Jan 2025 20:27:19 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tXmYX-0002LO-Db; Tue, 14 Jan 2025 14:26:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tXmYS-0002KO-Di for emacs-orgmode@gnu.org; Tue, 14 Jan 2025 14:26:25 -0500 Received: from mail-vs1-xe2a.google.com ([2607:f8b0:4864:20::e2a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tXmYM-00075o-O2 for emacs-orgmode@gnu.org; Tue, 14 Jan 2025 14:26:21 -0500 Received: by mail-vs1-xe2a.google.com with SMTP id ada2fe7eead31-4affab62589so1872014137.1 for ; Tue, 14 Jan 2025 11:26:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chen-becker.org; s=google; t=1736882776; x=1737487576; darn=gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=gqzOvpBebxP674K0IphUdf6QIajeykQxor8J3KEkw3I=; b=VgrmkpMsB5hWXMwapHECCsP5UKeAsNgQqiy1KEfxQfPxbZwqwjTvuc9rbY2E60Hb0p 3UZLziDbx0xy4hxPH2FetC3WGlprBJElY5dCXBdjvRX0bBSoGYMQf9tELVndCxlU2zc3 wdAlOQ48zdqbU1VLNPKlr4d/WFj8jhItbsnAa42FxPTQMLz2jh0QfJ4OYRyxcN2hiv4M 4QPDkkYW7BvCe6x2nu6bboIFXRIF2PCiw/yEkjQR/Kv0j8a/FtaIYmOFOKbGfu8WjpYc X2jLLe86V6WDHaoC4RmeYrgdzBFbOtg/As5fsTlUarBGpdac5dGX9Fl/9RTAJ0NZvBqT Yg5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736882776; x=1737487576; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=gqzOvpBebxP674K0IphUdf6QIajeykQxor8J3KEkw3I=; b=wiY/p1o3DRn8B5rsIeW/VpAh3OKgEq5UeplpKEcG1Oa1HKEoy5kGB5vTmcBjc9n6mN SWRBzGob9G2dgY+rz6Iw+BZCj/0FUq6/xucUC+2mYcl9CxkLhLmRozEy2/xihxJN9FW8 UyqXWNi28G6L+urQUFXPu+pC9GbYS+mfFulqHff4HZgsJFwxRWzB0BX4dXSr2AIjEeiT nUIpZooGBXtdbvPs/ztAMmv3sNVnA7MbqnvBlbduGu0mhtfUx3c8sR3EQOEOxfCVlRUY 3Wj9qWwqLYUEHrmb8JFAGxFT91zpsX9Zo5vwfTApNITZ0EU9uh1OcsJR5yiwbgv93rSZ C9Wg== X-Gm-Message-State: AOJu0YwoMJi/Tsn7wyE9/UzEix3C0xhVD/zy31bzpZZ9F0km1adYIO/e OV+8Y+vU+7ixXRQ5Mb0EtpdzohACKMREu4hLaJSz1yN45pDgSuHrlelVoCuQhR1E8MGU/5djGN7 CfJdR2izvY/4hYaDONZUUWQEJa5REMi+SSbLA+Ic3sSxhuODg X-Gm-Gg: ASbGncuhpTuWouAz+w4DCedLA1mg1yedB0hIgFBOAikzv5yqbZSQzsCWUFKMgOmW4qX jVGZMBli01NXg9pysTQw20mmH5WoBGN3XNZ42p+0= X-Google-Smtp-Source: AGHT+IFJLMGNhwUaDaFYfF0K+DXhRjGHNDeJdK026G3knj/61oqHlHQsl0d0jVbvS2N6PNYTGDfridZlfp/7K5Sr6As= X-Received: by 2002:a05:6102:3595:b0:4b5:aa82:926d with SMTP id ada2fe7eead31-4b5aa8297fdmr18910217137.6.1736882776429; Tue, 14 Jan 2025 11:26:16 -0800 (PST) MIME-Version: 1.0 References: <2dijBN1CGUPtmZzcNXZAe54y8u0pC8V_DYIBCL4rSR1eh2s8TFJGW5V3q7pkiCRFtEHYXy66CU7F6kK3NN_VAX-R_RbAXptG0b5vOlUQsi8=@protonmail.com> <87y15bcbi1.fsf@localhost> <877c7zede2.fsf@localhost> <874j2z7a8u.fsf@localhost> <87ttatigrx.fsf@localhost> <87msfxd81c.fsf@localhost> <87sepox9oy.fsf@localhost> <87wmey7hmb.fsf@localhost> <87v7uhe0tg.fsf@localhost> In-Reply-To: <87v7uhe0tg.fsf@localhost> From: Derek Chen-Becker Date: Tue, 14 Jan 2025 12:26:05 -0700 X-Gm-Features: AbW1kvYkvD-o6MjvmfJiayCuUfrYd-mjL2zEZnfthwhZ1hHBOPUYcZnWC0XxU8I Message-ID: Subject: Re: [BUG] Cannot tangle src block in capture buffer [9.7.6] To: Ihor Radchenko Cc: emacs-orgmode@gnu.org Content-Type: multipart/alternative; boundary="000000000000e7fb0c062baf8831" Received-SPF: pass client-ip=2607:f8b0:4864:20::e2a; envelope-from=derek@chen-becker.org; helo=mail-vs1-xe2a.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, HTML_MESSAGE=0.001, 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.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Queue-Id: 8BF3B7045 X-Migadu-Scanner: mx13.migadu.com X-Migadu-Spam-Score: 1.06 X-Spam-Score: 1.06 X-TUID: lettNL10Hodr --000000000000e7fb0c062baf8831 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thanks for the comments! This is my first real foray into non-trivial elisp so I really appreciate your patience and help. Let me try and get these addressed. Cheers, derek On Tue, Jan 14, 2025 at 10:54=E2=80=AFAM Ihor Radchenko wrote: > Derek Chen-Becker writes: > > > Thanks for the help on this! I've reworked the changes into two patches > > (one for the README and one for tangle) and I think I've covered your > > concerns. I also added a unit test for the org-base-buffer-file-name > > function to cover the miss on provided buffers. Please let me know if y= ou > > have any questions. > > Thanks! > Although, I am afraid that the second set of unit tests is a bit much > - they no longer fit within TINYCHANGE (15-20 significant LOC). > We have a legal limit on how much code we can accept without requiring > copyright assignment. See > https://orgmode.org/worg/org-contribute.html#copyright > > More comments below. > > > * lisp/ob-tangle.el (org-babel-tangle): Update to utilize the new > > org-base-buffer-file-name function. > > Our convention is to quote Elisp symbols in commit messages like `this'. > > > The previous use of buffer-file-name would fail inside of a capture > buffer > > because it is indirect and does not have an associated filename. This > > Another convention is double space between sentences. > > > +(defun org-base-buffer-file-name (&optional BUFFER) > > Elisp convention is to use lower case for function arguments. > Upper case in the docstring is used to highlight the function arguments; > it does not mean that the arguments themselves need to be in upper case. > > > + (if (buffer-base-buffer BUFFER) > > + (buffer-file-name (buffer-base-buffer BUFFER)) > > + (buffer-file-name BUFFER))) > > Nit: Can also use `if-let*' to avoid calling `buffer-base-buffer' twice. > > > +;; See https://list.orgmode.org/87msfxd81c.fsf@localhost/T/#t > > +(ert-deftest ob-tangle/tangle-from-capture-buffer () > > + "Test tangling of source blocks from within a capture buffer. > > +This is to ensure that we properly resolve the buffer name." > > + (org-test-with-temp-text-in-file > > + "* Header\n\nCapture after this point:\n" > > + (should > > + (unwind-protect > > + (progn > > + (let ((org-capture-templates '(("t" "Test" entry (here) "* > Test Header\n\n")))) > > + (org-capture nil "t") > > + (goto-char (point-max)) > > + (insert " > > +#+begin_src elisp :tangle yes :comments org > > + (message \"FOO\") > > +#+end_src") > > + (search-backward "message") > > + (org-babel-tangle 4))) > > + ;; Clean up the tangled file with the filename from > org-test-with-temp-text-in-file > > + (delete-file (format "%s.el" file)))))) > > This is not the best style. > While technically `file' variable will be let-bound within the > `org-test-with-temp-text-in-file' body, it is an internal implementation > detail that we should not rely upon. Instead, it is a good idea to > examine `buffer-file-name' inside the macro body to get the file name. > > Also, what if "%s.el" file does not exist? Say, tangling does happen, > but to a wrong file. Note that `delete-file' does not throw any error > when there is nothing to delete. > > -- > Ihor Radchenko // yantar92, > Org mode maintainer, > Learn more about Org mode at . > Support Org development at , > or support my work at > --=20 +---------------------------------------------------------------+ | Derek Chen-Becker | | GPG Key available at https://keybase.io/dchenbecker and | | https://pgp.mit.edu/pks/lookup?search=3Dderek%40chen-becker.org | | Fngrprnt: EB8A 6480 F0A3 C8EB C1E7 7F42 AFC5 AFEE 96E4 6ACC | +---------------------------------------------------------------+ --000000000000e7fb0c062baf8831 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thanks for the comments! This is my fir= st real foray into non-trivial elisp so I really appreciate your patience a= nd help. Let me try and get these addressed.

Cheers,

derek

On Tue, Jan 14, 2025 at 10:54=E2= =80=AFAM Ihor Radchenko <yantar92= @posteo.net> wrote:
Derek Chen-Becker <derek@chen-becker.org> writes:

> Thanks for the help on this! I've reworked the changes into two pa= tches
> (one for the README and one for tangle) and I think I've covered y= our
> concerns. I also added a unit test for the org-base-buffer-file-name > function to cover the miss on provided buffers. Please let me know if = you
> have any questions.

Thanks!
Although, I am afraid that the second set of unit tests is a bit much
- they no longer fit within TINYCHANGE (15-20 significant LOC).
We have a legal limit on how much code we can accept without requiring
copyright assignment. See https://orgmode.org/= worg/org-contribute.html#copyright

More comments below.

> * lisp/ob-tangle.el (org-babel-tangle): Update to utilize the new
> org-base-buffer-file-name function.

Our convention is to quote Elisp symbols in commit messages like `this'= .

> The previous use of buffer-file-name would fail inside of a capture bu= ffer
> because it is indirect and does not have an associated filename. This<= br>
Another convention is double space between sentences.

> +(defun org-base-buffer-file-name (&optional BUFFER)

Elisp convention is to use lower case for function arguments.
Upper case in the docstring is used to highlight the function arguments; it does not mean that the arguments themselves need to be in upper case.
> +=C2=A0 (if (buffer-base-buffer BUFFER)
> +=C2=A0 =C2=A0 =C2=A0 (buffer-file-name (buffer-base-buffer BUFFER)) > +=C2=A0 =C2=A0 (buffer-file-name BUFFER)))

Nit: Can also use `if-let*' to avoid calling `buffer-base-buffer' t= wice.

> +;; See https://list.orgmode.org/87msfxd8= 1c.fsf@localhost/T/#t
> +(ert-deftest ob-tangle/tangle-from-capture-buffer ()
> +=C2=A0 "Test tangling of source blocks from within a capture buf= fer.
> +This is to ensure that we properly resolve the buffer name."
> +=C2=A0 (org-test-with-temp-text-in-file
> +=C2=A0 =C2=A0"* Header\n\nCapture after this point:\n<point&g= t;"
> +=C2=A0 =C2=A0(should
> +=C2=A0 =C2=A0 (unwind-protect
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 (progn
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (let ((org-capture-templates '= (("t" "Test" entry (here) "* Test Header\n\n"= ))))
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (org-capture nil "t&qu= ot;)
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (goto-char (point-max))
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (insert "
> +#+begin_src elisp :tangle yes :comments org
> +=C2=A0 (message \"FOO\")
> +#+end_src")
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (search-backward "mess= age")
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (org-babel-tangle 4)))
> +=C2=A0 =C2=A0 =C2=A0 ;; Clean up the tangled file with the filename f= rom org-test-with-temp-text-in-file
> +=C2=A0 =C2=A0 =C2=A0 (delete-file (format "%s.el" file)))))= )

This is not the best style.
While technically `file' variable will be let-bound within the
`org-test-with-temp-text-in-file' body, it is an internal implementatio= n
detail that we should not rely upon. Instead, it is a good idea to
examine `buffer-file-name' inside the macro body to get the file name.<= br>
Also, what if "%s.el" file does not exist? Say, tangling does hap= pen,
but to a wrong file. Note that `delete-file' does not throw any error when there is nothing to delete.

--
Ihor Radchenko // yantar92,
Org mode maintainer,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,=
or support my work at <https://liberapay.com/yantar92>


--
+-----------------------------------------------------------= ----+
| Derek Chen-Bec= ker=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0|
| GPG Key available at https://= keybase.io/dchenbecker = and=C2=A0 =C2=A0 =C2=A0 =C2=A0|
| Fngrprnt: EB8A 6480 F0A3 C8EB C1E7=C2=A0 7F42 AFC5 AFEE 96E4 6ACC= =C2=A0 |
+------------= ---------------------------------------------------+

<= /div>
--000000000000e7fb0c062baf8831--