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:
6
12
7
- (eval-when-compile (require 'cl ))
8
13
(eval-when-compile (require 'misc ))
9
14
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
+
10
22
; ; Syntax definitions and helpers
11
23
(defvar rust-mode-syntax-table
12
24
(let ((table (make-syntax-table )))
13
25
14
26
; ; Operators
15
- (loop for i in '(?+ ?- ?* ?/ ?& ?| ?^ ?! ?< ?> ?~ ?@ )
16
- do (modify-syntax-entry i " ." table))
27
+ (dolist (i '(?+ ?- ?* ?/ ?& ?| ?^ ?! ?< ?> ?~ ?@ ) )
28
+ (modify-syntax-entry i " ." table))
17
29
18
30
; ; Strings
19
31
(modify-syntax-entry ?\" " \" " table)
30
42
31
43
table))
32
44
33
- (defgroup rust-mode nil " Support for Rust code." )
45
+ (defgroup rust-mode nil
46
+ " Support for Rust code."
47
+ :link '(url-link " http://www.rust-lang.org/" )
48
+ :group 'languages )
34
49
35
50
(defcustom rust-indent-offset 4
36
- " *Indent Rust code by this number of spaces."
51
+ " Indent Rust code by this number of spaces."
52
+ :type 'integer
37
53
:group 'rust-mode )
38
54
39
55
(defun rust-paren-level () (nth 0 (syntax-ppss )))
226
242
)
227
243
228
244
; ; Item definitions
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 ))))
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 )))))
240
255
241
256
(defun rust-fill-prefix-for-comment-start (line-start )
242
257
" Determine what to use for `fill-prefix' based on what is at the beginning of a line."
350
365
351
366
; ;; Imenu support
352
367
(defvar rust-imenu-generic-expression
353
- (append (loop for item in
354
- '( " enum " " struct " " type " " mod " " fn " " trait " )
355
- collect `( nil ,(rust-re-item-def item) 1 ))
368
+ (append (mapcar #' ( lambda ( x )
369
+ ( list nil (rust-re-item-def x) 1 ) )
370
+ '( " enum " " struct " " type " " mod " " fn " " trait " ))
356
371
`((" Impl" ,(rust-re-item-def " impl" ) 1 )))
357
372
" Value for `imenu-generic-expression' in Rust mode.
358
373
359
374
Create a flat index of the item definitions in a Rust file.
360
375
361
376
Imenu will show all the enums, structs, etc. at the same level.
362
- Implementations will be shown under the `Impl` subheading.
363
- Use idomenu (imenu with ido-mode) for best mileage." )
377
+ Implementations will be shown under the `Impl` subheading. Use
378
+ idomenu (imenu with ` ido-mode' ) for best mileage." )
364
379
365
380
; ;; Defun Motions
366
381
@@ -369,8 +384,7 @@ Use idomenu (imenu with ido-mode) for best mileage.")
369
384
(concat " ^\\ s-*\\ (?:priv\\ |pub\\ )?\\ s-*"
370
385
(regexp-opt
371
386
'(" enum" " struct" " type" " mod" " use" " fn" " static" " impl"
372
- " extern" " impl" " static" " trait"
373
- ))))
387
+ " extern" " impl" " static" " trait" ))))
374
388
375
389
(defun rust-beginning-of-defun (&optional arg )
376
390
" Move backward to the beginning of the current defun.
@@ -411,52 +425,43 @@ This is written mainly to be used as `end-of-defun-function' for Rust."
411
425
(define-derived-mode rust-mode rust-parent-mode " Rust"
412
426
" Major mode for Rust code."
413
427
:group 'rust-mode
414
-
415
- ; ; Basic syntax
416
- (set-syntax-table rust-mode-syntax-table)
428
+ :syntax-table rust-mode-syntax-table
417
429
418
430
; ; Indentation
419
- (set (make-local-variable 'indent-line-function )
420
- 'rust-mode-indent-line )
431
+ (setq-local indent-line-function 'rust-mode-indent-line )
421
432
422
433
; ; Fonts
423
- (set (make-local-variable 'font-lock-defaults )
424
- '(rust-mode-font-lock-keywords nil nil nil nil ))
434
+ (setq-local font-lock-defaults '(rust-mode-font-lock-keywords nil nil nil nil ))
425
435
426
436
; ; Misc
427
- (set ( make -local-variable ' comment-start) " // " )
428
- (set ( make -local-variable ' comment-end) " " )
429
- (set ( make -local-variable ' indent-tabs-mode) nil )
437
+ (setq -local comment-start " // " )
438
+ (setq -local comment-end " " )
439
+ (setq -local indent-tabs-mode nil )
430
440
431
441
; ; Allow paragraph fills for comments
432
- (set (make-local-variable 'comment-start-skip )
433
- " \\ (?://[/!]*\\ |/\\ *[*!]?\\ )[[:space:]]*" )
434
- (set (make-local-variable 'paragraph-start )
442
+ (setq-local comment-start-skip " \\ (?://[/!]*\\ |/\\ *[*!]?\\ )[[:space:]]*" )
443
+ (setq-local paragraph-start
435
444
(concat " [[:space:]]*\\ (?:" comment-start-skip " \\ |\\ */?[[:space:]]*\\ |\\ )$" ))
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
-
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 ))
448
455
449
456
;;;### autoload
450
- (add-to-list 'auto-mode-alist '(" \\ .rs$ " . rust-mode))
457
+ (add-to-list 'auto-mode-alist '(" \\ .rs\\ ' " . rust-mode))
451
458
452
459
(defun rust-mode-reload ()
453
460
(interactive )
454
461
(unload-feature 'rust-mode )
455
462
(require 'rust-mode )
456
463
(rust-mode ))
457
464
458
- (provide 'rust-mode )
459
-
460
465
; ; Issue #6887: Rather than inheriting the 'gnu compilation error
461
466
; ; regexp (which is broken on a few edge cases), add our own 'rust
462
467
; ; compilation error regexp and use it instead.
@@ -480,4 +485,6 @@ See `compilation-error-regexp-alist for help on their format.")
480
485
(cons 'rustc rustc-compilation-regexps))
481
486
(add-to-list 'compilation-error-regexp-alist 'rustc )))
482
487
488
+ (provide 'rust-mode )
489
+
483
490
; ;; rust-mode.el ends here
0 commit comments