org.el (org-adaptive-fill-function): Fix various bugs when filling in message-mode

* org.el (org-adaptive-fill-function): In message-mode, don't
lines in the message header, nor table lines in the body.
Correctly fill lines starting with `org-outline-regexp' in the
body.
This commit is contained in:
Bastien Guerry 2013-01-22 13:55:57 +01:00
parent 84d2251e57
commit a85b393994

View file

@ -20989,53 +20989,56 @@ hierarchy of headlines by UP levels before marking the subtree."
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."
(let (prefix) (let (prefix)
(when (and (derived-mode-p 'message-mode) (message-in-body-p)) (catch 'exit
(save-excursion (when (derived-mode-p 'message-mode)
(beginning-of-line) (save-excursion
(cond ((looking-at message-cite-prefix-regexp) (beginning-of-line)
(setq prefix (match-string-no-properties 0))) (cond ((or (not (message-in-body-p))
((looking-at org-outline-regexp) (looking-at orgtbl-line-start-regexp))
(setq prefix ""))))) (throw 'exit nil))
(or prefix ((looking-at message-cite-prefix-regexp)
(org-with-wide-buffer (throw 'exit (match-string-no-properties 0)))
(let* ((p (line-beginning-position)) ((looking-at org-outline-regexp)
(element (save-excursion (beginning-of-line) (org-element-at-point))) (throw 'exit (make-string (length (match-string 0)) ? ))))))
(type (org-element-type element)) (org-with-wide-buffer
(post-affiliated (let* ((p (line-beginning-position))
(save-excursion (element (save-excursion (beginning-of-line) (org-element-at-point)))
(goto-char (org-element-property :begin element)) (type (org-element-type element))
(while (looking-at org-element--affiliated-re) (forward-line)) (post-affiliated
(point)))) (save-excursion
(unless (< p post-affiliated) (goto-char (org-element-property :begin element))
(case type (while (looking-at org-element--affiliated-re) (forward-line))
(comment (looking-at "[ \t]*# ?") (match-string 0)) (point))))
(footnote-definition "") (unless (< p post-affiliated)
((item plain-list) (case type
(make-string (org-list-item-body-column post-affiliated) ? )) (comment (looking-at "[ \t]*# ?") (match-string 0))
(paragraph (footnote-definition "")
;; Fill prefix is usually the same as the current line, ((item plain-list)
;; except if the paragraph is at the beginning of an item. (make-string (org-list-item-body-column post-affiliated) ? ))
(let ((parent (org-element-property :parent element))) (paragraph
(cond ((eq (org-element-type parent) 'item) ;; Fill prefix is usually the same as the current line,
(make-string (org-list-item-body-column ;; except if the paragraph is at the beginning of an item.
(org-element-property :begin parent)) (let ((parent (org-element-property :parent element)))
? )) (cond ((eq (org-element-type parent) 'item)
((save-excursion (beginning-of-line) (looking-at "[ \t]+")) (make-string (org-list-item-body-column
(match-string 0)) (org-element-property :begin parent))
(t "")))) ? ))
(comment-block ((save-excursion (beginning-of-line) (looking-at "[ \t]+"))
;; Only fill contents if P is within block boundaries. (match-string 0))
(let* ((cbeg (save-excursion (goto-char post-affiliated) (t ""))))
(forward-line) (comment-block
(point))) ;; Only fill contents if P is within block boundaries.
(cend (save-excursion (let* ((cbeg (save-excursion (goto-char post-affiliated)
(goto-char (org-element-property :end element)) (forward-line)
(skip-chars-backward " \r\t\n") (point)))
(line-beginning-position)))) (cend (save-excursion
(when (and (>= p cbeg) (< p cend)) (goto-char (org-element-property :end element))
(if (save-excursion (beginning-of-line) (looking-at "[ \t]+")) (skip-chars-backward " \r\t\n")
(match-string 0) (line-beginning-position))))
""))))))))))) (when (and (>= p cbeg) (< p cend))
(if (save-excursion (beginning-of-line) (looking-at "[ \t]+"))
(match-string 0)
"")))))))))))
(declare-function message-goto-body "message" ()) (declare-function message-goto-body "message" ())
(defvar message-cite-prefix-regexp) ; From message.el (defvar message-cite-prefix-regexp) ; From message.el