emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@posteo.net>
To: gerard.vermeulen@posteo.net
Cc: Emacs orgmode <emacs-orgmode@gnu.org>
Subject: Re: [PATCH] org-babel-demarcate-block: split using org-element instead of  regexp
Date: Thu, 04 Jan 2024 14:43:37 +0000	[thread overview]
Message-ID: <87y1d55fc6.fsf@localhost> (raw)
In-Reply-To: <7f23ea966f0f0aad3fad29b0b96864f3@posteo.net>

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
<point>

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 <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


  reply	other threads:[~2024-01-04 14:41 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
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 [this message]
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=87y1d55fc6.fsf@localhost \
    --to=yantar92@posteo.net \
    --cc=emacs-orgmode@gnu.org \
    --cc=gerard.vermeulen@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).