In AUCTeX M-RET is bound to (LaTeX-insert-item)
which makes a new properly indented line and inserts \item
and a space after which the cursor is placed. I would like to extend this feature so that C-M-RET has similar functionality but for \item[description]
.
What I would like is for C-M-RET to
\item[]
,\item[]
as Tab is pressed.The following function is cribbed from latex.el, and modified slightly to call the argument-prompting version LaTeX-item-argument
instead of just inserting the item directly.
(defun LaTeX-insert-item-arg ()
"Insert a new item in an environment, prompting for an item label.
You may use `LaTeX-item-list' to change the routines used to insert the item."
(interactive "*")
(let ((environment (LaTeX-current-environment)))
(when (and (TeX-active-mark)
(> (point) (mark)))
(exchange-point-and-mark))
(unless (bolp) (LaTeX-newline))
(if (assoc environment LaTeX-item-list)
(funcall (cdr (assoc environment LaTeX-item-list)))
(LaTeX-item-argument)) ;; ONLY THIS LINE IS DIFFERENT
(indent-according-to-mode)))
You can bind that function to any key you like:
(add-hook 'LaTeX-mode-hook (lambda ()
(local-set-key [(control return)] 'LaTeX-insert-item-arg)))
If you want M-C-RET
, use (meta control return)
instead, though it only seems to work with the Alt
key, and not the Esc
key (which usually behaves the same...)