Merge branch 'maint'

This commit is contained in:
Nicolas Goaziou 2013-07-28 10:17:17 +02:00
commit aef1b17773
2 changed files with 66 additions and 17 deletions

View File

@ -22155,7 +22155,8 @@ hierarchy of headlines by UP levels before marking the subtree."
(defun org-adaptive-fill-function () (defun org-adaptive-fill-function ()
"Compute a fill prefix for the current line. "Compute a fill prefix for the current line.
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. For convenience, if `adaptive-fill-regexp'
matches in paragraphs or comments, use it."
(let (prefix) (let (prefix)
(catch 'exit (catch 'exit
(when (derived-mode-p 'message-mode) (when (derived-mode-p 'message-mode)
@ -22179,7 +22180,15 @@ meant to be filled."
(post-affiliated (org-element-property :post-affiliated element))) (post-affiliated (org-element-property :post-affiliated element)))
(unless (and post-affiliated (< p post-affiliated)) (unless (and post-affiliated (< p post-affiliated))
(case type (case type
(comment (looking-at "[ \t]*# ?") (match-string 0)) (comment
(save-excursion
(beginning-of-line)
(looking-at "[ \t]*#")
(goto-char (match-end 0))
(let ((comment-prefix (match-string 0)))
(if (looking-at adaptive-fill-regexp)
(concat comment-prefix (match-string 0))
comment-prefix))))
(footnote-definition "") (footnote-definition "")
((item plain-list) ((item plain-list)
(make-string (org-list-item-body-column (make-string (org-list-item-body-column
@ -22188,15 +22197,17 @@ meant to be filled."
? )) ? ))
(paragraph (paragraph
;; Fill prefix is usually the same as the current line, ;; Fill prefix is usually the same as the current line,
;; except if the paragraph is at the beginning of an item. ;; unless the paragraph is at the beginning of an item.
(let ((parent (org-element-property :parent element))) (let ((parent (org-element-property :parent element)))
(cond ((eq (org-element-type parent) 'item) (save-excursion
(make-string (org-list-item-body-column (beginning-of-line)
(org-element-property :begin parent)) (cond ((eq (org-element-type parent) 'item)
? )) (make-string (org-list-item-body-column
((save-excursion (beginning-of-line) (looking-at "[ \t]+")) (org-element-property :begin parent))
(match-string 0)) ? ))
(t "")))) ((looking-at adaptive-fill-regexp) (match-string 0))
((looking-at "[ \t]+") (match-string 0))
(t "")))))
(comment-block (comment-block
;; Only fill contents if P is within block boundaries. ;; Only fill contents if P is within block boundaries.
(let* ((cbeg (save-excursion (goto-char post-affiliated) (let* ((cbeg (save-excursion (goto-char post-affiliated)
@ -22339,13 +22350,17 @@ a footnote definition, try to fill the first paragraph within."
(1- (line-beginning-position)) (1- (line-beginning-position))
(skip-chars-backward " \r\t\n") (skip-chars-backward " \r\t\n")
(line-end-position))))) (line-end-position)))))
;; Do not fill comments when at a blank line or at ;; Do not fill comments when at a blank line.
;; affiliated keywords. (when (> end begin)
(let ((fill-prefix (save-excursion (let ((fill-prefix
(beginning-of-line) (save-excursion
(looking-at "[ \t]*#") (beginning-of-line)
(concat (match-string 0) " ")))) (looking-at "[ \t]*#")
(when (> end begin) (let ((comment-prefix (match-string 0)))
(goto-char (match-end 0))
(if (looking-at adaptive-fill-regexp)
(concat comment-prefix (match-string 0))
(concat comment-prefix " "))))))
(save-excursion (save-excursion
(fill-region-as-paragraph begin end justify)))))) (fill-region-as-paragraph begin end justify))))))
t)) t))

View File

@ -176,6 +176,14 @@
(narrow-to-region 1 8) (narrow-to-region 1 8)
(org-fill-paragraph) (org-fill-paragraph)
(buffer-string))))) (buffer-string)))))
;; Handle `adaptive-fill-regexp' in paragraphs.
(should
(equal "> a b"
(org-test-with-temp-text "> a\n> b"
(let ((fill-column 5)
(adaptive-fill-regexp "[ \t]*>+[ \t]*"))
(org-fill-paragraph)
(buffer-string)))))
;; Special case: Fill first paragraph when point is at an item or ;; Special case: Fill first paragraph when point is at an item or
;; a plain-list or a footnote reference. ;; a plain-list or a footnote reference.
(should (should
@ -225,6 +233,14 @@
(let ((fill-column 20)) (let ((fill-column 20))
(org-fill-paragraph) (org-fill-paragraph)
(buffer-string))))) (buffer-string)))))
;; Handle `adaptive-fill-regexp' in comments.
(should
(equal "# > a b"
(org-test-with-temp-text "# > a\n# > b"
(let ((fill-column 20)
(adaptive-fill-regexp "[ \t]*>+[ \t]*"))
(org-fill-paragraph)
(buffer-string)))))
;; Do nothing at affiliated keywords. ;; Do nothing at affiliated keywords.
(org-test-with-temp-text "#+NAME: para\nSome\ntext." (org-test-with-temp-text "#+NAME: para\nSome\ntext."
(let ((fill-column 20)) (let ((fill-column 20))
@ -255,6 +271,15 @@
(end-of-line) (end-of-line)
(org-auto-fill-function) (org-auto-fill-function)
(buffer-string))))) (buffer-string)))))
;; Auto fill paragraph when `adaptive-fill-regexp' matches.
(should
(equal "> 12345\n> 7890"
(org-test-with-temp-text "> 12345 7890"
(let ((fill-column 5)
(adaptive-fill-regexp "[ \t]*>+[ \t]*"))
(end-of-line)
(org-auto-fill-function)
(buffer-string)))))
;; Auto fill comments. ;; Auto fill comments.
(should (should
(equal " # 12345\n # 7890" (equal " # 12345\n # 7890"
@ -263,6 +288,15 @@
(end-of-line) (end-of-line)
(org-auto-fill-function) (org-auto-fill-function)
(buffer-string))))) (buffer-string)))))
;; Auto fill comments when `adaptive-fill-regexp' matches.
(should
(equal " # > 12345\n # > 7890"
(org-test-with-temp-text " # > 12345 7890"
(let ((fill-column 10)
(adaptive-fill-regexp "[ \t]*>+[ \t]*"))
(end-of-line)
(org-auto-fill-function)
(buffer-string)))))
;; A hash within a line isn't a comment. ;; A hash within a line isn't a comment.
(should-not (should-not
(equal "12345 # 7890\n# 1" (equal "12345 # 7890\n# 1"