|
@@ -8875,7 +8875,8 @@ hook gets called. When a region or a plain list is sorted, the cursor
|
|
|
will be in the first entry of the sorted region/list.")
|
|
|
|
|
|
(defun org-sort-entries
|
|
|
- (&optional with-case sorting-type getkey-func compare-func property)
|
|
|
+ (&optional with-case sorting-type getkey-func compare-func property
|
|
|
+ interactive?)
|
|
|
"Sort entries on a certain level of an outline tree.
|
|
|
If there is an active region, the entries in the region are sorted.
|
|
|
Else, if the cursor is before the first entry, sort the top-level items.
|
|
@@ -8905,8 +8906,9 @@ t By date/time, either the first active time stamp in the entry, or, if
|
|
|
Capital letters will reverse the sort order.
|
|
|
|
|
|
If the SORTING-TYPE is ?f or ?F, then GETKEY-FUNC specifies a function to be
|
|
|
-called with point at the beginning of the record. It must return either
|
|
|
-a string or a number that should serve as the sorting key for that record.
|
|
|
+called with point at the beginning of the record. It must return a
|
|
|
+value that is compatible with COMPARE-FUNC, the function used to
|
|
|
+compare entries.
|
|
|
|
|
|
Comparing entries ignores case by default. However, with an optional argument
|
|
|
WITH-CASE, the sorting considers case as well.
|
|
@@ -8914,8 +8916,11 @@ WITH-CASE, the sorting considers case as well.
|
|
|
Sorting is done against the visible part of the headlines, it ignores hidden
|
|
|
links.
|
|
|
|
|
|
-When sorting is done, call `org-after-sorting-entries-or-items-hook'."
|
|
|
- (interactive "P")
|
|
|
+When sorting is done, call `org-after-sorting-entries-or-items-hook'.
|
|
|
+
|
|
|
+A non-nil value for INTERACTIVE? is used to signal that this
|
|
|
+function is being called interactively."
|
|
|
+ (interactive (list current-prefix-arg nil nil nil nil t))
|
|
|
(let ((case-func (if with-case 'identity 'downcase))
|
|
|
(cmstr
|
|
|
;; The clock marker is lost when using `sort-subr', let's
|
|
@@ -8984,21 +8989,22 @@ When sorting is done, call `org-after-sorting-entries-or-items-hook'."
|
|
|
[t]ime [s]cheduled [d]eadline [c]reated cloc[k]ing
|
|
|
A/N/P/R/O/F/T/S/D/C/K means reversed:"
|
|
|
what)
|
|
|
- (setq sorting-type (read-char-exclusive))
|
|
|
-
|
|
|
- (unless getkey-func
|
|
|
- (and (= (downcase sorting-type) ?f)
|
|
|
- (setq getkey-func
|
|
|
- (completing-read "Sort using function: "
|
|
|
- obarray 'fboundp t nil nil))
|
|
|
- (setq getkey-func (intern getkey-func))))
|
|
|
-
|
|
|
- (and (= (downcase sorting-type) ?r)
|
|
|
- (not property)
|
|
|
- (setq property
|
|
|
- (completing-read "Property: "
|
|
|
- (mapcar #'list (org-buffer-property-keys t))
|
|
|
- nil t))))
|
|
|
+ (setq sorting-type (read-char-exclusive)))
|
|
|
+
|
|
|
+ (unless getkey-func
|
|
|
+ (and (= (downcase sorting-type) ?f)
|
|
|
+ (setq getkey-func
|
|
|
+ (or (and interactive?
|
|
|
+ (org-read-function
|
|
|
+ "Function for extracting keys: "))
|
|
|
+ (error "Missing key extractor")))))
|
|
|
+
|
|
|
+ (and (= (downcase sorting-type) ?r)
|
|
|
+ (not property)
|
|
|
+ (setq property
|
|
|
+ (completing-read "Property: "
|
|
|
+ (mapcar #'list (org-buffer-property-keys t))
|
|
|
+ nil t)))
|
|
|
|
|
|
(when (member sorting-type '(?k ?K)) (org-clock-sum))
|
|
|
(message "Sorting entries...")
|
|
@@ -9082,7 +9088,13 @@ When sorting is done, call `org-after-sorting-entries-or-items-hook'."
|
|
|
nil
|
|
|
(cond
|
|
|
((= dcst ?a) 'string<)
|
|
|
- ((= dcst ?f) compare-func)
|
|
|
+ ((= dcst ?f)
|
|
|
+ (or compare-func
|
|
|
+ (and interactive?
|
|
|
+ (org-read-function
|
|
|
+ (concat "Function for comparing keys "
|
|
|
+ "(empty for default `sort-subr' predicate): ")
|
|
|
+ 'allow-empty))))
|
|
|
((member dcst '(?p ?t ?s ?d ?c ?k)) '<)))))
|
|
|
(run-hooks 'org-after-sorting-entries-or-items-hook)
|
|
|
;; Reset the clock marker if needed
|