all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alan Mackenzie<none@example.invalid>
Subject: Elisp:  How do I move to the start of the next list?
Date: Wed, 1 Oct 2003 19:18:42 +0000	[thread overview]
Message-ID: <ia9flb.r5.ln@acm.acm> (raw)

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: aacm@muuc.dee; to decode, wherever there is a repeated letter
(like "aa"), remove half of them (leaving, say, "a").

                 reply	other threads:[~2003-10-01 19:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ia9flb.r5.ln@acm.acm \
    --to=none@example.invalid \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.