Skip to content

Commit 6b57bbf

Browse files
committed
Make features (and their tests) work on emacs 23
1 parent d2c6d6c commit 6b57bbf

File tree

2 files changed

+17
-30
lines changed

2 files changed

+17
-30
lines changed

rust-mode-tests.el

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,11 @@ very very very long string
289289
(rust-test-manip-code
290290
deindented
291291
1
292-
(lambda () (indent-region 1 (buffer-size)))
292+
(lambda ()
293+
;; The indentation will fial in some cases if the syntax properties are
294+
;; not set. This only happens when font-lock fontifies the buffer.
295+
(font-lock-fontify-buffer)
296+
(indent-region 1 (buffer-size)))
293297
indented)))
294298

295299

rust-mode.el

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
;; be undone via tab.
117117

118118
(when (looking-at (concat "\s*\." rust-re-ident))
119-
(previous-line)
119+
(previous-logical-line)
120120
(end-of-line)
121121

122122
(let
@@ -311,6 +311,14 @@
311311
("fn" . font-lock-function-name-face)
312312
("static" . font-lock-constant-face)))))
313313

314+
(defvar rust-mode-font-lock-syntactic-keywords
315+
(mapcar (lambda (re) (list re '(1 "\"") '(2 "\"")))
316+
'("\\('\\)[^']\\('\\)"
317+
"\\('\\)\\\\['nrt]\\('\\)"
318+
"\\('\\)\\\\x[[:xdigit:]]\\{2\\}\\('\\)"
319+
"\\('\\)\\\\u[[:xdigit:]]\\{4\\}\\('\\)"
320+
"\\('\\)\\\\U[[:xdigit:]]\\{8\\}\\('\\)")))
321+
314322
(defun rust-fill-prefix-for-comment-start (line-start)
315323
"Determine what to use for `fill-prefix' based on what is at the beginning of a line."
316324
(let ((result
@@ -569,7 +577,7 @@ This is written mainly to be used as `end-of-defun-function' for Rust."
569577
(setq-local indent-line-function 'rust-mode-indent-line)
570578

571579
;; Fonts
572-
(setq-local font-lock-defaults '(rust-mode-font-lock-keywords nil nil nil nil))
580+
(setq-local font-lock-defaults '(rust-mode-font-lock-keywords nil nil nil nil (font-lock-syntactic-keywords . rust-mode-font-lock-syntactic-keywords)))
573581

574582
;; Misc
575583
(setq-local comment-start "// ")
@@ -591,33 +599,8 @@ This is written mainly to be used as `end-of-defun-function' for Rust."
591599
(setq-local beginning-of-defun-function 'rust-beginning-of-defun)
592600
(setq-local end-of-defun-function 'rust-end-of-defun)
593601
(setq-local parse-sexp-lookup-properties t)
594-
(add-hook 'syntax-propertize-extend-region-functions 'rust-syntax-propertize-extend-region)
595-
(add-hook 'post-self-insert-hook 'rust-match-angle-bracket-hook)
596-
(setq-local syntax-propertize-function 'rust-syntax-propertize))
597-
598-
(defun rust-syntax-propertize-extend-region (start end)
599-
(save-excursion
600-
(goto-char start)
601-
(beginning-of-defun)
602-
(cons
603-
(point)
604-
(progn
605-
(goto-char end)
606-
(end-of-defun)
607-
(point)))))
608-
609-
(defun rust-syntax-propertize (start end)
610-
;; Find character literals and make the syntax table recognize the single quote as the string delimiter
611-
(dolist (char-lit-re
612-
'("'[^']'"
613-
"'\\\\['nrt]'"
614-
"'\\\\x[[:xdigit:]]\\{2\\}'"
615-
"'\\\\u[[:xdigit:]]\\{4\\}'"
616-
"'\\\\U[[:xdigit:]]\\{8\\}'"))
617-
(save-excursion
618-
(goto-char start)
619-
(while (re-search-forward char-lit-re end t)
620-
(put-text-property (match-beginning 0) (match-end 0) 'syntax-table rust-mode-character-literal-syntax-table)))))
602+
(setq-local syntax-begin-function 'beginning-of-defun)
603+
(add-hook 'post-self-insert-hook 'rust-match-angle-bracket-hook))
621604

622605
;;;###autoload
623606
(add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-mode))

0 commit comments

Comments
 (0)