# Navigating arguments with AUCTeX

Is there a key combination to move the insertion point backward and forward through arguments using AUCTeX? For example, where "|" is my insertion point:

\frac{|}{}


Then I would want a command to move it:

\frac{}{|}


And perhaps another command to move it back:

\frac{|}{}


And another to move it out:

\frac{}{}|

• yasnippet does this sort of thing very well. Somebody has already written quite a few snippets for LaTeX, such as this one for \frac{}. yasnippet can be used in other modes and languages as well as in TeX. Oct 5 '13 at 22:48

## 1 Answer

To move between empty groups I use these functions (can be improved of course):

(defun mg-TeX-forward-group ()
"Move to the next empty group."
(interactive)
(let ((group (save-excursion (search-forward-regexp "{[^}]*}" nil t))))
(when group
(set-mark (point))
(deactivate-mark)
(goto-char group)
(backward-char 1))))
(eval-after-load "tex"
'(define-key TeX-mode-map [M-right] 'mg-TeX-forward-group))
(defun mg-TeX-backward-group ()
"Move to the previous empty group."
(interactive)
(let ((group (save-excursion (search-backward-regexp "{[^}]*}" nil t))))
(when group
(set-mark (point))
(deactivate-mark)
(goto-char group)
(forward-char 1))))
(eval-after-load "tex"
'(define-key TeX-mode-map [M-left] 'mg-TeX-backward-group))

• Changing search-forward "{}" to search-forward-regexp "{[^}]*}" and search-backward "{}" to search-backward-regexp "{[^}]*}" is more what I was looking for. Oct 6 '13 at 4:43
• @Geremia Your change has been approved, but you need to then change what the OP wrote about moving between empty groups. The change you made will pick up non-empty groups too. Oct 7 '13 at 17:35
• @A.Ellett That's fine. Nov 7 '13 at 23:31
• Upon starting Emacs, I get this strange error when putting your code in my ~/.emacs file: Symbol's value as variable is void: TeX-mode-map. Nov 7 '13 at 23:40
• @Geremia I keep forgetting to wrap an eval-after-load around define-keys. I'll update my answer. Nov 8 '13 at 0:34