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#27306: Regression: Emacs Lisp Indentation Date: Sat, 10 Jun 2017 11:33:44 -0400 Message-ID: <87a85fx3fr.fsf@users.sourceforge.net> References: <88de418a-0e23-9ff7-5cea-cd2add2dab8c@Alexander.Shukaev.name> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1497108790 1986 195.159.176.226 (10 Jun 2017 15:33:10 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 10 Jun 2017 15:33:10 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2.50 (gnu/linux) Cc: 27306@debbugs.gnu.org To: Alexander Shukaev Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Jun 10 17:33:06 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 1dJiNu-0000Gl-HB for geb-bug-gnu-emacs@m.gmane.org; Sat, 10 Jun 2017 17:33:06 +0200 Original-Received: from localhost ([::1]:58812 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dJiNz-0003PD-TO for geb-bug-gnu-emacs@m.gmane.org; Sat, 10 Jun 2017 11:33:11 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39879) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dJiNu-0003LN-22 for bug-gnu-emacs@gnu.org; Sat, 10 Jun 2017 11:33:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dJiNq-0004k7-Vd for bug-gnu-emacs@gnu.org; Sat, 10 Jun 2017 11:33:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:36382) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dJiNq-0004k1-RT for bug-gnu-emacs@gnu.org; Sat, 10 Jun 2017 11:33:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dJiNq-0006v9-FB for bug-gnu-emacs@gnu.org; Sat, 10 Jun 2017 11:33:02 -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: Sat, 10 Jun 2017 15:33:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 27306 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 27306-submit@debbugs.gnu.org id=B27306.149710873426544 (code B ref 27306); Sat, 10 Jun 2017 15:33:02 +0000 Original-Received: (at 27306) by debbugs.gnu.org; 10 Jun 2017 15:32:14 +0000 Original-Received: from localhost ([127.0.0.1]:39059 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dJiN3-0006tz-VC for submit@debbugs.gnu.org; Sat, 10 Jun 2017 11:32:14 -0400 Original-Received: from mail-it0-f68.google.com ([209.85.214.68]:36851) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dJiN1-0006tf-NE; Sat, 10 Jun 2017 11:32:12 -0400 Original-Received: by mail-it0-f68.google.com with SMTP id 185so5646979itv.3; Sat, 10 Jun 2017 08:32:11 -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=L65X9AMPlOqXdFVeEJnjE45MLJEbsB4sGln6QSeIemE=; b=CdVGCEYTKwItBNL4eOhw+sCBsO9/mIGlY7fTV1tnS8pLWfreDOb3aCFQ/TMHS19HOh 512PXAEA2DHSqqV6DW3g5c4tb1AINepSjVhFoSNfw6NqxpqOYjRJg6OJjIHN6IBzzNbM 9sjTKsdx6mxI35HoAvX6MKLy/X/ci8lvuwusNxtlaC+A48pIzIjM7/o0myKpilEIxnWj VP7o8uE2cJzmS1ZlKGVSVAs4dN9EFrczVvCseqloOSVQKLHltXZ2P22t84kZhckyiJHB WuVi+d5/ahqnW2wUW5KHS1VqAHHi0nhsxSIAwqU6LTl87mBP+AZxLNLg25vs7yTQO6xr CtGw== 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=L65X9AMPlOqXdFVeEJnjE45MLJEbsB4sGln6QSeIemE=; b=tSQJAcvmR4C6YlSG8fClovo6S3o0ELXNYA50Hdvi75hGXkvRXKirH+TC3JV1JlQcZD ANXNkiuaDTHax49TRfPzMEFUY8yTQ9LKP1wrjQMqmXINijNsOsIV0NywxUCog2Nb7gRl /fNJkkhwbdFcoxatC8UPGQSMjJwWxX90tcGJ1k0hYG6zH7JZdszAalgBft3CdMtX/0R9 cuMVT5ra8uawr6ceMriqLt8wwQNRGRhMTWLsDzvykzw52XjHUAcAerpNESwiIP6sH7EI DwkU0/VGxuQiBujVIax2pg28xwzdltvot/4VRFrjJ9pAVdZoBEzX+R7RkYVIZE4sqDd0 ctpg== X-Gm-Message-State: AODbwcDJqsJbQIIe9+k4syzXh3OZm+Jk9n40alSFbKEHhOlo9l1/j4aP yN7+Rk67AtLjZNkt X-Received: by 10.36.60.132 with SMTP id m126mr4797936ita.75.1497108725908; Sat, 10 Jun 2017 08:32:05 -0700 (PDT) Original-Received: from zony ([45.2.7.65]) by smtp.googlemail.com with ESMTPSA id 68sm1575879iox.41.2017.06.10.08.32.04 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 10 Jun 2017 08:32:05 -0700 (PDT) In-Reply-To: <88de418a-0e23-9ff7-5cea-cd2add2dab8c@Alexander.Shukaev.name> (Alexander Shukaev's message of "Sat, 10 Jun 2017 14:59:01 +0200") 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:133446 Archived-At: --=-=-= Content-Type: text/plain tags 27306 patch quit Alexander Shukaev writes: > In Emacs 26 series, a call to `indent-region' changes the above > indentation to > > (user-error "Unexpected initialization file: `%s' > Expected initialization file: `%s'" > (abbreviate-file-name user-init-file) > (abbreviate-file-name this-init-file)) > > which appears wrong to me. Please, take a look at this. Thank you. Thanks for reporting, here's a patch: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=v1-0001-Fix-wrong-indentation-after-string-literal-Bug-27.patch Content-Description: patch >From 9e5c05a5cff6ab4eea5667792cf277c020b95426 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Sat, 10 Jun 2017 09:50:48 -0400 Subject: [PATCH v1] Fix wrong indentation after string literal (Bug#27306) * lisp/emacs-lisp/lisp-mode.el (lisp-indent-state) (lisp-indent-calc-next): Remove `depth' field, use (car ppss) instead. * test/lisp/emacs-lisp/lisp-mode-tests.el (lisp-indent-region-after-string-literal): New test. --- lisp/emacs-lisp/lisp-mode.el | 27 +++++++++++++-------------- test/lisp/emacs-lisp/lisp-mode-tests.el | 13 +++++++++++++ 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el index 1e38d44e1b..59db00d5f9 100644 --- a/lisp/emacs-lisp/lisp-mode.el +++ b/lisp/emacs-lisp/lisp-mode.el @@ -773,11 +773,9 @@ (cl-defstruct (lisp-indent-state (:constructor lisp-indent-initial-state (&aux (ppss (lisp-ppss)) (ppss-point (point)) - (depth (car ppss)) - (stack (make-list (1+ depth) nil))))) + (stack (make-list (1+ (car ppss)) nil))))) stack ;; Cached indentation, per depth. ppss - depth ppss-point) (defun lisp-indent-calc-next (state) @@ -785,9 +783,11 @@ (defun lisp-indent-calc-next (state) STATE is updated by side effect, the first state should be created by `lisp-indent-initial-state'. This function may move by more than one line to cross a string literal." - (pcase-let (((cl-struct lisp-indent-state - (stack indent-stack) ppss depth ppss-point) - state)) + (pcase-let* (((cl-struct lisp-indent-state + (stack indent-stack) ppss ppss-point) + state) + (indent-depth (car ppss)) ; Corresponding to indent-stack. + (depth indent-depth)) ;; Parse this line so we can learn the state to indent the ;; next line. (while (let ((last-sexp (nth 2 ppss))) @@ -799,22 +799,22 @@ (defun lisp-indent-calc-next (state) (if (and (not (nth 2 ppss)) (= depth (car ppss))) (setf (nth 2 ppss) last-sexp) (setq last-sexp (nth 2 ppss))) + (setq depth (car ppss)) ;; Skip over newlines within strings. (nth 3 ppss)) (let ((string-start (nth 8 ppss))) - (setq ppss (parse-partial-sexp (point) (point-max) - nil nil ppss 'syntax-table)) - (setf (nth 2 ppss) string-start)) ; Finished a complete string. + (setq ppss (parse-partial-sexp (point) (point-max) + nil nil ppss 'syntax-table)) + (setf (nth 2 ppss) string-start) ; Finished a complete string. + (setq depth (car ppss))) (setq ppss-point (point))) (setq ppss-point (point)) - (let* ((next-depth (car ppss)) - (depth-delta (- next-depth depth))) + (let* ((depth-delta (- depth indent-depth))) (cond ((< depth-delta 0) (setq indent-stack (nthcdr (- depth-delta) indent-stack))) ((> depth-delta 0) (setq indent-stack (nconc (make-list depth-delta nil) - indent-stack)))) - (setq depth next-depth)) + indent-stack))))) (prog1 (let (indent) (cond ((= (forward-line 1) 1) nil) @@ -826,7 +826,6 @@ (defun lisp-indent-calc-next (state) ;; This only happens if we're in a string. (t (error "This shouldn't happen")))) (setf (lisp-indent-state-stack state) indent-stack) - (setf (lisp-indent-state-depth state) depth) (setf (lisp-indent-state-ppss-point state) ppss-point) (setf (lisp-indent-state-ppss state) ppss)))) diff --git a/test/lisp/emacs-lisp/lisp-mode-tests.el b/test/lisp/emacs-lisp/lisp-mode-tests.el index f2fe7a6cf4..582041cfc2 100644 --- a/test/lisp/emacs-lisp/lisp-mode-tests.el +++ b/test/lisp/emacs-lisp/lisp-mode-tests.el @@ -185,6 +185,19 @@ (ert-deftest lisp-indent-region-in-sexp () (indent-region (point) (point-max)) (should (equal (buffer-string) correct))))) +(ert-deftest lisp-indent-region-after-string-literal () + (with-temp-buffer + (insert "\ +\(user-error \"Unexpected initialization file: `%s' +Expected initialization file: `%s'\" + (abbreviate-file-name user-init-file) + (abbreviate-file-name this-init-file))") + (let ((indent-tabs-mode nil) + (correct (buffer-string))) + (emacs-lisp-mode) + (indent-region (point-min) (point-max)) + (should (equal (buffer-string) correct))))) + (provide 'lisp-mode-tests) ;;; lisp-mode-tests.el ends here -- 2.11.1 --=-=-=--