Browse Source

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.
Nicolas Goaziou 10 years ago
parent
commit
98a1bc868a
4 changed files with 73 additions and 18 deletions
  1. 3 0
      etc/ORG-NEWS
  2. 1 1
      lisp/org-capture.el
  3. 21 17
      lisp/org.el
  4. 48 0
      testing/lisp/test-org.el

+ 3 - 0
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

+ 1 - 1
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

+ 21 - 17
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.

+ 48 - 0
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.