Re: [Bug] org-in-src-block-p returns t when not in source block

2023-11-29 Thread Ihor Radchenko
Jens Schmidt  writes:

> On 2023-11-27  21:30, Ihor Radchenko wrote:
>
>> Fixed, on main.
>> https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=6d7c7917a
>
> Which is currently my HEAD, and there are still edge cases that do not
> seem to be handled well.
> ...
> When I wrote my own inner-boundary function, I looked with envy at
> the elegance of the arithmetic done in `org-in-src-block-p' but thought
> that this probably would not always work ... or did I misunderstand
> something here?

You are right.
Fixed, on main.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=57b94f344

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: [Bug] org-in-src-block-p returns t when not in source block

2023-11-28 Thread Jens Schmidt
On 2023-11-27  21:30, Ihor Radchenko wrote:

> Fixed, on main.
> https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=6d7c7917a

Which is currently my HEAD, and there are still edge cases that do not
seem to be handled well.

Start off from "make vanilla" and the following buffer

- test.org -
#+begin_src shell
foo
#+end_src

bar
- test.org -

Navigate to BOL of the "#+end_src" line and

  M-: (org-in-src-block-p t)
  => nil

As expected.  Now add a space on the empty line *after* the
"#+end_src" line, navigate back to BOL of the "#+end_src" line and

  M-: (org-in-src-block-p t)
  => t

When I wrote my own inner-boundary function, I looked with envy at
the elegance of the arithmetic done in `org-in-src-block-p' but thought
that this probably would not always work ... or did I misunderstand
something here?

Thanks  Jens

Here is the lossage corresponding to my test case, just in case:

 C-s  ;; isearch-forward
 #;; isearch-printing-char
 +;; isearch-printing-char
 e;; isearch-printing-char
 n;; isearch-printing-char
 d;; isearch-printing-char
 C-a  ;; org-beginning-of-line
 M-: (org-in-src-block-p t)
  ;; read--expression-try-read
 C-n  ;; next-line
 SPC  ;; org-self-insert-command
 C-a  ;; org-beginning-of-line
 C-p  ;; previous-line
 M-: (org-in-src-block-p t)
  ;; read--expression-try-read



Re: [Bug] org-in-src-block-p returns t when not in source block

2023-11-27 Thread No Wayman

Ihor Radchenko  writes:


point on trailing blank line: FAIL


Fixed, on main.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=6d7c7917a


Confirmed on my end by adding `:packages* org` to the previous 
test:


Yodel[1] Report 2023-11-27 15:34:45
===

STDOUT
==

INFO Scraping files for loaddefs... 
  INFO Scraping files for loaddefs...done

  GEN  ../elpaca-autoloads.el
Cloning into '/tmp/yodel-yCfbwq/elpaca/repos/elpaca'...
Your branch is up to date with 'origin/master'.
Checking /tmp/yodel-yCfbwq/elpaca/repos/elpaca...
Compiling 
/tmp/yodel-yCfbwq/elpaca/repos/elpaca/elpaca-info.el...

Compiling /tmp/yodel-yCfbwq/elpaca/repos/elpaca/elpaca-log.el...
Compiling 
/tmp/yodel-yCfbwq/elpaca/repos/elpaca/elpaca-manager.el...
Compiling 
/tmp/yodel-yCfbwq/elpaca/repos/elpaca/elpaca-menu-elpa.el...
Compiling 
/tmp/yodel-yCfbwq/elpaca/repos/elpaca/elpaca-menu-melpa.el...
Compiling 
/tmp/yodel-yCfbwq/elpaca/repos/elpaca/elpaca-menu-org.el...
Compiling 
/tmp/yodel-yCfbwq/elpaca/repos/elpaca/elpaca-process.el...
Compiling 
/tmp/yodel-yCfbwq/elpaca/repos/elpaca/elpaca-test.el...

Compiling /tmp/yodel-yCfbwq/elpaca/repos/elpaca/elpaca-ui.el...
Compiling /tmp/yodel-yCfbwq/elpaca/repos/elpaca/elpaca.el...
Checking /tmp/yodel-yCfbwq/elpaca/repos/elpaca/doc...
Compiling 
/tmp/yodel-yCfbwq/elpaca/repos/elpaca/doc/early-init.el...

Compiling /tmp/yodel-yCfbwq/elpaca/repos/elpaca/doc/init.el...
Checking /tmp/yodel-yCfbwq/elpaca/repos/elpaca/extensions...
Compiling 
/tmp/yodel-yCfbwq/elpaca/repos/elpaca/extensions/elpaca-use-package.el...

Checking /tmp/yodel-yCfbwq/elpaca/repos/elpaca/images...
Checking /tmp/yodel-yCfbwq/elpaca/repos/elpaca/test...
Compiling 
/tmp/yodel-yCfbwq/elpaca/repos/elpaca/test/elpaca-test.el...

Done (Total of 11 files compiled, 3 skipped in 4 directories)



Downloading MELPA recipes...
Downloading MELPA recipes...100%
Downloading NonGNU-devel ELPA...
Downloading GNU-devel ELPA...
Downloading NonGNU ELPA...
Downloading GNU ELPA...
Org mode version 9.7-pre (9.7-pre-n/a-g6d7c79
 @ /tmp/yodel-yCfbwq/elpaca/builds/org/)
(org-in-source-block-p ’inside)
point on preceding blank line: PASS
point on begin_src: PASS
point between begin_src end_src: PASS
point on end_src (non-blank line after): PASS
point on end_src (blank line after): PASS
point on end_src (no line after): PASS
point on trailing blank line: PASS


Environment
===

- emacs version: GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, 
 GTK+ Version 3.24.38, cairo version 1.18.0)

of 2023-11-16
- system type: gnu/linux

Packages


- elpaca 
 https://github.com/progfolio/elpaca/commit/86a562c0a7c0a009803172eb0ed55fdaf17c4559
- org 
 https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=6d7c7917a0294bb71c3294119984207b1d9b0385


[1] https://www.github.com/progfolio/yodel



Thanks again.



Re: [Bug] org-in-src-block-p returns t when not in source block

2023-11-27 Thread Ihor Radchenko
No Wayman  writes:

>> What about the attached patch?
>
> That is much clearer. Thank you.

Applied, onto main.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=bd7fab212

>> If you want to check if point is inside source block code, use INSIDE
>> argument.
>
> Using the INSIDE argument still appears to fail in some cases:
>
> ...
>> Org mode version 9.6.11 (release_9.6.11 @ /usr/share/emacs/30.0.50/lisp/org/)
>> (org-in-source-block-p ’inside)
>> point on preceding blank line: PASS
>> point on begin_src: PASS
>> point between begin_src end_src: PASS
>> point on end_src (non-blank line after): PASS
>> point on end_src (blank line after): PASS
>> point on end_src (no line after): FAIL

This one passed on main.

>> point on trailing blank line: FAIL

Fixed, on main.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=6d7c7917a

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: [Bug] org-in-src-block-p returns t when not in source block

2023-11-27 Thread No Wayman


[Apologies for the duplicate message, Ihor. mu4e recently changed it's default
reply behavior without my noticing]

Ihor Radchenko  writes:

> This is very different from LAX argument in `org-at-timestamp-p' -
> timestamp-like text may not be proper syntactically correct Org markup
> element, but is still considered by agenda for historical and practical
> reasons.

Fair enough.
 
> What about the attached patch?

That is much clearer. Thank you.

> If you want to check if point is inside source block code, use INSIDE
> argument.

Using the INSIDE argument still appears to fail in some cases:

Yodel[1] Report 2023-11-27 14:55:05
===

--8<---cut here---start->8---
(yodel
  :post*
  (require 'org)
  (org-version nil 'full 'message)
  (message "(org-in-source-block-p 'inside)")
  (yodel-file "before.org" :point "|"
:with* "|\n#+begin_src text\ntest\n#+end_src\n"
:then* (message "point on preceding blank line: %s"
 (if (org-in-src-block-p 'inside) "FAIL" "PASS")))
  (yodel-file "begin.org" :point "|"
:with* "\n#+begin|_src text\ntest\n#+end_src\n"
:then* (message "point on begin_src: %s"
 (if (org-in-src-block-p 'inside) "FAIL" "PASS")))
  (yodel-file "in.org" :point "|"
:with* "\n#+begin_src text\nte|st\n#+end_src\n"
:then* (message "point between begin_src end_src: %s"
 (if (org-in-src-block-p 'inside) "PASS" "FAIL")))
  (yodel-file "end-non-blank.org" :point "|"
:with* "\n#+begin_src text\ntest\n#+end|_src\ntest"
:then* (message "point on end_src (non-blank line after): %s"
 (if (org-in-src-block-p 'inside) "FAIL" "PASS")))
  (yodel-file "end.org" :point "|"
:with* "\n#+begin_src text\ntest\n#+end|_src\n"
:then* (message "point on end_src (blank line after): %s"
 (if (org-in-src-block-p 'inside) "FAIL" "PASS")))
  (yodel-file "end-eobp.org" :point "|"
:with* "\n#+begin_src text\ntest\n#+end|_src"
:then* (message "point on end_src (no line after): %s"
 (if (org-in-src-block-p 'inside) "FAIL" "PASS")))
  (yodel-file "after.org" :point "|"
:with* "\n#+begin_src text\ntest\n#+end_src\n|"
:then* (message "point on trailing blank line: %s"
(if (org-in-src-block-p 'inside) "FAIL" "PASS"
--8<---cut here---end--->8---

STDOUT
==

> Org mode version 9.6.11 (release_9.6.11 @ /usr/share/emacs/30.0.50/lisp/org/)
> (org-in-source-block-p ’inside)
> point on preceding blank line: PASS
> point on begin_src: PASS
> point between begin_src end_src: PASS
> point on end_src (non-blank line after): PASS
> point on end_src (blank line after): PASS
> point on end_src (no line after): FAIL
> point on trailing blank line: FAIL

Environment
===

- emacs version: GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
3.24.38, cairo version 1.18.0)
 of 2023-11-16
- system type: gnu/linux

[1] https://www.github.com/progfolio/yodel



Re: [Bug] org-in-src-block-p returns t when not in source block

2023-11-27 Thread Ihor Radchenko
[ Adding Org mailing list back to CC ]

No Wayman  writes:

>> This is not a bug - Org considers blank lines after element as a 
>> part of
>> it. This includes source blocks.
>
> I would've reversed the semantics of the INSIDE argument.
> e.g.
>
> (defun org-in-src-block-p ( lax element)
> ...
> That's less confusing and mirrors other functions, such as 
> org-at-timestamp-p.

This is very different from LAX argument in `org-at-timestamp-p' -
timestamp-like text may not be proper syntactically correct Org markup
element, but is still considered by agenda for historical and practical
reasons.

