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

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

font-lock-defaults doesn't work??


From: Peter Tury
Subject: font-lock-defaults doesn't work??
Date: 13 Apr 2007 08:35:48 -0700
User-agent: G2/1.0

Hi,

I am trying to create a new major mode from scratch. I found that
syntax parsing doesn't work properly sometimes. Why? Am I missed
something or this is a bug?

Details:

I have the following defun for start. If I remove the "secretly
must-to-have parts" (see below) then M-: (syntax-ppss) returns lists
as if it would parse a lisp buffer: characters in a line after `;'
reported as in-comment chars, and real comments (= delimited by `/*'
and `*/' doesn't recognized as comments. However, fontification works
nicely -- most of the time, but not always: _sometimes_, if I put `;'
inside a /*-comment and then delete this `;', then comment-color is
removed... More interestingly once I got nil for the value of
font-lock-syntax-table (queried via C-h v font-lock-syntax-table from
the buffer where I activated this new mode via M-x t-mode
previously)!?

So it seems syntax parsing is wrong and fontification is
indeterministic iff I set(??) font-lock-syntax-table via
font-lock-defaults, but everything works well if I directly set it via
set-syntax-table.

Is this normal? Do you know the reason? Should I report it as a bug?

(defun t-mode ()
  "test major mode"
  (interactive)

  (kill-all-local-variables)
  (setq major-mode (quote t-mode))
  (setq mode-name "t-mode")

  ;; secretly must-to-have parts -- start
  (let ((t-syntax-table (make-syntax-table)))
    (modify-syntax-entry ?/ ". 14" t-syntax-table)
    (modify-syntax-entry ?* ". 23" t-syntax-table)
    (set-syntax-table t-syntax-table))
  ;; secretly must-to-have parts -- end

  (set (make-local-variable 'font-lock-defaults)
       '(nil nil t
             ((?/ . ". 14")
              (?* . ". 23"))))

  (run-mode-hooks 't-mode-hook))

Note: emacs' help writes for font-lock-syntax-table: "this is normally
set via `font-lock-defaults'", while elisp manual writes for
make-syntax-table (in 35.3): "most major mode syntax tables are
created in this way" -- however I would think that make-syntax-table
is unusable if I set font-lock-syntax-table via font-lock-
defaults...??

(I use patched EmacsW32 v feb.20.2007, and haven't tested the
situation with -Q...)

Thanks for your help in advance,
P



reply via email to

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