[英]Emacs: font-lock-fontify-region and multiline
I am writing a minor mode for php/html files.我正在为 php/html 文件编写一个次要模式。 I use a function (cf.
font-lock-keywords
) to fontify <?php
?>
blocs.我使用 function (参见
font-lock-keywords
)来字体化<?php
?>
blocs。
In order to fontify multilined blocs, I need to set font-lock-multiline
to t.为了字体化多行块,我需要将
font-lock-multiline
设置为 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 1/ 这个问题有简单的解决方案吗
if not 2/ is there any way to trigger font-lock-fontify-buffer
each time I type those two chars: '?''>'如果不是 2/ 每次我输入这两个字符时有什么方法可以触发
font-lock-fontify-buffer
:'?''>'
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. 3/更好,有没有办法触发这种功能:当我输入
?>
我找到开始标签<?php
并在这个块上强制使用font-lock-fontify-region
。
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.