emacs-devel
[Top][All Lists]
Advanced

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

Re: Giving "text quotes" syntax in font-lock-syntax-table only


From: Ikumi Keita
Subject: Re: Giving "text quotes" syntax in font-lock-syntax-table only
Date: Wed, 20 May 2020 22:24:11 +0900

Hi!

>>>>> Stefan Monnier <address@hidden> writes:
> The best way to do that is to set `syntax-ppss-table` to the
> syntax-table that should be used.

I suppose that you are suggesting that something like this:
----------------------------------------------------------------------
(defvar bug-repro-mode-syntax-table
  (let ((st (make-syntax-table)))
    (modify-syntax-entry ?$ "$" st)
    (modify-syntax-entry ?% "<" st)
    (modify-syntax-entry ?\n ">" st)
    st))

(defun bug-repro-syntactic-face-function (state)
  (let ((char (nth 3 state)))
    (if char
        font-lock-string-face
      font-lock-comment-face)))

(define-derived-mode bug-repro-mode nil "BugRepro"
  :syntax-table bug-repro-mode-syntax-table
  (add-hook 'pre-command-hook #'syntax-ppss nil t)
  (setq font-lock-multiline t)
  (setq syntax-ppss-table
        (let ((st (make-syntax-table bug-repro-mode-syntax-table)))
          (modify-syntax-entry ?$ "\"" st)
          st))
  (setq font-lock-defaults
        '(nil nil nil nil ; ((?$ . "\""))
              (font-lock-syntactic-face-function
               . bug-repro-syntactic-face-function))))
----------------------------------------------------------------------
This resembles the method to modify the major mode's syntax table
(without setting `syntax-ppss-table'). It does eliminate the wrong
fontification, but brings another problem in actual use cases of AUCTeX.

When `syntax-ppss-table' is non-nil, all functions using `syntax-ppss'
obey that syntax table, so they regard math expression $...$ as string
constant. This can be problematic for cases like this:
----------------------------------------------------------------------
\documentclass{article}
\begin{document}
$x^{2}+y^{2} % syntax-ppss wouldn't regard me as a comment.
=z^{2}$
\end{document}
----------------------------------------------------------------------

In other words, what we want to carry out is:
- to use modified syntax table only within font lock
- while keeping to use major mode's syntax table for all other purposes.

If we temporarily bind `syntax-ppss-table' during font lock by `let',
the problem of conflicting cache emerges again and it causes the
inverted fontification, if I understand correctly.

I can think of no way to achieve our intention in the current framework
of syntax.el and font lock.

I'm speaking without knowing the detail of syntax.el, so please correct
me if I understand something wrongly.

Regards,
Ikumi Keita



reply via email to

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