From b7ae1e8027b7b935098bb4354a957722b55afb1d Mon Sep 17 00:00:00 2001 From: Nick Dokos 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