help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Elisp: How do I move to the start of the next list?


From: Alan Mackenzie
Subject: Elisp: How do I move to the start of the next list?
Date: Wed, 1 Oct 2003 19:18:42 +0000
User-agent: tin/1.4.5-20010409 ("One More Nightmare") (UNIX) (Linux/2.0.35 (i686))

Frequently in an Elisp program, I'd like to move point to the start of
the next list.  For example, say point is here:

    starting point
          |
          v
    (cond ((eq action 'space)
           (+ col value))
          ;; comment
          ((eq action 'column)
          ^
          |
desired target point

I'd like a command which would move it forward to the desired target
point.  Something like what C-M-n does.

However, C-M-n `forward-list' doesn't do quite what I want.  It moves to
the end of the current list, rather than the start of the next list.  I
frequently find myself doing C-M-n twice followed by C-M-p, or C-M-n
followed by manually moving point to the start of the next list, which
has been irritating me more and more AND MORE AND MORE .... to the point
WHERE I JUST CAN'T STAND IT, AND I'M _SCREAMING_ EVERY TIME I WANT TO DO
THIS.

So, before I beg the busy people on the Emacs core team to upgrade
forward-list to something like the following, so that C-u C-M-n will do
what I want:

(defun forward-list (&optional arg)
  "Move forward across one balanced group of parentheses.
With ARG, do it that many times.
Negative arg -N means move backward across N groups of parentheses.
With bare C-u prefix, move forward to the start of the next list."
  (interactive "P")
  (if (consp arg)
      (let (state
            (lim                     ; pos of closing ) of current expression.
             (save-excursion
               (setq state (parse-partial-sexp (point) (point-max) -1))
                             ; (if (nth 2 state) (nth 2 state) (point-max)))))
               (point))))
        ;; If we're already at a list, scan over it.
        (if (looking-at "\\s(")
            (goto-char (or (scan-lists (point) 1 0) (buffer-end arg))))
        ;; Advance point to the next (, if it's not already at one.  Do not go
        ;; outside the enclosing list.
        (setq state (parse-partial-sexp (point) lim 1))
        (goto-char (or (nth 1 state) (1- (point)))))
    (goto-char (or (scan-lists (point) (prefix-numeric-value arg) 0)
                   (buffer-end arg)))))

, is there any convenient way in the current Emacs already which moves to
the start of the next list?

-- 
Alan Mackenzie (Munich, Germany)
Email: address@hidden; to decode, wherever there is a repeated letter
(like "aa"), remove half of them (leaving, say, "a").



reply via email to

[Prev in Thread] Current Thread [Next in Thread]