Skip to content

Commit 8cc0a94

Browse files
committed
fix: set syntax-propertize function
- `$` in atom and string - Tripled-quoted string in doc or Var
1 parent 60ee341 commit 8cc0a94

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

erlang-ts.el

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,38 @@ Use `treesit-font-lock-level' or `treesit-font-lock-feature-list'
311311
t
312312
nil)))
313313

314+
(defvar erlang-ts--syntax-propertize-query
315+
(when (treesit-available-p)
316+
(treesit-query-compile
317+
'erlang
318+
'(((atom) @node-atom)
319+
((string) @node-string-triple-quoted (:match "^\"\"\"" @node-string-triple-quoted))
320+
((string) @node-string)))))
321+
322+
(defun erlang-ts--process-node (node)
323+
"Apply syntax-descriptor as `w' for atom or normal string NODE."
324+
(let* ((string-start (1+ (treesit-node-start node)))
325+
(string-end (1- (treesit-node-end node))))
326+
(put-text-property string-start string-end 'syntax-table (string-to-syntax "w"))))
327+
328+
(defun erlang-ts--process-node-triple-quoted (node)
329+
"Apply syntax-descriptor as `|' for triple-quoted string NODE."
330+
(let* ((node-start (treesit-node-start node))
331+
(node-end (treesit-node-end node))
332+
(node-text (treesit-node-text node)))
333+
(when (string-suffix-p "\"\"\"" node-text)
334+
(put-text-property node-start node-end 'syntax-table (string-to-syntax "|")))))
335+
336+
(defun erlang-ts--syntax-propertize (start end)
337+
"Apply syntax properties for Erlang specific patterns from START to END."
338+
(let ((captures
339+
(treesit-query-capture 'erlang erlang-ts--syntax-propertize-query start end)))
340+
(pcase-dolist (`(,name . ,node) captures)
341+
(pcase name
342+
('node-atom (erlang-ts--process-node node))
343+
('node-string (erlang-ts--process-node node))
344+
('node-string-triple-quoted (erlang-ts--process-node-triple-quoted node))))))
345+
314346
(defun erlang-ts-setup ()
315347
"Setup treesit for erlang."
316348

@@ -367,7 +399,8 @@ Use `treesit-font-lock-level' or `treesit-font-lock-feature-list'
367399
(advice-add #'erlang-font-lock-level-3 :around #'erlang-ts--font-lock-level-3)
368400
(advice-add #'erlang-font-lock-level-4 :around #'erlang-ts--font-lock-level-4)
369401

370-
(treesit-major-mode-setup))
402+
(treesit-major-mode-setup)
403+
(setq-local syntax-propertize-function #'erlang-ts--syntax-propertize))
371404

372405

373406
(defun erlang-ts-unload-function ()

0 commit comments

Comments
 (0)