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#32003: 26.0.90; nxml wrong indentation after multi-line attribute Date: Thu, 18 Apr 2019 23:48:31 -0400 Message-ID: <87wojqvenk.fsf@gmail.com> References: <877emiszjs.fsf@riefenstahl-linux.mecom.de> 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="261108"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) Cc: Vincent Lefevre , David Carlisle , Stefan Monnier , 32003@debbugs.gnu.org To: Benjamin Riefenstahl Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Apr 19 05:49: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 1hHKWX-0015li-HF for geb-bug-gnu-emacs@m.gmane.org; Fri, 19 Apr 2019 05:49:13 +0200 Original-Received: from localhost ([127.0.0.1]:50767 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hHKWW-0008Pz-Hz for geb-bug-gnu-emacs@m.gmane.org; Thu, 18 Apr 2019 23:49:12 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:34188) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hHKWP-0008Os-1G for bug-gnu-emacs@gnu.org; Thu, 18 Apr 2019 23:49:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hHKWN-0004Y6-9D for bug-gnu-emacs@gnu.org; Thu, 18 Apr 2019 23:49:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:57572) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hHKWM-0004Xf-35 for bug-gnu-emacs@gnu.org; Thu, 18 Apr 2019 23:49:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hHKWL-0005xG-Pc for bug-gnu-emacs@gnu.org; Thu, 18 Apr 2019 23:49:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Noam Postavsky Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 19 Apr 2019 03:49:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 32003 X-GNU-PR-Package: emacs Original-Received: via spool by 32003-submit@debbugs.gnu.org id=B32003.155564572322862 (code B ref 32003); Fri, 19 Apr 2019 03:49:01 +0000 Original-Received: (at 32003) by debbugs.gnu.org; 19 Apr 2019 03:48:43 +0000 Original-Received: from localhost ([127.0.0.1]:42883 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hHKW3-0005wb-0S for submit@debbugs.gnu.org; Thu, 18 Apr 2019 23:48:43 -0400 Original-Received: from mail-qk1-f170.google.com ([209.85.222.170]:41393) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hHKW0-0005wF-0O; Thu, 18 Apr 2019 23:48:40 -0400 Original-Received: by mail-qk1-f170.google.com with SMTP id p185so2250306qkb.8; Thu, 18 Apr 2019 20:48: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=2aQ8aidFT5tItq9DNf/jWKMi1WZkfUVs1ITyoB66keA=; b=ACto+PJ2dWLfWLsZx0HMZFrObvKg+EBajp5SaLuAeo1W5jWO64Hcon5q/YBI5H6Xub SDqbeY0J+7ysBvds17fk7SJCJ7AZFYh4y6/41/WMEsTwmy4mrvRh7HWbOreYVX26gHt6 17wEfLpnMqSkR7Kb7RZ7mO1CXWuig5H5lHPLyNKm2WS49QZSUtY4UhLgaz6PU6Obq+0U b1Sv3KVGafvZkbQenQ11wn/W7Wiynl2zJw7sNaPltJzGTkPjVD+RMhvQbJ8wdDysP93x UwXhO+Vd+t30wV/GIwJcfc8oGCIlNwLM91t6XN+cq975kiF5hMd5s8h/VzKo3io7+I/T Bsgw== 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=2aQ8aidFT5tItq9DNf/jWKMi1WZkfUVs1ITyoB66keA=; b=Lt39ILFuA/Pm/PGcMVZ04mDZ/jjnu8EnRRWjDYMEsY+7xXGxgiFR71CnGcoEDnCx+6 PqvPQ/A+6VxbCTP3J0/9s578uiKrJ+RxbQ08RaDSRrlsQNsmkiM/ENw7GjrWkYAnkzUn KiDA9JuEZa4XZb7hDl23Y3L7zA0WkgTOsfYoTKy9Spaq0xtw6fUHidV23khZJY0Eb9JJ sZgh35Vi847AHB6PdP8oohpn8tJ+PucGbxrt6NPZuGPgIE3eprfzP++v08JhNS1Su2Kp U5bdi0iBBmqwxshKkisJJwdA1eRe3NLKxIl7Mm1uElymQ8W0M201Uskd2tCyfIwbBXqM LfeQ== X-Gm-Message-State: APjAAAXJLHfffPz0HOv49JbZMZA10KYhnAaVuB3lmPT/b2OOxPxvXT2U tVu7BKqz9wRMGsTioA2VPcSWBTdV X-Google-Smtp-Source: APXvYqzsWh+7Kp+KxqS+mJEQykNyGR54z+vBtFohcUJgGhNzmrxkOrLKMcu34YlOCmykAxcfMUOqTA== X-Received: by 2002:a37:6645:: with SMTP id a66mr1495031qkc.84.1555645714330; Thu, 18 Apr 2019 20:48:34 -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 s1sm1784659qtq.43.2019.04.18.20.48.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 18 Apr 2019 20:48:32 -0700 (PDT) In-Reply-To: <877emiszjs.fsf@riefenstahl-linux.mecom.de> (Benjamin Riefenstahl's message of "Fri, 29 Jun 2018 11:38:15 +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: 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:157820 Archived-At: --=-=-= Content-Type: text/plain forcemerge 32003 33873 tags 32003 + patch quit Benjamin Riefenstahl writes: > xmlns="http://maven.apache.org/SETTINGS/1.0.0" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 > https://maven.apache.org/xsd/settings-1.0.0.xsd"> > > ... > > Here's a patch to fix this bug, Bug#33873, and the indentation part of Bug#32897. --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=0001-Fix-nxml-get-inside-Bug-32003.patch Content-Description: patch >From fb5f2cfd8404acc3591ac38dae2eaeb14807d853 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Thu, 18 Apr 2019 23:36:04 -0400 Subject: [PATCH] Fix nxml-get-inside (Bug#32003) The change from 2016-01-16 "lisp/nxml: Use syntax-tables for comments" made nxml-get-inside return non-nil for any string or comment, including attribute strings. This caused incorrect and therefore indentation. * lisp/nxml/nxml-rap.el: Update commentary to reflect changes to nxml-mode parsing. (nxml-get-inside): Only return non-nil when inside comments and generic strings, not normal quote-delimited strings. * test/lisp/nxml/nxml-mode-tests.el: New tests. --- lisp/nxml/nxml-rap.el | 40 ++++++++++++------------- test/lisp/nxml/nxml-mode-tests.el | 62 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 22 deletions(-) create mode 100644 test/lisp/nxml/nxml-mode-tests.el diff --git a/lisp/nxml/nxml-rap.el b/lisp/nxml/nxml-rap.el index 2bd758be3a..4a535b2c40 100644 --- a/lisp/nxml/nxml-rap.el +++ b/lisp/nxml/nxml-rap.el @@ -35,35 +35,25 @@ ;; ;; Our strategy is to keep track of just the problematic things. ;; Specifically, we keep track of all comments, CDATA sections and -;; processing instructions in the instance. We do this by marking all -;; except the first character of these with a non-nil nxml-inside text -;; property. The value of the nxml-inside property is comment, -;; cdata-section or processing-instruction. The first character does -;; not have the nxml-inside property so we can find the beginning of -;; the construct by looking for a change in a text property value -;; (Emacs provides primitives for this). We use text properties -;; rather than overlays, since the implementation of overlays doesn't -;; look like it scales to large numbers of overlays in a buffer. -;; -;; We don't in fact track all these constructs, but only track them in -;; some initial part of the instance. +;; processing instructions in the instance. We do this by marking +;; the first character of these with the generic string syntax by setting +;; a 'syntax-table' text property in `sgml-syntax-propertize'. ;; ;; Thus to parse some random point in the file we first ensure that we -;; have scanned up to that point. Then we search backwards for a -;; <. Then we check whether the < has an nxml-inside property. If it -;; does we go backwards to first character that does not have an -;; nxml-inside property (this character must be a <). Then we start -;; parsing forward from the < we have found. +;; have scanned up to that point. Then we search backwards for a <. +;; Then we check whether the < has the generic string syntax. If it +;; does we go backwards to first character of the generic string (this +;; character must be a <). Then we start parsing forward from the < +;; we have found. ;; ;; The prolog has to be parsed specially, so we also keep track of the ;; end of the prolog in `nxml-prolog-end'. The prolog is reparsed on ;; every change to the prolog. This won't work well if people try to ;; edit huge internal subsets. Hopefully that will be rare. ;; -;; We keep track of the changes by adding to the buffer's -;; after-change-functions hook. Scanning is also done as a -;; prerequisite to fontification by adding to fontification-functions -;; (in the same way as jit-lock). This means that scanning for these +;; We rely on the `syntax-propertize-function' machinery to keep track +;; of the changes in the buffer. Fontification also relies on correct +;; `syntax-table' properties. This means that scanning for these ;; constructs had better be quick. Fortunately it is. Firstly, the ;; typical proportion of comments, CDATA sections and processing ;; instructions is small relative to other things. Secondly, to scan @@ -79,7 +69,13 @@ (defvar-local nxml-prolog-end nil "Integer giving position following end of the prolog.") (defsubst nxml-get-inside (pos) - (save-excursion (nth 8 (syntax-ppss pos)))) + "Return non-nil if inside comment, CDATA, or PI." + (let ((ppss (save-excursion (syntax-ppss pos)))) + (or + ;; Inside comment. + (nth 4 ppss) + ;; Inside "generic" string, happens for CDATA, and PI. + (eq t (nth 3 ppss))))) (defun nxml-inside-end (pos) "Return the end of the inside region containing POS. diff --git a/test/lisp/nxml/nxml-mode-tests.el b/test/lisp/nxml/nxml-mode-tests.el new file mode 100644 index 0000000000..57a731ad18 --- /dev/null +++ b/test/lisp/nxml/nxml-mode-tests.el @@ -0,0 +1,62 @@ +;;; nxml-mode-tests.el --- Test NXML Mode -*- lexical-binding: t; -*- + +;; Copyright (C) 2019 Free Software Foundation, Inc. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see . + +;;; Code: + +(require 'ert) +(require 'nxml-mode) + +(defun nxml-mode-tests-correctly-indented-string (str) + (with-temp-buffer + (nxml-mode) + (insert str) + (indent-region (point-min) (point-max)) + (equal (buffer-string) str))) + +(ert-deftest nxml-indent-line-after-attribute () + (should (nxml-mode-tests-correctly-indented-string " + + + ... + + +")) + (should (nxml-mode-tests-correctly-indented-string "\ + + + + + + +"))) + +(ert-deftest nxml-balanced-close-start-tag-inline () + (with-temp-buffer + (nxml-mode) + (insert "") + (search-backward "") + (nxml-balanced-close-start-tag-inline) + (should (equal (buffer-string) "")))) + +(provide 'nxml-mode-tests) +;;; nxml-mode-tests.el ends here -- 2.11.0 --=-=-=--