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

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

Some parts of font locking in my new major mode works only after modifyi


From: mathias . dahl
Subject: Some parts of font locking in my new major mode works only after modifying the buffer
Date: Sun, 18 Aug 2013 14:04:48 -0700 (PDT)
User-agent: G2/1.0

Hi,

I see a strange fenomen with my new major mode. I have only two keyword regexps 
(see below). If I load a file that uses this major mode (or runs the major mode 
again, or calls font-lock-fontify-buffer manually), the first part of the first 
non-empty line after a comment line, does not get coloured. The rest of the 
text is correctly colored. What's more, if I modify the buffer, either the line 
that has missing colours, or a line before it (I can insert a space, and then 
delete it), suddenly the missing color is added. I have tried to understand if 
there is anything wrong with the regexps but since they work on all other 
lines, I cannot understand how they would be wrong.

Here is some example buffer content:

1 <editword> <n> Words = {Esc} $2 $1;
2 
3 ### Lines
4
5 New Line = {Enter};
6 Newline Indent = {Ctrl+j};

(line numbers are added here, by me)

Above, "New Line" on line 5 is not coloured with font-lock-variable-name-face 
like it should, but "Newline Indent" on line 6 does. And, again, if I touch the 
buffer before line 5, it suddenly works, even if I later undo that change.

Here is the code:

(defvar vocola-mode-syntax-table
  (let ((st (make-syntax-table)))
    (modify-syntax-entry ?# "<" st)
    (modify-syntax-entry ?\n ">" st)
    (modify-syntax-entry ?\{ "(" st)
    (modify-syntax-entry ?\} ")" st)
    st)
  "Syntax table used while in `vocola-mode'.")

(defvar vocola-font-lock-keywords
  '(("^\\([^=]+\\)=" 1 font-lock-variable-name-face)
    ("{\\(.+?\\)}" 1 font-lock-type-face)))

(defvar vocola-font-lock-defaults
  '(vocola-font-lock-keywords
    nil nil))

;;;###autoload
(define-derived-mode vocola-mode prog-mode "Vocola"
  "Major mode for editing Vocola speech macro files"
  (set (make-local-variable 'font-lock-defaults) vocola-font-lock-defaults)  
  (abbrev-mode 1))

(See http://paste.lisp.org/+2YVF for a colorful version)

Any ideas?

Thanks!

/Mathias



reply via email to

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