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
32
config.org
32
config.org
|
|
@ -3364,20 +3364,24 @@ Writing header arguments for source code blocks is confusing, so let's automate
|
|||
#+begin_src emacs-lisp
|
||||
(defun ~/yas-org-src-header-p ()
|
||||
"Determine whether `point' is within a src-block header or header-args."
|
||||
(let ((context (org-element-context)))
|
||||
(pcase (org-element-type context)
|
||||
('src-block (< (point) ; before code part of the src-block
|
||||
(save-excursion
|
||||
(goto-char (org-element-property :begin context))
|
||||
(forward-line 1)
|
||||
(point))))
|
||||
('inline-src-block (< (point) ; before code part of the inline-src-block
|
||||
(save-excursion
|
||||
(goto-char (org-element-property :begin context))
|
||||
(search-forward "]{")
|
||||
(point))))
|
||||
('keyword (string-match-p "^header-args"
|
||||
(org-element-property :value context))))))
|
||||
;; 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)))
|
||||
(pcase (org-element-type context)
|
||||
('src-block (< (point) ; before code part of the src-block
|
||||
(progn
|
||||
(goto-char (org-element-property :begin context))
|
||||
(forward-line 1)
|
||||
(point))))
|
||||
('inline-src-block (< (point) ; before code part of the inline-src-block
|
||||
(progn
|
||||
(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 ()
|
||||
"Try to find the current language of the src/header at `point'.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue