[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rust-mode bc78d17 075/486: rust-mode cleanup.
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rust-mode bc78d17 075/486: rust-mode cleanup. |
Date: |
Sat, 7 Aug 2021 09:24:52 -0400 (EDT) |
branch: elpa/rust-mode
commit bc78d1712e82fbc504a86b0f819be40563c5483d
Author: RĂ¼diger Sonderfeld <ruediger@c-plusplus.de>
Commit: RĂ¼diger Sonderfeld <ruediger@c-plusplus.de>
rust-mode cleanup.
* Use `setq-local' instead of (set (make-local-variable ...) value).
Provides a version for older Emacsen.
* Remove use of `cl.el'.
* Use \' in file regexp instead of line end match $.
* Use type for defcustom and add parent group.
---
rust-mode.el | 109 +++++++++++++++++++++++++++++++----------------------------
1 file changed, 58 insertions(+), 51 deletions(-)
diff --git a/rust-mode.el b/rust-mode.el
index 26bdf7d..f436bcb 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -3,17 +3,29 @@
;; Version: 0.2.0
;; Author: Mozilla
;; Url: https://github.com/mozilla/rust
+;; Keywords: languages
+
+;;; Commentary:
+;;
+
+;;; Code:
-(eval-when-compile (require 'cl))
(eval-when-compile (require 'misc))
+;; for GNU Emacs < 24.3
+(eval-when-compile
+ (unless (fboundp 'setq-local)
+ (defmacro setq-local (var val)
+ "Set variable VAR to value VAL in current buffer."
+ (list 'set (list 'make-local-variable (list 'quote var)) val))))
+
;; Syntax definitions and helpers
(defvar rust-mode-syntax-table
(let ((table (make-syntax-table)))
;; Operators
- (loop for i in '(?+ ?- ?* ?/ ?& ?| ?^ ?! ?< ?> ?~ ?@)
- do (modify-syntax-entry i "." table))
+ (dolist (i '(?+ ?- ?* ?/ ?& ?| ?^ ?! ?< ?> ?~ ?@))
+ (modify-syntax-entry i "." table))
;; Strings
(modify-syntax-entry ?\" "\"" table)
@@ -30,10 +42,14 @@
table))
-(defgroup rust-mode nil "Support for Rust code.")
+(defgroup rust-mode nil
+ "Support for Rust code."
+ :link '(url-link "http://www.rust-lang.org/")
+ :group 'languages)
(defcustom rust-indent-offset 4
- "*Indent Rust code by this number of spaces."
+ "Indent Rust code by this number of spaces."
+ :type 'integer
:group 'rust-mode)
(defun rust-paren-level () (nth 0 (syntax-ppss)))
@@ -226,17 +242,16 @@
)
;; Item definitions
- (loop for (item . face) in
-
- '(("enum" . font-lock-type-face)
- ("struct" . font-lock-type-face)
- ("type" . font-lock-type-face)
- ("mod" . font-lock-type-face)
- ("use" . font-lock-type-face)
- ("fn" . font-lock-function-name-face)
- ("static" . font-lock-constant-face))
-
- collect `(,(rust-re-item-def item) 1 ,face))))
+ (mapcar #'(lambda (x)
+ (list (rust-re-item-def (car x))
+ 1 (cdr x)))
+ '(("enum" . font-lock-type-face)
+ ("struct" . font-lock-type-face)
+ ("type" . font-lock-type-face)
+ ("mod" . font-lock-type-face)
+ ("use" . font-lock-type-face)
+ ("fn" . font-lock-function-name-face)
+ ("static" . font-lock-constant-face)))))
(defun rust-fill-prefix-for-comment-start (line-start)
"Determine what to use for `fill-prefix' based on what is at the beginning
of a line."
@@ -350,17 +365,17 @@
;;; Imenu support
(defvar rust-imenu-generic-expression
- (append (loop for item in
- '("enum" "struct" "type" "mod" "fn" "trait")
- collect `(nil ,(rust-re-item-def item) 1))
+ (append (mapcar #'(lambda (x)
+ (list nil (rust-re-item-def x) 1))
+ '("enum" "struct" "type" "mod" "fn" "trait"))
`(("Impl" ,(rust-re-item-def "impl") 1)))
"Value for `imenu-generic-expression' in Rust mode.
Create a flat index of the item definitions in a Rust file.
Imenu will show all the enums, structs, etc. at the same level.
-Implementations will be shown under the `Impl` subheading.
-Use idomenu (imenu with ido-mode) for best mileage.")
+Implementations will be shown under the `Impl` subheading. Use
+idomenu (imenu with `ido-mode') for best mileage.")
;;; Defun Motions
@@ -369,8 +384,7 @@ Use idomenu (imenu with ido-mode) for best mileage.")
(concat "^\\s-*\\(?:priv\\|pub\\)?\\s-*"
(regexp-opt
'("enum" "struct" "type" "mod" "use" "fn" "static" "impl"
- "extern" "impl" "static" "trait"
- ))))
+ "extern" "impl" "static" "trait"))))
(defun rust-beginning-of-defun (&optional arg)
"Move backward to the beginning of the current defun.
@@ -411,43 +425,36 @@ This is written mainly to be used as
`end-of-defun-function' for Rust."
(define-derived-mode rust-mode rust-parent-mode "Rust"
"Major mode for Rust code."
:group 'rust-mode
-
- ;; Basic syntax
- (set-syntax-table rust-mode-syntax-table)
+ :syntax-table rust-mode-syntax-table
;; Indentation
- (set (make-local-variable 'indent-line-function)
- 'rust-mode-indent-line)
+ (setq-local indent-line-function 'rust-mode-indent-line)
;; Fonts
- (set (make-local-variable 'font-lock-defaults)
- '(rust-mode-font-lock-keywords nil nil nil nil))
+ (setq-local font-lock-defaults '(rust-mode-font-lock-keywords nil nil nil
nil))
;; Misc
- (set (make-local-variable 'comment-start) "// ")
- (set (make-local-variable 'comment-end) "")
- (set (make-local-variable 'indent-tabs-mode) nil)
+ (setq-local comment-start "// ")
+ (setq-local comment-end "")
+ (setq-local indent-tabs-mode nil)
;; Allow paragraph fills for comments
- (set (make-local-variable 'comment-start-skip)
- "\\(?://[/!]*\\|/\\*[*!]?\\)[[:space:]]*")
- (set (make-local-variable 'paragraph-start)
+ (setq-local comment-start-skip "\\(?://[/!]*\\|/\\*[*!]?\\)[[:space:]]*")
+ (setq-local paragraph-start
(concat "[[:space:]]*\\(?:" comment-start-skip
"\\|\\*/?[[:space:]]*\\|\\)$"))
- (set (make-local-variable 'paragraph-separate) paragraph-start)
- (set (make-local-variable 'normal-auto-fill-function) 'rust-do-auto-fill)
- (set (make-local-variable 'fill-paragraph-function) 'rust-fill-paragraph)
- (set (make-local-variable 'fill-forward-paragraph-function)
'rust-fill-forward-paragraph)
- (set (make-local-variable 'adaptive-fill-function) 'rust-find-fill-prefix)
- (set (make-local-variable 'comment-multi-line) t)
- (set (make-local-variable 'comment-line-break-function)
'rust-comment-indent-new-line)
- (set (make-local-variable 'imenu-generic-expression)
rust-imenu-generic-expression)
- (set (make-local-variable 'beginning-of-defun-function)
'rust-beginning-of-defun)
- (set (make-local-variable 'end-of-defun-function) 'rust-end-of-defun)
- )
-
+ (setq-local paragraph-separate paragraph-start)
+ (setq-local normal-auto-fill-function 'rust-do-auto-fill)
+ (setq-local fill-paragraph-function 'rust-fill-paragraph)
+ (setq-local fill-forward-paragraph-function 'rust-fill-forward-paragraph)
+ (setq-local adaptive-fill-function 'rust-find-fill-prefix)
+ (setq-local comment-multi-line t)
+ (setq-local comment-line-break-function 'rust-comment-indent-new-line)
+ (setq-local imenu-generic-expression rust-imenu-generic-expression)
+ (setq-local beginning-of-defun-function 'rust-beginning-of-defun)
+ (setq-local end-of-defun-function 'rust-end-of-defun))
;;;###autoload
-(add-to-list 'auto-mode-alist '("\\.rs$" . rust-mode))
+(add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-mode))
(defun rust-mode-reload ()
(interactive)
@@ -455,8 +462,6 @@ This is written mainly to be used as
`end-of-defun-function' for Rust."
(require 'rust-mode)
(rust-mode))
-(provide 'rust-mode)
-
;; Issue #6887: Rather than inheriting the 'gnu compilation error
;; regexp (which is broken on a few edge cases), add our own 'rust
;; compilation error regexp and use it instead.
@@ -480,4 +485,6 @@ See `compilation-error-regexp-alist for help on their
format.")
(cons 'rustc rustc-compilation-regexps))
(add-to-list 'compilation-error-regexp-alist 'rustc)))
+(provide 'rust-mode)
+
;;; rust-mode.el ends here
- [nongnu] elpa/rust-mode df31a6e 393/486: Don't call syntax-ppss twice for strings ending with r., (continued)
- [nongnu] elpa/rust-mode df31a6e 393/486: Don't call syntax-ppss twice for strings ending with r., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 942d465 398/486: Update Debian installation instructions, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode af84c0f 403/486: Merge pull request #319 from phillord/feature/update-emacs-versions, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 4c8754b 430/486: Merge pull request #343 from haroldcarr/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 4381a89 433/486: Fix scrolling after rustfmt. (#351), ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 2a8ca9e 443/486: rust-format-show-buffer: default to true., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 15d31a9 013/486: removed a comma from the keyword list to get, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode e39142b 033/486: Allow customization of indent offset, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 8dc92b2 073/486: Update emacs mode to support new `#![inner(attribute)]` syntax., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 0800660 068/486: Emacs: stay at the correct position when indenting, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode bc78d17 075/486: rust-mode cleanup.,
ELPA Syncer <=
- [nongnu] elpa/rust-mode 5e34201 061/486: Add defun motions for rust-mode., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 0e58eb3 076/486: emacs: Add 'box' to keywords, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 226102c 086/486: emacs: Add shebang to test script, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 186583d 096/486: Mark _ as a word constituent to avoid highlighting parts of identifiers as keywords, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 04e4b49 103/486: Add .travis.yml, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode ec81a95 114/486: Merge pull request #22 from nikomatsakis/align-method-chain, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 351cc91 112/486: Merge pull request #16 from MicahChalmer/add-travis, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode b3f87b9 122/486: Make the test driver script a little more informative., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 19bc0e9 121/486: Merge pull request #30 from MicahChalmer/emacs23-fixup, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode bddc933 124/486: Fix typo in comment, ELPA Syncer, 2021/08/07