[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#3416: down-list
From: |
Andreas Röhler |
Subject: |
bug#3416: down-list |
Date: |
Fri, 29 May 2009 20:04:48 +0200 |
User-agent: |
Thunderbird 2.0.0.19 (X11/20081227) |
martin rudalics wrote:
> > you are right. Nonetheless, as strings are common
> > elements of lists, not just in Python, its such an
> > inconvenience, it qualifies as bug in my eyes.
> >
> > If you don't want to dig into scan-list, that trivial
> > line I've sent is enough to cure it.
>
> IIUC you want to skip anything but a left paren before starting the
> scan. This means you might skip the start of a comment or string and
> end up before the first left paren within that comment or string.
>
> The only right way to do that is to parse the syntax until point first
> and handle the case where you are in a comment or string
OK, but checking for string seems enough, as we are inside a list.
> appropriately.
> That approach has been suggested a number of times but so far no one has
> implemented it.
>
> martin
>
Very bad, as going down a list is a very basic task for any editor.
This should work:
(defun down-list (&optional arg)
"Move forward down one level of parentheses.
With ARG, do this that many times.
A negative argument means move backward but still go down a level.
This command assumes point is not in a string or comment."
(interactive "^p")
(or arg (setq arg 1))
(let ((inc (if (> arg 0) 1 -1)))
(while (/= arg 0)
;; 2009-05-29 a.roehler@web.de changed section start
(while (or (not (looking-at "\\s(")) (and (looking-at
"\\s(")(in-string-p)))
(forward-char 1)
(skip-syntax-forward "^\\s("))
;; 2009-05-29 a.roehler@web.de changed section end
(goto-char (or (scan-lists (point) inc -1) (buffer-end arg)))
(setq arg (- arg inc)))))
(defun in-string-p (&optional pos)
(let ((orig (or pos (point))))
(save-excursion
(save-restriction
(widen)
(beginning-of-defun)
(numberp (nth 3 (parse-partial-sexp (point) orig)))))))
Grüße
Andreas