diff options
author | Nicolas Goaziou <n.goaziou@gmail.com> | 2012-04-25 20:40:13 +0200 |
---|---|---|
committer | Nicolas Goaziou <n.goaziou@gmail.com> | 2012-04-26 14:49:29 +0200 |
commit | 206ce6e0b52269eff533673b4a5055f9d6bbe27d (patch) | |
tree | 0ff3bde96327b8b66daae744f56083cc3b10e640 | |
parent | 84a358e381235630e34f87cabab9982ed7a46f16 (diff) | |
download | org-mode-206ce6e0b52269eff533673b4a5055f9d6bbe27d.tar.gz |
org-element: Ignore blank lines when removing element indentation
* contrib/lisp/org-element.el (org-element-normalize-contents): Ignore
blank and empty lines when removing element indentation.
* testing/lisp/test-org-element.el: Add tests.
-rw-r--r-- | contrib/lisp/org-element.el | 7 | ||||
-rw-r--r-- | testing/lisp/test-org-element.el | 49 |
2 files changed, 45 insertions, 11 deletions
diff --git a/contrib/lisp/org-element.el b/contrib/lisp/org-element.el index 8912d6a..8b38a54 100644 --- a/contrib/lisp/org-element.el +++ b/contrib/lisp/org-element.el @@ -3592,7 +3592,9 @@ indentation is not done with TAB characters." (cond ((stringp object) (let ((start 0)) - (while (string-match "\n\\( *\\)" object start) + ;; Avoid matching blank or empty lines. + (while (and (string-match "\n\\( *\\)\\(.\\)" object start) + (not (equal (match-string 2 object) " "))) (setq start (match-end 0)) (push (length (match-string 1 object)) ind-list)))) ((memq (org-element-type object) org-element-recursive-objects) @@ -3624,7 +3626,8 @@ indentation is not done with TAB characters." ((stringp object) (replace-regexp-in-string (format "\n \\{%d\\}" mci) "\n" object)) - ((memq (org-element-type object) org-element-recursive-objects) + ((memq (org-element-type object) + org-element-recursive-objects) (funcall build object mci first-flag)) (t object))) (org-element-contents blob))))))) diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el index 8c7f4a7..4e184c9 100644 --- a/testing/lisp/test-org-element.el +++ b/testing/lisp/test-org-element.el @@ -313,15 +313,7 @@ Paragraph \\alpha." nil 'first-match))) (should (stringp (org-element-property :tag item))))) - ;; 1.3. Test with `verse-block' type. - (org-test-with-temp-text "#+BEGIN_VERSE\nTest\n#+END_VERSE" - (let ((verse-block (org-element-map (org-element-parse-buffer 'element) - 'verse-block - 'identity - nil - 'first-match))) - (should (stringp (org-element-property :value verse-block))))) - ;; 1.4. Test with `inlinetask' type, if avalaible. + ;; 1.3. Test with `inlinetask' type, if avalaible. (when (featurep 'org-inlinetask) (let ((org-inlinetask-min-level 15)) (org-test-with-temp-text "*************** Inlinetask" @@ -377,6 +369,45 @@ Paragraph \\alpha." +;;;; Normalize contents + +(ert-deftest test-org-element/normalize-contents () + "Test `org-element-normalize-contents' specifications." + ;; 1. Remove maximum common indentation from element's contents. + (should + (equal + (org-element-normalize-contents + '(paragraph nil " Two spaces\n Three spaces")) + '(paragraph nil "Two spaces\n Three spaces"))) + ;; 2. Ignore objects within contents when computing maximum common + ;; indentation. + (should + (equal + (org-element-normalize-contents + '(paragraph nil " One " (emphasis nil "space") "\n Two spaces")) + '(paragraph nil "One " (emphasis nil "space") "\n Two spaces"))) + ;; 3. Ignore blank lines. + (should + (equal + (org-element-normalize-contents + '(paragraph nil " Two spaces\n\n \n Two spaces")) + '(paragraph nil "Two spaces\n\n \nTwo spaces"))) + ;; 4. Recursively enter objects in order to compute common + ;; indentation. + (should + (equal + (org-element-normalize-contents + '(paragraph nil " Two spaces " (emphasis nil " and\n One space"))) + '(paragraph nil " Two spaces " (emphasis nil " and\nOne space")))) + ;; 5. When optional argument is provided, ignore first line + ;; indentation. + (should + (equal + (org-element-normalize-contents + '(paragraph nil "No space\n Two spaces\n Three spaces") t) + '(paragraph nil "No space\nTwo spaces\n Three spaces")))) + + ;;;; Navigation tools. (ert-deftest test-org-element/forward-element () |