From 60851f4fc714a0f71645203fb3e8bfc67169e1f1 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Fri, 15 Aug 2014 21:46:46 +0200 Subject: [PATCH 1/2] org-element: Fix common indentation removal in verse block * lisp/org-element.el (org-element-normalize-contents): Fix indentation removal when there is an empty line within a verse block. * testing/lisp/test-org-element.el (test-org-element/normalize-contents): Add test. --- lisp/org-element.el | 46 ++++++++++++++++---------------- testing/lisp/test-org-element.el | 5 ++++ 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/lisp/org-element.el b/lisp/org-element.el index 23cd121e0..bbd5d7db6 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -4612,29 +4612,29 @@ indentation is not done with TAB characters." (let* ((min-ind most-positive-fixnum) find-min-ind ; For byte-compiler. (find-min-ind - (function - ;; Return minimal common indentation within BLOB. This is - ;; done by walking recursively BLOB and updating MIN-IND - ;; along the way. FIRST-FLAG is non-nil when the first - ;; string hasn't been seen yet. It is required as this - ;; string is the only one whose indentation doesn't happen - ;; after a newline character. - (lambda (blob first-flag) - (dolist (object (org-element-contents blob)) - (when (and first-flag (stringp object)) - (setq first-flag nil) - (string-match "\\`\\( *\\)" object) - (let ((len (length (match-string 1 object)))) - ;; An indentation of zero means no string will be - ;; modified. Quit the process. - (if (zerop len) (throw 'zero (setq min-ind 0)) - (setq min-ind (min len min-ind))))) - (cond - ((stringp object) - (dolist (line (delq "" (cdr (org-split-string object " *\n")))) - (setq min-ind (min (org-get-indentation line) min-ind)))) - ((memq (org-element-type object) org-element-recursive-objects) - (funcall find-min-ind object first-flag)))))))) + ;; Return minimal common indentation within BLOB. This is + ;; done by walking recursively BLOB and updating MIN-IND + ;; along the way. FIRST-FLAG is non-nil when the first + ;; string hasn't been seen yet. It is required as this + ;; string is the only one whose indentation doesn't happen + ;; after a newline character. + (lambda (blob first-flag) + (dolist (object (org-element-contents blob)) + (when (and first-flag (stringp object)) + (setq first-flag nil) + (string-match "\\` *" object) + (let ((len (match-end 0))) + ;; An indentation of zero means no string will be + ;; modified. Quit the process. + (if (zerop len) (throw 'zero (setq min-ind 0)) + (setq min-ind (min len min-ind))))) + (cond + ((stringp object) + (dolist (line (cdr (org-split-string object " *\n"))) + (unless (string= line "") + (setq min-ind (min (org-get-indentation line) min-ind))))) + ((memq (org-element-type object) org-element-recursive-objects) + (funcall find-min-ind object first-flag))))))) ;; Find minimal indentation in ELEMENT. (catch 'zero (funcall find-min-ind element (not ignore-first))) (if (or (zerop min-ind) (= min-ind most-positive-fixnum)) element diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el index 389fe8740..b18895087 100644 --- a/testing/lisp/test-org-element.el +++ b/testing/lisp/test-org-element.el @@ -2923,6 +2923,11 @@ Text '(paragraph nil " Two spaces\n" (verbatim nil "V") "\n Two spaces") (org-element-normalize-contents '(paragraph nil " Two spaces\n " (verbatim nil "V") "\n Two spaces")))) + (should + (equal + '(verse-block nil "line 1\n\nline 2") + (org-element-normalize-contents + '(verse-block nil " line 1\n\n line 2")))) ;; Recursively enter objects in order to compute common indentation. (should (equal From c1bc68550097416b7434e513df3080133e52d578 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Fri, 15 Aug 2014 21:51:42 +0200 Subject: [PATCH 2/2] org-list: Fix failing test * testing/lisp/test-org-list.el (test-org-list/to-texinfo): Fix failing test. --- testing/lisp/test-org-list.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/lisp/test-org-list.el b/testing/lisp/test-org-list.el index f8d31fa50..4a518462b 100644 --- a/testing/lisp/test-org-list.el +++ b/testing/lisp/test-org-list.el @@ -839,7 +839,7 @@ (ert-deftest test-org-list/to-texinfo () "Test `org-list-to-latex' specifications." (should - (equal "@itemize\n@item \na\n\n@end itemize" + (equal "@itemize\n@item\na\n@end itemize" (with-temp-buffer (insert "@c BEGIN RECEIVE ORGLST name @c END RECEIVE ORGLST name