Browse Source

Inlined comment syntax is reduced to "#"

* lisp/org.el (org-mode): Define new comment syntax.
(org-fontify-meta-lines-and-blocks-1, org-strip-protective-commas,
org-fill-context-prefix, org-insert-comment,
org-comment-or-uncomment-region): Use new comment syntax.
* lisp/org-element.el (org-element-comment-parser,
  org-element-comment-interpreter, org-element--current-element): Use
  new comment syntax.
* testing/lisp/test-org-element.el: Update tests.
* testing/lisp/test-org.el: Update tests.
Nicolas Goaziou 12 years ago
parent
commit
a8e00ff0dc
4 changed files with 39 additions and 67 deletions
  1. 11 24
      lisp/org-element.el
  2. 8 10
      lisp/org.el
  3. 8 8
      testing/lisp/test-org-element.el
  4. 12 25
      testing/lisp/test-org.el

+ 11 - 24
lisp/org-element.el

@@ -1358,24 +1358,17 @@ Assume point is at comment beginning."
   (save-excursion
     (let* ((keywords (org-element--collect-affiliated-keywords))
 	   (begin (car keywords))
-	   ;; Match first line with a loose regexp since it might as
-	   ;; well be an ill-defined keyword.
-	   (value (progn
-		    (looking-at "#\\+? ?")
-		    (buffer-substring-no-properties
-		     (match-end 0) (progn (forward-line) (point)))))
+	   value
 	   (com-end
 	    ;; Get comments ending.
 	    (progn
-	      (while (and (< (point) limit)
-			  (looking-at "\\(\\(# ?\\)[^+]\\|[ \t]*#\\+\\( \\|$\\)\\)"))
-		;; Accumulate lines without leading hash and plus sign
-		;; if any.  First whitespace is also ignored.
+	      (while (and (< (point) limit) (looking-at "[ \t]*# ?"))
+		;; Accumulate lines without leading hash and first
+		;; whitespace.
 		(setq value
 		      (concat value
 			      (buffer-substring-no-properties
-			       (or (match-end 2) (match-end 3))
-			       (progn (forward-line) (point))))))
+			       (match-end 0) (progn (forward-line) (point))))))
 	      (point)))
 	   (end (progn (goto-char com-end)
 		       (skip-chars-forward " \r\t\n" limit)
@@ -1391,7 +1384,7 @@ Assume point is at comment beginning."
 (defun org-element-comment-interpreter (comment contents)
   "Interpret COMMENT element as Org syntax.
 CONTENTS is nil."
-  (replace-regexp-in-string "^" "#+ " (org-element-property :value comment)))
+  (replace-regexp-in-string "^" "# " (org-element-property :value comment)))
 
 
 ;;;; Comment Block
@@ -3324,32 +3317,26 @@ element it has to parse."
 	(org-element-fixed-width-parser limit))
        ;; Inline Comments, Blocks, Babel Calls, Dynamic Blocks and
        ;; Keywords.
