summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Guerry <bzg@altern.org>2013-01-22 12:55:57 (GMT)
committer Bastien Guerry <bzg@altern.org>2013-01-22 12:55:57 (GMT)
commita85b393994d9dcfe12a457c5c9dd62d9090bdb06 (patch)
treec1dfd135983ea3396798c3a80e2083ea17beaf38
parent84d2251e57d0922d89640380bac8163bac8e6235 (diff)
downloadorg-mode-a85b393994d9dcfe12a457c5c9dd62d9090bdb06.zip
org-mode-a85b393994d9dcfe12a457c5c9dd62d9090bdb06.tar.gz
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.
-rw-r--r--lisp/org.el97
1 files changed, 50 insertions, 47 deletions
diff --git a/lisp/org.el b/lisp/org.el
index 9409fec..27c30c1 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -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
meant to be filled."
(let (prefix)
- (when (and (derived-mode-p 'message-mode) (message-in-body-p))
- (save-excursion
- (beginning-of-line)
- (cond ((looking-at message-cite-prefix-regexp)
- (setq prefix (match-string-no-properties 0)))
- ((looking-at org-outline-regexp)
- (setq prefix "")))))
- (or prefix
- (org-with-wide-buffer
- (let* ((p (line-beginning-position))
- (element (save-excursion (beginning-of-line) (org-element-at-point)))
- (type (org-element-type element))
- (post-affiliated
- (save-excursion
- (goto-char (org-element-property :begin element))
- (while (looking-at org-element--affiliated-re) (forward-line))
- (point))))
- (unless (< p post-affiliated)
- (case type
- (comment (looking-at "[ \t]*# ?") (match-string 0))
- (footnote-definition "")
- ((item plain-list)
- (make-string (org-list-item-body-column post-affiliated) ? ))
- (paragraph
- ;; Fill prefix is usually the same as the current line,
- ;; except if the paragraph is at the beginning of an item.
- (let ((parent (org-element-property :parent element)))
- (cond ((eq (org-element-type parent) 'item)
- (make-string (org-list-item-body-column
- (org-element-property :begin parent))
- ? ))
- ((save-excursion (beginning-of-line) (looking-at "[ \t]+"))
- (match-string 0))
- (t ""))))
- (comment-block
- ;; Only fill contents if P is within block boundaries.
- (let* ((cbeg (save-excursion (goto-char post-affiliated)
- (forward-line)
- (point)))
- (cend (save-excursion
- (goto-char (org-element-property :end element))
- (skip-chars-backward " \r\t\n")
- (line-beginning-position))))
- (when (and (>= p cbeg) (< p cend))
- (if (save-excursion (beginning-of-line) (looking-at "[ \t]+"))
- (match-string 0)
- "")))))))))))
+ (catch 'exit
+ (when (derived-mode-p 'message-mode)
+ (save-excursion
+ (beginning-of-line)
+ (cond ((or (not (message-in-body-p))
+ (looking-at orgtbl-line-start-regexp))
+ (throw 'exit nil))
+ ((looking-at message-cite-prefix-regexp)
+ (throw 'exit (match-string-no-properties 0)))
+ ((looking-at org-outline-regexp)
+ (throw 'exit (make-string (length (match-string 0)) ? ))))))
+ (org-with-wide-buffer
+ (let* ((p (line-beginning-position))
+ (element (save-excursion (beginning-of-line) (org-element-at-point)))
+ (type (org-element-type element))
+ (post-affiliated
+ (save-excursion
+ (goto-char (org-element-property :begin element))
+ (while (looking-at org-element--affiliated-re) (forward-line))
+ (point))))
+ (unless (< p post-affiliated)
+ (case type
+ (comment (looking-at "[ \t]*# ?") (match-string 0))
+ (footnote-definition "")
+ ((item plain-list)
+ (make-string (org-list-item-body-column post-affiliated) ? ))
+ (paragraph
+ ;; Fill prefix is usually the same as the current line,
+ ;; except if the paragraph is at the beginning of an item.
+ (let ((parent (org-element-property :parent element)))
+ (cond ((eq (org-element-type parent) 'item)
+ (make-string (org-list-item-body-column
+ (org-element-property :begin parent))
+ ? ))
+ ((save-excursion (beginning-of-line) (looking-at "[ \t]+"))
+ (match-string 0))
+ (t ""))))
+ (comment-block
+ ;; Only fill contents if P is within block boundaries.
+ (let* ((cbeg (save-excursion (goto-char post-affiliated)
+ (forward-line)
+ (point)))
+ (cend (save-excursion
+ (goto-char (org-element-property :end element))
+ (skip-chars-backward " \r\t\n")
+ (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" ())
(defvar message-cite-prefix-regexp) ; From message.el