Created
October 14, 2012 18:59
-
-
Save dmj/3889487 to your computer and use it in GitHub Desktop.
Highlight annotations in PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defface php-annotations-annotation-face '((t . (:inherit 'font-lock-constant-face))) | |
"Face used to highlight annotations.") | |
(defconst php-annotations-re "\\(\\s-\\|{\\)\\(@[[:alpha:]]+\\)") | |
(defmacro php-annotations-inside-comment-p (pos) | |
"Return non-nil if POS is inside a comment." | |
`(eq (get-char-property ,pos 'face) 'font-lock-comment-face)) | |
(defun php-annotations-font-lock-find-annotation (limit) | |
(let ((match | |
(catch 'match | |
(save-match-data | |
(while (re-search-forward php-annotations-re limit t) | |
(when (php-annotations-inside-comment-p (match-beginning 0)) | |
(goto-char (match-end 0)) | |
(throw 'match (match-data)))))))) | |
(when match | |
(set-match-data match) | |
t))) | |
(eval-after-load 'php-mode | |
'(font-lock-add-keywords 'php-mode '((php-annotations-font-lock-find-annotation (2 'php-annotations-annotation-face t))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment