summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIhor Radchenko <yantar92@posteo.net>2023-12-17 14:55:43 +0100
committerIhor Radchenko <yantar92@posteo.net>2023-12-17 14:58:44 +0100
commit92fec81e2e91323911de630dbf6a70faf1e3490a (patch)
tree88747d8f802a6493f57bb57c80b6f9bea34f6c23
parent67ce9386ad1d050cb1ba75436619184197d58dd9 (diff)
downloadorg-mode-92fec81e2.tar.gz
lisp/org.el (org-sort-entries): Fix sorting partially selected subtree
* lisp/org.el (org-sort-entries): Make sure that we extend sorted region to the full subtree if it spans beyond end of region. * testing/lisp/test-org.el (test-org/sort-entries): Add test.
-rw-r--r--lisp/org.el20
-rw-r--r--testing/lisp/test-org.el20
2 files changed, 35 insertions, 5 deletions
diff --git a/lisp/org.el b/lisp/org.el
index f3679dd..8868388 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -7702,12 +7702,24 @@ function is being called interactively."
;; Find beginning and end of region to sort
(cond
((org-region-active-p)
+ (setq start (region-beginning)
+ end (region-end))
;; we will sort the region
- (setq end (region-end)
+ ;; Limit the region to full headings.
+ (goto-char start)
+ ;; Move to beginning of heading.
+ ;; If we are inside heading, move to next.
+ ;; If we are on heading, move to its begin position.
+ (if (org-at-heading-p)
+ (forward-line 0)
+ (outline-next-heading))
+ (setq start (point))
+ ;; Extend region end beyond the last subtree.
+ (goto-char end)
+ (org-end-of-subtree nil t)
+ (setq end (point)
what "region")
- (goto-char (region-beginning))
- (unless (org-at-heading-p) (outline-next-heading))
- (setq start (point)))
+ (goto-char start))
((or (org-at-heading-p)
(ignore-errors (progn (org-back-to-heading) t)))
;; we will sort the children of the current headline
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 612bfa1..2fab3ff 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -3916,7 +3916,25 @@ SCHEDULED: <2017-05-06 Sat>
(org-test-with-temp-text
"\n* B\n* A\n# Local Variables:\n# foo: t\n# End:"
(org-sort-entries nil ?a)
- (buffer-string)))))
+ (buffer-string))))
+ ;; Sort region
+ (should
+ (equal "
+* [#A] h2
+* [#B] h3
+* [#C] h1
+"
+ (org-test-with-temp-text
+ "
+<point>* [#C] h1
+* [#A] h2
+* [#B] h3"
+ (transient-mark-mode 1)
+ (push-mark (point) t t)
+ (search-forward "h3")
+ (org-sort-entries nil ?p)
+ (buffer-string))))
+ )
(ert-deftest test-org/string-collate-greaterp ()
"Test `org-string-collate-greaterp' specifications."