Skip to content

Commit 3abc350

Browse files
committed
auto merge of #10797 : pradeep90/rust/rust-mode-changes, r=brson
+ Delete trailing whitespace.
2 parents 70d66ae + 48b289f commit 3abc350

File tree

1 file changed

+33
-18
lines changed

1 file changed

+33
-18
lines changed

src/etc/emacs/rust-mode.el

+33-18
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
;; or one further indent from that if either current line
8585
;; begins with 'else', or previous line didn't end in
8686
;; semi, comma or brace (other than whitespace and line
87-
;; comments) , and wasn't an attribute. But if we have
87+
;; comments) , and wasn't an attribute. But if we have
8888
;; something after the open brace and ending with a comma,
8989
;; treat it as fields and align them. PHEW.
9090
((> level 0)
@@ -213,15 +213,15 @@
213213

214214
(defun rust-fill-prefix-for-comment-start (line-start)
215215
"Determine what to use for `fill-prefix' based on what is at the beginning of a line."
216-
(let ((result
216+
(let ((result
217217
;; Replace /* with same number of spaces
218218
(replace-regexp-in-string
219-
"\\(?:/\\*+\\)[!*]"
219+
"\\(?:/\\*+\\)[!*]"
220220
(lambda (s)
221221
;; We want the * to line up with the first * of the comment start
222222
(concat (make-string (- (length s) 2) ?\x20) "*"))
223223
line-start)))
224-
;; Make sure we've got at least one space at the end
224+
;; Make sure we've got at least one space at the end
225225
(if (not (= (aref result (- (length result) 1)) ?\x20))
226226
(setq result (concat result " ")))
227227
result))
@@ -247,14 +247,14 @@
247247
;; inferring it from the comment start.
248248
(let ((next-bol (line-beginning-position 2)))
249249
(while (save-excursion
250-
(end-of-line)
251-
(syntax-ppss-flush-cache 1)
252-
(and (nth 4 (syntax-ppss))
253-
(save-excursion
254-
(beginning-of-line)
255-
(looking-at paragraph-start))
256-
(looking-at "[[:space:]]*$")
257-
(nth 4 (syntax-ppss next-bol))))
250+
(end-of-line)
251+
(syntax-ppss-flush-cache 1)
252+
(and (nth 4 (syntax-ppss))
253+
(save-excursion
254+
(beginning-of-line)
255+
(looking-at paragraph-start))
256+
(looking-at "[[:space:]]*$")
257+
(nth 4 (syntax-ppss next-bol))))
258258
(goto-char next-bol)))
259259

260260
(syntax-ppss-flush-cache 1)
@@ -269,10 +269,10 @@
269269

270270
(defun rust-with-comment-fill-prefix (body)
271271
(let*
272-
((line-string (buffer-substring-no-properties
272+
((line-string (buffer-substring-no-properties
273273
(line-beginning-position) (line-end-position)))
274274
(line-comment-start
275-
(when (nth 4 (syntax-ppss))
275+
(when (nth 4 (syntax-ppss))
276276
(cond
277277
;; If we're inside the comment and see a * prefix, use it
278278
((string-match "^\\([[:space:]]*\\*+[[:space:]]*\\)"
@@ -281,9 +281,9 @@
281281
;; If we're at the start of a comment, figure out what prefix
282282
;; to use for the subsequent lines after it
283283
((string-match (concat "[[:space:]]*" comment-start-skip) line-string)
284-
(rust-fill-prefix-for-comment-start
284+
(rust-fill-prefix-for-comment-start
285285
(match-string 0 line-string))))))
286-
(fill-prefix
286+
(fill-prefix
287287
(or line-comment-start
288288
fill-prefix)))
289289
(funcall body)))
@@ -294,7 +294,7 @@
294294
(defun rust-fill-paragraph (&rest args)
295295
"Special wrapping for `fill-paragraph' to handle multi-line comments with a * prefix on each line."
296296
(rust-in-comment-paragraph
297-
(lambda ()
297+
(lambda ()
298298
(rust-with-comment-fill-prefix
299299
(lambda ()
300300
(let
@@ -321,6 +321,20 @@
321321
(rust-with-comment-fill-prefix
322322
(lambda () (comment-indent-new-line arg))))
323323

324+
;;; Imenu support
325+
(defvar rust-imenu-generic-expression
326+
(append (loop for item in
327+
'("enum" "struct" "type" "mod" "fn")
328+
collect `(nil ,(rust-re-item-def item) 1))
329+
`(("Impl" ,(rust-re-item-def "impl") 1)))
330+
"Value for `imenu-generic-expression' in Rust mode.
331+
332+
Create a flat index of the item definitions in a Rust file.
333+
334+
Imenu will show all the enums, structs, etc. at the same level.
335+
Implementations will be shown under the `Impl` subheading.
336+
Use idomenu (imenu with ido-mode) for best mileage.")
337+
324338
;; For compatibility with Emacs < 24, derive conditionally
325339
(defalias 'rust-parent-mode
326340
(if (fboundp 'prog-mode) 'prog-mode 'fundamental-mode))
@@ -348,7 +362,7 @@
348362
(set (make-local-variable 'indent-tabs-mode) nil)
349363

350364
;; Allow paragraph fills for comments
351-
(set (make-local-variable 'comment-start-skip)
365+
(set (make-local-variable 'comment-start-skip)
352366
"\\(?://[/!]*\\|/\\*[*!]?\\)[[:space:]]*")
353367
(set (make-local-variable 'paragraph-start)
354368
(concat "[[:space:]]*\\(?:" comment-start-skip "\\|\\*/?[[:space:]]*\\|\\)$"))
@@ -359,6 +373,7 @@
359373
(set (make-local-variable 'adaptive-fill-function) 'rust-find-fill-prefix)
360374
(set (make-local-variable 'comment-multi-line) t)
361375
(set (make-local-variable 'comment-line-break-function) 'rust-comment-indent-new-line)
376+
(set (make-local-variable 'imenu-generic-expression) rust-imenu-generic-expression)
362377
)
363378

364379

0 commit comments

Comments
 (0)