Browse Source

Do not handle `adaptive-fill-regexp' in comments

* lisp/org.el (org-adaptive-fill-function): Do not handle
  `adaptive-fill-regexp' in comments as the behaviour is not
  satisfying.
* testing/lisp/test-org.el: Remove test.
Nicolas Goaziou 11 years ago
parent
commit
2e3f5558d7
2 changed files with 65 additions and 79 deletions
  1. 65 70
      lisp/org.el
  2. 0 9
      testing/lisp/test-org.el

+ 65 - 70
lisp/org.el

@@ -22182,78 +22182,73 @@ 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.  For convenience, if `adaptive-fill-regexp'
 matches in paragraphs or comments, use it."
-  (let (prefix)
-    (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)
-			 (or (ignore-errors (org-element-at-point))
-			     (user-error "An element cannot be parsed line %d"
-					 (line-number-at-pos (point))))))
-	      (type (org-element-type element))
-	      (post-affiliated (org-element-property :post-affiliated element)))
-	 (unless (and post-affiliated (< p post-affiliated))
-	   (case type
-	     (comment
+  (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)
+		       (or (ignore-errors (org-element-at-point))
+			   (user-error "An element cannot be parsed line %d"
+				       (line-number-at-pos (point))))))
+	    (type (org-element-type element))
+	    (post-affiliated (org-element-property :post-affiliated element)))
+       (unless (and post-affiliated (< p post-affiliated))
+	 (case type
+	   (comment
+	    (save-excursion
+	      (beginning-of-line)
+	      (looking-at "[ \t]*")
+	      (concat (match-string 0) "# ")))
+	   (footnote-definition "")
+	   ((item plain-list)
+	    (make-string (org-list-item-body-column
+			  (or post-affiliated
+			      (org-element-property :begin element)))
+			 ? ))
+	   (paragraph
+	    ;; Fill prefix is usually the same as the current line,
+	    ;; unless the paragraph is at the beginning of an item.
+	    (let ((parent (org-element-property :parent element)))
 	      (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
-			    (or post-affiliated
-				(org-element-property :begin element)))
-			   ? ))
-	     (paragraph
-	      ;; Fill prefix is usually the same as the current line,
-	      ;; unless the paragraph is at the beginning of an item.
-	      (let ((parent (org-element-property :parent element)))
-		(save-excursion
-		  (beginning-of-line)
-		  (cond ((eq (org-element-type parent) 'item)
-			 (make-string (org-list-item-body-column
-				       (org-element-property :begin parent))
-				      ? ))
-			((and adaptive-fill-regexp
-			      ;; Locally disable
-			      ;; `adaptive-fill-function' to let
-			      ;; `fill-context-prefix' handle
-			      ;; `adaptive-fill-regexp' variable.
-			      (let (adaptive-fill-function)
-				(fill-context-prefix
-				 post-affiliated
-				 (org-element-property :end element)))))
-			((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)
-		    "")))))))))))
+		(cond ((eq (org-element-type parent) 'item)
+		       (make-string (org-list-item-body-column
+				     (org-element-property :begin parent))
+				    ? ))
+		      ((and adaptive-fill-regexp
+			    ;; Locally disable
+			    ;; `adaptive-fill-function' to let
+			    ;; `fill-context-prefix' handle
+			    ;; `adaptive-fill-regexp' variable.
+			    (let (adaptive-fill-function)
+			      (fill-context-prefix
+			       post-affiliated
+			       (org-element-property :end element)))))
+		      ((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

+ 0 - 9
testing/lisp/test-org.el

@@ -305,15 +305,6 @@
 	      (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"