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 ()
(interactive)
(beginning-of-line)
(push-mark nil t t)
(end-of-line)
(call-interactively #'org-insert-structure-template)
(pop-mark))
#+end_src
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.