2013-10-25 47 views
1

我想設置的標籤自定義顏色背景,但其他不碰emacs的定製的PHP代碼突出語法

(define-derived-mode php-mode fundamental-mode 
    "php-mode" 
    :syntax-table php-syntax-table 
    (setq font-lock-defaults '(php-keywords))) 

(defvar php-syntax-table (make-syntax-table) "Syntax table for php-mode") 
(make-face 'php-region-face) 
(set-face-background 'php-region-face "red") 
(setq php-keywords '(("<\\?php[[:ascii:]]*?\\?>" 0 'php-region-face t))) 

但突出的背景標籤不正確,見下圖: enter image description here

回答

1

你」我們希望設置多行字體鎖並定義字體鎖搜索的邊界(所以它不需要太多時間)。我的信息(和此代碼)來自this SO question

在這裏,我定義了多行字體鎖定發生在標籤內(< ...>)。如果將其添加到您的定義派生模式中,它將按您所描述的方式工作。

(set (make-local-variable 'font-lock-multiline) t) 
(add-hook 'font-lock-extend-region-functions 
      'test-font-lock-extend-region) 

(defun test-font-lock-extend-region() 
    "Extend the search region to include an entire SGML tag." 
    ;; Avoid compiler warnings about these global variables from font-lock.el. 
    ;; See the documentation for variable `font-lock-extend-region-functions'. 
    (eval-when-compile (defvar font-lock-beg) (defvar font-lock-end)) 
    (save-excursion 
    (goto-char font-lock-beg) 
    (let ((found (or (re-search-backward "<" nil t) (point-min)))) 
(goto-char font-lock-end) 
(when (re-search-forward ">" nil t) 
    (beginning-of-line) 
    (setq font-lock-end (point))) 
(setq font-lock-beg found)))) 

編輯:出於某種原因,SO不喜歡我的代碼格式。

相關問題