Subject: bug#13844: [PATCH] Fix html-mode quotes syntax in text

From: Dale <[email-masked]>
Date: Thu, 28 Feb 2013 19:01:30 -0600

Hi,

	I noticed Emacs was colorizing the following sample wrong in
html-mode:

~~~~~~
<pre>
" Dangling quote makes the closing tag get highlighted as a string
</pre>
" Highlighting now fixed: <hr />

Additionally, if you have apostrophe in sgml-specials, this more common
usage will break:

Dave's bar
Now this tag will have incorrect highlighting:
<br />
~~~~~~

	I believe I've tracked this down to two problems:

1. sgml-syntax-propertize-function is already prepared to correctly set
the syntax on " (double quotes) within text, but returns "." for the
syntax-table property value.  That's not a valid value for syntax-table
propertize.  It needs to use (string-to-syntax ".").

2. sgml-syntax-propertize-function doesn't account for the fact that you
could have set ' (apostrophe) in sgml-specials, which causes apostrophe
to be set as string syntax in the syntax table, just like " is by
default.

	The patch below hopefully fixes both problems.

	I believe I have filed my copyright assignment with the FSF for
Emacs already.

	ChangeLog entry:

~~~~~~
2013-02-28  Dale Sedivec <[email-masked]>

	* textmodes/sgml-mode.el (sgml-syntax-propertize-function):
	Return valid syntax-table property value when converting
	quotes within text from string syntax to punctuation syntax.
	Also perform this adjustment when apostrophe (?') is in
	sgml-specials.
~~~~~~

	Patch against Git master follows.

Dale

*** /var/folders/l1/l_tpw26n35zbm0fp4x22_vjh0000kk/T//85VjC0_sgml-mode.el	2013-02-28 19:00:02.000000000 -0600
--- lisp/textmodes/sgml-mode.el	2013-02-28 18:54:52.000000000 -0600
***************
*** 312,328 ****
  
  (defconst sgml-syntax-propertize-function
    (syntax-propertize-rules
!   ;; Use the `b' style of comments to avoid interference with the -- ... --
!   ;; comments recognized when `sgml-specials' includes ?-.
!   ;; FIXME: beware of <!--> blabla <!--> !!
     ("\\(<\\)!--" (1 "< b"))
!     ("--[ \t\n]*\\(>\\)" (1 "> b"))
!     ;; Double quotes outside of tags should not introduce strings.
!     ;; Be careful to call `syntax-ppss' on a position before the one we're
!     ;; going to change, so as not to need to flush the data we just computed.
!     ("\"" (0 (if (prog1 (zerop (car (syntax-ppss (match-beginning 0))))
!                    (goto-char (match-end 0)))
!                  "."))))
    "Syntactic keywords for `sgml-mode'.")
  
  ;; internal
--- 312,335 ----
  
  (defconst sgml-syntax-propertize-function
    (syntax-propertize-rules
!    ;; Use the `b' style of comments to avoid interference with the -- ... --
!    ;; comments recognized when `sgml-specials' includes ?-.
!    ;; FIXME: beware of <!--> blabla <!--> !!
     ("\\(<\\)!--" (1 "< b"))
!    ("--[ \t\n]*\\(>\\)" (1 "> b"))
!    ;; Quotes (single or double) outside of tags should not introduce
!    ;; strings.  Be careful to call `syntax-ppss' on a position before
!    ;; the one we're going to change, so as not to need to flush the
!    ;; data we just computed.
!    ((let (string-delimiters)
!       (when (memq ?\" sgml-specials)
!         (setq string-delimiters (cons ?\" string-delimiters)))
!       (when (memq ?' sgml-specials)
!         (setq string-delimiters (cons ?' string-delimiters)))
!       (regexp-opt-charset string-delimiters))
!     (0 (if (prog1 (zerop (car (syntax-ppss (match-beginning 0))))
!              (goto-char (match-end 0)))
!            (string-to-syntax ".")))))
    "Syntactic keywords for `sgml-mode'.")
  
  ;; internal