Skip to content

Commit 741d2a1

Browse files
Michael Swanantifuchs
authored andcommitted
Correctly recognize ? character quote tokens
This introduces a syntax-propertize function that will ferret out non-constituent ? characters and apply the generic string delimiter syntax text property to it and the character it escapes. (This handles ?\# sequences too.) Fixes #26.
1 parent 1e9668d commit 741d2a1

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

elixir-mode.el

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,6 @@
342342

343343
(defconst elixir-mode-font-lock-defaults
344344
(list
345-
;; comments:
346-
'("#.*$" . font-lock-comment-face)
347-
348345
;; records and modules at point of definition:
349346
'("^\\s *def\\(module\\|record\\|protocol\\|impl\\)\\s +\\([^( \t\n,]+\\)" 2 font-lock-type-face)
350347

@@ -551,6 +548,8 @@ Argument END End of the region."
551548
(set (make-local-variable 'comment-end) "")
552549
(set (make-variable-buffer-local 'tab-width) elixir-basic-offset)
553550
(set (make-variable-buffer-local 'default-tab-width) elixir-basic-offset)
551+
(if (boundp 'syntax-propertize-function)
552+
(set (make-local-variable 'syntax-propertize-function) 'elixir-syntax-propertize))
554553
(smie-setup elixir-smie-grammar 'verbose-elixir-smie-rules ; 'elixir-smie-rules
555554
:forward-token 'elixir-smie-forward-token
556555
:backward-token 'elixir-smie-backward-token)

elixir-smie.el

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212

1313
(defvar elixir-mode-syntax-table
1414
(let ((elixir-mode-syntax-table (make-syntax-table)))
15+
16+
;; Note that ?_ might be better as class "_", but either seems to
17+
;; work:
1518
(modify-syntax-entry ?_ "w" elixir-mode-syntax-table)
19+
(modify-syntax-entry ?? "w" elixir-mode-syntax-table)
20+
1621
(modify-syntax-entry ?' "\"" elixir-mode-syntax-table)
1722
(modify-syntax-entry ?# "<" elixir-mode-syntax-table)
1823
(modify-syntax-entry ?\n ">" elixir-mode-syntax-table)
@@ -27,6 +32,30 @@
2732
elixir-mode-syntax-table)
2833
"Elixir mode syntax table.")
2934

35+
(defun elixir-syntax-propertize (start end)
36+
(save-excursion
37+
(goto-char start)
38+
;; The ? character on its own is supposed to escape whatever comes
39+
;; after it (including any escaped chars. Examples: ?\# and ?#.
40+
(while (search-forward "?" end t)
41+
(unless (or (= (char-syntax (char-before (- (point) 1))) ?w)
42+
(= (char-syntax (char-before (- (point) 1))) ?_))
43+
(put-text-property (1- (point))
44+
(point)
45+
'syntax-table
46+
'(?|))
47+
(when (= (char-after) ?\\)
48+
(forward-char)
49+
(put-text-property (1- (point))
50+
(point)
51+
'syntax-table
52+
'(?\s)))
53+
(forward-char)
54+
(put-text-property (1- (point))
55+
(point)
56+
'syntax-table
57+
'(?|))))))
58+
3059
(defmacro elixir-smie-debug (message &rest format-args)
3160
`(progn
3261
(when elixir-smie-verbose-p
@@ -79,7 +108,7 @@ Return non-nil if any line breaks were skipped."
79108
80109
Return non-nil if any line breaks were skipped."
81110
(let ((start-line-no (line-number-at-pos (point))))
82-
(forward-comment (point))
111+
(forward-comment (buffer-size))
83112
(/= start-line-no (line-number-at-pos (point)))))
84113

85114
(defun elixir-smie-next-token-no-lookaround (forwardp nested)

0 commit comments

Comments
 (0)