emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nick Dokos <ndokos@gmail.com>
To: Nick Dokos <ndokos@gmail.com>
Cc: Ihor Radchenko <yantar92@posteo.net>,  emacs-orgmode@gnu.org
Subject: [PATCH] `org-babel-header-arg-expand': more stringent check for appropriate context
Date: Tue, 15 Oct 2024 21:55:26 -0400	[thread overview]
Message-ID: <874j5c3j75.fsf_-_@pierrot.dokosmarshall.org> (raw)
In-Reply-To: <b7d3b5c5-960b-4e21-87b6-b44f215aef4a@gmail.com> (Nick Dokos's message of "Thu, 10 Oct 2024 14:21:40 -0400")

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


  reply	other threads:[~2024-10-16  1:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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     ` Nick Dokos [this message]
2024-10-18 17:43       ` [PATCH] `org-babel-header-arg-expand': more stringent check for appropriate context Ihor Radchenko
2024-10-20 14:08         ` Nick Dokos

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=874j5c3j75.fsf_-_@pierrot.dokosmarshall.org \
    --to=ndokos@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=yantar92@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).