summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2015-01-30 19:26:36 +0100
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2015-01-30 19:31:27 +0100
commit98a1bc868a35e2c09800fa0d6ff0cbc27b8b993f (patch)
tree9aa449949d24010d39331c32475faece115bfc89
parentf7e68cec78d0d2ad9578583797177e60ab74c9a7 (diff)
downloadorg-mode-98a1bc868a35e2c09800fa0d6ff0cbc27b8b993f.tar.gz
Replace `org-end-of-meta-data-and-drawers'
* lisp/org.el (org-end-of-meta-data): New function. (org-end-of-meta-data-and-drawers): Remove function. * lisp/org-capture.el (org-capture-place-plain-text): Use new function. * testing/lisp/test-org.el (test-org/end-of-meta-data): New test. * etc/ORG-NEWS: Document removal.
-rw-r--r--etc/ORG-NEWS3
-rw-r--r--lisp/org-capture.el2
-rwxr-xr-xlisp/org.el38
-rw-r--r--testing/lisp/test-org.el48
4 files changed, 73 insertions, 18 deletions
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 7fcfdd9..2f8d2ab 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -80,6 +80,9 @@ it provides more features and covers all export back-ends. It is also
accessible from the export dispatcher.
*** Removed function ~org-timer-cancel-timer~
~org-timer-stop~ now stops both relative and countdown timers.
+*** Removed function ~org-end-of-meta-data-and-drawers~
+The function is superseded by ~org-end-of-meta-data~, called with an
+optional argument.
** Removed options
*** ~org-list-empty-line-terminates-plain-lists~ is deprecated
It will be kept in code base until next release, for backward
diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index 65de098..6de5f6b 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -1221,7 +1221,7 @@ Of course, if exact position has been required, just put it there."
;; we should place the text into this entry
(if (org-capture-get :prepend)
;; Skip meta data and drawers
- (org-end-of-meta-data-and-drawers)
+ (org-end-of-meta-data t)
;; go to ent of the entry text, before the next headline
(outline-next-heading)))
(t
diff --git a/lisp/org.el b/lisp/org.el
index 1a66965..26c3603 100755
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -24019,24 +24019,28 @@ If there is no such heading, return nil."
(forward-char -1))))))
(point))
-(defun org-end-of-meta-data-and-drawers ()
- "Jump to the first text after meta data and drawers in the current entry.
-This will move over empty lines, lines with planning time stamps,
-clocking lines, and drawers."
+(defun org-end-of-meta-data (&optional full)
+ "Skip planning line and properties drawer in current entry.
+When optional argument FULL is non-nil, also skip empty lines,
+clocking lines and regular drawers at the beginning of the
+entry."
(org-back-to-heading t)
- (let ((end (save-excursion (outline-next-heading) (point)))
- (re (concat "\\(" org-drawer-regexp "\\)"
- "\\|" "[ \t]*" org-keyword-time-regexp)))
- (forward-line 1)
- (while (re-search-forward re end t)
- (if (not (match-end 1))
- ;; empty or planning line
- (forward-line 1)
- ;; a drawer, find the end
- (re-search-forward "^[ \t]*:END:" end 'move)
- (forward-line 1)))
- (and (re-search-forward "[^\n]" nil t) (backward-char 1))
- (point)))
+ (forward-line)
+ (when (org-looking-at-p org-planning-line-re) (forward-line))
+ (when (looking-at org-property-drawer-re)
+ (goto-char (match-end 0))
+ (forward-line))
+ (when (and full (not (org-at-heading-p)))
+ (catch 'exit
+ (let ((end (save-excursion (outline-next-heading) (point)))
+ (re (concat "[ \t]*$" "\\|" org-clock-line-re)))
+ (while (not (eobp))
+ (cond ((org-looking-at-p org-drawer-regexp)
+ (if (re-search-forward "^[ \t]*:END:[ \t]*$" end t)
+ (forward-line)
+ (throw 'exit t)))
+ ((org-looking-at-p re) (forward-line))
+ (t (throw 'exit t))))))))
(defun org-forward-heading-same-level (arg &optional invisible-ok)
"Move forward to the ARG'th subheading at same level as this one.
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index f206ac2..6faabdd 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -1563,6 +1563,54 @@ drops support for Emacs 24.1 and 24.2."
;;; Navigation
+(ert-deftest test-org/end-of-meta-data ()
+ "Test `org-end-of-meta-data' specifications."
+ ;; Skip planning line.
+ (should
+ (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
+ (org-end-of-meta-data)
+ (eobp)))
+ ;; Skip properties drawer.
+ (should
+ (org-test-with-temp-text
+ "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
+ (org-end-of-meta-data)
+ (eobp)))
+ ;; Skip both.
+ (should
+ (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
+ (org-end-of-meta-data)
+ (eobp)))
+ ;; Nothing to skip, go to first line.
+ (should
+ (org-test-with-temp-text "* Headline\nContents"
+ (org-end-of-meta-data)
+ (looking-at "Contents")))
+ ;; With option argument, skip empty lines, regular drawers and
+ ;; clocking lines.
+ (should
+ (org-test-with-temp-text "* Headline\n\nContents"
+ (org-end-of-meta-data t)
+ (looking-at "Contents")))
+ (should
+ (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
+ (org-end-of-meta-data t)
+ (looking-at "Contents")))
+ (should
+ (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
+ (org-end-of-meta-data t)
+ (looking-at "Contents")))
+ ;; Special case: do not skip incomplete drawers.
+ (should
+ (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
+ (org-end-of-meta-data t)
+ (looking-at ":LOGBOOK:")))
+ ;; Special case: Be careful about consecutive headlines.
+ (should-not
+ (org-test-with-temp-text "* H1\n*H2\nContents"
+ (org-end-of-meta-data t)
+ (looking-at "Contents"))))
+
(ert-deftest test-org/beginning-of-line ()
"Test `org-beginning-of-line' specifications."
;; Standard test.