From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: [BUG] `org-fill-paragraph' doesn't use `fill-prefix' Date: Sat, 27 Jul 2013 22:45:17 +0200 Message-ID: <874nbf3f6q.fsf@gmail.com> References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:58346) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V3BMW-0007m5-Kz for emacs-orgmode@gnu.org; Sat, 27 Jul 2013 16:45:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V3BMR-0006JM-0h for emacs-orgmode@gnu.org; Sat, 27 Jul 2013 16:45:12 -0400 Received: from mail-we0-x232.google.com ([2a00:1450:400c:c03::232]:41074) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V3BMQ-0006Ii-LP for emacs-orgmode@gnu.org; Sat, 27 Jul 2013 16:45:06 -0400 Received: by mail-we0-f178.google.com with SMTP id u57so2880211wes.37 for ; Sat, 27 Jul 2013 13:45:05 -0700 (PDT) In-Reply-To: (Daniel Hackney's message of "Sat, 27 Jul 2013 14:47:26 -0400") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Daniel Hackney Cc: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Daniel Hackney writes: > I proposed a fix [1] for this back in 2010, but it seems to have regressed > again. `org-fill-paragraph' no longer makes use of a `fill-prefix', so > filling things like email comments no longer works. It has been discussed on this ML already. Org mode is not Message mode and ">" prefix means nothing to it. Also, it has its own set of special prefixes, which are not found in Fundamental mode. For example, you can never have " : " as a fill prefix since it creates a fixed-width area. Therefore, I don't consider it to be a regression since it's not an expected feature in the first place. But I admit it is still convenient. Maybe we can introduce some support for `adaptive-fill-regexp' in paragraphs and comments filling. Would you mind testing the following patch? Regards, -- Nicolas Goaziou --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Add-support-for-adaptive-fill-regexp-in-paragraphs-a.patch >From d460b8048d7b3b308cd93794b1de46837438a8e6 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sat, 27 Jul 2013 22:02:45 +0200 Subject: [PATCH] Add support for `adaptive-fill-regexp' in paragraphs and comments * lisp/org.el (org-adaptive-fill-function, org-fill-paragraph): Add support for `adaptive-fill-regexp' in paragraphs and comments. * testing/lisp/test-org.el: Add test. --- lisp/org.el | 43 ++++++++++++++++++++++++++++++------------- testing/lisp/test-org.el | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 13 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 2f619cc..c852550 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -22179,7 +22179,15 @@ meant to be filled." (post-affiliated (org-element-property :post-affiliated element))) (unless (and post-affiliated (< p post-affiliated)) (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 "") ((item plain-list) (make-string (org-list-item-body-column @@ -22188,15 +22196,19 @@ meant to be filled." ? )) (paragraph ;; Fill prefix is usually the same as the current line, - ;; except if the paragraph is at the beginning of an item. + ;; except if the paragraph is at the beginning of an + ;; item. For convenience, if `adaptive-fill-regexp' + ;; matches, use it. (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 "")))) + (save-excursion + (beginning-of-line) + (cond ((eq (org-element-type parent) 'item) + (make-string (org-list-item-body-column + (org-element-property :begin parent)) + ? )) + ((looking-at adaptive-fill-regexp) (match-string 0)) + ((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) @@ -22341,10 +22353,15 @@ a footnote definition, try to fill the first paragraph within." (line-end-position))))) ;; Do not fill comments when at a blank line or at ;; affiliated keywords. - (let ((fill-prefix (save-excursion - (beginning-of-line) - (looking-at "[ \t]*#") - (concat (match-string 0) " ")))) + (let ((fill-prefix + (save-excursion + (beginning-of-line) + (looking-at "[ \t]*#") + (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 " ")))))) (when (> end begin) (save-excursion (fill-region-as-paragraph begin end justify)))))) diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index 504defa..517d0d1 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -176,6 +176,14 @@ (narrow-to-region 1 8) (org-fill-paragraph) (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 ;; a plain-list or a footnote reference. (should @@ -225,6 +233,14 @@ (let ((fill-column 20)) (org-fill-paragraph) (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. (org-test-with-temp-text "#+NAME: para\nSome\ntext." (let ((fill-column 20)) @@ -255,6 +271,15 @@ (end-of-line) (org-auto-fill-function) (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. (should (equal " # 12345\n # 7890" @@ -263,6 +288,15 @@ (end-of-line) (org-auto-fill-function) (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. (should-not (equal "12345 # 7890\n# 1" -- 1.8.3.4 --=-=-=--