summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGustav Wikström <gustav@whil.se>2019-10-31 23:56:03 +0100
committerGustav Wikström <gustav@whil.se>2019-10-31 23:56:03 +0100
commit00646ad8173e6a397c7b135433a44de4177c165b (patch)
treeac5d91d5feb96c4e3b26ac81e24ff3f478aff494
parent64ab701078ecc7f99ca5f6ec0f7a867fed488994 (diff)
downloadorg-mode-00646ad8173e6a397c7b135433a44de4177c165b.tar.gz
Fix newline-issue with document property drawer
A bug was squashed where newlines after insertion of document property drawers wasn't handled correctly. * testing/lisp/test-org.el (test-org/insert-property-drawer): Add test to verify that the document property drawer is inserted above keyword lines. Also fix the specification for document property drawer so it doesn't remove existing blank rows if inserted at the top of a buffer. * lisp/org.el (org-insert-property-drawer): Make sure to add newline after document property drawers.
-rw-r--r--lisp/org.el8
-rw-r--r--testing/lisp/test-org.el10
2 files changed, 11 insertions, 7 deletions
diff --git a/lisp/org.el b/lisp/org.el
index 9942940..6b09925 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -13627,14 +13627,12 @@ drawer is immediately hidden."
;; next one. It prevents extending text properties or overlays
;; belonging to the latter.
(when (and (bolp) (> (point) (point-min))) (backward-char))
- (let ((begin (if (= (point) (point-min))
- (point)
- (1+ (point))))
+ (let ((begin (if (bobp) (point) (1+ (point))))
(inhibit-read-only t))
- (unless (= begin (point-min)) (insert "\n"))
+ (unless (bobp) (insert "\n"))
(insert ":PROPERTIES:\n:END:")
(org-flag-drawer t nil (line-end-position 0) (point))
- (when (eobp) (insert "\n"))
+ (when (or (eobp) (= begin (point-min))) (insert "\n"))
(org-indent-region begin (point))))))
(defun org-insert-drawer (&optional arg drawer)
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 7c996c8..902a467 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -481,6 +481,12 @@
(org-test-with-temp-text "# C\n#+TITLE: T"
(let ((org-adapt-indentation nil)) (org-insert-property-drawer))
(buffer-string))))
+ ;; Insert drawer in document header with existing keyword.
+ (should
+ (equal ":PROPERTIES:\n:END:\n#+TITLE: T"
+ (org-test-with-temp-text "#+TITLE: T"
+ (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
+ (buffer-string))))
(should
(equal ":PROPERTIES:\n:END:"
(org-test-with-temp-text ":PROPERTIES:\n:END:"
@@ -488,8 +494,8 @@
(buffer-string))))
;; Insert drawer in document header with one existing heading in buffer.
(should
- (equal ":PROPERTIES:\n:END:\n* T\n"
- (org-test-with-temp-text "<point>\n* T\n"
+ (equal ":PROPERTIES:\n:END:\n\n* T\n"
+ (org-test-with-temp-text "\n* T\n"
(let ((org-adapt-indentation nil)) (org-insert-property-drawer))
(buffer-string))))
;; Insert drawer right after headline if there is no planning line,