From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:1008:1e59::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id UItoDDTlm2UPUAEAkFu2QA (envelope-from ) for ; Mon, 08 Jan 2024 13:06:12 +0100 Received: from aspmx1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id sB/FBjTlm2UMjwAA62LTzQ (envelope-from ) for ; Mon, 08 Jan 2024 13:06:12 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=Fop4HK93; 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=pass (policy=none) header.from=posteo.net ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1704715572; 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=qV3k3tl4sVFVSxmrubxnRB+BO4JL8BDFYSxppqaKG64=; b=Fm5O7Zi/wo9eCRNFxakNo9qZmElfx4M8Ez4KdldNY+c5x+QAnE/zVAcebqekknAOxnuusw mckWsPbQ1eMkDoqHovd3Tm+wl+b2dMwmpFcnxkcTa8wZH2TChjmhYRxoijtQXTyhnc69I0 5P/QT56PYyunYRyc/UcQ6xS5N7+PuSSiwi0cWJCYl4LEhi8t+/ckzyry+wlgkqB0XTSXPT gERRJKR7es06MVZIYYN6vMIVC4h1QqqQNPqajQoGBQ9gIz3cq2JZX6gdD5tQtR+oOpRbDI B5odmmd4dNqT78zW24nSoizXVFrWjn1dp+i+Rq5G7B6sqOsUfCrKeZMpTL4aHA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1704715572; a=rsa-sha256; cv=none; b=mEGgNij0+1fwpPqFDitdIW+ZekqFLPk2cn/8EM59F7pNrbN3h4nz4w85xZX79RBvnejlcB TDk3vAiFiotmtgNBSfQS4lSutXQngPS9cyFztWE+quXq/A8vSPOC6PIC425/DAYvyXDm65 vFTICHCzelTV7hy0UJHu5C0hta4UihXklfdW/nQqzL7JzV6pwEZIyYzrV7gpbdzU8U8Lk8 OSjVANyj+bmVF3sYWYXlMYdlvaDj04bG9L1IU6azp93TSoeEyQV3TdiZXXcTGYoi4z1nRs 8ST+GGNJLN51omUC6odPgEilr9JkaMeBJdV3NkceCc0XQFkWD1ivIyTiakW0fQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=Fop4HK93; 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=pass (policy=none) header.from=posteo.net 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 8A01D27295 for ; Mon, 8 Jan 2024 13:06:11 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rMoNX-0002cX-Nn; Mon, 08 Jan 2024 07:05:15 -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 1rMoNV-0002am-M3 for emacs-orgmode@gnu.org; Mon, 08 Jan 2024 07:05:13 -0500 Received: from mout01.posteo.de ([185.67.36.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rMoNP-00064y-CN for emacs-orgmode@gnu.org; Mon, 08 Jan 2024 07:05:13 -0500 Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 282D7240027 for ; Mon, 8 Jan 2024 13:05:04 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1704715504; bh=RQ77jUAquxBLBbpayqtTQSd8V1tlvFjHJvSr56ZVkHo=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:From; b=Fop4HK93MO6lrf8x22qmZnEMSWRVCJ2/8/VtPoH41TffF9Shxvyb6FEQXbmSpIEot 2XdutSBTSF/T3YOyBvaJlcZUbsl3DNl45vp71EBx2igFVVhw0a2jrJ66gFEIYfFRqV CIwIXYdenrSD0r5Jqt/07zQfEQKBMgcrKM4amKTEuAWNdEJW8bZMVaLZviLNLVQ5pY hELnxLdLPAjKoSA4fJnr+txiQ1bh0UmGW3szdJ0tgE0L7mfWhKXVyALtbYxXl0KJ+V qXUE64IP3tv7MMvDVU1EGbZLeXDWd6XvDt7fJgJh1LIBionDsylYeJnVa2oGrS5s+4 k6ciZxItZqu9Q== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4T7t6Q5RYhz6tyn; Mon, 8 Jan 2024 13:05:02 +0100 (CET) From: Ihor Radchenko To: gerard.vermeulen@posteo.net Cc: Emacs orgmode Subject: Re: [PATCH] org-babel-demarcate-block: split using element API In-Reply-To: <37fdcc4bfcf734c2e5ec439d40b4f7d8@posteo.net> References: <7e41f9b6e9026a404e256f33371e974c@posteo.net> <87zfxq78ff.fsf@localhost> <87zfxo3taa.fsf@localhost> <87v88a78qd.fsf@localhost> <7f23ea966f0f0aad3fad29b0b96864f3@posteo.net> <87y1d55fc6.fsf@localhost> <37fdcc4bfcf734c2e5ec439d40b4f7d8@posteo.net> Date: Mon, 08 Jan 2024 12:08:15 +0000 Message-ID: <878r50yqmo.fsf@localhost> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=185.67.36.65; envelope-from=yantar92@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=0.01 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-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Queue-Id: 8A01D27295 X-Migadu-Scanner: mx10.migadu.com X-Migadu-Spam-Score: -9.51 X-Spam-Score: -9.51 X-TUID: YimTS9nrDTDO gerard.vermeulen@posteo.net writes: > On 04.01.2024 15:43, Ihor Radchenko wrote: >> gerard.vermeulen@posteo.net writes: >> > Attached you'll find a new version of the patch that addresses your > comments. I have modified the ERT test so that it checks most of > your examples showing where the older versions of the patch failed. > The test is now called `test-ob/demarcate-block' Thanks! I've tested your patch and found two problems: 1. #+name: lines are duplicated, while they should not 2. Your patch does not create space between the src blocks, unlike what we have on main. I think that you need to (1) create a single blank lines between blocks (set :post-blank property to 1); (2) keep the number blank lines after the last block the same as in the initial block (copy the :post-blank property and assign it to the last inserted src block). For C-u argument, do not do anything special - just keep the original :post-blank as is. It is the closest to what we have on main. > Below, I compare region splitting using main or my patch. White-space > differs between main and the patch and one might argue that the result > produced by the patch is more consistent. Agree. > Agreed, this is wrong. A partial explanation is that I attached too > much value to the doc-string of `org-babel-get-src-block-info' > telling "Return nil if point is not on a source block. Otherwise," > which > is for me in contradiction with documentation (string and start > comment) in `org-babel-demarcate-block'. `org-babel-get-src-block-info' docstring were not wrong. You just missed the Org mode's convention that blank lines after src blocks or other syntax elements belong to these elements. That said, we may clarify the `org-babel-get-src-block-info' docstring to highlight this fact and avoid future confusion. > Now demarcating with point below a source block works again and > checking this is part of the ERT test. The ERT test does not check removing #+caption from the original block. Also, as I said above, we should remove #+name. >> `org-indent-block' should honor `org-adapt-indentation'. You do not >> need >> to call it conditionally. Re-indenting unconditionally should be better >> here. > OK. I have always used `org-adapt-indentation' set to nil and I do not > like > the result of `org-indent-block' when it is non-nil (#+begin_src and > #+end_src > indented and the code pushed to the left), but I will have to get used > to it. Note that indentation of src blocks has been refactored recently on main. It should be more reliable now. If not, please report any issues. > -;; Copyright (C) 2009-2024 Free Software Foundation, Inc. > +;; Copyright (C) 2009-2023 Free Software Foundation, Inc. This is a spurious change :) > -Return nil if point is not on a source block. Otherwise, return > -a list with the following pattern: > +Return nil if point is not on a source block or not within blank > +lines after a source block. Otherwise, return a list with the > +following pattern: I'd rather say: Return nil if point is not on a source block (blank lines after a source block are considered a part of that source block). It would be more accurate. > + (let* ((copy (org-element-copy (org-element-at-point))) > + (before (org-element-begin copy)) > + (beyond (org-element-end copy)) > + (parts (sort (if (org-region-active-p) > + (list body-beg (mark) (point) body-end) > + (list body-beg (point) body-end)) > + #'<))) > + ;; Prevent #+caption:, #+header:, and #+begin_src lines in block. This comment is out of place. Also, we do preserve #+header and #+begin_src lines, don't we? And we need to remove #+name lines. > + (unless (and (>= (point) body-beg)) > + (user-error "move point within the source block body to split it")) Please start error message from capital letter. It is Elisp convention (see `user-error' docstring). > + (setq parts (mapcar (lambda (p) (buffer-substring (car p) (cdr p))) > + (seq-mapn #'cons parts (cdr parts)))) > + (delete-region before beyond) > + (deactivate-mark) AFAIK, `deactivate-mark' should be unnecessary here. To indicate that region should be deactivated after finishing a command, we simply set `deactivate-mark' _variable_ to t. See the docstring. -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at