unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Noam Postavsky <npostavs@gmail.com>
To: 35381@debbugs.gnu.org
Cc: stefan monnier <monnier@iro.umontreal.ca>
Subject: bug#35381: 26.2; nxml-mode doesn't fontify attributes in single quotes
Date: Mon, 22 Apr 2019 12:08:55 -0400	[thread overview]
Message-ID: <87imv6rpig.fsf@gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 677 bytes --]

X-Debbugs-CC: Stefan Monnier <monnier@iro.umontreal.ca>
Tags: patch

In an nxml-mode buffer, put the following text:

<x a="foo" b='bar'/>

Only "foo" is fontified in as a string, while bar is not.  This is a
regression since Emacs 25.3.  The patch below seems solves problem,
though I'm not entirely sure about it: there are some confusing comments
in sgml-mode.el about drawbacks and tradeoffs of recognizing single
quotes that I'm not really following (are they applicable to SGML only,
and not XML?).

There's also the difference that attribute values are now fontified with
font-lock-string-face rather than nxml-attribute-value, though I'm not
sure that's worth fixing.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Possible patch --]
[-- Type: text/x-diff, Size: 3822 bytes --]

From a3d2dbcd0c4e272802a45a7c751877b6982fb257 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Sun, 21 Apr 2019 22:44:50 -0400
Subject: [PATCH] Make nxml-mode recognize single quote attribute again

* lisp/nxml/nxml-mode.el (nxml-syntax-propertize): New function.
(nxml-tag-syntax-table): New constant.
(nxml-mode): Set them as syntax-propertize-function and
syntax-ppss-table, respectively.
* test/lisp/nxml/nxml-mode-tests.el (nxml-mode-font-lock-quotes): New
test.
---
 lisp/nxml/nxml-mode.el            | 22 ++++++++++++++++++++--
 test/lisp/nxml/nxml-mode-tests.el | 20 ++++++++++++++++++++
 2 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/lisp/nxml/nxml-mode.el b/lisp/nxml/nxml-mode.el
index ab035b927e..94fbe4b781 100644
--- a/lisp/nxml/nxml-mode.el
+++ b/lisp/nxml/nxml-mode.el
@@ -426,6 +426,24 @@ (defun nxml-parent-document-set (parent-document)
 (defvar tildify-space-string)
 (defvar tildify-foreach-region-function)
 
+(defun nxml-syntax-propertize (start end)
+  "Syntactic keywords for `nxml-mode'."
+  (goto-char start)
+  (sgml-syntax-propertize-inside end)
+  (funcall
+   (syntax-propertize-rules
+    sgml-syntax-propertize-rules
+    ;; Like the " rule in `sgml-syntax-propertize-rules', but for '.
+    ("'" (0 (if (prog1 (zerop (car (syntax-ppss (match-beginning 0))))
+                  (goto-char (match-end 0)))
+                (string-to-syntax ".")))))
+   start end))
+
+(defconst nxml-tag-syntax-table
+  (let ((table (make-syntax-table sgml-tag-syntax-table)))
+    (modify-syntax-entry ?\' "\"'" table))
+  "Syntax table used to parse XML tags.")
+
 ;;;###autoload
 (define-derived-mode nxml-mode text-mode "nXML"
   ;; We use C-c C-i instead of \\[nxml-balanced-close-start-tag-inline]
@@ -517,8 +535,8 @@ (define-derived-mode nxml-mode text-mode "nXML"
       (with-silent-modifications
 	(nxml-with-invisible-motion
 	  (nxml-scan-prolog)))))
-  (setq-local syntax-ppss-table sgml-tag-syntax-table)
-  (setq-local syntax-propertize-function #'sgml-syntax-propertize)
+  (setq-local syntax-ppss-table nxml-tag-syntax-table)
+  (setq-local syntax-propertize-function #'nxml-syntax-propertize)
   (add-hook 'change-major-mode-hook #'nxml-cleanup nil t)
 
   ;; Emacs 23 handles the encoding attribute on the xml declaration
diff --git a/test/lisp/nxml/nxml-mode-tests.el b/test/lisp/nxml/nxml-mode-tests.el
index 57a731ad18..92744be619 100644
--- a/test/lisp/nxml/nxml-mode-tests.el
+++ b/test/lisp/nxml/nxml-mode-tests.el
@@ -58,5 +58,25 @@ (ert-deftest nxml-balanced-close-start-tag-inline ()
     (nxml-balanced-close-start-tag-inline)
     (should (equal (buffer-string) "<a><b c=\"\"></b></a>"))))
 
+(ert-deftest nxml-mode-font-lock-quotes ()
+  (with-temp-buffer
+    (nxml-mode)
+    (insert "<x a=\"dquote attr\" b='squote attr'>\"dquote text\"'squote text'</x>")
+    (font-lock-ensure)
+    (let ((squote-txt-pos (search-backward "squote text"))
+          (dquote-txt-pos (search-backward "dquote text"))
+          (squote-att-pos (search-backward "squote attr"))
+          (dquote-att-pos (search-backward "dquote attr")))
+      ;; Just make sure that each quote uses the same face for quoted
+      ;; attribute values, and a different face for quoted text
+      ;; outside tags.  Don't test `font-lock-string-face' vs
+      ;; `nxml-attribute-value' here.
+      (should (equal (get-text-property squote-att-pos 'face)
+                     (get-text-property dquote-att-pos 'face)))
+      (should (equal (get-text-property squote-txt-pos 'face)
+                     (get-text-property dquote-txt-pos 'face)))
+      (should-not (equal (get-text-property squote-txt-pos 'face)
+                         (get-text-property dquote-att-pos 'face))))))
+
 (provide 'nxml-mode-tests)
 ;;; nxml-mode-tests.el ends here
-- 
2.11.0


             reply	other threads:[~2019-04-22 16:08 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-22 16:08 Noam Postavsky [this message]
2019-04-23 16:09 ` bug#35381: 26.2; nxml-mode doesn't fontify attributes in single quotes Stefan Monnier
2019-04-24  1:28   ` Noam Postavsky
2019-04-24 14:52     ` Stefan Monnier
2019-04-25  2:24       ` Noam Postavsky
2019-04-25 12:47         ` Stefan Monnier
2019-04-26 11:32           ` Noam Postavsky
2019-04-29 21:23             ` Stefan Monnier
2019-05-05  3:52               ` Noam Postavsky
2019-05-05 13:06                 ` Stefan Monnier
2019-05-05 13:49                   ` Noam Postavsky
2019-05-05 14:20                     ` martin rudalics
2019-05-05 14:36                       ` Noam Postavsky
2019-05-09 11:45                 ` Noam Postavsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87imv6rpig.fsf@gmail.com \
    --to=npostavs@gmail.com \
    --cc=35381@debbugs.gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).