Skip to content

Commit e7c8770

Browse files
committed
---
yaml --- r: 150861 b: refs/heads/try2 c: daa1f50 h: refs/heads/master i: 150859: cd8dc17 v: v3
1 parent 4e37537 commit e7c8770

File tree

18 files changed

+334
-1160
lines changed

18 files changed

+334
-1160
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 9f3fd9337dc57cd98b03fb1ddc827750c7222420
8+
refs/heads/try2: daa1f5099f96170a290b5a5249041a8c6a8beaed
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/etc/emacs/rust-mode.el

Lines changed: 51 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,17 @@
33
;; Version: 0.2.0
44
;; Author: Mozilla
55
;; Url: https://github.com/mozilla/rust
6-
;; Keywords: languages
7-
8-
;;; Commentary:
9-
;;
10-
11-
;;; Code:
126

7+
(eval-when-compile (require 'cl))
138
(eval-when-compile (require 'misc))
149

15-
;; for GNU Emacs < 24.3
16-
(eval-when-compile
17-
(unless (fboundp 'setq-local)
18-
(defmacro setq-local (var val)
19-
"Set variable VAR to value VAL in current buffer."
20-
(list 'set (list 'make-local-variable (list 'quote var)) val))))
21-
2210
;; Syntax definitions and helpers
2311
(defvar rust-mode-syntax-table
2412
(let ((table (make-syntax-table)))
2513

2614
;; Operators
27-
(dolist (i '(?+ ?- ?* ?/ ?& ?| ?^ ?! ?< ?> ?~ ?@))
28-
(modify-syntax-entry i "." table))
15+
(loop for i in '(?+ ?- ?* ?/ ?& ?| ?^ ?! ?< ?> ?~ ?@)
16+
do (modify-syntax-entry i "." table))
2917

3018
;; Strings
3119
(modify-syntax-entry ?\" "\"" table)
@@ -42,14 +30,10 @@
4230

4331
table))
4432

45-
(defgroup rust-mode nil
46-
"Support for Rust code."
47-
:link '(url-link "http://www.rust-lang.org/")
48-
:group 'languages)
33+
(defgroup rust-mode nil "Support for Rust code.")
4934

5035
(defcustom rust-indent-offset 4
51-
"Indent Rust code by this number of spaces."
52-
:type 'integer
36+
"*Indent Rust code by this number of spaces."
5337
:group 'rust-mode)
5438

5539
(defun rust-paren-level () (nth 0 (syntax-ppss)))
@@ -242,16 +226,17 @@
242226
)
243227

244228
;; Item definitions
245-
(mapcar #'(lambda (x)
246-
(list (rust-re-item-def (car x))
247-
1 (cdr x)))
248-
'(("enum" . font-lock-type-face)
249-
("struct" . font-lock-type-face)
250-
("type" . font-lock-type-face)
251-
("mod" . font-lock-type-face)
252-
("use" . font-lock-type-face)
253-
("fn" . font-lock-function-name-face)
254-
("static" . font-lock-constant-face)))))
229+
(loop for (item . face) in
230+
231+
'(("enum" . font-lock-type-face)
232+
("struct" . font-lock-type-face)
233+
("type" . font-lock-type-face)
234+
("mod" . font-lock-type-face)
235+
("use" . font-lock-type-face)
236+
("fn" . font-lock-function-name-face)
237+
("static" . font-lock-constant-face))
238+
239+
collect `(,(rust-re-item-def item) 1 ,face))))
255240

256241
(defun rust-fill-prefix-for-comment-start (line-start)
257242
"Determine what to use for `fill-prefix' based on what is at the beginning of a line."
@@ -365,17 +350,17 @@
365350

366351
;;; Imenu support
367352
(defvar rust-imenu-generic-expression
368-
(append (mapcar #'(lambda (x)
369-
(list nil (rust-re-item-def x) 1))
370-
'("enum" "struct" "type" "mod" "fn" "trait"))
353+
(append (loop for item in
354+
'("enum" "struct" "type" "mod" "fn" "trait")
355+
collect `(nil ,(rust-re-item-def item) 1))
371356
`(("Impl" ,(rust-re-item-def "impl") 1)))
372357
"Value for `imenu-generic-expression' in Rust mode.
373358
374359
Create a flat index of the item definitions in a Rust file.
375360
376361
Imenu will show all the enums, structs, etc. at the same level.
377-
Implementations will be shown under the `Impl` subheading. Use
378-
idomenu (imenu with `ido-mode') for best mileage.")
362+
Implementations will be shown under the `Impl` subheading.
363+
Use idomenu (imenu with ido-mode) for best mileage.")
379364

380365
;;; Defun Motions
381366

@@ -384,7 +369,8 @@ idomenu (imenu with `ido-mode') for best mileage.")
384369
(concat "^\\s-*\\(?:priv\\|pub\\)?\\s-*"
385370
(regexp-opt
386371
'("enum" "struct" "type" "mod" "use" "fn" "static" "impl"
387-
"extern" "impl" "static" "trait"))))
372+
"extern" "impl" "static" "trait"
373+
))))
388374

389375
(defun rust-beginning-of-defun (&optional arg)
390376
"Move backward to the beginning of the current defun.
@@ -425,43 +411,52 @@ This is written mainly to be used as `end-of-defun-function' for Rust."
425411
(define-derived-mode rust-mode rust-parent-mode "Rust"
426412
"Major mode for Rust code."
427413
:group 'rust-mode
428-
:syntax-table rust-mode-syntax-table
414+
415+
;; Basic syntax
416+
(set-syntax-table rust-mode-syntax-table)
429417

430418
;; Indentation
431-
(setq-local indent-line-function 'rust-mode-indent-line)
419+
(set (make-local-variable 'indent-line-function)
420+
'rust-mode-indent-line)
432421

433422
;; Fonts
434-
(setq-local font-lock-defaults '(rust-mode-font-lock-keywords nil nil nil nil))
423+
(set (make-local-variable 'font-lock-defaults)
424+
'(rust-mode-font-lock-keywords nil nil nil nil))
435425

436426
;; Misc
437-
(setq-local comment-start "// ")
438-
(setq-local comment-end "")
439-
(setq-local indent-tabs-mode nil)
427+
(set (make-local-variable 'comment-start) "// ")
428+
(set (make-local-variable 'comment-end) "")
429+
(set (make-local-variable 'indent-tabs-mode) nil)
440430

441431
;; Allow paragraph fills for comments
442-
(setq-local comment-start-skip "\\(?://[/!]*\\|/\\*[*!]?\\)[[:space:]]*")
443-
(setq-local paragraph-start
432+
(set (make-local-variable 'comment-start-skip)
433+
"\\(?://[/!]*\\|/\\*[*!]?\\)[[:space:]]*")
434+
(set (make-local-variable 'paragraph-start)
444435
(concat "[[:space:]]*\\(?:" comment-start-skip "\\|\\*/?[[:space:]]*\\|\\)$"))
445-
(setq-local paragraph-separate paragraph-start)
446-
(setq-local normal-auto-fill-function 'rust-do-auto-fill)
447-
(setq-local fill-paragraph-function 'rust-fill-paragraph)
448-
(setq-local fill-forward-paragraph-function 'rust-fill-forward-paragraph)
449-
(setq-local adaptive-fill-function 'rust-find-fill-prefix)
450-
(setq-local comment-multi-line t)
451-
(setq-local comment-line-break-function 'rust-comment-indent-new-line)
452-
(setq-local imenu-generic-expression rust-imenu-generic-expression)
453-
(setq-local beginning-of-defun-function 'rust-beginning-of-defun)
454-
(setq-local end-of-defun-function 'rust-end-of-defun))
436+
(set (make-local-variable 'paragraph-separate) paragraph-start)
437+
(set (make-local-variable 'normal-auto-fill-function) 'rust-do-auto-fill)
438+
(set (make-local-variable 'fill-paragraph-function) 'rust-fill-paragraph)
439+
(set (make-local-variable 'fill-forward-paragraph-function) 'rust-fill-forward-paragraph)
440+
(set (make-local-variable 'adaptive-fill-function) 'rust-find-fill-prefix)
441+
(set (make-local-variable 'comment-multi-line) t)
442+
(set (make-local-variable 'comment-line-break-function) 'rust-comment-indent-new-line)
443+
(set (make-local-variable 'imenu-generic-expression) rust-imenu-generic-expression)
444+
(set (make-local-variable 'beginning-of-defun-function) 'rust-beginning-of-defun)
445+
(set (make-local-variable 'end-of-defun-function) 'rust-end-of-defun)
446+
)
447+
455448

456449
;;;###autoload
457-
(add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-mode))
450+
(add-to-list 'auto-mode-alist '("\\.rs$" . rust-mode))
458451

459452
(defun rust-mode-reload ()
460453
(interactive)
461454
(unload-feature 'rust-mode)
462455
(require 'rust-mode)
463456
(rust-mode))
464457

458+
(provide 'rust-mode)
459+
465460
;; Issue #6887: Rather than inheriting the 'gnu compilation error
466461
;; regexp (which is broken on a few edge cases), add our own 'rust
467462
;; compilation error regexp and use it instead.
@@ -485,6 +480,4 @@ See `compilation-error-regexp-alist for help on their format.")
485480
(cons 'rustc rustc-compilation-regexps))
486481
(add-to-list 'compilation-error-regexp-alist 'rustc)))
487482

488-
(provide 'rust-mode)
489-
490483
;;; rust-mode.el ends here

0 commit comments

Comments
 (0)