emacs-pretest-bug
[Top][All Lists]
Advanced

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

Re: up-list gives error inside strings


From: martin rudalics
Subject: Re: up-list gives error inside strings
Date: Thu, 26 Apr 2007 08:57:00 +0200
User-agent: Mozilla Thunderbird 1.0 (Windows/20041206)

> Using this, it was very easy to get the function I wanted.

Calling `syntax-ppss' repeatedly can become costly for deeply nested
positions.  I'd propose something like the below:

(defun up-list-forward (arg)
  "Move forward out of one level of parentheses.
With arg, do this that many times.
A negative argument means move backward but still to a less deep spot."
  (interactive "p")
  (or arg (setq arg 1))
  (unless (zerop arg)
    (let* ((pos (point))
           (abs (abs arg))
           (ppss (syntax-ppss pos))
           (depth (nth 0 ppss))
           (ninth (nth 9 (syntax-ppss pos))))
      (if (< depth abs)
          (error "Reached top level")
        (goto-char (nth (- depth abs) ninth))
        (unless (< arg 0)
          (condition-case nil
              (forward-sexp)
            (scan-error
             ;; Improve as soon as `scan-error' gets documented somewhere.
             (goto-char pos)
             (error "No enclosing list"))))))))





reply via email to

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