4

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{}{}|
1
  • 1
    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. Commented Oct 5, 2013 at 22:48

1 Answer 1

5

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))
8
  • Changing search-forward "{}" to search-forward-regexp "{[^}]*}" and search-backward "{}" to search-backward-regexp "{[^}]*}" is more what I was looking for.
    – Geremia
    Commented Oct 6, 2013 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.
    – A.Ellett
    Commented Oct 7, 2013 at 17:35
  • @A.Ellett That's fine.
    – Geremia
    Commented Nov 7, 2013 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.
    – Geremia
    Commented Nov 7, 2013 at 23:40
  • @Geremia I keep forgetting to wrap an eval-after-load around define-keys. I'll update my answer.
    – giordano
    Commented Nov 8, 2013 at 0:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .