|
243 | 243 | "For use with atoms & map keys."
|
244 | 244 | :group 'font-lock-faces)
|
245 | 245 |
|
| 246 | +(defun elixir-syntax-propertize-interpolation () |
| 247 | + (let* ((beg (match-beginning 0)) |
| 248 | + (context (save-excursion (save-match-data (syntax-ppss beg))))) |
| 249 | + (put-text-property beg (1+ beg) 'elixir-interpolation |
| 250 | + (cons (nth 3 context) (match-data))))) |
| 251 | + |
| 252 | +(defun elixir-syntax-propertize-function (start end) |
| 253 | + (let ((case-fold-search nil)) |
| 254 | + (goto-char start) |
| 255 | + (remove-text-properties start end '(elixir-interpolation)) |
| 256 | + (funcall |
| 257 | + (syntax-propertize-rules |
| 258 | + ((rx (group "#{" (0+ (not (any "}"))) "}")) |
| 259 | + (0 (ignore (elixir-syntax-propertize-interpolation))))) |
| 260 | + start end))) |
| 261 | + |
| 262 | +(defun elixir-match-interpolation (limit) |
| 263 | + (let ((pos (next-single-char-property-change (point) 'elixir-interpolation |
| 264 | + nil limit))) |
| 265 | + (when (and pos (> pos (point))) |
| 266 | + (goto-char pos) |
| 267 | + (let ((value (get-text-property pos 'elixir-interpolation))) |
| 268 | + (if (eq (car value) ?\") |
| 269 | + (progn |
| 270 | + (set-match-data (cdr value)) |
| 271 | + t) |
| 272 | + (elixir-match-interpolation limit)))))) |
246 | 273 |
|
247 | 274 | (eval-when-compile
|
248 | 275 | (defconst elixir-rx-constituents
|
|
353 | 380 | (t
|
354 | 381 | (rx-to-string (car sexps) t))))))
|
355 | 382 |
|
356 |
| -(defconst elixir-mode-font-lock-defaults |
| 383 | +(defconst elixir-font-lock-keywords |
357 | 384 | `(
|
| 385 | + ;; String interpolation |
| 386 | + (elixir-match-interpolation 0 font-lock-variable-name-face t) |
| 387 | + |
358 | 388 | ;; Module-defining & namespace builtins
|
359 | 389 | (,(elixir-rx (or builtin-declaration builtin-namespace)
|
360 | 390 | space
|
@@ -593,13 +623,17 @@ Argument END End of the region."
|
593 | 623 | "Major mode for editing Elixir code.
|
594 | 624 |
|
595 | 625 | \\{elixir-mode-map}"
|
596 |
| - (set (make-local-variable 'font-lock-defaults) '(elixir-mode-font-lock-defaults)) |
| 626 | + (set (make-local-variable 'font-lock-defaults) |
| 627 | + '(elixir-font-lock-keywords)) |
597 | 628 | (set (make-local-variable 'comment-start) "# ")
|
598 | 629 | (set (make-local-variable 'comment-end) "")
|
599 | 630 | (set (make-local-variable 'comment-use-syntax) t)
|
600 | 631 | (set (make-local-variable 'tab-width) elixir-basic-offset)
|
601 |
| - (set (make-local-variable 'imenu-generic-expression) elixir-imenu-generic-expression) |
602 |
| - (smie-setup elixir-smie-grammar 'verbose-elixir-smie-rules ; 'elixir-smie-rules |
| 632 | + (set (make-local-variable 'syntax-propertize-function) |
| 633 | + #'elixir-syntax-propertize-function) |
| 634 | + (set (make-local-variable 'imenu-generic-expression) |
| 635 | + elixir-imenu-generic-expression) |
| 636 | + (smie-setup elixir-smie-grammar 'verbose-elixir-smie-rules |
603 | 637 | :forward-token 'elixir-smie-forward-token
|
604 | 638 | :backward-token 'elixir-smie-backward-token))
|
605 | 639 |
|
|
0 commit comments