From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Noam Postavsky Newsgroups: gmane.emacs.bugs Subject: bug#35286: 26.2; indent-sexp broken Date: Tue, 16 Apr 2019 08:16:31 -0400 Message-ID: <8736miywkg.fsf@gmail.com> References: <87sguizurg.fsf@gmail.com> <87ftqizs5d.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="25800"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) Cc: 35286@debbugs.gnu.org To: Leo Liu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Apr 16 14:17:14 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hGN1V-0006TQ-L7 for geb-bug-gnu-emacs@m.gmane.org; Tue, 16 Apr 2019 14:17:13 +0200 Original-Received: from localhost ([127.0.0.1]:35854 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hGN1U-0003wD-JO for geb-bug-gnu-emacs@m.gmane.org; Tue, 16 Apr 2019 08:17:12 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:52296) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hGN1M-0003w5-2z for bug-gnu-emacs@gnu.org; Tue, 16 Apr 2019 08:17:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hGN1K-0001b6-TC for bug-gnu-emacs@gnu.org; Tue, 16 Apr 2019 08:17:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:51456) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hGN1K-0001aZ-GD for bug-gnu-emacs@gnu.org; Tue, 16 Apr 2019 08:17:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hGN1J-0004IN-Vj for bug-gnu-emacs@gnu.org; Tue, 16 Apr 2019 08:17:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Noam Postavsky Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 16 Apr 2019 12:17:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 35286 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 35286-submit@debbugs.gnu.org id=B35286.155541700116473 (code B ref 35286); Tue, 16 Apr 2019 12:17:01 +0000 Original-Received: (at 35286) by debbugs.gnu.org; 16 Apr 2019 12:16:41 +0000 Original-Received: from localhost ([127.0.0.1]:36767 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hGN0z-0004Hd-D1 for submit@debbugs.gnu.org; Tue, 16 Apr 2019 08:16:41 -0400 Original-Received: from mail-qt1-f172.google.com ([209.85.160.172]:43344) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hGN0x-0004HQ-8r for 35286@debbugs.gnu.org; Tue, 16 Apr 2019 08:16:39 -0400 Original-Received: by mail-qt1-f172.google.com with SMTP id v32so22907313qtc.10 for <35286@debbugs.gnu.org>; Tue, 16 Apr 2019 05:16:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=lxt22yqASnWSIdXPYd8rksKglF5HGmn5Fz1fKDoRang=; b=WPUUwX6djr/7WoDFFmszt+2cQ349jMIbApYljizlWg+Y0rvPobWSXCNgjxQh3MJGww vlUeU9J+jd99B1nX1u4dJebtBAOvtFDaRH2tms62V8hHCufJlq7EAhK5skRau6aRZ7Zu F0N0U7yO72SVpSPURpX1f0FBJUWosymqyi4ibdGVH2FYkiwDhER+R+t3EtD4Ugk4IDQ2 CC3oba5aW17oHTXvehIK4DnL5bBYgiTPuqPRyei+Dx6aZZUJ747goxdCfgrCIix+z/4p IV/Npw7cvc7Rk1nU4Ls299QOmXWqAZ9IaP1gr9aEDXumzi1S4zk8VawTVywee/bsnzzr lK0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=lxt22yqASnWSIdXPYd8rksKglF5HGmn5Fz1fKDoRang=; b=PHJQ1So1rwMbg2aAYI6lhUHMuDTNxk6Mvvnl8BsfT/nodSO63uNzF+Gsnd4FJ4S7t9 EPTYbfFAOrqs2GI9fA4JmeLg5wYoP55Oz1VLNXrY7w11hM0RDZQT9TNZhSgqX7Nh7dyA /RyUw1WaL9BEEybTUS/+C0ymgUE8fIm+Sh4S5LgK8q4q6oUtodC+o7DHAE0DJO5ASSk+ MobXzUjKvcvayOBchZ4Qi2OzdtKwkFm3hsB7/8xyDEEeIrx3axhs8r+uvUVVraJ23Y4e NuHNjXNR/NMMGG2tYlVZ5+cauNyMTi20/P0QP29tYp517sQ/WlpydeUp1TuKDX+q3QyH CgJQ== X-Gm-Message-State: APjAAAWLBrZf7r1bIWdujJ5/y90e+KqHDlpMhoNIX3XORG2tHzWELX5t 9GOTiOB0y/QYUZGqP0OV9tA7NVAI X-Google-Smtp-Source: APXvYqwC4SmAlozazRGpLtj6iMQ2/lxXTKRw2tbpOR6KwGQe60VwQleNNkFpdsFFfOXm7RTro9lb2g== X-Received: by 2002:aed:35e3:: with SMTP id d32mr63839459qte.43.1555416993640; Tue, 16 Apr 2019 05:16:33 -0700 (PDT) Original-Received: from minid (cbl-45-2-119-34.yyz.frontiernetworks.ca. [45.2.119.34]) by smtp.googlemail.com with ESMTPSA id m18sm35200333qki.64.2019.04.16.05.16.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 16 Apr 2019 05:16:32 -0700 (PDT) In-Reply-To: (Leo Liu's message of "Tue, 16 Apr 2019 11:19:00 +0800") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:157706 Archived-At: --=-=-= Content-Type: text/plain Leo Liu 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. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Be-more-careful-about-indent-sexp-going-over-eol-Bug.patch Content-Description: patch >From 0739d40a3c1aa5690442f84cc7bf5fa093f5b06e Mon Sep 17 00:00:00 2001 From: Noam Postavsky 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 --=-=-=--