Skip to content

Commit cb5781d

Browse files
committed
Merge pull request #46 from MicahChalmer/fix-fill-region
Make fill-region work correctly in comments
2 parents b15b0eb + f2d709e commit cb5781d

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

rust-mode-tests.el

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@
4242
original point-pos manip-func expected (buffer-string)))))
4343

4444
(defun test-fill-paragraph (unfilled expected &optional start-pos end-pos)
45-
"We're going to run through many scenarios here--the point should be able to be anywhere from the start-pos (defaults to 1) through end-pos (defaults to the length of what was passed in) and (fill-paragraph) should return the same result.
45+
"We're going to run through many scenarios here--the point should be able to be anywhere from the start-pos (defaults to 1) through end-pos (defaults to the length of what was passed in) and (fill-paragraph) should return the same result. It should also work with fill-region from start-pos to end-pos.
4646
47-
Also, the result should be the same regardless of whether the code is at the beginning or end of the file. (If you're not careful, that can make a difference.) So we test each position given above with the passed code at the beginning, the end, neither and both. So we do this a total of (end-pos - start-pos)*4 times. Oy."
47+
Also, the result should be the same regardless of whether the code is at the beginning or end of the file. (If you're not careful, that can make a difference.) So we test each position given above with the passed code at the beginning, the end, neither and both. So we do this a total of 1 + (end-pos - start-pos)*4 times. Oy."
4848
(let* ((start-pos (or start-pos 1))
4949
(end-pos (or end-pos (length unfilled)))
5050
(padding "\n \n")
@@ -69,7 +69,16 @@ Also, the result should be the same regardless of whether the code is at the beg
6969
(lambda ()
7070
(let ((fill-column rust-test-fill-column))
7171
(fill-paragraph)))
72-
(concat padding-beginning expected padding-end)))))))
72+
(concat padding-beginning expected padding-end)))))
73+
;; In addition to all the fill-paragraph tests, check that it works using fill-region
74+
(rust-test-manip-code
75+
unfilled
76+
start-pos
77+
(lambda ()
78+
(let ((fill-column rust-test-fill-column))
79+
(fill-region start-pos end-pos)))
80+
expected)
81+
))
7382

7483
(ert-deftest fill-paragraph-top-level-multi-line-style-doc-comment-second-line ()
7584
(test-fill-paragraph
@@ -223,7 +232,7 @@ fn bar() { }"
223232
/// This is my comment. This is
224233
/// more of my comment. This is
225234
/// even more.
226-
fn bar() { }" 14 67))
235+
fn bar() { }" 14 85))
227236

228237
(defun test-auto-fill (initial position inserted expected)
229238
(rust-test-manip-code

rust-mode.el

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@
508508
(funcall body)))
509509

510510
(defun rust-find-fill-prefix ()
511-
(rust-with-comment-fill-prefix (lambda () fill-prefix)))
511+
(rust-in-comment-paragraph (lambda () (rust-with-comment-fill-prefix (lambda () fill-prefix)))))
512512

513513
(defun rust-fill-paragraph (&rest args)
514514
"Special wrapping for `fill-paragraph' to handle multi-line comments with a * prefix on each line."
@@ -704,6 +704,7 @@ This is written mainly to be used as `end-of-defun-function' for Rust."
704704
(setq-local fill-paragraph-function 'rust-fill-paragraph)
705705
(setq-local fill-forward-paragraph-function 'rust-fill-forward-paragraph)
706706
(setq-local adaptive-fill-function 'rust-find-fill-prefix)
707+
(setq-local adaptive-fill-first-line-regexp "")
707708
(setq-local comment-multi-line t)
708709
(setq-local comment-line-break-function 'rust-comment-indent-new-line)
709710
(setq-local imenu-generic-expression rust-imenu-generic-expression)

0 commit comments

Comments
 (0)