2

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 ()
  (interactive)
  (select-current-line)
  (org-insert-structure-template)
  )

1 Answer 1

2

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.

1
  • 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.