Add yas org snippet helper functions

and a few little similar tweaks
This commit is contained in:
TEC 2020-12-16 03:01:35 +08:00
parent bc1a07af46
commit 325d1a31e3
2 changed files with 14 additions and 3 deletions

View File

@ -4541,18 +4541,29 @@ Return nil otherwise."
(when (re-search-forward "header-args:")
(buffer-substring-no-properties
(point)
(or (and (forward-word) (point))
(or (and (forward-symbol 1) (point))
(1+ (point))))))
("#+begin_src"
(buffer-substring-no-properties
(point)
(or (and (forward-word) (point))
(or (and (forward-symbol 1) (point))
(1+ (point)))))
("#+header:"
(search-forward "#+begin_src")
(+yas/org-src-lang))
(_ nil))))
(defun +yas/org-src-header-p ()
(or
(looking-back "^#\\+property:[ \t]+header-args:.*" (line-beginning-position))
(looking-back "^#\\+header:.*" (line-beginning-position))))
(defun +yas/org-last-src-lang ()
(save-excursion
(beginning-of-line)
(when (search-backward "#+begin_src" nil t)
(+yas/org-src-lang))))
(defun +yas/org-most-common-no-property-lang ()
"Find the lang with the most source blocks that has no global header-args, else nil."
(let (src-langs header-langs)

View File

@ -1,6 +1,6 @@
# -*- mode: snippet -*-
# name: Property - header arg
# key: h
# condition: (or (looking-back "#\\+PROPERTY:.*" (line-beginning-position)) ((looking-back "#\\+property:.*" (line-beginning-position))))
# condition: (or (looking-back "^#\\+PROPERTY:.*" (line-beginning-position)) (looking-back "^#\\+property:.*" (line-beginning-position)))
# --
header-args:${1:`(or (+yas/org-most-common-no-property-lang) "?")`} $0