> However, that's a breaking change, and I feel like adding another, 
> similarly named function will cause more confusion than it 
> prevents.

This too.

> ... With that in mind, the docstring could be improved.
> ...

What about the attached patch?

>From e5d5ab915eb4309082a4a274170fddc60a75c28b Mon Sep 17 00:00:00 2001
Message-ID: 
From: Ihor Radchenko 
Date: Mon, 27 Nov 2023 20:54:42 +0100
Subject: [PATCH] lisp/org.el (org-in-src-block-p): Improve docstring

* lisp/org.el (org-in-src-block-p):

Reported-by: No Wayman 
Link: https://orgmode.org/list/87il5n9owq@gmail.com
---
 lisp/org.el | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index d2cd0b9b7..19887ff1e 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -18786,9 +18786,13 @@ (defun org-quote-vert (s)
   s)
 
 (defun org-in-src-block-p ( inside element)
-  "Whether point is in a code source block.
-When INSIDE is non-nil, don't consider we are within a source
-block when point is at #+BEGIN_SRC or #+END_SRC.
+  "Return t when point is at a source block element.
+When INSIDE is non-nil, return t only when point is between #+BEGIN_SRC
+and #+END_SRC lines.
+
+Note that affiliated keywords and blank lines after are considered a
+part of a source block.
+
 When ELEMENT is provided, it is considered to be element at point."
   (save-match-data (setq element (or element (org-element-at-point
   (when (org-element-type-p element 'src-block)
-- 
2.42.0


-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 


Re: [Bug] org-in-src-block-p returns t when not in source block

2023-11-27 Thread Ihor Radchenko
No Wayman  writes:

> When on an empty line before a source block, org-in-src-block-p 
> correctly returns nil.
> However, when on an empty line after a source block, it returns t.
> This is reproducible on my end with both the built-in version of 
> Org and 9.7-pre. 

This is not a bug - Org considers blank lines after element as a part of
it. This includes source blocks.

If you want to check if point is inside source block code, use INSIDE
argument.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



[Bug] org-in-src-block-p returns t when not in source block

2023-11-27 Thread No Wayman



When on an empty line before a source block, org-in-src-block-p 
correctly returns nil.

However, when on an empty line after a source block, it returns t.
This is reproducible on my end with both the built-in version of 
Org and 9.7-pre. 


Yodel[1] Report 2023-11-27 10:42:54
===

--8<---cut here---start->8---
(yodel
 :post*
 (require 'org)
 (org-version nil 'full 'message)
 (yodel-file
   :point "|"
   :with* "#+begin_src text\n#+end_src\n|"
   :then* (message "org-in-src-block-p below: %s" 
   (org-in-src-block-p)))

 (yodel-file
   :point "|"
   :with* "|\n#+begin_src text\n#+end_src"
   :then* (message "org-in-src-block-p above: %s" 
   (org-in-src-block-p

--8<---cut here---end--->8---

STDOUT
==

Org mode version 9.6.11 (release_9.6.11 @ 
/usr/share/emacs/30.0.50/lisp/org/)

org-in-src-block-p below: t
org-in-src-block-p above: nil


Environment
===

- emacs version: GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, 
 GTK+ Version 3.24.38, cairo version 1.18.0)

of 2023-11-16
- system type: gnu/linux

[1] https://www.github.com/progfolio/yodel