-       ((looking-at "[ \t]*#\\+")
+       ((looking-at "[ \t]*#")
 	(goto-char (match-end 0))
-	(cond ((looking-at "$\\| ")
-	       (beginning-of-line)
-	       (org-element-comment-parser limit))
-	      ((looking-at "BEGIN_\\(\\S-+\\)")
+	(cond ((looking-at "\\+BEGIN_\\(\\S-+\\)")
 	       (beginning-of-line)
 	       (let ((parser (assoc (upcase (match-string 1))
 				    org-element-block-name-alist)))
 		 (if parser (funcall (cdr parser) limit)
 		   (org-element-special-block-parser limit))))
-	      ((looking-at "CALL")
+	      ((looking-at "\\+CALL")
 	       (beginning-of-line)
 	       (org-element-babel-call-parser limit))
-	      ((looking-at "BEGIN:? ")
+	      ((looking-at "\\+BEGIN:? ")
 	       (beginning-of-line)
 	       (org-element-dynamic-block-parser limit))
-	      ((looking-at "\\S-+:")
+	      ((looking-at "\\+\\S-+:")
 	       (beginning-of-line)
 	       (org-element-keyword-parser limit))
-	      ;; Ill-formed syntax is considered as a comment.
 	      (t
 	       (beginning-of-line)
 	       (org-element-comment-parser limit))))
-       ;; Comments.
-       ((eq (char-after) ?#) (org-element-comment-parser limit))
        ;; Footnote Definition.
        ((looking-at org-footnote-definition-re)
         (org-element-footnote-definition-parser limit))

+ 8 - 10
lisp/org.el

@@ -5062,8 +5062,8 @@ The following commands are available:
   (org-update-radio-target-regexp)
   ;; Comments
   (org-set-local 'comment-use-syntax nil)
-  (org-set-local 'comment-start "#+")
-  (org-set-local 'comment-start-skip "\\(?:^#\\|#\\+\\)\\(?: \\|$\\)")
+  (org-set-local 'comment-start "#")
+  (org-set-local 'comment-start-skip "# ?")
   (org-set-local 'comment-insert-comment-function 'org-insert-comment)
   (org-set-local 'comment-region-function 'org-comment-or-uncomment-region)
   (org-set-local 'uncomment-region-function 'org-comment-or-uncomment-region)
@@ -5475,7 +5475,7 @@ by a #."
   "Fontify #+ lines and blocks, in the correct ways."
   (let ((case-fold-search t))
     (if (re-search-forward
-	 "^\\([ \t]*#\\+\\(\\([a-zA-Z]+:?\\| \\|$\\)\\(_\\([a-zA-Z]+\\)\\)?\\)[ \t]*\\(\\([^ \t\n]*\\)[ \t]*\\(.*\\)\\)\\)"
+	 "^\\([ \t]*#\\(\\(\\+\\[a-zA-Z]+:?\\| \\|$\\)\\(_\\([a-zA-Z]+\\)\\)?\\)[ \t]*\\(\\([^ \t\n]*\\)[ \t]*\\(.*\\)\\)\\)"
 	 limit t)
 	(let ((beg (match-beginning 0))
 	      (block-start (match-end 0))
@@ -5582,7 +5582,7 @@ by a #."
 			   "[^[:space:]]" end t)
 			  (goto-char (match-beginning 0))
 			  (current-column))))
-	(while (re-search-forward "^[ \t]*\\(,\\)\\([*]\\|#\\+\\)" end t)
+	(while (re-search-forward "^[ \t]*\\(,\\)\\([*]\\|#\\)" end t)
 	  (goto-char (match-beginning 1))
 	  (when (= (current-column) front-line)
 	    (replace-match "" nil nil nil 1)))))))
@@ -20651,8 +20651,6 @@ If point is in an inline task, mark that task instead."
 	 column)
     (beginning-of-line 1)
     (cond
-     ;; Comments
-     ((looking-at "# ") (setq column 0))
      ;; Headings
      ((looking-at org-outline-regexp) (setq column 0))
      ;; Included files
@@ -20854,7 +20852,7 @@ meant to be filled."
 	      (point))))
       (unless (< p post-affiliated)
 	(case type
-	  (comment (looking-at "[ \t]*#\\+? ?") (match-string 0))
+	  (comment (looking-at "[ \t]*# ?") (match-string 0))
 	  ((item plain-list)
 	   (make-string (org-list-item-body-column
 			 (org-element-property :begin element))
@@ -21013,7 +21011,7 @@ If the line is empty, insert comment at its beginning."
   (beginning-of-line)
   (if (looking-at "\\s-*$") (replace-match "") (open-line 1))
   (org-indent-line)
-  (insert "#+ "))
+  (insert "# "))
 
 (defun org-comment-or-uncomment-region (beg end &rest ignore)
   "Comment or uncomment each non-blank line in the region.
@@ -21038,9 +21036,9 @@ contains commented lines.  Otherwise, comment them."
           (end (copy-marker end)))
       (while (< (point) end)
         (unless (looking-at "\\s-*$")
-          (if (not uncommentp) (progn (back-to-indentation) (insert "#+ "))
+          (if (not uncommentp) (progn (back-to-indentation) (insert "# "))
             ;; Only comments and blank lines in region: uncomment it.
-            (looking-at "[ \t]*\\(#\\+? ?\\)")
+            (looking-at "[ \t]*\\(# ?\\)")
             (replace-match "" nil nil nil 1)))
         (forward-line))
       (set-marker end nil))))

+ 8 - 8
testing/lisp/test-org-element.el

@@ -279,14 +279,14 @@ CLOCK: [2012-01-01 sun. 00:01]--[2012-01-01 sun. 00:02] =>  0:01"
      (org-element-map (org-element-parse-buffer) 'comment 'identity)))
   ;; Inline comment.
   (should
-   (org-test-with-temp-text "#+ Comment"
+   (org-test-with-temp-text "  # Comment"
      (org-element-map (org-element-parse-buffer) 'comment 'identity)))
   ;; Preserve indentation.
   (should
    (equal
     (org-element-property
      :value
-     (org-test-with-temp-text "#+ No blank\n#+  One blank"
+     (org-test-with-temp-text "# No blank\n#  One blank"
        (org-element-map (org-element-parse-buffer) 'comment 'identity nil t)))
      "No blank\n One blank"))
   ;; Comment with blank lines.
@@ -294,7 +294,7 @@ CLOCK: [2012-01-01 sun. 00:01]--[2012-01-01 sun. 00:02] =>  0:01"
    (equal
     (org-element-property
      :value
-     (org-test-with-temp-text "#+ First part\n#+ \n#+\n#+ Second part"
+     (org-test-with-temp-text "# First part\n# \n#\n# Second part"
        (org-element-map (org-element-parse-buffer) 'comment 'identity nil t)))
     "First part\n\n\nSecond part"))
   ;; Keywords without colons are treated as comments.
@@ -1763,13 +1763,13 @@ CLOCK: [2012-01-01 sun. 00:01]--[2012-01-01 sun. 00:02] =>  0:01"))
 (ert-deftest test-org-element/comment-interpreter ()
   "Test comment interpreter."
   ;; Regular comment.
-  (should (equal (org-test-parse-and-interpret "#Comment") "#+ Comment\n"))
+  (should (equal (org-test-parse-and-interpret "#Comment") "# Comment\n"))
   ;; Inline comment.
-  (should (equal (org-test-parse-and-interpret "  #+ Comment")
-		 "#+ Comment\n"))
+  (should (equal (org-test-parse-and-interpret "  # Comment")
+		 "# Comment\n"))
   ;; Preserve indentation.
-  (should (equal (org-test-parse-and-interpret "  #+ No blank\n#+  One blank")
-		 "#+ No blank\n#+  One blank\n")))
+  (should (equal (org-test-parse-and-interpret "  # No blank\n#  One blank")
+		 "# No blank\n#  One blank\n")))
 
 (ert-deftest test-org-element/comment-block-interpreter ()
   "Test comment block interpreter."

+ 12 - 25
testing/lisp/test-org.el

@@ -188,16 +188,10 @@ http://article.gmane.org/gmane.emacs.orgmode/21459/"
 	(org-fill-paragraph)
 	(buffer-string)))
     "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
-  ;; Fill `comment' elements, indented or not.
+  ;; Fill `comment' elements.
   (should
-   (equal "# A B"
-	  (org-test-with-temp-text "# A\n#B"
-	    (let ((fill-column 20))
-	      (org-fill-paragraph)
-	      (buffer-string)))))
-  (should
-   (equal "  #+ A B"
-	  (org-test-with-temp-text "  #+ A\n  #+ B"
+   (equal "  # A B"
+	  (org-test-with-temp-text "  # A\n  # B"
 	    (let ((fill-column 20))
 	      (org-fill-paragraph)
 	      (buffer-string)))))
@@ -225,17 +219,10 @@ http://article.gmane.org/gmane.emacs.orgmode/21459/"
 	      (end-of-line)
 	      (org-auto-fill-function)
 	      (buffer-string)))))
-  ;; Auto fill comments, indented or not.
-  (should
-   (equal "# 12345\n# 7890"
-	  (org-test-with-temp-text "# 12345 7890"
-	    (let ((fill-column 7))
-	      (end-of-line)
-	      (org-auto-fill-function)
-	      (buffer-string)))))
+  ;; Auto fill comments.
   (should
-   (equal "  #+ 12345\n  #+ 7890"
-	  (org-test-with-temp-text "  #+ 12345 7890"
+   (equal "  # 12345\n  # 7890"
+	  (org-test-with-temp-text "  # 12345 7890"
 	    (let ((fill-column 10))
 	      (end-of-line)
 	      (org-auto-fill-function)
@@ -291,21 +278,21 @@ http://article.gmane.org/gmane.emacs.orgmode/21459/"
   ;; No region selected, no comment on current line and line not
   ;; empty: insert comment on line above.
   (should
-   (equal "#+ \nComment"
+   (equal "# \nComment"
 	  (org-test-with-temp-text "Comment"
 	    (progn (call-interactively 'comment-dwim)
 		   (buffer-string)))))
   ;; No region selected, no comment on current line and line empty:
   ;; insert comment on this line.
   (should
-   (equal "#+ \nParagraph"
+   (equal "# \nParagraph"
 	  (org-test-with-temp-text "\nParagraph"
 	    (progn (call-interactively 'comment-dwim)
 		   (buffer-string)))))
   ;; No region selected, and a comment on this line: indent it.
   (should
-   (equal "* Headline\n  #+ Comment"
-	  (org-test-with-temp-text "* Headline\n#+ Comment"
+   (equal "* Headline\n  # Comment"
+	  (org-test-with-temp-text "* Headline\n# Comment"
 	    (progn (forward-line)
 		   (let ((org-adapt-indentation t))
 		     (call-interactively 'comment-dwim))
@@ -321,7 +308,7 @@ http://article.gmane.org/gmane.emacs.orgmode/21459/"
   ;; un-comment all commented lines.
   (should
    (equal "Comment 1\n\nComment 2"
-	  (org-test-with-temp-text "#+ Comment 1\n\n#+ Comment 2"
+	  (org-test-with-temp-text "# Comment 1\n\n# Comment 2"
 	    (progn
 	      (transient-mark-mode 1)
 	      (push-mark (point) t t)
@@ -330,7 +317,7 @@ http://article.gmane.org/gmane.emacs.orgmode/21459/"
 	      (buffer-string)))))
   ;; Region selected without comments: comment all non-blank lines.
   (should
-   (equal "#+ Comment 1\n\n#+ Comment 2"
+   (equal "# Comment 1\n\n# Comment 2"
 	  (org-test-with-temp-text "Comment 1\n\nComment 2"
 	    (progn
 	      (transient-mark-mode 1)