elixir-editors / emacs-elixir

Emacs major mode for Elixir
445 stars 94 forks source link

?) confuses syntax highlighter #411

Open onelesd opened 6 years ago

onelesd commented 6 years ago

Similar to #185, ?) confuses the syntax highlighter. Escaping like ?\) does unbreak it. ?] also confuses it.

screen shot 2018-03-07 at 6 31 19 pm

dgutov commented 5 years ago

This should be a more comprehensive fix:

diff --git a/elixir-mode.el b/elixir-mode.el
index b7426e1..980645f 100644
--- a/elixir-mode.el
+++ b/elixir-mode.el
@@ -277,9 +277,15 @@ is used to limit the scan."
     (goto-char start)
     (funcall
      (syntax-propertize-rules
-      ("\\(\\?\\)[\"']"
-       (1 (if (save-excursion (nth 3 (syntax-ppss (match-beginning 0))))
-              ;; Within a string, skip.
+      ("\\(\\?\\)[][(){}\"']"
+       (1
+        (if (or
+             ;; Probably a part of function name.
+             (not (memq (char-before (match-beginning 0))
+                        '(nil ?\[ ?\s ?\( ?,)))
+             ;; Within a string.
+             (save-excursion (nth 3 (syntax-ppss (match-beginning 0)))))
+              ;; So skip it.
               (ignore
                (goto-char (match-end 1)))
             (put-text-property (match-end 1) (match-end 0)

It will allow you to quote other important characters like all types of parens.