emacs-devel
[Top][All Lists]
Advanced

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

Proposal: make up-list escape strings


From: Daniel Colascione
Subject: Proposal: make up-list escape strings
Date: Tue, 08 Apr 2014 16:14:58 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0

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)


Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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