org.el (org-fill-context-prefix): Fix auto-filling in `message-mode'.

* org.el (org-fill-context-prefix): Fix auto-filling in
`message-mode'.
This commit is contained in:
Bastien Guerry 2012-08-13 09:56:39 +02:00
parent 3496df0b4d
commit bbc1dde930
1 changed files with 41 additions and 39 deletions

View File

@ -20924,45 +20924,47 @@ hierarchy of headlines by UP levels before marking the subtree."
"Compute a fill prefix for the line at point P. "Compute a fill prefix for the line at point P.
Return fill prefix, as a string, or nil if current line isn't Return fill prefix, as a string, or nil if current line isn't
meant to be filled." meant to be filled."
(save-excursion (unless (and (derived-mode-p 'message-mode) (not (message-in-body-p)))
(goto-char p) ;; FIXME: This is really the job of orgstruct++-mode
(beginning-of-line) (save-excursion
(let* ((element (org-element-at-point)) (goto-char p)
(type (org-element-type element)) (beginning-of-line)
(post-affiliated (let* ((element (org-element-at-point))
(progn (type (org-element-type element))
(goto-char (org-element-property :begin element)) (post-affiliated
(while (looking-at org-element--affiliated-re) (forward-line)) (progn
(point)))) (goto-char (org-element-property :begin element))
(unless (< p post-affiliated) (while (looking-at org-element--affiliated-re) (forward-line))
(case type (point))))
(comment (looking-at "[ \t]*# ?") (match-string 0)) (unless (< p post-affiliated)
(footnote-definition "") (case type
((item plain-list) (comment (looking-at "[ \t]*# ?") (match-string 0))
(make-string (org-list-item-body-column (footnote-definition "")
(org-element-property :begin element)) ((item plain-list)
? )) (make-string (org-list-item-body-column
(paragraph (org-element-property :begin element))
;; Fill prefix is usually the same as the current line, ? ))
;; except if the paragraph is at the beginning of an item. (paragraph
(let ((parent (org-element-property :parent element))) ;; Fill prefix is usually the same as the current line,
(cond ((eq (org-element-type parent) 'item) ;; except if the paragraph is at the beginning of an item.
(make-string (org-list-item-body-column (let ((parent (org-element-property :parent element)))
(org-element-property :begin parent)) (cond ((eq (org-element-type parent) 'item)
? )) (make-string (org-list-item-body-column
((looking-at "\\s-+") (match-string 0)) (org-element-property :begin parent))
(t "")))) ? ))
((comment-block verse-block) ((looking-at "\\s-+") (match-string 0))
;; Only fill contents if P is within block boundaries. (t ""))))
(let* ((cbeg (save-excursion (goto-char post-affiliated) ((comment-block verse-block)
(forward-line) ;; Only fill contents if P is within block boundaries.
(point))) (let* ((cbeg (save-excursion (goto-char post-affiliated)
(cend (save-excursion (forward-line)
(goto-char (org-element-property :end element)) (point)))
(skip-chars-backward " \r\t\n") (cend (save-excursion
(line-beginning-position)))) (goto-char (org-element-property :end element))
(when (and (>= p cbeg) (< p cend)) (skip-chars-backward " \r\t\n")
(if (looking-at "\\s-+") (match-string 0) ""))))))))) (line-beginning-position))))
(when (and (>= p cbeg) (< p cend))
(if (looking-at "\\s-+") (match-string 0) ""))))))))))
(declare-function message-in-body-p "message" ()) (declare-function message-in-body-p "message" ())
(defvar org-element-paragraph-separate) ; From org-element.el (defvar org-element-paragraph-separate) ; From org-element.el