3
3
; ; Version: 0.2.0
4
4
; ; Author: Mozilla
5
5
; ; Url: https://github.com/mozilla/rust
6
- ; ; Keywords: languages
7
-
8
- ; ;; Commentary:
9
- ; ;
10
-
11
- ; ;; Code:
12
6
7
+ (eval-when-compile (require 'cl ))
13
8
(eval-when-compile (require 'misc ))
14
9
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
-
22
10
; ; Syntax definitions and helpers
23
11
(defvar rust-mode-syntax-table
24
12
(let ((table (make-syntax-table )))
25
13
26
14
; ; Operators
27
- (dolist (i '(?+ ?- ?* ?/ ?& ?| ?^ ?! ?< ?> ?~ ?@ ) )
28
- (modify-syntax-entry i " ." table))
15
+ (loop for i in '(?+ ?- ?* ?/ ?& ?| ?^ ?! ?< ?> ?~ ?@ )
16
+ do (modify-syntax-entry i " ." table))
29
17
30
18
; ; Strings
31
19
(modify-syntax-entry ?\" " \" " table)
42
30
43
31
table))
44
32
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." )
49
34
50
35
(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."
53
37
:group 'rust-mode )
54
38
55
39
(defun rust-paren-level () (nth 0 (syntax-ppss )))
242
226
)
243
227
244
228
; ; 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 ))))
255
240
256
241
(defun rust-fill-prefix-for-comment-start (line-start )
257
242
" Determine what to use for `fill-prefix' based on what is at the beginning of a line."
365
350
366
351
; ;; Imenu support
367
352
(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 ))
371
356
`((" Impl" ,(rust-re-item-def " impl" ) 1 )))
372
357
" Value for `imenu-generic-expression' in Rust mode.
373
358
374
359
Create a flat index of the item definitions in a Rust file.
375
360
376
361
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." )
379
364
380
365
; ;; Defun Motions
381
366
@@ -384,7 +369,8 @@ idomenu (imenu with `ido-mode') for best mileage.")
384
369
(concat " ^\\ s-*\\ (?:priv\\ |pub\\ )?\\ s-*"
385
370
(regexp-opt
386
371
'(" enum" " struct" " type" " mod" " use" " fn" " static" " impl"
387
- " extern" " impl" " static" " trait" ))))
372
+ " extern" " impl" " static" " trait"
373
+ ))))
388
374
389
375
(defun rust-beginning-of-defun (&optional arg )
390
376
" 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."
425
411
(define-derived-mode rust-mode rust-parent-mode " Rust"
426
412
" Major mode for Rust code."
427
413
:group 'rust-mode
428
- :syntax-table rust-mode-syntax-table
414
+
415
+ ; ; Basic syntax
416
+ (set-syntax-table rust-mode-syntax-table)
429
417
430
418
; ; Indentation
431
- (setq-local indent-line-function 'rust-mode-indent-line )
419
+ (set (make-local-variable 'indent-line-function )
420
+ 'rust-mode-indent-line )
432
421
433
422
; ; 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 ))
435
425
436
426
; ; 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 )
440
430
441
431
; ; 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 )
444
435
(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
+
455
448
456
449
;;;### autoload
457
- (add-to-list 'auto-mode-alist '(" \\ .rs\\ ' " . rust-mode))
450
+ (add-to-list 'auto-mode-alist '(" \\ .rs$ " . rust-mode))
458
451
459
452
(defun rust-mode-reload ()
460
453
(interactive )
461
454
(unload-feature 'rust-mode )
462
455
(require 'rust-mode )
463
456
(rust-mode ))
464
457
458
+ (provide 'rust-mode )
459
+
465
460
; ; Issue #6887: Rather than inheriting the 'gnu compilation error
466
461
; ; regexp (which is broken on a few edge cases), add our own 'rust
467
462
; ; compilation error regexp and use it instead.
@@ -485,6 +480,4 @@ See `compilation-error-regexp-alist for help on their format.")
485
480
(cons 'rustc rustc-compilation-regexps))
486
481
(add-to-list 'compilation-error-regexp-alist 'rustc )))
487
482
488
- (provide 'rust-mode )
489
-
490
483
; ;; rust-mode.el ends here
0 commit comments