emacs-devel
[Top][All Lists]
Advanced

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

Re: Proposal: make up-list escape strings


From: Andreas Röhler
Subject: Re: Proposal: make up-list escape strings
Date: Wed, 09 Apr 2014 08:17:04 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.2.0

Am 09.04.2014 01:14, schrieb Daniel Colascione:
Here's a small patch that makes backward-up-list and up-list escape
strings as well as explicit lists. This behavior is active only when
these functions are called interactively or when lisp explicitly asks
for this behavior, so the change shouldn't pose a compatibility risk.
Backing out of strings is generally a useful thing to do when you want
to operate on the string as a whole.

=== modified file 'lisp/emacs-lisp/lisp.el'
--- lisp/emacs-lisp/lisp.el     2014-02-26 02:31:27 +0000
+++ lisp/emacs-lisp/lisp.el     2014-04-08 23:12:16 +0000
@@ -140,38 +140,58 @@
        (goto-char (or (scan-lists (point) inc -1) (buffer-end arg)))
        (setq arg (- arg inc)))))

-(defun backward-up-list (&optional arg)
+(defun backward-up-list (&optional arg escape-strings)
    "Move backward out of one level of parentheses.
  This command will also work on other parentheses-like expressions
  defined by the current language mode.
  With ARG, do this that many times.
  A negative argument means move forward but still to a less deep spot.
-This command assumes point is not in a string or comment."
-  (interactive "^p")
-  (up-list (- (or arg 1))))
+This command assumes point is not in a string or comment.
+If ESCAPE-STRINGS is non-nil (as it is interactively), treat
+encoding strings as sexps."
+  (interactive "^p\nd")
+  (up-list (- (or arg 1)) escape-strings))

-(defun up-list (&optional arg)
+(defun up-list (&optional arg escape-strings)
    "Move forward out of one level of parentheses.
  This command will also work on other parentheses-like expressions
  defined by the current language mode.
  With ARG, do this that many times.
  A negative argument means move backward but still to a less deep spot.
-This command assumes point is not in a string or comment."
-  (interactive "^p")
+If ESCAPE-STRINGS is non-nil (as it is interactively), treat
+encoding strings as sexps."
+  (interactive "^p\nd")
    (or arg (setq arg 1))
    (let ((inc (if (> arg 0) 1 -1))
          pos)
      (while (/= arg 0)
        (if (null forward-sexp-function)
-          (goto-char (or (scan-lists (point) inc 1) (buffer-end arg)))
+          (condition-case err
+              (goto-char (or (scan-lists (point) inc 1) (buffer-end arg)))
+            (scan-error
+             (or (and escape-strings
+                      (let ((syntax (syntax-ppss)))
+                        (and (nth 3 syntax)
+                             (nth 8 syntax))
+                        (goto-char (nth 8 syntax))
+                        (when (> arg 0) (forward-sexp))
+                        t))
+                 (signal (car err) (cdr err)))))
        (condition-case err
            (while (progn (setq pos (point))
                          (forward-sexp inc)
                          (/= (point) pos)))
          (scan-error (goto-char (nth (if (> arg 0) 3 2) err))))
        (if (= (point) pos)
-            (signal 'scan-error
-                    (list "Unbalanced parentheses" (point) (point)))))
+            (or (and escape-strings
+                     (let ((syntax (syntax-ppss)))
+                       (and (nth 3 syntax)
+                            (nth 8 syntax))
+                       (goto-char (nth 8 syntax))
+                       (when (> arg 0) (forward-sexp))
+                       t))
+             (signal 'scan-error
+                     (list "Unbalanced parentheses" (point) (point))))))
        (setq arg (- arg inc)))))

  (defun kill-sexp (&optional arg)



Probably the most ancient bug :-)

IMO you don't need "and" going out of comments/strings

just (goto-char (nth 8 syntax))


Here is the form I'm using for ages:

(defun ar-up-list (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")
  (let ((orig (point))
        (pps (syntax-ppss))
        erg)
    (and (nth 8 pps) (goto-char (nth 8 pps)))
    (ignore-errors (up-list arg))
    (and (< orig (point)) (setq erg (point)))
    (when (interactive-p) (message "%s" erg))
    erg))

Cheers,

Andreas




reply via email to

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