all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Some parts of font locking in my new major mode works only after modifying the buffer
@ 2013-08-18 21:04 mathias.dahl
  2013-08-25 13:46 ` Stefan Monnier
  0 siblings, 1 reply; 2+ messages in thread
From: mathias.dahl @ 2013-08-18 21:04 UTC (permalink / raw)
  To: help-gnu-emacs

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



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

* Re: Some parts of font locking in my new major mode works only after modifying the buffer
  2013-08-18 21:04 Some parts of font locking in my new major mode works only after modifying the buffer mathias.dahl
@ 2013-08-25 13:46 ` Stefan Monnier
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Monnier @ 2013-08-25 13:46 UTC (permalink / raw)
  To: help-gnu-emacs

> 1 <editword> <n> Words = {Esc} $2 $1;
> 2 
> 3 ### Lines
> 4
> 5 New Line = {Enter};
> 6 Newline Indent = {Ctrl+j};
[...]
>   '(("^\\([^=]+\\)=" 1 font-lock-variable-name-face)

This regexp will match (on the first call) "<editword> <n> Words =" on
the first call.  And on the second it will match:

" {Esc} $2 $1;

### Lines
New Line ="

This text includes parts that are already highlighted (the "### Lines"
comment), so font-lock doesn't apply the text-property.  You can force
it to apply the text property (using the OVERRIDE part of the rule, see
C-h v font-lock-keywords), but I doubt that's what you want anyway,


        Stefan


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

end of thread, other threads:[~2013-08-25 13:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-18 21:04 Some parts of font locking in my new major mode works only after modifying the buffer mathias.dahl
2013-08-25 13:46 ` Stefan Monnier

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.