unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Proposal: make up-list escape strings
@ 2014-04-08 23:14 Daniel Colascione
  2014-04-09  1:11 ` Stefan Monnier
  2014-04-09  6:17 ` Andreas Röhler
  0 siblings, 2 replies; 10+ messages in thread
From: Daniel Colascione @ 2014-04-08 23:14 UTC (permalink / raw)
  To: Emacs developers

[-- Attachment #1: Type: text/plain, Size: 3476 bytes --]

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 #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 901 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2014-04-09 16:09 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-08 23:14 Proposal: make up-list escape strings Daniel Colascione
2014-04-09  1:11 ` Stefan Monnier
2014-04-09  1:47   ` Daniel Colascione
2014-04-09  3:54     ` Stefan Monnier
2014-04-09  3:56     ` Stefan Monnier
2014-04-09  4:12       ` Daniel Colascione
2014-04-09  6:30         ` Daniel Colascione
2014-04-09 12:41           ` Stefan Monnier
2014-04-09 16:09             ` Daniel Colascione
2014-04-09  6:17 ` Andreas Röhler

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).