all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Re: font-lock-defaults doesn't work??
@ 2007-04-15  7:48 martin rudalics
  0 siblings, 0 replies; 7+ messages in thread
From: martin rudalics @ 2007-04-15  7:48 UTC (permalink / raw)
  To: tury.peter; +Cc: help-gnu-emacs

The problem is that for `t-syntax-table' you use `make-syntax-table'
which inherits from `standard-syntax-table' (the one used for
Fundamental mode) since you don't specify an OLDTABLE argument.
`font-lock-set-defaults' first uses `copy-syntax-table' with the value
returned by `syntax-table' as argument (which could be
`emacs-lisp-mode-syntax-table' since you encounter problems with
semicolons) and then applies the modifications you provided.

But when you define t-mode you eventually have to think about other
things as well - moving around in that buffer, parsing, skipping
comments, ...  Hence you eventually need t-syntax-table with the
comment-syntax you define anyway for buffers in t-mode.  What's wrong
with providing that syntax-table as the current one to font-locking?

^ permalink raw reply	[flat|nested] 7+ messages in thread
* font-lock-defaults doesn't work??
@ 2007-04-13 15:35 Peter Tury
  2007-04-14  9:42 ` Tim X
  2007-04-16 10:07 ` Peter Tury
  0 siblings, 2 replies; 7+ messages in thread
From: Peter Tury @ 2007-04-13 15:35 UTC (permalink / raw)
  To: help-gnu-emacs

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2007-04-16 10:07 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-15  7:48 font-lock-defaults doesn't work?? martin rudalics
  -- strict thread matches above, loose matches on Subject: below --
2007-04-13 15:35 Peter Tury
2007-04-14  9:42 ` Tim X
2007-04-14 10:13   ` Peter Tury
2007-04-14 10:47     ` Lennart Borgman (gmail)
2007-04-15  3:54     ` Tim X
2007-04-16 10:07 ` Peter Tury

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.