From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: npostavs@users.sourceforge.net Newsgroups: gmane.emacs.bugs Subject: bug#26619: 26.0.50; Wrong indentation in emacs-lisp-mode Date: Tue, 25 Apr 2017 23:22:10 -0400 Message-ID: <87pofzontp.fsf@users.sourceforge.net> References: <87shkzsidm.fsf@calancha-pc> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1493176873 7712 195.159.176.226 (26 Apr 2017 03:21:13 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 26 Apr 2017 03:21:13 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) Cc: 26619@debbugs.gnu.org To: Kaushal Modi , Michael Heerdegen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Apr 26 05:21:07 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d3DVq-0001q9-QU for geb-bug-gnu-emacs@m.gmane.org; Wed, 26 Apr 2017 05:21:07 +0200 Original-Received: from localhost ([::1]:52359 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3DVw-0006z1-NF for geb-bug-gnu-emacs@m.gmane.org; Tue, 25 Apr 2017 23:21:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40745) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3DVp-0006yi-La for bug-gnu-emacs@gnu.org; Tue, 25 Apr 2017 23:21:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d3DVm-0005ft-Ew for bug-gnu-emacs@gnu.org; Tue, 25 Apr 2017 23:21:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:42169) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d3DVl-0005f4-VL for bug-gnu-emacs@gnu.org; Tue, 25 Apr 2017 23:21:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1d3DVl-0008LA-PM for bug-gnu-emacs@gnu.org; Tue, 25 Apr 2017 23:21:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: npostavs@users.sourceforge.net Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 26 Apr 2017 03:21:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 26619 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 26619-submit@debbugs.gnu.org id=B26619.149317684732030 (code B ref 26619); Wed, 26 Apr 2017 03:21:01 +0000 Original-Received: (at 26619) by debbugs.gnu.org; 26 Apr 2017 03:20:47 +0000 Original-Received: from localhost ([127.0.0.1]:40368 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d3DVX-0008KY-BV for submit@debbugs.gnu.org; Tue, 25 Apr 2017 23:20:47 -0400 Original-Received: from mail-it0-f65.google.com ([209.85.214.65]:34966) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d3DVV-0008KK-6a for 26619@debbugs.gnu.org; Tue, 25 Apr 2017 23:20:45 -0400 Original-Received: by mail-it0-f65.google.com with SMTP id 70so5267723ita.2 for <26619@debbugs.gnu.org>; Tue, 25 Apr 2017 20:20:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=WG9sQTE+lbdZ+QvcE9qcRGLz1q16CGxQ8RFJQyDNVes=; b=m7P+0A5xgAe9JihoyIvdyWwUUUxaw0yq/n/j+UGaGZHo58ud/yxp2mdFd7y68x2/NK DsuPlCKfbm6IpA70+YzdjPv1MJbkmJCGaoMb/OafSStHVy7dfQBCTs4UZelkLluPsBJs v6G5ZQiuvr9jggfKsmFE5+TCXWzb0DV0EBt2fEdcJWyHj7BSwOvIACKsq8PmVRwg0ADt KSZUpfuLc1wfhzY7oea/WcDABJLEB1zWlov1Z4aQIyUQrQM7fP2qOMywHAwB/xVnPvm7 07bz6yTYn08pFmfW7Sy3Vkwasgn7ofb0z7qrr9WXw4Awem78j1IfsgULcFxIxJXjourR 3zuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:references:date :in-reply-to:message-id:user-agent:mime-version; bh=WG9sQTE+lbdZ+QvcE9qcRGLz1q16CGxQ8RFJQyDNVes=; b=emwl4/l6bhcsTj/MDJYdMdrTUoTCq8RHA27I69mwdG/nVJrQkKCJe64gEtygQ4zGNZ 8oQr7hMjl+L/mA9ClfaxAsnBd8LB74rtyBG1t6DOmX1VyZfVtG7ohytrONVHE3luo45h rtukHCqkGs6EXB025v4zFUo2xAAZNJDG9ppFQEgEd5pHgMtwX0+2HfSmjyb3lJ4lx/BQ LcctAObxnr0ub2xZhfSnSnX3LLu1ZInoc+W1OHj1BMqP7AgD2iFXYQE0A+V6P4DEa71B YVNbZXvO25RQtGmy7R0UvRgnx22wt/h1cNnl4F31HMCFEVC7KTCWv8w3KpjCadMyKuI1 nFnQ== X-Gm-Message-State: AN3rC/6cPjGkhCbilygCYe0YEILeJnR94SPrunCOVhiddJWf4ticfj5N fFyK13eIZNUrjw== X-Received: by 10.36.233.2 with SMTP id f2mr4605990ith.40.1493176839697; Tue, 25 Apr 2017 20:20:39 -0700 (PDT) Original-Received: from zony ([45.2.7.65]) by smtp.googlemail.com with ESMTPSA id r141sm3366931ita.2.2017.04.25.20.20.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 25 Apr 2017 20:20:39 -0700 (PDT) In-Reply-To: (Kaushal Modi's message of "Mon, 24 Apr 2017 21:03:38 +0000") 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: 208.118.235.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:131988 Archived-At: --=-=-= Content-Type: text/plain Kaushal Modi writes: > > But indentation is still broken in cases like these: > > (with-eval-after-load 'foo > (setq bar `( > baz))) > Michael Heerdegen writes: > > There must be more cases. I already get wrong indentation with very > simple cases. E.g. here: > > #+begin_src emacs-lisp > (defun test () > "A test function" > (switch-to-buffer "*Messages*") > 17) > #+end_src Hmm, I was too aggressive about preserving the last sexp position of the parse state. The following patch fixes both these cases for indent-region (it applies on top of the previous one), though it needs to be redone more cleanly. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=v1-0002-WIP-Fix-additional-indentation-problems-Bug-26619.patch Content-Description: patch, part 2 >From 101fa466c3e5303458dc6abd2d24ef55d508d9cd Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Tue, 25 Apr 2017 23:16:12 -0400 Subject: [PATCH v1 2/2] [WIP] Fix additional indentation problems (Bug#26619) * lisp/emacs-lisp/lisp-mode.el (lisp-indent-region): Don't use last sexp from different depths. --- lisp/emacs-lisp/lisp-mode.el | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el index d619dd8f4c..12fd53140c 100644 --- a/lisp/emacs-lisp/lisp-mode.el +++ b/lisp/emacs-lisp/lisp-mode.el @@ -811,14 +811,25 @@ lisp-indent-region (unless (and (bolp) (eolp)) (lisp-indent-line (funcall calc-indent parse-state))) (forward-line 1) - (let ((last-sexp (nth 2 parse-state))) - (setq parse-state (parse-partial-sexp last-syntax-point (point) - nil nil parse-state)) - ;; It's important to preserve last sexp location for - ;; `calculate-lisp-indent'. - (unless (nth 2 parse-state) - (setf (nth 2 parse-state) last-sexp)) - (setq last-syntax-point (point))) + (let ((oldstate parse-state) + (target-point (point))) + (while + (progn + (setq parse-state (parse-partial-sexp last-syntax-point target-point + nil t oldstate)) + (if (>= (point) target-point) + nil ; Done. + (when (= (nth 0 parse-state) (nth 0 oldstate)) ; Stopped before open paren. + (setq parse-state (parse-partial-sexp last-syntax-point target-point + (1+ (nth 0 parse-state)) nil parse-state))) + (setq last-syntax-point (point)) + ;; It's important to preserve last sexp location for + ;; `calculate-lisp-indent', but it's only relevant at the + ;; same depth. + (unless (or (nth 2 parse-state) (/= (nth 0 parse-state) (nth 0 oldstate))) + (setf (nth 2 parse-state) (nth 2 oldstate))) + t)) + (setq oldstate parse-state))) ;; Update cache's depth stack. (funcall calc-indent (car parse-state)) (and pr (progress-reporter-update pr (point)))) @@ -1169,7 +1180,8 @@ indent-sexp ;; Parse this line so we can learn the state to indent the ;; next line. Preserve element 2 of the state (last sexp) for ;; `calculate-lisp-indent'. - (let ((last-sexp (nth 2 state))) + (let ((last-depth (nth 0 state)) + (last-sexp (nth 2 state))) (while (progn (setq state (parse-partial-sexp last-syntax-point (progn (end-of-line) (point)) @@ -1179,7 +1191,9 @@ indent-sexp (nth 3 state)) (setq state (parse-partial-sexp (point) (point-max) nil nil state 'syntax-table)) - (setq last-sexp (or (nth 2 state) last-sexp)) + (when (nth 2 state) + (setq last-sexp (nth 2 state)) + (setq last-depth (nth 0 state))) (setq last-syntax-point (point))) (setf (nth 2 state) last-sexp)) ;; Update cache's depth stack. -- 2.11.1 --=-=-=--