[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rust-mode d6b2c32 060/486: Add Imenu support for rust-mode
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rust-mode d6b2c32 060/486: Add Imenu support for rust-mode. |
Date: |
Sat, 7 Aug 2021 09:24:48 -0400 (EDT) |
branch: elpa/rust-mode
commit d6b2c329a4951940f6c48dedb095de97790d66b9
Author: S Pradeep Kumar <gohanpra@gmail.com>
Commit: S Pradeep Kumar <gohanpra@gmail.com>
Add Imenu support for rust-mode.
+ Delete trailing whitespace.
---
rust-mode.el | 51 +++++++++++++++++++++++++++++++++------------------
1 file changed, 33 insertions(+), 18 deletions(-)
diff --git a/rust-mode.el b/rust-mode.el
index a3b7581..2a5f2d9 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -84,7 +84,7 @@
;; or one further indent from that if either current line
;; begins with 'else', or previous line didn't end in
;; semi, comma or brace (other than whitespace and line
- ;; comments) , and wasn't an attribute. But if we have
+ ;; comments) , and wasn't an attribute. But if we have
;; something after the open brace and ending with a comma,
;; treat it as fields and align them. PHEW.
((> level 0)
@@ -213,15 +213,15 @@
(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."
- (let ((result
+ (let ((result
;; Replace /* with same number of spaces
(replace-regexp-in-string
- "\\(?:/\\*+\\)[!*]"
+ "\\(?:/\\*+\\)[!*]"
(lambda (s)
;; We want the * to line up with the first * of the comment start
(concat (make-string (- (length s) 2) ?\x20) "*"))
line-start)))
- ;; Make sure we've got at least one space at the end
+ ;; Make sure we've got at least one space at the end
(if (not (= (aref result (- (length result) 1)) ?\x20))
(setq result (concat result " ")))
result))
@@ -247,14 +247,14 @@
;; inferring it from the comment start.
(let ((next-bol (line-beginning-position 2)))
(while (save-excursion
- (end-of-line)
- (syntax-ppss-flush-cache 1)
- (and (nth 4 (syntax-ppss))
- (save-excursion
- (beginning-of-line)
- (looking-at paragraph-start))
- (looking-at "[[:space:]]*$")
- (nth 4 (syntax-ppss next-bol))))
+ (end-of-line)
+ (syntax-ppss-flush-cache 1)
+ (and (nth 4 (syntax-ppss))
+ (save-excursion
+ (beginning-of-line)
+ (looking-at paragraph-start))
+ (looking-at "[[:space:]]*$")
+ (nth 4 (syntax-ppss next-bol))))
(goto-char next-bol)))
(syntax-ppss-flush-cache 1)
@@ -269,10 +269,10 @@
(defun rust-with-comment-fill-prefix (body)
(let*
- ((line-string (buffer-substring-no-properties
+ ((line-string (buffer-substring-no-properties
(line-beginning-position) (line-end-position)))
(line-comment-start
- (when (nth 4 (syntax-ppss))
+ (when (nth 4 (syntax-ppss))
(cond
;; If we're inside the comment and see a * prefix, use it
((string-match "^\\([[:space:]]*\\*+[[:space:]]*\\)"
@@ -281,9 +281,9 @@
;; If we're at the start of a comment, figure out what prefix
;; to use for the subsequent lines after it
((string-match (concat "[[:space:]]*" comment-start-skip)
line-string)
- (rust-fill-prefix-for-comment-start
+ (rust-fill-prefix-for-comment-start
(match-string 0 line-string))))))
- (fill-prefix
+ (fill-prefix
(or line-comment-start
fill-prefix)))
(funcall body)))
@@ -294,7 +294,7 @@
(defun rust-fill-paragraph (&rest args)
"Special wrapping for `fill-paragraph' to handle multi-line comments with a
* prefix on each line."
(rust-in-comment-paragraph
- (lambda ()
+ (lambda ()
(rust-with-comment-fill-prefix
(lambda ()
(let
@@ -321,6 +321,20 @@
(rust-with-comment-fill-prefix
(lambda () (comment-indent-new-line arg))))
+;;; Imenu support
+(defvar rust-imenu-generic-expression
+ (append (loop for item in
+ '("enum" "struct" "type" "mod" "fn")
+ collect `(nil ,(rust-re-item-def item) 1))
+ `(("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.")
+
;; For compatibility with Emacs < 24, derive conditionally
(defalias 'rust-parent-mode
(if (fboundp 'prog-mode) 'prog-mode 'fundamental-mode))
@@ -348,7 +362,7 @@
(set (make-local-variable 'indent-tabs-mode) nil)
;; Allow paragraph fills for comments
- (set (make-local-variable 'comment-start-skip)
+ (set (make-local-variable 'comment-start-skip)
"\\(?://[/!]*\\|/\\*[*!]?\\)[[:space:]]*")
(set (make-local-variable 'paragraph-start)
(concat "[[:space:]]*\\(?:" comment-start-skip
"\\|\\*/?[[:space:]]*\\|\\)$"))
@@ -359,6 +373,7 @@
(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)
)
- [nongnu] elpa/rust-mode 9f9dec0 028/486: rust-mode.el uses the 'cl macros, so it should actually require them, (continued)
- [nongnu] elpa/rust-mode 9f9dec0 028/486: rust-mode.el uses the 'cl macros, so it should actually require them, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 1076b9c 035/486: Note incompatibility with global-whitespace-mode., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode e976207 029/486: emacs mode: Highlight 'foo as a lifetime, not a character constant., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode f962be4 038/486: rust-mode: make indentation customizable, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 5488368 039/486: compilation error regexp specific to rustc., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 0a81930 041/486: extend file regexp to match files with embedded spaces., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 6a6dc4e 042/486: fix typo in rust-mode.el, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 5b34e59 053/486: Add paragraph fill and auto-fill for multi-line comments, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 69811ea 052/486: Add custom group for rust-mode, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 0bf2920 048/486: Fix glitches with struct field aligned indents, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode d6b2c32 060/486: Add Imenu support for rust-mode.,
ELPA Syncer <=
- [nongnu] elpa/rust-mode 131cebb 055/486: Fix regression of multi-line statement indents, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode b5de342 070/486: Fix typo in emacs ERT test, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode fa51087 057/486: Minor cleanup and formatting tweaks to the rust-mode README, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 4e0a334 081/486: emacs: do not highlight `#foo]` as an attribute, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 2d12c3e 072/486: Emacs: always jump the cursor if needed on indent, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 5ebe4c7 080/486: emacs: highlight `macro_name!` in macro invocations using [] delimiters, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 76bcb8d 074/486: etc: attempts at fixing editor highlighting for new attribute syntax, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode a59ef8e 090/486: Fix spelling mistakes in comments., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 9c0846a 101/486: Add test for '\'' single quote char literal, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 55080f6 100/486: Fix syntax and highlighting for char literals, ELPA Syncer, 2021/08/07