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/
This commit is contained in:
Nick Dokos 2024-10-15 21:28:32 -04:00 committed by Ihor Radchenko
parent 23eb697df6
commit 8b4b89b14b
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
1 changed files with 11 additions and 2 deletions

View File

@ -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 ()
"Return non-nil when `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)