When I insert a code block, I usually first mark the current line, before I issue org-insert-structure-template, but can I encapsulate the current line, without selecting it?

Something like this, but which works;)

(defun org-insert-contextual-structure-template ()

1 Answer 1


You can but I'm not sure it's worth it. Here's a function to do it:

#+begin_src elisp
  (defun my/org-wrap-current-line-in-structure-template ()
    (push-mark nil t t)
    (call-interactively #'org-insert-structure-template)

It doesn't do a save-excursion, so point will end up after the #+begin_src so that you can enter the language.

Unfortunately, when org-insert-structure-template is to apply to a region, it depends on the region being active (that's what the last t argument in the push-mark call above does: it makes the mark (and hence the region) active). It would be nicer IMO if it took a region as argument, so that we wouldn't have to resort to using call-interactively, but c'est la vie.

  • Yet another question, another answer and ... crickets.
    – NickD
    Commented Dec 19, 2023 at 22:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.