emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: gerard.vermeulen@posteo.net
To: Ihor Radchenko <yantar92@posteo.net>
Cc: Emacs orgmode <emacs-orgmode@gnu.org>
Subject: Re: [PATCH] org-babel-demarcate-block: duplicate switches too
Date: Mon, 01 Jan 2024 12:52:45 +0000	[thread overview]
Message-ID: <d02fe29f0b7bb9375b1bcdce15089b35@posteo.net> (raw)
In-Reply-To: <87zfxq78ff.fsf@localhost>

[-- Attachment #1: Type: text/plain, Size: 1025 bytes --]


On 31.12.2023 15:28, Ihor Radchenko wrote:
> gerard.vermeulen@posteo.net writes:
> 
>> The purpose of this patch is to duplicate switches when
>> org-babel-demarcate-block
>> duplicates headers (meaning point in the source block when 
>> demarcating).
> 
> Thanks for the patch!
> Would you mind also adding a test for `org-babel-demarcate-block' in
> testing/lisp/test-ob.el?

I have attached a new patch with a test named 
`test-ob/demarcate-block-split'.
Besides testing the duplication of switches and some header arguments, 
it also
shows that multi-line header arguments are not duplicated.

Whether this is a bug or a feature in `org-babel-demarcate-block' may be 
a
point of discussion. I have no real opinion.

The code of the 4 (should ...) forms in the test below the line
;; unduplicated multi-line header arguments:
feels a bit clumsy. Does Org have a function to extract the value that a 
particular
var-name has from the association list returned by 
`org-babel-get-src-block-info'?

Regards -- Gerard
Regards

[-- Attachment #2: 0001-org-babel-demarcate-block-duplicate-switches-too.patch --]
[-- Type: application/octet-stream, Size: 3624 bytes --]

From 5501c0632f323bde472ff94a25ed85bf05f4c1ca Mon Sep 17 00:00:00 2001
From: Gerard Vermeulen <gerard.vermeulen@posteo.net>
Date: Sat, 30 Dec 2023 19:25:25 +0100
Subject: [PATCH] org-babel-demarcate-block: duplicate switches too

* lisp/ob-babel.el (org-babel-demarcate-block): duplicate switches when
the demarcation duplicates headers.
* testing/lisp/test-ob.el (test-ob/demarcate-block-split): New test
for block splitting by demarcation.  It checks that switches and
header arguments (with the exception of multi-line header arguments)
are duplicated.
---
 lisp/ob-core.el         |  3 +++
 testing/lisp/test-ob.el | 37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index f7e4e255f..634b7626b 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -2078,6 +2078,7 @@ block of the same language with the previous."
            (save-excursion
              (goto-char place)
              (let ((lang (nth 0 info))
+                   (switches (nth 3 info))
                    (indent (make-string (org-current-text-indentation) ?\s)))
 	       (when (string-match "^[[:space:]]*$"
                                    (buffer-substring (line-beginning-position)
@@ -2089,6 +2090,8 @@ block of the same language with the previous."
 		        (if arg stars indent) "\n"
 		        indent (if upper-case-p "#+BEGIN_SRC " "#+begin_src ")
 		        lang
+                        (if (> (length switches) 1)
+                            (concat " " switches) switches)
 		        (if (> (length headers) 1)
 			    (concat " " headers) headers)
 		        (if (looking-at "[\n\r]")
diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el
index 42c77ca56..70d56d199 100644
--- a/testing/lisp/test-ob.el
+++ b/testing/lisp/test-ob.el
@@ -26,6 +26,43 @@
 (require 'org-table)
 (eval-and-compile (require 'cl-lib))
 
+(ert-deftest test-ob/demarcate-block-split ()
+  "Test duplication of headers and switches in demarcation block splitting."
+  (org-test-with-temp-text "
+#+header: :var edge=\"unduplicated\"
+#+header: :wrap \"src any-spanish -i -n\"
+#+begin_src any-english -i -n :var here=\"seen\"
+
+above split
+<point>
+below split
+
+#+end_src
+"
+    (let (above below)
+      (org-babel-demarcate-block)
+      (setq above (org-babel-get-src-block-info))
+      (org-babel-next-src-block)
+      (setq below (org-babel-get-src-block-info))
+      ;; unduplicated multi-line header arguments:
+      (should (equal '(edge . "unduplicated")
+                     (cdr (assq :var (cdr (nth 2 above))))))
+      (should (not (equal '(edge . "unduplicated")
+                          (cdr (assq :var (cdr (nth 2 below)))))))
+      (should (equal "src any-spanish -i -n"
+                     (cdr (assq :wrap (nth 2 above)))))
+      (should (not (equal "src any-spanish -i -n"
+                          (cdr (assq :wrap (nth 2 below))))))
+      ;; duplicated headers and switches:
+      (should (string= "any-english" (nth 0 above)))
+      (should (string= "any-english" (nth 0 below)))
+      (should (string= "above split" (org-trim (nth 1 above))))
+      (should (string= "below split" (org-trim (nth 1 below))))
+      (should (equal '(here . "seen") (cdr (assq :var (nth 2 above)))))
+      (should (equal '(here . "seen") (cdr (assq :var (nth 2 below)))))
+      (should (string= "-i -n" (nth 3 above)))
+      (should (string= "-i -n" (nth 3 below))))))
+
 (ert-deftest test-ob/indented-cached-org-bracket-link ()
   "When the result of a source block is a cached indented link it
 should still return the link."
-- 
2.42.0


  reply	other threads:[~2024-01-01 12:53 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-30 19:13 [PATCH] org-babel-demarcate-block: duplicate switches too gerard.vermeulen
2023-12-31 14:28 ` Ihor Radchenko
2024-01-01 12:52   ` gerard.vermeulen [this message]
2024-01-02 10:48     ` Ihor Radchenko
2024-01-02 20:20       ` [PATCH] org-babel-demarcate-block: split using org-element instead of regexp gerard.vermeulen
2024-01-03 15:11         ` Ihor Radchenko
2024-01-04  8:59           ` gerard.vermeulen
2024-01-04 14:43             ` Ihor Radchenko
2024-01-07 18:49               ` [PATCH] org-babel-demarcate-block: split using element API gerard.vermeulen
2024-01-08 12:08                 ` Ihor Radchenko
2024-01-08 20:25                   ` gerard.vermeulen
2024-01-09  7:49                     ` gerard.vermeulen
2024-01-09 10:50                       ` gerard.vermeulen
2024-01-09 14:49                         ` Ihor Radchenko
2024-01-13 14:04                           ` gerard.vermeulen
2024-01-13 15:17                             ` Ihor Radchenko
2024-01-13 20:16                               ` gerard.vermeulen
2024-01-14 10:53                                 ` gerard.vermeulen
2024-01-14 12:16                                   ` Ihor Radchenko
2024-01-14 19:18                                     ` gerard.vermeulen
2024-01-15  9:37                                       ` gerard.vermeulen
2024-01-16 13:34                                         ` Ihor Radchenko
2024-02-19  9:46                                           ` Ihor Radchenko
2024-02-19 13:01                                             ` gerard.vermeulen
2024-02-21  9:40                                               ` Ihor Radchenko
2024-02-21 18:19                                                 ` gerard.vermeulen
2024-02-22 16:28                                                   ` gerard.vermeulen
2024-02-23 13:43                                                     ` Ihor Radchenko
2024-02-25 12:06                                                       ` gerard.vermeulen
2024-02-25 12:21                                                         ` Ihor Radchenko
2024-02-26  8:51                                                           ` gerard.vermeulen
2024-02-28 11:54                                                             ` Ihor Radchenko
2024-02-29  9:50                                                               ` gerard.vermeulen
2024-02-29 11:56                                                                 ` Ihor Radchenko
2024-02-29 17:33                                                                   ` gerard.vermeulen
2024-03-03 13:08                                                                     ` Ihor Radchenko
2024-03-03 15:45                                                                       ` gerard.vermeulen
2024-03-04 10:12                                                                         ` Ihor Radchenko
2024-03-04 11:40                                                                           ` gerard.vermeulen
2024-03-04 11:51                                                                             ` Ihor Radchenko
2024-02-26  9:06                                                           ` gerard.vermeulen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d02fe29f0b7bb9375b1bcdce15089b35@posteo.net \
    --to=gerard.vermeulen@posteo.net \
    --cc=emacs-orgmode@gnu.org \
    --cc=yantar92@posteo.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).