diff options
author | Kyle Meyer <kyle@kyleam.com> | 2015-04-03 01:08:04 -0400 |
---|---|---|
committer | Kyle Meyer <kyle@kyleam.com> | 2015-04-03 01:08:04 -0400 |
commit | ee9efe4a885db42bf87f21736213796c4bb0ef95 (patch) | |
tree | 5203c1a1c6ffd47de96c4047a5b48d05e7677d11 /lisp | |
parent | a4d627b752ba66838781283bc35cefcdb2ad5f71 (diff) | |
download | emacs.d-ee9efe4a885db42bf87f21736213796c4bb0ef95.tar.gz |
Rewrite org-sort-parent
Search for whole heading line instead of using
org-find-exact-headline-in-buffer.
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/init-org.el | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/lisp/init-org.el b/lisp/init-org.el index 76b00ec..be79d25 100644 --- a/lisp/init-org.el +++ b/lisp/init-org.el @@ -174,19 +174,20 @@ heading." After sorting, return point to its previous location under the current heading." (interactive "p") - (let ((heading (org-no-properties (org-get-heading t t))) - (starting-pos (point)) - chars-after-heading) + (let ((starting-pos (point))) (org-back-to-heading t) - (setq chars-after-heading (- starting-pos (point))) - (outline-up-heading arg) - (call-interactively #'org-sort) - ;; Sorting doesn't play well with `save-restriction' or markers, - ;; so just put the point where it was relative to the original - ;; heading. This may not actually be the same tree if there are - ;; redundant headings. - (goto-char (+ (org-find-exact-headline-in-buffer heading nil t) - chars-after-heading)))) + (let ((heading-line (buffer-substring-no-properties + (point-at-bol) (point-at-eol))) + (chars-after-heading (- starting-pos (point)))) + (outline-up-heading arg) + (call-interactively #'org-sort) + ;; Sorting doesn't play well with `save-restriction' or markers, + ;; so just put the point where it was relative to the original + ;; heading. This may not actually be the same tree if there are + ;; redundant headings. + (re-search-forward heading-line) + (beginning-of-line) + (goto-char (+ (point) chars-after-heading))))) (defun km/org-sort-heading-ignoring-articles () "Sort alphabetically, but ignore any leading articles." |