diff options
| author | Noam Postavsky | 2019-06-23 21:27:43 -0400 |
|---|---|---|
| committer | Noam Postavsky | 2019-06-25 18:58:23 -0400 |
| commit | e62ad04963982ea9cc7622b32484778845bc2ec1 (patch) | |
| tree | 70e80f572dce3f269acdf6136278fb29e049cdd9 | |
| parent | 06b35b2f922150a11d6b4b5c68a40e9957a69e52 (diff) | |
| download | emacs-e62ad04963982ea9cc7622b32484778845bc2ec1.tar.gz emacs-e62ad04963982ea9cc7622b32484778845bc2ec1.zip | |
Fix sgml-mode handling of quotes within parens (Bug#36347)
* lisp/textmodes/sgml-mode.el (sgml-syntax-propertize): Use
syntax-ppss-table if set. This is only needed on the release branch,
on master the caller (syntax-propertize) already does this.
(sgml-mode): Set syntax-ppss-table to sgml-tag-syntax-table. This
correctly classifies parens as punctuation, so they won't confuse the
parser.
* test/lisp/textmodes/sgml-mode-tests.el (sgml-tests--quotes-syntax):
New test copied from master, with two cases added for this bug.
| -rw-r--r-- | lisp/textmodes/sgml-mode.el | 10 | ||||
| -rw-r--r-- | test/lisp/textmodes/sgml-mode-tests.el | 22 |
2 files changed, 28 insertions, 4 deletions
diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el index 128e58810e5..c9724e0e3f7 100644 --- a/lisp/textmodes/sgml-mode.el +++ b/lisp/textmodes/sgml-mode.el | |||
| @@ -357,10 +357,11 @@ Any terminating `>' or `/' is not matched.") | |||
| 357 | (defun sgml-syntax-propertize (start end) | 357 | (defun sgml-syntax-propertize (start end) |
| 358 | "Syntactic keywords for `sgml-mode'." | 358 | "Syntactic keywords for `sgml-mode'." |
| 359 | (goto-char start) | 359 | (goto-char start) |
| 360 | (sgml-syntax-propertize-inside end) | 360 | (with-syntax-table (or syntax-ppss-table (syntax-table)) |
| 361 | (funcall | 361 | (sgml-syntax-propertize-inside end) |
| 362 | (syntax-propertize-rules sgml-syntax-propertize-rules) | 362 | (funcall |
| 363 | start end)) | 363 | (syntax-propertize-rules sgml-syntax-propertize-rules) |
| 364 | start end))) | ||
| 364 | 365 | ||
| 365 | (defun sgml-syntax-propertize-inside (end) | 366 | (defun sgml-syntax-propertize-inside (end) |
| 366 | (let ((ppss (syntax-ppss))) | 367 | (let ((ppss (syntax-ppss))) |
| @@ -568,6 +569,7 @@ Do \\[describe-key] on the following bindings to discover what they do. | |||
| 568 | sgml-font-lock-keywords-2) | 569 | sgml-font-lock-keywords-2) |
| 569 | nil t)) | 570 | nil t)) |
| 570 | (setq-local syntax-propertize-function #'sgml-syntax-propertize) | 571 | (setq-local syntax-propertize-function #'sgml-syntax-propertize) |
| 572 | (setq-local syntax-ppss-table sgml-tag-syntax-table) | ||
| 571 | (setq-local facemenu-add-face-function 'sgml-mode-facemenu-add-face-function) | 573 | (setq-local facemenu-add-face-function 'sgml-mode-facemenu-add-face-function) |
| 572 | (setq-local sgml-xml-mode (sgml-xml-guess)) | 574 | (setq-local sgml-xml-mode (sgml-xml-guess)) |
| 573 | (unless sgml-xml-mode | 575 | (unless sgml-xml-mode |
diff --git a/test/lisp/textmodes/sgml-mode-tests.el b/test/lisp/textmodes/sgml-mode-tests.el index 7318a667b36..0000b352ff0 100644 --- a/test/lisp/textmodes/sgml-mode-tests.el +++ b/test/lisp/textmodes/sgml-mode-tests.el | |||
| @@ -130,5 +130,27 @@ The point is set to the beginning of the buffer." | |||
| 130 | (sgml-delete-tag 1) | 130 | (sgml-delete-tag 1) |
| 131 | (should (string= "Winter is comin'" (buffer-string))))) | 131 | (should (string= "Winter is comin'" (buffer-string))))) |
| 132 | 132 | ||
| 133 | (ert-deftest sgml-tests--quotes-syntax () | ||
| 134 | (dolist (str '("a\"b <t>c'd</t>" | ||
| 135 | "a'b <t>c\"d</t>" | ||
| 136 | "<t>\"a'</t>" | ||
| 137 | "<t>'a\"</t>" | ||
| 138 | "<t>\"a'\"</t>" | ||
| 139 | "<t>'a\"'</t>" | ||
| 140 | "a\"b <tag>c'd</tag>" | ||
| 141 | ;;"<tag>c>'d</tag>" Fixed in master. | ||
| 142 | "<t><!-- \" --></t>" | ||
| 143 | "<t><!-- ' --></t>" | ||
| 144 | "<t>(')</t>" | ||
| 145 | "<t>(\")</t>" | ||
| 146 | )) | ||
| 147 | (with-temp-buffer | ||
| 148 | (sgml-mode) | ||
| 149 | (insert str) | ||
| 150 | (ert-info ((format "%S" str) :prefix "Test case: ") | ||
| 151 | ;; Check that last tag is parsed as a tag. | ||
| 152 | (should (= 1 (car (syntax-ppss (1- (point-max)))))) | ||
| 153 | (should (= 0 (car (syntax-ppss (point-max))))))))) | ||
| 154 | |||
| 133 | (provide 'sgml-mode-tests) | 155 | (provide 'sgml-mode-tests) |
| 134 | ;;; sgml-mode-tests.el ends here | 156 | ;;; sgml-mode-tests.el ends here |