2

I am using Org Mode version 9.3 with (require 'org-tempo) in my configuration.


Observed behaviour:

A.

Given

* Heading

<s

TAB produces

* Heading

  #+begin_src 

  #+end_src

B.

Given

* Heading
Text
<s

TAB produces

* Heading
Text
#+begin_src 

#+end_src

Desired behaviour:

Given

* Heading

<s

TAB produces

* Heading

#+begin_src 

#+end_src

2
+50

For this particular case, the indentation resulting from the expansion of the structure template is probably caused by org-tempo respecting org-adapt-indentation, which is set to t by default. The "B" case appears to work because the indentation is already broken by the first line after the heading.

With org-adapt-indentation:

Org assumes that you write outlines by indenting text in each node to align with the headline (after the stars).

With it TAB will indent to it, drawers and planning info will adapt to it, etc. And org-tempo structure templates too.

So, if you don't want this indentation in general, set org-adapt-indentation to nil. If you do, Org thus enables you to stick to this consistently in the structure template expansion from org-tempo.

There has also been a recent change in the master branch (hopefully soon available more generally) in response to a question about this default value (https://lists.gnu.org/archive/html/emacs-orgmode/2020-02/msg00326.html). When it comes, we'll have also value headline-data for org-adapt-indentation to indent planning, properties and logbook, but keep the contend unindented.

| improve this answer | |
1

The package org-structtempl.el brings back the old structure template mechanism to Orgmode.
Therewith your desired behavior is the default.

The actual reason for extracting the old code from Org 9.1.14 and putting it in its own package org-structtempl.el is that the old mechanism was more general than that one of org-tempo.el. For an instance there is no way to mimic the following entry of org-structtempl-alist with org-tempo.el:

("m" "\\begin{align*}\n?\n\\end{align*}")

Furthermore, I had heavily customized the structure templates with the help of the advice-mechanism. That suddenly didn't work anymore when Org 9.2 was out. My customization does not interfere with the old functionality. Therefore, I plan to add it to org-structtempl.el. With my customization the following substitution is possible:

<s emacs-lisp :results silent
(cl-loop for i from 0 upto 3 do
  (message "Structure templates are cool.")
)

With all that stuff marked as region, it is substituted by the following stuff when pressing tab:

#+BEGIN_SRC emacs-lisp :results silent
(cl-loop for i from 0 upto 3 do
  (message "Structure templates are cool.")
)
#+END_SRC

Another feature of my modifications is that TAB-completion of a line only containing <m asks you for a LaTeX environment and substitutes it for the shortcut <m.

To make this additional stuff already now available to you, I've put it into org+-structtempl.el.

You can install both packages by saving them somewhere into your load-path and adding the following lines to your init file:

(with-eval-after-load 'org
  (require 'org-structtempl)
  (require 'org+-structtempl))
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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