bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#43941: HTML+ mode: dangerous apostrophe after fullwidth parenthesis


From: Stephen Berman
Subject: bug#43941: HTML+ mode: dangerous apostrophe after fullwidth parenthesis
Date: Tue, 13 Oct 2020 12:37:32 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

On Mon, 12 Oct 2020 23:26:15 +0200 Stephen Berman <stephen.berman@gmx.net> 
wrote:

> On Mon, 12 Oct 2020 20:38:15 +0300 Eli Zaretskii <eliz@gnu.org> wrote:
>
[...]
>> It shouldn't be hard to add to the list some of the characters that
>> have the paired bracket semantics, see uni-brackets.el.
>
> Some, but which?  I used the following the code to add all the
> paired-bracket characters listed in that file:
[...]
> But this fails to prevent the unwanted string face fontification.

I made a silly mistake (it was late and I was tired).  Here is a
corrected version:

diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el
index f3d8695e24..26ca536004 100644
--- a/lisp/textmodes/sgml-mode.el
+++ b/lisp/textmodes/sgml-mode.el
@@ -192,8 +192,19 @@ sgml-mode-syntax-table
   "Syntax table used in SGML mode.  See also `sgml-specials'.")

 (defconst sgml-tag-syntax-table
-  (let ((table (sgml-make-syntax-table sgml-specials)))
-    (dolist (char '(?\( ?\) ?\{ ?\} ?\[ ?\] ?$ ?% ?& ?* ?+ ?/))
+  (let ((table (sgml-make-syntax-table sgml-specials))
+       brackets)
+    (map-char-table
+     (lambda (key value)
+       (setq brackets (cons (list
+                            (if (consp key)
+                                (list (car key) (cdr key))
+                              key)
+                            value)
+                           brackets)))
+     (unicode-property-table-internal 'paired-bracket))
+    (setq brackets (delete-dups (flatten-tree brackets)))
+    (dolist (char (append brackets (list ?$ ?% ?& ?* ?+ ?/)))
       (modify-syntax-entry char "." table))
     (unless (memq ?' sgml-specials)
       ;; Avoid that skipping a tag backwards skips any "'" prefixing it.
With this patch, when any of the paired-bracket characters is followed
by `'' in html-mode, there is indeed no string face fontification on the
latter (and following characters).  The following function demonstrates
this:

(defun sgml-test-brackets ()
  "Test fontification of apostrophe preceded by paired-bracket character."
  (interactive)
  (let ((buf (get-buffer-create "*sgml-test*"))
        brackets results)
    (map-char-table
     (lambda (key value)
       (setq brackets (cons (list
                             (if (consp key)
                                 (list (car key) (cdr key))
                               key)
                             value)
                            brackets)))
     (unicode-property-table-internal 'paired-bracket))
    (setq brackets (delete-dups (flatten-tree brackets)))
    (setq brackets (append brackets (list ?$ ?% ?& ?* ?+ ?/)))
    (while brackets
      (let ((char (string (pop brackets)))
            (face "default"))
        (with-current-buffer buf
          ;; (erase-buffer)
          (fundamental-mode)
          (insert (concat "<p>" char "'s</p>\n"))
          (html-mode)
          ;; (let ((val (get-text-property 5 'face)))
          ;;   (when val (setq face (symbol-name val))))
          ;; (push (concat char " : " face "\n") results)
          )))
    ;; (with-current-buffer buf
    ;;   (newline)
    ;;   (while results
    ;;  (insert (pop results))))
    (switch-to-buffer buf)))

I wanted to turn this function into a test, and that's what the
commented out lines are supposed to do.  But when I uncomment these
lines and call this function with the unpatched (i.e. current) version
of sgml-mode-syntax-table, it still shows default face for `'' with all
the paired-bracket characters.  Yet when I step through the function
with Ediff, I do see some cases with font-lock-string-face.  I don't
understand what's going on here.

Steve Berman

reply via email to

[Prev in Thread] Current Thread [Next in Thread]