To answer my own question
(add-hook 'LaTeX-after-insert-env-hooks 'LaTeX-after-insert-hint nil t)
where I have defined LaTeX-after-insert-hint, just remember that the hook is given env (name of environment, should test to see if it is the one the hook should be acting on), start (pos just before the inserted \begin) and end (pos just before inserted \end)
EDIT: In the the present case, I'm editing a book, where the author sometimes write hints within the exercises. I'd like those to have a consistent look, so I wrap a hint environment around it. The hints often start with Hint:, I'd like the environment to provide that, so I want a hook that can clean the contents of the hint environment after I have wrapped hint around it using C-c C-e. This does the trick
;; remember start is just before inserted \begin
(defun LaTeX-after-insert-hint (env start end)
"Do some cleanup of the hint env"
(when (string-equal env "hint")
(save-excursion
(goto-char start)
(forward-line 1)
;; only clean if there is a match
(when (looking-at "[ \t\n]*Hint\: *")
(delete-region (match-beginning 0) (match-end 0))
)
(LaTeX-fill-environment 'left)
)
)
)
(add-hook 'LaTeX-after-insert-env-hooks 'LaTeX-after-insert-hint nil t)
The (LaTeX-fill-environment 'left) is not necessary, it is just a nice extra feature.
latex.elI think it have found the answerLaTeX-after-insert-env-hooks,doc.eluse this to add a hook to makesuremacrocodeenv is formatted correctly. Sounds like exactly what I'm looking for. – daleif Jan 17 at 10:42