From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:303:5f26::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id YIILCKPDlmVUTwEAkFu2QA (envelope-from ) for ; Thu, 04 Jan 2024 15:41:39 +0100 Received: from aspmx1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id mO3lAqPDlmXcWwAAqHPOHw (envelope-from ) for ; Thu, 04 Jan 2024 15:41:39 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=csAktEgO; 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=1704379298; 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=h30PiqMBJXMd5JmNS16l+0j+JnrdK2Zxa4Ek65xAwqQ=; b=hGmGpcexfXMI3b74Tmq710kzE5ALwF0N3dqpLDW3ph6iivsHO5i2BSVk3OESPqGDxltgME t2TdVCFc1ZrKRkyPORHrdQqhEker6IcXNYxvuPJs26cVkVRGKX87HVJZNuHNXX9XAlwLZD 8ueYQHk07FdIAUEqyuSTMVlp4c/3/KOrcLWQeFEzUcwv7E1f+hh2o4nLze+2VnIBUHHLUN 0dJW8kB3ztEwO7c51WhVMCEVopMJzXQ6FgKLu7eEBzL6yZ+J47+hrhX4fDQvXbi2NMRbUN fXPaXqireNdBSaidcqor8CvhAosB0dPGiLZd7r0zlJ5kWFow4GggBSr6MA1zUA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=csAktEgO; 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-Seal: i=1; s=key1; d=yhetil.org; t=1704379298; a=rsa-sha256; cv=none; b=EI0GaGdxvM4ueI/SVuePYkSrq4OvrKY1QLhHVBja70+3w3T1dkObHQAgqsALz7APvJPbM5 FYXPwzGh2a3n3mumD9nxOfW7FG0ANPw22Xr7y5hv4YQa7NWSk4k3GSUKL9PjzU0cS+QjFG wz2XblmFx3v3ipMyHsAO3wC8uLdrSxDZ+iPmB46+/Q7shfKZDEPEWOwIIuU8uJK5meFJBT L9DAG0c2+js+HS9Hk1xVr9qcLa1CBXrq/9IPaqyc8GKgYEXVjDobC9siSOCmv00YEI40Et ed93nBi7VwnQ4e/3UpmbKlfnJIUWVDUjEDyl4o1kaMcw5H5EUO+gIMVA4LBDRw== 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 D066523ED8 for ; Thu, 4 Jan 2024 15:41:38 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rLOtq-0001MR-SZ; Thu, 04 Jan 2024 09:40:46 -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 1rLOtj-0001Lf-MZ for emacs-orgmode@gnu.org; Thu, 04 Jan 2024 09:40:40 -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 1rLOta-0003Oy-6v for emacs-orgmode@gnu.org; Thu, 04 Jan 2024 09:40:32 -0500 Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id B06B924002D for ; Thu, 4 Jan 2024 15:40:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1704379226; bh=fb54D3RHsEvjhBSOOb8p0gnUgiutwbp3LGP7kCCiCm8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:From; b=csAktEgOalwlzI9eELTw7a39PD3DC6U2tfHWNU6SCqKpSKKz3mK7TYj3cSkDQjmQg tapHv74ukoMr+MbH8eqNo9NzaK1JEIiLkhQHdSo/uKYFAZ5ORKJ0wYAgeyTZCz1YO/ csvEZNjjV2UuYDm5/4rl9KGugfetNwGww6o0T1N375ff4r+CHRYKvHkJC/2XKb5CB0 /rlhn0G0mGrHxM7phKPeyoBbdoZeMlJVnwJhKsQjaHUQm4Hc2+F05LsFau2QNMJG84 puzJRtlDMX+HkGNc7wPrH9ohG1AhR1jF2zY98gwQQGXnNSDNbSIQd2NyKNv2ADOzeM s6ziscHuJXnyg== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4T5TlY6t5Xz6tyq; Thu, 4 Jan 2024 15:40:25 +0100 (CET) From: Ihor Radchenko To: gerard.vermeulen@posteo.net Cc: Emacs orgmode Subject: Re: [PATCH] org-babel-demarcate-block: split using org-element instead of regexp In-Reply-To: <7f23ea966f0f0aad3fad29b0b96864f3@posteo.net> References: <7e41f9b6e9026a404e256f33371e974c@posteo.net> <87zfxq78ff.fsf@localhost> <87zfxo3taa.fsf@localhost> <87v88a78qd.fsf@localhost> <7f23ea966f0f0aad3fad29b0b96864f3@posteo.net> Date: Thu, 04 Jan 2024 14:43:37 +0000 Message-ID: <87y1d55fc6.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, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -9.50 X-Spam-Score: -9.50 X-Migadu-Queue-Id: D066523ED8 X-Migadu-Scanner: mx10.migadu.com X-TUID: vk172MwIuTOi gerard.vermeulen@posteo.net writes: >> I made some adjustments to the patch, making use of org-element API. >> See the attached updated version of the patch. Thanks! See my comments inline. > I have tried to clean up the code. I have also tried to get `body-beg' > and > `body-end' marking the text between the #+begin_src and #+end_src lines > from the element API, but I failed and had to fall back to > `org-babel-where-is-src-block-head'. But only for that. org-element API does not provide this information for now. Maybe it is a good opportunity to alter the parser, so that code boundaries are provided... > (defun org-babel-demarcate-block (&optional arg) > ... > -When called within blank lines after a code block, create a new code > -block of the same language with the previous." Is there any reason why you dropped this feature? When I try #+begin_src emacs-lisp (+ 1 2) #+end_src M-x org-babel-demacrate-block throws an error with your patch. It creates a new block with the same language before your patch. > + (let ((copy (org-element-copy (org-element-at-point))) > + (stars (concat (make-string (or (org-current-level) 1) ?*) " "))) > + (if (eq 'src-block (car copy)) You can instead use `org-element-type-p' > + ;; Keep this branch in sync with test-ob/demarcate-block-split. > + ;; _start is never nil, since there is a source block element at point. May you elaborate what you mean by "keep in sync"? > + (let* ((_start (org-babel-where-is-src-block-head)) Are you using (org-babel-where-is-src-block-head) for side effect of modifying the match data? If so, please do it outside let, with appropriate comment. > + (if (not org-adapt-indentation) > + ;; Move point to the left of the lower block line #+begin_src. > + (org-previous-block 1) > + ;; Adapt the indentation: upper block first and lower block second. > + (org-previous-block 2) > + (org-indent-block) > + ;; Move point to the left of the lower block line #+begin_src. > + (org-next-block 1) > + (org-indent-block))) `org-indent-block' should honor `org-adapt-indentation'. You do not need to call it conditionally. Re-indenting unconditionally should be better here. > (let ((start (point)) > - (lang (or (car info) ; Reuse language from previous block. > - (completing-read > - "Lang: " > - (mapcar #'symbol-name > - (delete-dups > - (append (mapcar #'car org-babel-load-languages) > - (mapcar (lambda (el) (intern (car el))) > - org-src-lang-modes))))))) > + ;; (org-babel-get-src-block-info 'no-eval) returns nil, > + ;; since there is no source block at point. Therefore, this > + ;; cannot be used to get the language of a neighbour block. Why nil? The condition was (and info start) ;; At src block, but not within blank lines after it. So, this branch of the if used to be INFO - non-nil, and START nil -> re-use the information. And if INFO were nil, query. > + ;; Deleted code indicated that this may have worked in the past. > + ;; I have removed upper-case-p, since it could never be true here. The idea of UPPER-CASE-P is to keep user preference for keyword style (upper case or lower case). There is no reason to remove this feature. Although, since we are using `org-element-interpret-data', it might be a good idea to extend org-element parser to preserve the keyword case information. -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at