* Elisp: How do I move to the start of the next list?
@ 2003-10-01 19:18 Alan Mackenzie
0 siblings, 0 replies; only message in thread
From: Alan Mackenzie @ 2003-10-01 19:18 UTC (permalink / 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").
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2003-10-01 19:18 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-10-01 19:18 Elisp: How do I move to the start of the next list? Alan Mackenzie
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.