2

Can yasnippet be used to insert an org subtree of the same level as the last? For example, if one often writes

***** $1
#+BEGIN_SRC latex
    \paragraph{$1.}
    $0
#+END_SRC

how might one avoid having to adjust the number of stars manually?

Toothrot
  • 3,204
  • 1
  • 12
  • 30

1 Answers1

5

You can determine the current level within embedded Emacs-lisp code.

# -*- mode: snippet -*-
# name: org subtree
# key: ost
# --
`(make-string (org-current-level) ?*)` $1
#+BEGIN_SRC latex
    \paragraph{$1.}
    $0
#+END_SRC
Kyle Meyer
  • 6,914
  • 26
  • 22
  • This failed with invalid argument (wholep, nil) for me. `(make-string (if (org-current-level) (+ (org-current-level) 1) 1) ?*)` Packing List for $1 [/]` worked for me. – Adithya Bhat Apr 18 '23 at 13:48