From 560e695a09279ddd95fc908a0552fb815e9df0b0 Mon Sep 17 00:00:00 2001 From: Syohei YOSHIDA Date: Fri, 23 Oct 2015 10:59:06 +0900 Subject: [PATCH 1/2] Add unit test of sigils in string --- test/elixir-mode-font-test.el | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/elixir-mode-font-test.el b/test/elixir-mode-font-test.el index b0dadfc2..9ae19776 100644 --- a/test/elixir-mode-font-test.el +++ b/test/elixir-mode-font-test.el @@ -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 From a6b12cadf1551fe55e525b44275b9c9dd7ea8c53 Mon Sep 17 00:00:00 2001 From: Syohei YOSHIDA Date: Fri, 23 Oct 2015 11:01:30 +0900 Subject: [PATCH 2/2] Don't change sigil property if it is in string or comment --- elixir-mode.el | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/elixir-mode.el b/elixir-mode.el index 71f32cf4..846c9da8 100644 --- a/elixir-mode.el +++ b/elixir-mode.el @@ -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 @@ -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))