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:
parent
3e60f70420
commit
0e5c7e1c97
1 changed files with 24 additions and 6 deletions
|
@ -79,12 +79,13 @@ 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-ruby-tag 1 font-lock-preprocessor-face)
|
||||
(haml-highlight-ruby-script 1 font-lock-preprocessor-face)
|
||||
("^ *\\(\t\\)" 1 'haml-tab-face)
|
||||
("^!!!.*" 0 font-lock-constant-face)
|
||||
("| *$" 0 font-lock-string-face)
|
||||
("^[ \t]*\\(/.*\\)$" 1 font-lock-comment-face append)))
|
||||
(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)
|
||||
("^!!!.*" 0 font-lock-constant-face)
|
||||
("| *$" 0 font-lock-string-face)
|
||||
("^[ \t]*\\(/.*\\)$" 1 font-lock-comment-face append)))
|
||||
|
||||
(defconst haml-filter-re "^ *\\(:\\)\\w+")
|
||||
(defconst haml-comment-re "^ *\\(-\\)\\#")
|
||||
|
@ -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."
|
||||
|
|
Loading…
Add table
Reference in a new issue