From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Noam Postavsky Newsgroups: gmane.emacs.bugs Subject: bug#30891: 26.0.91; indent of malformed lisp Date: Tue, 20 Mar 2018 21:19:35 -0400 Message-ID: <87y3imrzrs.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1521595091 30125 195.159.176.226 (21 Mar 2018 01:18:11 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 21 Mar 2018 01:18:11 +0000 (UTC) To: 30891@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Mar 21 02:18:07 2018 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 1eySOF-0007kW-DU for geb-bug-gnu-emacs@m.gmane.org; Wed, 21 Mar 2018 02:18:07 +0100 Original-Received: from localhost ([::1]:52352 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eySQI-00070y-EB for geb-bug-gnu-emacs@m.gmane.org; Tue, 20 Mar 2018 21:20:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45489) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eySQ9-0006ya-Pa for bug-gnu-emacs@gnu.org; Tue, 20 Mar 2018 21:20:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eySQ6-0002fV-H6 for bug-gnu-emacs@gnu.org; Tue, 20 Mar 2018 21:20:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:36558) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eySQ6-0002fN-Br for bug-gnu-emacs@gnu.org; Tue, 20 Mar 2018 21:20:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1eySQ6-000394-2r for bug-gnu-emacs@gnu.org; Tue, 20 Mar 2018 21:20: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: Wed, 21 Mar 2018 01:20:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 30891 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.152159519212067 (code B ref -1); Wed, 21 Mar 2018 01:20:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 21 Mar 2018 01:19:52 +0000 Original-Received: from localhost ([127.0.0.1]:44455 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eySPw-00038Z-7J for submit@debbugs.gnu.org; Tue, 20 Mar 2018 21:19:52 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:54423) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eySPu-00038J-5J for submit@debbugs.gnu.org; Tue, 20 Mar 2018 21:19:50 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eySPn-0002Yd-W1 for submit@debbugs.gnu.org; Tue, 20 Mar 2018 21:19:44 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:38034) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eySPn-0002YV-RY for submit@debbugs.gnu.org; Tue, 20 Mar 2018 21:19:43 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45382) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eySPm-0006pd-Na for bug-gnu-emacs@gnu.org; Tue, 20 Mar 2018 21:19:43 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eySPj-0002X4-CP for bug-gnu-emacs@gnu.org; Tue, 20 Mar 2018 21:19:42 -0400 Original-Received: from mail-it0-x230.google.com ([2607:f8b0:4001:c0b::230]:39526) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eySPj-0002Wp-2J for bug-gnu-emacs@gnu.org; Tue, 20 Mar 2018 21:19:39 -0400 Original-Received: by mail-it0-x230.google.com with SMTP id e98-v6so4770543itd.4 for ; Tue, 20 Mar 2018 18:19:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version; bh=+6GDrI4/uyTwEpZXDVhqI6AY9zcByCCxbIGWZE+0AaM=; b=DlNfvR4MCSE1gzSP2QnADVd0d/SlOF/XOdEpVgwLSrvZVpWQ9uCMcO0bFkDwn94LuN BSKNlBFOvSykd1tmc1DV6xx3a1ZUwAppWh0ygyrFtcIm2TcZvxSajg3KVs9kOBM0ykFA bi/VZJD4+aG+/E6/PIifeaeukkq1HHdZMKboXME8dQVtWtr436Jqto0P+KPOm8bsRyRK v3zJG6r7usOoviX4SuoCkCrupplqV08gqCSD0ncySG9hz27IOQ4w+xah6/dVznzyZSo0 7ZYu0lmUinSFMPfa3b0BbpUBAMxsD/beLosoLzyozrLa5MttnJYOats0cfq2uRsxomsY qk3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=+6GDrI4/uyTwEpZXDVhqI6AY9zcByCCxbIGWZE+0AaM=; b=CFi/36fLWyJV9NyHBDHKYT/U7RwNQc9XYOcGLIfO9CLaLijaDmyhPiNdWLCvk/w1+s cgegUqrVxdW2QhyLm7fF+hOXKoLpA8urHrUJjkj+mfgfMbjOjScl6nWhIlMrgQjYhBU2 R8PkXQtb7ve1dJJP3cmFyFjUtgwrWmXhcloZKl123beSOAMbiKq4H/UL+POWdEjOH4+Z b4SIyE7m7bMx5p5voSgK8YiNwnq8/CQ9bKch9L9otS83cYFm8G+PwpLk33uOpX23EtN4 0/RXjuQwfL4FQvLEd+blHlvvegbG2hi3cYySmIqr7piA6RIsWob9gmPMrN+cCg8yIwHk yrcA== X-Gm-Message-State: AElRT7FDqgfQGTdWCRdeMYX7/sX0jeBmXruzB6WyX96wdNUpoBDCqCxG ehWuPwOiN/XLK2t3WHmd8u4aEQ== X-Google-Smtp-Source: AG47ELtJYLFJVFQsTtkMt4StYUiodm2Dk+eoHuNLhnvLWGlYa1xSLlQKtqHENLjzksVgCeXNwX70+g== X-Received: by 2002:a24:5e83:: with SMTP id h125-v6mr2039676itb.79.1521595178173; Tue, 20 Mar 2018 18:19:38 -0700 (PDT) Original-Received: from zebian (cbl-45-2-119-34.yyz.frontiernetworks.ca. [45.2.119.34]) by smtp.googlemail.com with ESMTPSA id q99sm1930953ioi.40.2018.03.20.18.19.36 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Mar 2018 18:19:36 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x 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:144479 Archived-At: --=-=-= Content-Type: text/plain I recently got a private report about a problem with the new lisp indent functions: they don't work well when the buffer contains syntax errors. For example, indent-region in a buffer containing: ) (+ 2 3) gives Debugger entered--Lisp error: (wrong-type-argument consp nil) lisp-indent-calc-next(#s(lisp-indent-state :stack (nil) :ppss (0 nil nil nil nil nil 0 nil nil nil nil) :ppss-point 146)) lisp-indent-region(146 158) indent-region(146 158 nil) funcall-interactively(indent-region 146 158 nil) call-interactively(indent-region nil nil) command-execute(indent-region) The error can be fixed with the patch below, I think it's safe for emacs-26. But, it still gives wrong indentation if you do indent-region on the latter two lines. That could be fixed with (advice-add 'lisp-ppss :override #'lisp-ppss-open-paren-in-column-0-is-defun-start) The lisp-ppss-open-paren-in-column-0-is-defun-start function is included (but uncalled) in the patch. Using it in the override suggested above will bring back Bug#27920 though. We could include the function and suggest to use it (with the aforementioned caveat) in etc/NEWS or PROBLEMS perhaps? --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=v1-0001-Handle-indentation-of-malformed-Lisp.patch Content-Description: patch >From da0916b591a983c9b4ee9c8201600a77ba506b92 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Sat, 17 Mar 2018 21:14:11 -0400 Subject: [PATCH v1] Handle indentation of malformed Lisp * lisp/emacs-lisp/lisp-mode.el (lisp-ppss-open-paren-in-column-0-is-defun-start): New function. * lisp/emacs-lisp/lisp-mode.el (lisp-indent-calc-next): If we run out of indent stack, reset the parse state. --- lisp/emacs-lisp/lisp-mode.el | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el index f082983d48..58710e9876 100644 --- a/lisp/emacs-lisp/lisp-mode.el +++ b/lisp/emacs-lisp/lisp-mode.el @@ -794,6 +794,21 @@ lisp-ppss (parse-partial-sexp sexp-start pos nil nil (syntax-ppss sexp-start))) pss))) +(defun lisp-ppss-open-paren-in-column-0-is-defun-start (&optional pos) + (save-excursion + (if pos + (goto-char pos) + (setq pos (point))) + (or (looking-at-p "^(") + (re-search-backward "^(" nil t) + (goto-char (point-min))) + (let ((ppss (parse-partial-sexp (point) pos))) + (if (< (car ppss) 0) + ;; Too many close parens, probably syntax error. Give a + ;; fresh state. + (parse-partial-sexp (point) (point)) + ppss)))) + (cl-defstruct (lisp-indent-state (:constructor nil) (:constructor lisp-indent-initial-state @@ -844,6 +859,10 @@ lisp-indent-calc-next (prog1 (let (indent) (cond ((= (forward-line 1) 1) nil) + ;; Negative depth, probably some kind of syntax error. + ((null indent-stack) + ;; Reset state. + (setq ppss (parse-partial-sexp (point) (point)))) ((car indent-stack)) ((integerp (setq indent (calculate-lisp-indent ppss))) (setf (car indent-stack) indent)) -- 2.11.0 --=-=-=--