emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [BUG] org-babel-header-arg-expand is rather cavalier about "appropriate context" [9.8-pre (release_9.7.10-127-g07dd3b @ /usr/local/share/emacs/site-lisp/org/)]
@ 2024-09-29  2:43 Nick Dokos
  2024-10-10 17:51 ` Ihor Radchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Nick Dokos @ 2024-09-29  2:43 UTC (permalink / raw)
  To: emacs-orgmode



Remember to cover the basics, that is, what you expected to happen and
what in fact did happen.  You don't know how to make a good report?  See

     https://orgmode.org/manual/Feedback.html#Feedback

Your bug report will be posted to the Org mailing list.
------------------------------------------------------------------------
This was reported by user @Addlai on Emacs SE. See
https://emacs.stackexchange.com/questions/82276/stop-org-cycle-from-prompting-for-header-args

`org-babel-header-arg-expand' is added to the hook
`org-cycle-tab-first-hook' so when a TAB is pressed, the function is
called to check whether the context is approrpiate to call
`org-babel-enter-header-arg-w-completion'.

But the only thing it checks is whether the preceding character is a
colon and whether we are in a source block (by calling
`org-babel-where-is src-block-head'), so if one presses TAB inside a
python source block after a colon, the context is deemed "appropriate"
and you are asked for a header arg.

It should probably check that it's *on* the header line of the source
block, not just that it is *inside* the header block.

Emacs  : GNU Emacs 31.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.43, cairo version 1.18.0)
 of 2024-08-09
Package: Org mode version 9.8-pre (release_9.7.10-127-g07dd3b @ /usr/local/share/emacs/site-lisp/org/)

-- 
Nick




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [BUG] org-babel-header-arg-expand is rather cavalier about "appropriate context" [9.8-pre (release_9.7.10-127-g07dd3b @ /usr/local/share/emacs/site-lisp/org/)]
  2024-09-29  2:43 [BUG] org-babel-header-arg-expand is rather cavalier about "appropriate context" [9.8-pre (release_9.7.10-127-g07dd3b @ /usr/local/share/emacs/site-lisp/org/)] Nick Dokos
@ 2024-10-10 17:51 ` Ihor Radchenko
  2024-10-10 18:21   ` Nick Dokos
  0 siblings, 1 reply; 4+ messages in thread
From: Ihor Radchenko @ 2024-10-10 17:51 UTC (permalink / raw)
  To: Nick Dokos; +Cc: emacs-orgmode

Nick Dokos <ndokos@gmail.com> writes:

> This was reported by user @Addlai on Emacs SE. See
> https://emacs.stackexchange.com/questions/82276/stop-org-cycle-from-prompting-for-header-args
>
> `org-babel-header-arg-expand' is added to the hook
> `org-cycle-tab-first-hook' so when a TAB is pressed, the function is
> called to check whether the context is approrpiate to call
> `org-babel-enter-header-arg-w-completion'.
>
> But the only thing it checks is whether the preceding character is a
> colon and whether we are in a source block (by calling
> `org-babel-where-is src-block-head'), so if one presses TAB inside a
> python source block after a colon, the context is deemed "appropriate"
> and you are asked for a header arg.

Confirmed.

> It should probably check that it's *on* the header line of the source
> block, not just that it is *inside* the header block.

Agree.
We need to compare the return value of
`org-babel-where-is-src-block-head' with point.

Would you be interested to submit a patch that fixes the issue?

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [BUG] org-babel-header-arg-expand is rather cavalier about "appropriate context" [9.8-pre (release_9.7.10-127-g07dd3b @ /usr/local/share/emacs/site-lisp/org/)]
  2024-10-10 17:51 ` Ihor Radchenko
@ 2024-10-10 18:21   ` Nick Dokos
  2024-10-16  1:55     ` [PATCH] `org-babel-header-arg-expand': more stringent check for appropriate context Nick Dokos
  0 siblings, 1 reply; 4+ messages in thread
From: Nick Dokos @ 2024-10-10 18:21 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

On 10/10/24 1:51 PM, Ihor Radchenko wrote:
> Nick Dokos <ndokos@gmail.com> writes:
>
>> This was reported by user @Addlai on Emacs SE. See
>> https://emacs.stackexchange.com/questions/82276/stop-org-cycle-from-prompting-for-header-args
>>
>> `org-babel-header-arg-expand' is added to the hook
>> `org-cycle-tab-first-hook' so when a TAB is pressed, the function is
>> called to check whether the context is approrpiate to call
>> `org-babel-enter-header-arg-w-completion'.
>>
>> But the only thing it checks is whether the preceding character is a
>> colon and whether we are in a source block (by calling
>> `org-babel-where-is src-block-head'), so if one presses TAB inside a
>> python source block after a colon, the context is deemed "appropriate"
>> and you are asked for a header arg.
> Confirmed.
>
>> It should probably check that it's *on* the header line of the source
>> block, not just that it is *inside* the header block.
> Agree.
> We need to compare the return value of
> `org-babel-where-is-src-block-head' with point.
>
> Would you be interested to submit a patch that fixes the issue?

Sure - it'll take me a few days, but I should be able to get one 
togother by early next week.


Thanks!

-- 

Nick


>



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] `org-babel-header-arg-expand': more stringent check for appropriate context
  2024-10-10 18:21   ` Nick Dokos
@ 2024-10-16  1:55     ` Nick Dokos
  0 siblings, 0 replies; 4+ messages in thread
From: Nick Dokos @ 2024-10-16  1:55 UTC (permalink / raw)
  To: Nick Dokos; +Cc: Ihor Radchenko, emacs-orgmode

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

Patch attached.

Thanks!
-- 
Nick

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: [PATCH] `org-babel-header-arg-expand': more stringent check for appropriate context --]
[-- Type: text/x-patch, Size: 2067 bytes --]

From b7ae1e8027b7b935098bb4354a957722b55afb1d Mon Sep 17 00:00:00 2001
From: Nick Dokos <ndokos@gmail.com>
Date: Tue, 15 Oct 2024 21:28:32 -0400
Subject: [PATCH] `org-babel-header-arg-expand': more stringent check for
 appropriate context

The check for appropriate context in `org-babel-header-arg-expand' was
inadequate: a colon was deemed appropriate anywhere in the source
block, not just in the header.

* lisp/ob-core.el (org-babel-header-arg-expand): the function now uses
`org-babel-in-src-block-header-p' to check for appropriate context.
(org-babel-in-src-block-header-p): New function.

Reported-by: use @Addlai on Emacs SE.
Link: https://list.orgmode.org/orgmode/87zfnrb2nu.fsf@pierrot.dokosmarshall.org/
---
 lisp/ob-core.el | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index e6db422c9d20..60705036cc7e 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -1093,10 +1093,19 @@ completion from lists of common args and values."
       (unless (= (char-before (point)) ?\ ) (insert " "))
       (insert ":" header-arg) (when value (insert " " value)))))
 
