|
32 | 32 | (run-hooks 'rdoc-mode-hook)
|
33 | 33 | )
|
34 | 34 |
|
35 |
| -(defun rdoc-fill-paragraph (&rest args) |
| 35 | +(defun rdoc-fill-paragraph (&optional justify region) |
36 | 36 | "Fills paragraph, except for cited region"
|
37 | 37 | (interactive (progn
|
38 | 38 | (barf-if-buffer-read-only)
|
39 | 39 | (list (if current-prefix-arg 'full))))
|
40 | 40 | (save-excursion
|
41 | 41 | (beginning-of-line)
|
42 |
| - (unless (looking-at "^ +") |
43 |
| - (apply 'fill-paragraph args)))) |
| 42 | + (save-restriction |
| 43 | + (let ((pos (point)) beg end indent hanging) |
| 44 | + (cond |
| 45 | + ((looking-at "^ +\\(\\*\\s *\\)") |
| 46 | + (setq indent (- (match-end 0) (match-beginning 0)) |
| 47 | + hanging (- (match-end 1) (match-beginning 1)))) |
| 48 | + ((looking-at "^ +") |
| 49 | + (setq indent (- (match-end 0) (match-beginning 0))) |
| 50 | + (when (and (re-search-backward "^[^ ]\\|^\\( *\\(\\* *\\)\\)" nil t) |
| 51 | + (match-beginning 1) |
| 52 | + (= indent (- (match-end 1) (match-beginning 1)))) |
| 53 | + (setq hanging (- (match-end 2) (match-beginning 2))) |
| 54 | + (setq beg (match-beginning 1)))) |
| 55 | + ((setq beg t))) |
| 56 | + (when beg |
| 57 | + (when indent |
| 58 | + (goto-char pos) |
| 59 | + (while (progn (beginning-of-line 2) |
| 60 | + (and (looking-at "^\\( +\\)\\S ") |
| 61 | + (= indent (- (match-end 1) (match-beginning 1)))))) |
| 62 | + (setq end (point)) |
| 63 | + (when (and beg (not region)) |
| 64 | + (setq region (list beg end)) |
| 65 | + (narrow-to-region beg end) |
| 66 | + )) |
| 67 | + (goto-char pos) |
| 68 | + (fill-paragraph justify region) |
| 69 | + (when (and indent |
| 70 | + (or (goto-char beg) t) |
| 71 | + (or (beginning-of-line 2) t) |
| 72 | + (looking-at "^\\( +\\)") |
| 73 | + (= (- indent hanging) (- (match-end 0) (match-beginning 0)))) |
| 74 | + (insert-char ?\s hanging) |
| 75 | + (beginning-of-line) |
| 76 | + (narrow-to-region (point) end) |
| 77 | + (fill-paragraph justify (list (point) end)))))))) |
44 | 78 |
|
45 | 79 | (defun rdoc-setup-keys ()
|
46 | 80 | (interactive)
|
|
0 commit comments