From a6c8346da12a013c98b6016304a946eeaa3a723a Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 14 Mar 2014 04:29:35 +0000 Subject: 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 --- misc/rdoc-mode.el | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'misc') diff --git a/misc/rdoc-mode.el b/misc/rdoc-mode.el index 1bfd34bf2d..c26c2ee564 100644 --- a/misc/rdoc-mode.el +++ b/misc/rdoc-mode.el @@ -32,15 +32,49 @@ (run-hooks 'rdoc-mode-hook) ) -(defun rdoc-fill-paragraph (&rest args) +(defun rdoc-fill-paragraph (&optional justify region) "Fills paragraph, except for cited region" (interactive (progn (barf-if-buffer-read-only) (list (if current-prefix-arg 'full)))) (save-excursion (beginning-of-line) - (unless (looking-at "^ +") - (apply 'fill-paragraph args)))) + (save-restriction + (let ((pos (point)) beg end indent hanging) + (cond + ((looking-at "^ +\\(\\*\\s *\\)") + (setq indent (- (match-end 0) (match-beginning 0)) + hanging (- (match-end 1) (match-beginning 1)))) + ((looking-at "^ +") + (setq indent (- (match-end 0) (match-beginning 0))) + (when (and (re-search-backward "^[^ ]\\|^\\( *\\(\\* *\\)\\)" nil t) + (match-beginning 1) + (= indent (- (match-end 1) (match-beginning 1)))) + (setq hanging (- (match-end 2) (match-beginning 2))) + (setq beg (match-beginning 1)))) + ((setq beg t))) + (when beg + (when indent + (goto-char pos) + (while (progn (beginning-of-line 2) + (and (looking-at "^\\( +\\)\\S ") + (= indent (- (match-end 1) (match-beginning 1)))))) + (setq end (point)) + (when (and beg (not region)) + (setq region (list beg end)) + (narrow-to-region beg end) + )) + (goto-char pos) + (fill-paragraph justify region) + (when (and indent + (or (goto-char beg) t) + (or (beginning-of-line 2) t) + (looking-at "^\\( +\\)") + (= (- indent hanging) (- (match-end 0) (match-beginning 0)))) + (insert-char ?\s hanging) + (beginning-of-line) + (narrow-to-region (point) end) + (fill-paragraph justify (list (point) end)))))))) (defun rdoc-setup-keys () (interactive) -- cgit v1.2.3