summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig Earls <enderw88@gmail.com>2013-03-02 20:19:43 -0700
committerCraig Earls <enderw88@gmail.com>2013-03-02 20:19:43 -0700
commitc85a91b030f27b8cc22fa71bf0215b846b2be246 (patch)
treee77e6fc51fa3e77c39e4bb52626b64fe23185a0c
parent9a86fe022cb5ef95c675ebc59269a7c7e63d1077 (diff)
downloadfork-ledger-c85a91b030f27b8cc22fa71bf0215b846b2be246.tar.gz
fork-ledger-c85a91b030f27b8cc22fa71bf0215b846b2be246.tar.bz2
fork-ledger-c85a91b030f27b8cc22fa71bf0215b846b2be246.zip
Ad ledger-mode flags to limit sort region for sort buffer
-rw-r--r--doc/ledger-mode.texi15
-rw-r--r--lisp/ldg-sort.el13
2 files changed, 25 insertions, 3 deletions
diff --git a/doc/ledger-mode.texi b/doc/ledger-mode.texi
index 1d317725..f530d587 100644
--- a/doc/ledger-mode.texi
+++ b/doc/ledger-mode.texi
@@ -303,6 +303,21 @@ transactions like automated transaction, will be moved in the sorting
process and may not function correctly afterwards. For this reason
there is no key sequence.
+You can limit the allowed sort region by using embedded Ledger-mode
+markup within your ledger. For exmaple
+@smallexample
+<<< infomration to not sort >>>
+
+; Ledger-mode: Start sort
+
+<<< xacts to sort >>>
+
+;Ledger-mode: End sort
+
+<<< information to not sort >>>
+@end smallexample
+
+
@node Hiding Transactions, , Sorting Transactions, The Ledger Buffer
@section Hiding Transactions
diff --git a/lisp/ldg-sort.el b/lisp/ldg-sort.el
index 361eead8..cc036492 100644
--- a/lisp/ldg-sort.el
+++ b/lisp/ldg-sort.el
@@ -54,8 +54,8 @@
;; the beginning of next record
;; after the region
(setq new-end (point))
- (narrow-to-region beg end)
- (goto-char (point-min))
+ (narrow-to-region new-beg new-end)
+ (goto-char new-beg)
(let ((inhibit-field-text-motion t))
(sort-subr
@@ -66,7 +66,14 @@
(defun ledger-sort-buffer ()
"Sort the entire buffer."
(interactive)
- (ledger-sort-region (point-min) (point-max)))
+ (let ((sort-start (point-min))
+ (sort-end (point-max)))
+ (goto-char (point-min))
+ (if (re-search-forward ";.*Ledger-mode:.*Start sort" nil t)
+ (set 'sort-start (match-end 0)))
+ (if (re-search-forward ";.*Ledger-mode:.*End sort" nil t)
+ (set 'sort-end (match-end 0)))
+ (ledger-sort-region sort-start sort-end)))
(provide 'ldg-sort)