[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[AUCTeX-devel] font-latex.el [1/4]: Improve the code generated by font-l
From: |
Ikumi Keita |
Subject: |
[AUCTeX-devel] font-latex.el [1/4]: Improve the code generated by font-latex-make-match-defun |
Date: |
Thu, 16 Feb 2017 22:22:28 +0900 |
Hi all,
On xemacs, opening a latex file for the first time in the session always
leads to popping up of *Compile-Log-Show* buffer. Although that buffer
is empty, I see the following message when I switch to *Compile-Log*
buffer:
----------------------------------------------------------------------
While compiling toplevel forms:
** taking car of a constant: (quote font-lock-variable-name-face)
** taking car of a constant: (quote font-lock-constant-face)
** taking car of a constant: (quote font-lock-constant-face)
** taking car of a constant: (quote font-lock-function-name-face)
** taking car of a constant: (quote font-latex-slide-title-face)
** taking car of a constant: (quote font-lock-type-face)
** taking car of a constant: (quote font-latex-bold-face)
** taking car of a constant: (quote font-latex-italic-face)
** taking car of a constant: (quote font-latex-math-face)
** taking car of a constant: (quote font-lock-type-face)
----------------------------------------------------------------------
Since the last part of font-latex.el has two `byte-compile's, I
suspected the above message is a sign of existence of inefficient code
and began a survey. As a result, I found the origin and made patch to
fix it.
The problem is common to emacs and xemacs, so all the following
descriptions are based on emacs 25.1.
[Observation]
0. Start a new emacs session and open circ.tex.
1. After font-latex.elc is loaded, evaluate
(font-latex-make-built-in-keywords) to restore the uncompiled function
definition for font-latex-match-*, which were generated by
`font-latex-make-match-defun'.
2. Call `symbol-funtion' on those functions. For example, if you
evaluate (pp (symbol-function 'font-latex-match-variable)), the output
is
----------------------------------------------------------------------
(lambda (limit)
"Fontify `font-latex-match-variable' up to LIMIT.
Generated by `font-latex-make-match-defun'."
(when font-latex-match-variable
(font-latex-match-command-with-arguments
font-latex-match-variable
(append (when (boundp (quote font-latex-match-variable-keywords-local))
font-latex-match-variable-keywords-local)
font-latex-match-variable-keywords)
(if (and (listp (quote font-lock-variable-name-face))
(functionp (car (quote font-lock-variable-name-face))))
(eval (quote font-lock-variable-name-face))
(quote font-lock-variable-name-face)) limit)))
----------------------------------------------------------------------
after some manual filling and indentation. Look at the part
(if (and (listp (quote font-lock-variable-name-face))
(functionp (car (quote font-lock-variable-name-face))))
. Don't you feel odd? The oddness is much clearer if you see the
output of (pp (symbol-function 'font-latex-match-sectioning-0)):
----------------------------------------------------------------------
(lambda (limit)
... (snip) ...
(if (and (listp (if (eq font-latex-fontify-sectioning (quote color))
(quote font-lock-type-face) (quote
font-latex-sectioning-0-face)))
(functionp (car (if (eq font-latex-fontify-sectioning (quote
color)) (quote font-lock-type-face) (quote font-latex-sectioning-0-face)))))
(eval (if (eq font-latex-fontify-sectioning (quote color)) (quote
font-lock-type-face) (quote font-latex-sectioning-0-face)))
(if (eq font-latex-fontify-sectioning (quote color)) (quote
font-lock-type-face) (quote font-latex-sectioning-0-face))) limit)))
----------------------------------------------------------------------
This is ridiculous. The repeated form "(if (eq
font-latex-fontify-sectioning (quote color)) (quote font-lock-type-face)
(quote font-latex-sectioning-0-face))" comes from the definition of
`font-latex-built-in-keyword-classes'. It is obvious that the code
isn't generated as expected.
[Analysis]
The code in question is generated by the following part of
`font-latex-make-match-defun':
----------------------------------------------------------------------
;; `face' can be a face symbol, a form returning
;; a face symbol, or a list of face attributes.
(if (and (listp ,face) (functionp (car ,face)))
(eval ,face)
,face)
----------------------------------------------------------------------
, from which we can read out the intent that
(1) If `face' is a form returning a face symbol, evaluate the form.
(2) Otherwise, leave `face' as it is.
However, as shown above, the code actually generated fails to reflect
that intent.
[Patch]
I think the attached patch fixes this problem. With this fix, the
function definitions of the above two examples become:
----------------------------------------------------------------------
(lambda (limit)
"Fontify `font-latex-match-variable' up to LIMIT.
Generated by `font-latex-make-match-defun'."
(when font-latex-match-variable
(font-latex-match-command-with-arguments
font-latex-match-variable
(append
(when
(boundp 'font-latex-match-variable-keywords-local)
font-latex-match-variable-keywords-local)
font-latex-match-variable-keywords)
'font-lock-variable-name-face limit)))
----------------------------------------------------------------------
and
----------------------------------------------------------------------
(lambda (limit)
... (snip) ...
"Fontify `font-latex-match-sectioning-0' up to LIMIT.
Generated by `font-latex-make-match-defun'."
(when font-latex-match-sectioning-0
(font-latex-match-command-with-arguments
font-latex-match-sectioning-0
(append
(when
(boundp 'font-latex-match-sectioning-0-keywords-local)
font-latex-match-sectioning-0-keywords-local)
font-latex-match-sectioning-0-keywords)
(if
(eq font-latex-fontify-sectioning 'color)
'font-lock-type-face 'font-latex-sectioning-0-face)
limit)))
----------------------------------------------------------------------
respectively, which are more sensible. I also confirmed that the byte
compilation warning on xemacs went away with this patch.
[Another problem]
During the survey of the problem, I noticed that the treatment of the
face is not consistent at several places in font-latex.el and found bugs
raised by those inconsistency. The story continues to the next mail.
Regards,
Ikumi Keita
fix_font-latex-make-match-defun
Description: fix font-latex-make-match-defun
- [AUCTeX-devel] font-latex.el [1/4]: Improve the code generated by font-latex-make-match-defun,
Ikumi Keita <=