Do not make a special case for inlinetasks when marking a subtree

* lisp/org.el (org-mark-subtree): Do not make a special case for
  inlinetasks when marking a subtree. These are handled by
  `org-element-mark-element'.
* testing/lisp/test-org.el: Add test.
This commit is contained in:
Nicolas Goaziou 2012-08-07 13:30:09 +02:00
parent 7bc9b2242e
commit d70f965486
2 changed files with 38 additions and 22 deletions

View File

@ -20679,29 +20679,15 @@ which make use of the date at the cursor."
(defun org-mark-subtree (&optional up)
"Mark the current subtree.
This puts point at the start of the current subtree, and mark at
the end. If point is in an inline task, mark that task instead.
If a numeric prefix UP is given, move up into the hierarchy of
headlines by UP levels before marking the subtree."
the end. If a numeric prefix UP is given, move up into the
hierarchy of headlines by UP levels before marking the subtree."
(interactive "P")
(let ((inline-task-p
(and (featurep 'org-inlinetask)
(org-inlinetask-in-task-p)))
(beg))
;; Get beginning of subtree
(cond
(inline-task-p (org-inlinetask-goto-beginning))
((org-at-heading-p) (beginning-of-line))
(t (org-with-limited-levels (outline-previous-visible-heading 1))))
;; Move up
(when up (dotimes (c (abs up)) (ignore-errors (org-element-up))))
(setq beg (point))
;; Get end of it
(if inline-task-p
(org-inlinetask-goto-end)
(org-end-of-subtree))
;; Mark zone
(push-mark (point) nil t)
(goto-char beg)))
(when (org-with-limited-levels (org-before-first-heading-p))
(error "Not currently in a subtree"))
(if (org-at-heading-p) (beginning-of-line)
(org-with-limited-levels (outline-previous-visible-heading 1)))
(when up (dotimes (c (abs up)) (ignore-errors (org-element-up))))
(org-element-mark-element))
;;; Indentation

View File

@ -327,6 +327,36 @@ http://article.gmane.org/gmane.emacs.orgmode/21459/"
(buffer-string))))))
;;; Mark region
(ert-deftest test-org/mark-subtree ()
"Test `org-mark-subtree' specifications."
;; Error when point is before first headline.
(should-error
(org-test-with-temp-text "Paragraph\n* Headline\nBody"
(progn (transient-mark-mode 1)
(org-mark-subtree))))
;; Without argument, mark current subtree.
(should
(equal
'(12 32)
(org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
(progn (transient-mark-mode 1)
(forward-line 2)
(org-mark-subtree)
(list (region-beginning) (region-end))))))
;; With an argument, move ARG up.
(should
(equal
'(1 32)
(org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
(progn (transient-mark-mode 1)
(forward-line 2)
(org-mark-subtree 1)
(list (region-beginning) (region-end)))))))
(provide 'test-org)
;;; test-org.el ends here