Skip to content

Commit a6c8346

Browse files
committed
rdoc-mode.el: fill indented block
* misc/rdoc-mode.el (rdoc-fill-paragraph): fill indented block by list. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45333 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent cac997e commit a6c8346

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

misc/rdoc-mode.el

+37-3
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,49 @@
3232
(run-hooks 'rdoc-mode-hook)
3333
)
3434

35-
(defun rdoc-fill-paragraph (&rest args)
35+
(defun rdoc-fill-paragraph (&optional justify region)
3636
"Fills paragraph, except for cited region"
3737
(interactive (progn
3838
(barf-if-buffer-read-only)
3939
(list (if current-prefix-arg 'full))))
4040
(save-excursion
4141
(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))))))))
4478

4579
(defun rdoc-setup-keys ()
4680
(interactive)

0 commit comments

Comments
 (0)