fix: widen buffer when checking yasnippet condition

In certain circumstances, `yasnippet` will narrow the buffer to its own
region while expanding, which prevents certain snippet conditions from
working properly.
This commit is contained in:
Kiana Sheibani 2026-02-14 18:47:30 -05:00
parent 1ab7ecb9c9
commit 48fc692361
Signed by: toki
GPG key ID: 6CB106C25E86A9F7

View file

@ -3364,20 +3364,24 @@ Writing header arguments for source code blocks is confusing, so let's automate
#+begin_src emacs-lisp #+begin_src emacs-lisp
(defun ~/yas-org-src-header-p () (defun ~/yas-org-src-header-p ()
"Determine whether `point' is within a src-block header or header-args." "Determine whether `point' is within a src-block header or header-args."
(let ((context (org-element-context))) ;; Temporarily widen buffer
(pcase (org-element-type context) ;; This avoids issues when checking during nested expansion,
('src-block (< (point) ; before code part of the src-block ;; since yasnippet narrows to the current field in that case
(save-excursion (org-with-wide-buffer
(goto-char (org-element-property :begin context)) (let ((context (org-element-context)))
(forward-line 1) (pcase (org-element-type context)
(point)))) ('src-block (< (point) ; before code part of the src-block
('inline-src-block (< (point) ; before code part of the inline-src-block (progn
(save-excursion (goto-char (org-element-property :begin context))
(goto-char (org-element-property :begin context)) (forward-line 1)
(search-forward "]{") (point))))
(point)))) ('inline-src-block (< (point) ; before code part of the inline-src-block
('keyword (string-match-p "^header-args" (progn
(org-element-property :value context)))))) (goto-char (org-element-property :begin context))
(search-forward "]{")
(point))))
('keyword (string-match-p "^header-args"
(org-element-property :value context)))))))
(defun ~/yas-org-src-lang () (defun ~/yas-org-src-lang ()
"Try to find the current language of the src/header at `point'. "Try to find the current language of the src/header at `point'.