Skip to content

Fix syntax highlighting sigils in string #277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions elixir-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@
(t
(rx-to-string (car sexps) t))))))

(defsubst elixir-syntax-in-string-or-comment-p ()
(nth 8 (syntax-ppss)))

(defsubst elixir-syntax-count-quotes (quote-char &optional point limit)
"Count number of quotes around point (max is 3).
QUOTE-CHAR is the quote char to count. Optional argument POINT is
Expand Down Expand Up @@ -263,23 +266,24 @@ is used to limit the scan."
(?\[ . "]")))

(defun elixir-syntax-replace-property-in-sigil ()
(let ((heredoc-p (save-excursion
(goto-char (match-beginning 0))
(looking-at-p "~s\"\"\""))))
(unless heredoc-p
(forward-char 1)
(let* ((start-delim (char-after (1- (point))))
(end-delim (or (assoc-default start-delim elixir-sigil-delimiter-pair)
(char-to-string start-delim)))
(end (save-excursion
(skip-chars-forward (concat "^" end-delim))
(point)))
(word-syntax (string-to-syntax "w")))
(when (memq start-delim '(?' ?\"))
(setq end (1+ end))
(forward-char -1))
(while (re-search-forward "[\"'#]" end t)
(put-text-property (1- (point)) (point) 'syntax-table word-syntax))))))
(unless (elixir-syntax-in-string-or-comment-p)
(let ((heredoc-p (save-excursion
(goto-char (match-beginning 0))
(looking-at-p "~s\"\"\""))))
(unless heredoc-p
(forward-char 1)
(let* ((start-delim (char-after (1- (point))))
(end-delim (or (assoc-default start-delim elixir-sigil-delimiter-pair)
(char-to-string start-delim)))
(end (save-excursion
(skip-chars-forward (concat "^" end-delim))
(point)))
(word-syntax (string-to-syntax "w")))
(when (memq start-delim '(?' ?\"))
(setq end (1+ end))
(forward-char -1))
(while (re-search-forward "[\"'#]" end t)
(put-text-property (1- (point)) (point) 'syntax-table word-syntax)))))))

(defun elixir-syntax-propertize-function (start end)
(let ((case-fold-search nil))
Expand Down
13 changes: 13 additions & 0 deletions test/elixir-mode-font-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,19 @@ foo
(should-not (eq (elixir-test-face-at 19) 'font-lock-type-face))
(should (eq (elixir-test-face-at 21) 'font-lock-type-face))))

(ert-deftest elixir-mode-syntax-table/sigils-in-string ()
"https://github.com/elixir-lang/emacs-elixir/issues/275"
:tags '(fontification syntax-table)
(elixir-test-with-temp-buffer
"@one 1
@two \"~s\"
@three :tre
"
(should-not (eq (elixir-test-face-at 18) 'font-lock-string-face))
(should (eq (elixir-test-face-at 19) 'elixir-attribute-face))
(should-not (eq (elixir-test-face-at 25) 'font-lock-string-face))
(should (eq (elixir-test-face-at 26) 'elixir-atom-face))))

(provide 'elixir-mode-font-test)

;;; elixir-mode-font-test.el ends here