How to insert a docstrip tag environment in AUCTeX

I am working on literate programming in LaTeX. Actually, I am coding a lot of dtx files, which contain both the code and its documentation.

When working in Emacs, it uses AUCTeX and switches into TeXDoc-mode.

Quite often, I have to insert docstrip options or tags, which look like this:

%<*option>
...
%</option>


(That is: a percent sign in the first column and than the tag which is enclosed in less/greater brackets <>. The opening tag begins with a asteriks *, the closing tag has a slash /. Of course, the name of the tag (here: option) has to be spelled identically.)

I would love to have some kind of Emacs function, which inserts this special kind of enviroment. Using the classical LaTeX-environment is not suited, as it inserts \begin and '\end, which is not what I need.

I didn't find a hint in the manual.

Edit: I had a second question related to this theme.

You could write your own function and hook it into docTeX mode with a key binding, e.g. C-c g

(defun my/docTeX-guards ()
(interactive)
(LaTeX-newline)
(unless (equal (char-before) ?%)
(insert "%"))
(insert (concat "<*" guard ">"))
(newline)
(save-excursion
(newline)
(insert (concat "%</" guard ">")))))


• Arash, thank you very much. I added an newline` after the last insert. It works fine. I am very happy with it.