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:
parent
1ab7ecb9c9
commit
48fc692361
1 changed files with 18 additions and 14 deletions
10
config.org
10
config.org
|
|
@ -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."
|
||||||
|
;; Temporarily widen buffer
|
||||||
|
;; This avoids issues when checking during nested expansion,
|
||||||
|
;; since yasnippet narrows to the current field in that case
|
||||||
|
(org-with-wide-buffer
|
||||||
(let ((context (org-element-context)))
|
(let ((context (org-element-context)))
|
||||||
(pcase (org-element-type context)
|
(pcase (org-element-type context)
|
||||||
('src-block (< (point) ; before code part of the src-block
|
('src-block (< (point) ; before code part of the src-block
|
||||||
(save-excursion
|
(progn
|
||||||
(goto-char (org-element-property :begin context))
|
(goto-char (org-element-property :begin context))
|
||||||
(forward-line 1)
|
(forward-line 1)
|
||||||
(point))))
|
(point))))
|
||||||
('inline-src-block (< (point) ; before code part of the inline-src-block
|
('inline-src-block (< (point) ; before code part of the inline-src-block
|
||||||
(save-excursion
|
(progn
|
||||||
(goto-char (org-element-property :begin context))
|
(goto-char (org-element-property :begin context))
|
||||||
(search-forward "]{")
|
(search-forward "]{")
|
||||||
(point))))
|
(point))))
|
||||||
('keyword (string-match-p "^header-args"
|
('keyword (string-match-p "^header-args"
|
||||||
(org-element-property :value context))))))
|
(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'.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue