From: Noam Postavsky <npostavs@gmail.com>
To: Leo Liu <sdl.web@gmail.com>
Cc: 35286@debbugs.gnu.org
Subject: bug#35286: 26.2; indent-sexp broken
Date: Tue, 16 Apr 2019 08:16:31 -0400 [thread overview]
Message-ID: <8736miywkg.fsf@gmail.com> (raw)
In-Reply-To: <m1tveyy6vv.fsf@gmail.com> (Leo Liu's message of "Tue, 16 Apr 2019 11:19:00 +0800")
[-- Attachment #1: Type: text/plain, Size: 444 bytes --]
Leo Liu <sdl.web@gmail.com> writes:
> Treating things between parentheses as sexp [...] is not lisp-specific
This part makes sense to me.
> using indent-sexp to indent it is not lisp-specific
This is what surprises me. How does
lisp-indent-calc-next/calculate-lisp-indent give correct results for
non-lisp? I think using prog-indent-sexp for non-lisp would make more
sense.
Anyway, the following patch seems to work with your examples.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 3495 bytes --]
From 0739d40a3c1aa5690442f84cc7bf5fa093f5b06e Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Mon, 15 Apr 2019 18:49:57 -0400
Subject: [PATCH] Be more careful about indent-sexp going over eol (Bug#35286)
* lisp/emacs-lisp/lisp-mode.el (indent-sexp): Only go over multiple
sexps if the end of line is within a sexp.
---
lisp/emacs-lisp/lisp-mode.el | 22 ++++++++++++++--------
test/lisp/emacs-lisp/lisp-mode-tests.el | 12 ++++++++++++
2 files changed, 26 insertions(+), 8 deletions(-)
diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el
index 57f57175c5..74bf0c87c5 100644
--- a/lisp/emacs-lisp/lisp-mode.el
+++ b/lisp/emacs-lisp/lisp-mode.el
@@ -1205,19 +1205,25 @@ (defun indent-sexp (&optional endpos)
;; Get error now if we don't have a complete sexp
;; after point.
(save-excursion
+ (forward-sexp 1)
(let ((eol (line-end-position)))
- (forward-sexp 1)
;; We actually look for a sexp which ends
;; after the current line so that we properly
;; indent things like #s(...). This might not
;; be needed if Bug#15998 is fixed.
- (condition-case ()
- (while (and (< (point) eol) (not (eobp)))
- (forward-sexp 1))
- ;; But don't signal an error for incomplete
- ;; sexps following the first complete sexp
- ;; after point.
- (scan-error nil)))
+ (when (and (< (point) eol)
+ ;; Check if eol is within a sexp.
+ (> (nth 0 (save-excursion
+ (parse-partial-sexp
+ (point) eol)))
+ 0))
+ (condition-case ()
+ (while (< (point) eol)
+ (forward-sexp 1))
+ ;; But don't signal an error for incomplete
+ ;; sexps following the first complete sexp
+ ;; after point.
+ (scan-error nil))))
(point)))))
(save-excursion
(while (let ((indent (lisp-indent-calc-next parse-state))
diff --git a/test/lisp/emacs-lisp/lisp-mode-tests.el b/test/lisp/emacs-lisp/lisp-mode-tests.el
index a6370742ab..3782bad315 100644
--- a/test/lisp/emacs-lisp/lisp-mode-tests.el
+++ b/test/lisp/emacs-lisp/lisp-mode-tests.el
@@ -136,6 +136,18 @@ (ert-deftest indent-sexp-cant-go ()
(indent-sexp)
(should (equal (buffer-string) "(())"))))
+(ert-deftest indent-sexp-stop-before-eol-comment ()
+ "`indent-sexp' shouldn't look for more sexps after an eol comment."
+ ;; See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=35286.
+ (with-temp-buffer
+ (emacs-lisp-mode)
+ (let ((str "() ;;\n x"))
+ (insert str)
+ (goto-char (point-min))
+ (indent-sexp)
+ ;; The "x" is in the next sexp, so it shouldn't get indented.
+ (should (equal (buffer-string) str)))))
+
(ert-deftest lisp-indent-region ()
"Test basics of `lisp-indent-region'."
(with-temp-buffer
--
2.11.0
next prev parent reply other threads:[~2019-04-16 12:16 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-15 12:14 bug#35286: 26.2; indent-sexp broken Leo Liu
2019-04-15 23:57 ` Noam Postavsky
2019-04-16 0:35 ` Leo Liu
2019-04-16 0:54 ` Noam Postavsky
2019-04-16 3:19 ` Leo Liu
2019-04-16 12:16 ` Noam Postavsky [this message]
2019-04-16 12:57 ` Leo Liu
2019-04-16 13:13 ` Leo Liu
2019-04-21 8:41 ` Leo Liu
2019-04-22 16:51 ` Noam Postavsky
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=8736miywkg.fsf@gmail.com \
--to=npostavs@gmail.com \
--cc=35286@debbugs.gnu.org \
--cc=sdl.web@gmail.com \
/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.