1

I am writing a minor mode for php/html files. I use a function (cf. font-lock-keywords) to fontify <?php ?> blocs.

In order to fontify multilined blocs, I need to set font-lock-multiline to t.

Everything is running quite nicely. Their is just a problem in this case : When I have a multiline bloc and a delete the closing tag (?>) the bloc is unfontified. When I put the tag back, the block is not fontified again.

I have three questions :

1/ is there a simple solution to this problem

if not 2/ is there any way to trigger font-lock-fontify-buffer each time I type those two chars : '?''>'

3/ better, is there a way to trigger this kind a fonction : when I type ?> I find the opening tag <?php and force a font-lock-fontify-region on this bloc.

Luke Girvin
  • 13,221
  • 9
  • 64
  • 84
fxbois
  • 806
  • 9
  • 21
  • Why are you writing custom fontifying functions? Isn't better to use [php-mode](http://php-mode.sourceforge.net/) or even better [some up-to-date fork](https://github.com/rradonic/php-mode) which has quite good fontifying for php files... – Grzegorz Rożniecki Aug 17 '11 at 13:19

1 Answers1

1

This is a basic approach, and the logic is insufficient, but it demonstrates one option:

(defvar foo-minor-mode-map (make-keymap) "foo-minor-mode keymap.")
(define-key foo-minor-mode-map (kbd ">") 'foo-electric-gt)

(defun foo-electric-gt (&optional arg)
  (interactive "*p")
  (when (looking-back "\\?$")
    (save-excursion
      (let ((end (- (point) 1))
            (beg (+ (search-backward "<?php") 5)))
        (font-lock-fontify-region beg end))))
  (insert-char ?> arg))

(define-minor-mode foo-minor-mode
  "foo mode.

\\{foo-minor-mode-map}"
  :keymap 'foo-minor-mode-map)
phils
  • 71,335
  • 11
  • 153
  • 198
  • thx, I ve done almost the same thing with the hook : (add-hook 'after-change-functions 'psp-after-change t t) – fxbois Aug 17 '11 at 16:15