Skip to content

Commit 6d5b02e

Browse files
committed
Merge pull request #56 from pnkfelix/pr=fix-word-syntax
Fix word and symbol syntax distinction, take 2
2 parents 493cc99 + 2e800ee commit 6d5b02e

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

rust-mode.el

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@
3232
(modify-syntax-entry ?\" "\"" table)
3333
(modify-syntax-entry ?\\ "\\" table)
3434

35-
;; mark _ as a word constituent so that identifiers
36-
;; such as xyz_type don't cause type to be highlighted
37-
;; as a keyword
38-
(modify-syntax-entry ?_ "w" table)
39-
4035
;; Comments
4136
(modify-syntax-entry ?/ ". 124b" table)
4237
(modify-syntax-entry ?* ". 23" table)
@@ -145,7 +140,7 @@
145140
((skip-dot-identifier
146141
(lambda ()
147142
(when (looking-back (concat "\\." rust-re-ident))
148-
(backward-word 1)
143+
(forward-thing 'symbol -1)
149144
(backward-char)
150145
(- (current-column) rust-indent-offset)))))
151146
(cond
@@ -331,14 +326,19 @@
331326
(defun rust-re-item-def (itype)
332327
(concat (rust-re-word itype) "[[:space:]]+" (rust-re-grab rust-re-ident)))
333328

329+
;; (See PR #42 -- this is just like `(regexp-opt words 'symbols)` from
330+
;; newer Emacs versions, but will work on Emacs 23.)
331+
(defun regexp-opt-symbols (words)
332+
(concat "\\_<" (regexp-opt words t) "\\_>"))
333+
334334
(defvar rust-mode-font-lock-keywords
335335
(append
336336
`(
337337
;; Keywords proper
338-
(,(regexp-opt rust-mode-keywords 'words) . font-lock-keyword-face)
338+
(,(regexp-opt-symbols rust-mode-keywords) . font-lock-keyword-face)
339339

340340
;; Special types
341-
(,(regexp-opt rust-special-types 'words) . font-lock-type-face)
341+
(,(regexp-opt-symbols rust-special-types) . font-lock-type-face)
342342

343343
;; Attributes like `#[bar(baz)]` or `#![bar(baz)]` or `#[bar = "baz"]`
344344
(,(rust-re-grab (concat "#\\!?\\[" rust-re-ident "[^]]*\\]"))

0 commit comments

Comments
 (0)