From: "Mattias Engdegård" <mattiase@acm.org>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: 43489@debbugs.gnu.org
Subject: bug#43489: [PATCH] Don't signal scan-error when moving by sexp interactively
Date: Wed, 23 Sep 2020 11:17:35 +0200 [thread overview]
Message-ID: <EDCED21D-8DE6-4587-A4A2-5AAC4877A564@acm.org> (raw)
In-Reply-To: <87d02dj312.fsf@gnus.org>
[-- Attachment #1: Type: text/plain, Size: 465 bytes --]
22 sep. 2020 kl. 16.32 skrev Lars Ingebrigtsen <larsi@gnus.org>:
> Yeah, that makes sense to me.
Apologies for my indecision, but I'm not sure if they make sense to me.
But my personal flaws should not impede progress. How about I push what I've got (latest patch attached for reference) since we seem to agree that it's an improvement over what's in master, and if then you or anyone else want to further adjust the messages then I have no objections.
[-- Attachment #2: 0001-Don-t-signal-scan-error-when-moving-by-sexp-interact.patch --]
[-- Type: application/octet-stream, Size: 8920 bytes --]
From 3249aeba659d636d6344a7ab0e3b1ecbb83da160 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= <mattiase@acm.org>
Date: Fri, 18 Sep 2020 12:49:33 +0200
Subject: [PATCH] Don't signal scan-error when moving by sexp interactively
* lisp/emacs-lisp/lisp.el (forward-sexp, backward-sexp, forward-list)
(backward-list, down-list, up-list, mark-sexp, kill-sexp)
(backward-kill-sexp): Remove unsightly scan-error when running
interactively and no further movement by sexp can be made.
---
lisp/emacs-lisp/lisp.el | 134 ++++++++++++++++++++++++++--------------
1 file changed, 89 insertions(+), 45 deletions(-)
diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el
index ac4ba78897..f74243c890 100644
--- a/lisp/emacs-lisp/lisp.el
+++ b/lisp/emacs-lisp/lisp.el
@@ -55,7 +55,7 @@ forward-sexp-function
"If non-nil, `forward-sexp' delegates to this function.
Should take the same arguments and behave similarly to `forward-sexp'.")
-(defun forward-sexp (&optional arg)
+(defun forward-sexp (&optional arg noerror)
"Move forward across one balanced expression (sexp).
With ARG, do it that many times. Negative arg -N means move
backward across N balanced expressions. This command assumes
@@ -64,23 +64,31 @@ forward-sexp
If unable to move over a sexp, signal `scan-error' with three
arguments: a message, the start of the obstacle (usually a
parenthesis or list marker of some kind), and end of the
-obstacle."
- (interactive "^p")
- (or arg (setq arg 1))
- (if forward-sexp-function
- (funcall forward-sexp-function arg)
- (goto-char (or (scan-sexps (point) arg) (buffer-end arg)))
- (if (< arg 0) (backward-prefix-chars))))
-
-(defun backward-sexp (&optional arg)
+obstacle. If NOERROR is non-nil, as it is interactively,
+do not signal an error."
+ (interactive "^p\nd")
+ (if noerror
+ (condition-case _
+ (forward-sexp arg nil)
+ (scan-error (user-error (if (> arg 0)
+ "No next sexp"
+ "No previous sexp"))))
+ (or arg (setq arg 1))
+ (if forward-sexp-function
+ (funcall forward-sexp-function arg)
+ (goto-char (or (scan-sexps (point) arg) (buffer-end arg)))
+ (if (< arg 0) (backward-prefix-chars)))))
+
+(defun backward-sexp (&optional arg noerror)
"Move backward across one balanced expression (sexp).
With ARG, do it that many times. Negative arg -N means
move forward across N balanced expressions.
This command assumes point is not in a string or comment.
-Uses `forward-sexp' to do the work."
- (interactive "^p")
+Uses `forward-sexp' to do the work.
+If NOERROR is non-nil, as it is interactively, do not signal an error."
+ (interactive "^p\nd")
(or arg (setq arg 1))
- (forward-sexp (- arg)))
+ (forward-sexp (- arg) noerror))
(defun mark-sexp (&optional arg allow-extend)
"Set mark ARG sexps from point.
@@ -99,50 +107,75 @@ mark-sexp
(set-mark
(save-excursion
(goto-char (mark))
- (forward-sexp arg)
+ (condition-case error
+ (forward-sexp arg)
+ (scan-error
+ (user-error (if (equal (cadr error)
+ "Containing expression ends prematurely")
+ "No more sexp to select"
+ (cadr error)))))
(point))))
(t
(push-mark
(save-excursion
- (forward-sexp (prefix-numeric-value arg))
+ (condition-case error
+ (forward-sexp (prefix-numeric-value arg))
+ (scan-error
+ (user-error (if (equal (cadr error)
+ "Containing expression ends prematurely")
+ "No sexp to select"
+ (cadr error)))))
(point))
nil t))))
-(defun forward-list (&optional arg)
+(defun forward-list (&optional arg noerror)
"Move forward across one balanced group of parentheses.
This command will also work on other parentheses-like expressions
defined by the current language mode.
With ARG, do it that many times.
Negative arg -N means move backward across N groups of parentheses.
-This command assumes point is not in a string or comment."
- (interactive "^p")
- (or arg (setq arg 1))
- (goto-char (or (scan-lists (point) arg 0) (buffer-end arg))))
-
-(defun backward-list (&optional arg)
+This command assumes point is not in a string or comment.
+If NOERROR is non-nil, as it is interactively, do not signal an error."
+ (interactive "^p\nd")
+ (if noerror
+ (condition-case _
+ (forward-list arg nil)
+ (scan-error (user-error (if (> arg 0)
+ "No next group"
+ "No previous group"))))
+ (or arg (setq arg 1))
+ (goto-char (or (scan-lists (point) arg 0) (buffer-end arg)))))
+
+(defun backward-list (&optional arg noerror)
"Move backward across one balanced group of parentheses.
This command will also work on other parentheses-like expressions
defined by the current language mode.
With ARG, do it that many times.
Negative arg -N means move forward across N groups of parentheses.
-This command assumes point is not in a string or comment."
- (interactive "^p")
+This command assumes point is not in a string or comment.
+If NOERROR is non-nil, as it is interactively, do not signal an error."
+ (interactive "^p\nd")
(or arg (setq arg 1))
- (forward-list (- arg)))
+ (forward-list (- arg) noerror))
-(defun down-list (&optional arg)
+(defun down-list (&optional arg noerror)
"Move forward down 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 go down a level.
-This command assumes point is not in a string or comment."
- (interactive "^p")
- (or arg (setq arg 1))
- (let ((inc (if (> arg 0) 1 -1)))
- (while (/= arg 0)
- (goto-char (or (scan-lists (point) inc -1) (buffer-end arg)))
- (setq arg (- arg inc)))))
+This command assumes point is not in a string or comment.
+If NOERROR is non-nil, as it is interactively, do not signal an error."
+ (interactive "^p\nd")
+ (if noerror
+ (condition-case _
+ (down-list arg nil)
+ (scan-error (user-error "At bottom level")))
+ (or arg (setq arg 1))
+ (let ((inc (if (> arg 0) 1 -1)))
+ (while (/= arg 0)
+ (goto-char (or (scan-lists (point) inc -1) (buffer-end arg)))
+ (setq arg (- arg inc))))))
(defun backward-up-list (&optional arg escape-strings no-syntax-crossing)
"Move backward out of one level of parentheses.
@@ -229,26 +262,37 @@ up-list
(or (< inc 0)
(forward-comment 1))
(setf arg (+ arg inc)))
- (signal (car err) (cdr err))))))
+ (if no-syntax-crossing
+ ;; Assume called interactively; don't signal an error.
+ (user-error "At top level")
+ (signal (car err) (cdr err)))))))
(setq arg (- arg inc)))))
-(defun kill-sexp (&optional arg)
+(defun kill-sexp (&optional arg noerror)
"Kill the sexp (balanced expression) following point.
With ARG, kill that many sexps after point.
Negative arg -N means kill N sexps before point.
-This command assumes point is not in a string or comment."
- (interactive "p")
- (let ((opoint (point)))
- (forward-sexp (or arg 1))
- (kill-region opoint (point))))
-
-(defun backward-kill-sexp (&optional arg)
+This command assumes point is not in a string or comment.
+If NOERROR is non-nil, as it is interactively, do not signal an error."
+ (interactive "p\nd")
+ (if noerror
+ (condition-case _
+ (kill-sexp arg nil)
+ (scan-error (user-error (if (> arg 0)
+ "No next sexp"
+ "No previous sexp"))))
+ (let ((opoint (point)))
+ (forward-sexp (or arg 1))
+ (kill-region opoint (point)))))
+
+(defun backward-kill-sexp (&optional arg noerror)
"Kill the sexp (balanced expression) preceding point.
With ARG, kill that many sexps before point.
Negative arg -N means kill N sexps after point.
-This command assumes point is not in a string or comment."
- (interactive "p")
- (kill-sexp (- (or arg 1))))
+This command assumes point is not in a string or comment.
+If NOERROR is non-nil, as it is interactively, do not signal an error."
+ (interactive "p\nd")
+ (kill-sexp (- (or arg 1)) noerror))
;; After Zmacs:
(defun kill-backward-up-list (&optional arg)
--
2.21.1 (Apple Git-122.3)
next prev parent reply other threads:[~2020-09-23 9:17 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-18 11:31 bug#43489: [PATCH] Don't signal scan-error when moving by sexp interactively Mattias Engdegård
2020-09-18 13:13 ` Lars Ingebrigtsen
2020-09-18 13:18 ` Dmitry Gutov
2020-09-18 13:42 ` Lars Ingebrigtsen
2020-09-18 13:48 ` Dmitry Gutov
2020-09-18 15:13 ` Mattias Engdegård
2020-09-18 15:23 ` Lars Ingebrigtsen
2020-09-18 16:01 ` Mattias Engdegård
2020-09-19 14:13 ` Lars Ingebrigtsen
2020-09-20 17:33 ` Mattias Engdegård
2020-09-20 19:54 ` Lars Ingebrigtsen
2020-09-21 10:55 ` Mattias Engdegård
2020-09-21 14:47 ` Lars Ingebrigtsen
2020-09-21 17:12 ` Mattias Engdegård
2020-09-22 14:32 ` Lars Ingebrigtsen
2020-09-23 9:17 ` Mattias Engdegård [this message]
2020-09-23 13:40 ` Lars Ingebrigtsen
2020-09-23 14:33 ` Mattias Engdegård
2020-09-23 14:45 ` João Távora
2020-09-23 16:24 ` Mattias Engdegård
2020-09-23 16:37 ` João Távora
2020-09-24 15:50 ` Mattias Engdegård
2020-09-24 15:58 ` João Távora
2020-09-24 17:32 ` Stefan Monnier
2020-09-24 19:23 ` João Távora
2020-09-28 17:05 ` Stefan Monnier
2020-09-20 21:39 ` Dmitry Gutov
2020-09-21 11:21 ` Mattias Engdegård
2020-09-21 12:36 ` Dmitry Gutov
2020-09-21 17:12 ` Mattias Engdegård
2020-09-21 17:49 ` Dmitry Gutov
2020-09-21 8:49 ` João Távora
2020-09-21 14:43 ` Lars Ingebrigtsen
2020-09-21 17:12 ` Mattias Engdegård
2020-09-21 17:25 ` João Távora
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=EDCED21D-8DE6-4587-A4A2-5AAC4877A564@acm.org \
--to=mattiase@acm.org \
--cc=43489@debbugs.gnu.org \
--cc=larsi@gnus.org \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.