Skip to content

Commit 19bc0e9

Browse files
committed
Merge pull request #30 from MicahChalmer/emacs23-fixup
Emacs 23 Fixups
2 parents d2c6d6c + 2038365 commit 19bc0e9

File tree

4 files changed

+34
-32
lines changed

4 files changed

+34
-32
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ language: generic
22

33
env:
44
matrix:
5+
- EMACS=emacs23
56
- EMACS=emacs24
67
- EMACS=emacs-snapshot
78

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,9 @@ the packages for you (under `~/.emacs.d/elpa/`).
7676
The file `rust-mode-tests.el` contains tests that can be run via
7777
[ERT](http://www.gnu.org/software/emacs/manual/html_node/ert/index.html).
7878
You can use `run_rust_emacs_tests.sh` to run them in batch mode, if
79-
Emacs is somewhere in your `$PATH`.
79+
you set the environment variable EMACS to a program that runs emacs.
80+
81+
To test it under emacs 23, which does not ship with ERT, download ert.el from
82+
https://raw.githubusercontent.com/ohler/ert/c619b56c5bc6a866e33787489545b87d79973205/lisp/emacs-lisp/ert.el
83+
and put it in a place where emacs can find it. (ERT has shipped with emacs
84+
since emacs 24.)

rust-mode-tests.el

Lines changed: 14 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

@@ -1008,3 +1012,12 @@ fn main() {
10081012
}
10091013
"
10101014
)))
1015+
1016+
(ert-deftest indent-method-chains-after-comment ()
1017+
(let ((rust-indent-method-chain t)) (test-indent
1018+
"
1019+
fn main() { // comment here should not push next line out
1020+
foo.bar()
1021+
}
1022+
"
1023+
)))

rust-mode.el

Lines changed: 13 additions & 30 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
@@ -131,7 +131,7 @@
131131
;;
132132
((skip-dot-identifier
133133
(lambda ()
134-
(when (looking-back (concat "\." rust-re-ident))
134+
(when (looking-back (concat "\\." rust-re-ident))
135135
(backward-word 1)
136136
(backward-char)
137137
(- (current-column) rust-indent-offset)))))
@@ -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)