1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

[Emacs] Highlight interpolation using Ruby highlighting.

This commit is contained in:
Nathan Weizenbaum 2009-03-06 10:08:36 -08:00
parent 3e60f70420
commit 0e5c7e1c97

View file

@ -79,6 +79,7 @@ text nested beneath them.")
(defconst haml-font-lock-keywords
`((,(haml-nested-regexp "-#.*") 0 font-lock-comment-face)
(,(haml-nested-regexp ":\\w+") 0 font-lock-string-face)
(haml-highlight-interpolation 1 font-lock-variable-name-face)
(haml-highlight-ruby-tag 1 font-lock-preprocessor-face)
(haml-highlight-ruby-script 1 font-lock-preprocessor-face)
("^ *\\(\t\\)" 1 'haml-tab-face)
@ -148,6 +149,23 @@ For example, this will highlight all of the following:
(looking-at "\\(\\)"))
t)))
(defun haml-highlight-interpolation (limit)
"Highlight Ruby interpolation (#{foo})."
(when (re-search-forward "\\(#{\\)" limit t)
(save-match-data
(forward-char -1)
(let ((beg (point)))
(haml-limited-forward-sexp limit)
(haml-fontify-region-as-ruby (+ 1 beg) (point)))
;; Highlight the end of the interpolation.
;; The font-lock-face property gets overwritten by `haml-highlight-rub-tag',
;; so we just use face instead.
(when (eq (char-before) ?})
(put-text-property (- (point) 1) (point)
'face font-lock-variable-name-face))
t)))
(defun haml-limited-forward-sexp (limit &optional arg)
"Move forward using `forward-sexp' or to limit,
whichever comes first."