From: "Andreas Röhler" <andreas.roehler@online.de>
To: emacs-devel@gnu.org
Cc: Daniel Colascione <dan.colascione@gmail.com>,
Stefan Monnier <monnier@IRO.UMontreal.CA>
Subject: Re: Proposal: make up-list escape strings
Date: Wed, 09 Apr 2014 08:17:04 +0200 [thread overview]
Message-ID: <5344E5E0.8080709@online.de> (raw)
In-Reply-To: <534482F2.6010504@dancol.org>
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
prev parent reply other threads:[~2014-04-09 6:17 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5344E5E0.8080709@online.de \
--to=andreas.roehler@online.de \
--cc=dan.colascione@gmail.com \
--cc=emacs-devel@gnu.org \
--cc=monnier@IRO.UMontreal.CA \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).