+(defun org-babel-in-src-block-header-p ()
+  "Check whether `point' is in the header line of the source block."
+  (let ((beg (org-babel-where-is-src-block-head)))
+    (when beg
+      (let ((end (save-excursion (goto-char beg) (end-of-line) (point))))
+        (and (>= (point) beg) (<= (point) end))))))
+
 ;; Add support for completing-read insertion of header arguments after ":"
 (defun org-babel-header-arg-expand ()
-  "Call `org-babel-enter-header-arg-w-completion' in appropriate contexts."
-  (when (and (equal (char-before) ?\:) (org-babel-where-is-src-block-head))
+  "Call `org-babel-enter-header-arg-w-completion' in appropriate contexts
+(the header line of a source block)."
+  (when (and (equal (char-before) ?\:)
+             (org-babel-in-src-block-header-p))
     (org-babel-enter-header-arg-w-completion (match-string 2))))
 
 (defun org-babel-enter-header-arg-w-completion (&optional lang)
-- 
2.46.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-10-16  1:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-29  2:43 [BUG] org-babel-header-arg-expand is rather cavalier about "appropriate context" [9.8-pre (release_9.7.10-127-g07dd3b @ /usr/local/share/emacs/site-lisp/org/)] Nick Dokos
2024-10-10 17:51 ` Ihor Radchenko
2024-10-10 18:21   ` Nick Dokos
2024-10-16  1:55     ` [PATCH] `org-babel-header-arg-expand': more stringent check for appropriate context Nick Dokos

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).