Skip to content

Commit 62da428

Browse files
committed
Merge pull request #28 from antifuchs/recognize-qm-char-syntax
Recognize ? char syntax
2 parents 1e9668d + a5b298c commit 62da428

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-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: 32 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,32 @@
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+
(let ((start (1- (point))))
42+
(unless (or (= (char-syntax (char-before (- (point) 1))) ?w)
43+
(= (char-syntax (char-before (- (point) 1))) ?_))
44+
(put-text-property (1- (point))
45+
(point)
46+
'syntax-table
47+
'(?|))
48+
(when (= (char-after) ?\\)
49+
(forward-char)
50+
(put-text-property (1- (point))
51+
(point)
52+
'syntax-table
53+
'(?\s)))
54+
(forward-char)
55+
(put-text-property (1- (point))
56+
(point)
57+
'syntax-table
58+
'(?|))
59+
(put-text-property start (point) 'font-lock-face 'font-lock-string-face))))))
60+
3061
(defmacro elixir-smie-debug (message &rest format-args)
3162
`(progn
3263
(when elixir-smie-verbose-p
@@ -79,7 +110,7 @@ Return non-nil if any line breaks were skipped."
79110
80111
Return non-nil if any line breaks were skipped."
81112
(let ((start-line-no (line-number-at-pos (point))))
82-
(forward-comment (point))
113+
(forward-comment (buffer-size))
83114
(/= start-line-no (line-number-at-pos (point)))))
84115

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

test/elixir-mode-indentation-tests.el

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,19 @@ has_something(x) &&
131131
has_something(z)
132132
")
133133

134+
(elixir-def-indentation-test indents-last-commented-line
135+
(:expected-result :failed) ; #27
136+
"
137+
defmodule Bar do
138+
# ohai
139+
end
140+
"
141+
"
142+
defmodule Bar do
143+
# ohai
144+
end
145+
")
146+
134147
(elixir-def-indentation-test indents-if ()
135148
"
136149
if condition do

0 commit comments

Comments
 (0)