summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorthdox <thdox@free.fr>2015-01-21 00:49:04 +0100
committerthdox <thdox@free.fr>2015-01-21 10:50:20 +0100
commiteb9672c5506de874a697435f82098b6ba3ac9cff (patch)
treec1b9995438155c1cbdc3b4bc55375ffcc4b490c9 /lisp
parentba46240921ac7f70eef57c90e24923e528971d4f (diff)
downloadfork-ledger-eb9672c5506de874a697435f82098b6ba3ac9cff.tar.gz
fork-ledger-eb9672c5506de874a697435f82098b6ba3ac9cff.tar.bz2
fork-ledger-eb9672c5506de874a697435f82098b6ba3ac9cff.zip
Fix for bugzilla #1105.
You can now maximize the number of characters displayed for payee name and account name in the reconcile buffer.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ledger-reconcile.el70
1 files changed, 61 insertions, 9 deletions
diff --git a/lisp/ledger-reconcile.el b/lisp/ledger-reconcile.el
index 80e27ae3..68ac74cf 100644
--- a/lisp/ledger-reconcile.el
+++ b/lisp/ledger-reconcile.el
@@ -88,9 +88,22 @@ If non-nil, the name of the account being reconciled will be substituted
Available fields are date, status, code, payee, account,
amount. The format for each field is %WIDTH(FIELD), WIDTH can be
preced by a minus sign which mean to left justify and pad the
-field."
- :type 'string
- :group 'ledger-reconcile)
+field. WIDTH is the minimum number of characters to display;
+if string is longer, it is not truncated unless
+ledger-reconcile-buffer-payee-max-chars or
+ledger-reconcile-buffer-account-max-chars is defined."
+ :type 'string
+ :group 'ledger-reconcile)
+
+(defcustom ledger-reconcile-buffer-payee-max-chars -1
+ "If positive, truncate payee name right side to max number of characters."
+ :type 'integer
+ :group 'ledger-reconcile)
+
+(defcustom ledger-reconcile-buffer-account-max-chars -1
+ "If positive, truncate account name left side to max number of characters."
+ :type 'integer
+ :group 'ledger-reconcile)
(defcustom ledger-reconcile-sort-key "(0)"
"Default key for sorting reconcile buffer.
@@ -105,6 +118,41 @@ ledger file order, use '(0)'."
:type 'boolean
:group 'ledger-reconcile)
+;; s-functions below are copied from Magnars' s.el
+(defun s-pad-left (len padding s)
+ "If S is shorter than LEN, pad it with PADDING on the left."
+ (let ((extra (max 0 (- len (length s)))))
+ (concat (make-string extra (string-to-char padding))
+ s)))
+(defun s-pad-right (len padding s)
+ "If S is shorter than LEN, pad it with PADDING on the right."
+ (let ((extra (max 0 (- len (length s)))))
+ (concat s
+ (make-string extra (string-to-char padding)))))
+(defun s-left (len s)
+ "Return up to the LEN first chars of S."
+ (if (> (length s) len)
+ (substring s 0 len)
+ s))
+(defun s-right (len s)
+ "Return up to the LEN last chars of S."
+ (let ((l (length s)))
+ (if (> l len)
+ (substring s (- l len) l)
+ s)))
+
+(defun ledger-reconcile-truncate-right (str len)
+ "Truncate STR right side with max LEN characters, and pad with '…' if truncated."
+ (if (and (>= len 0) (> (length str) len))
+ (s-pad-right len "…" (s-left (- len 1) str))
+ str))
+
+(defun ledger-reconcile-truncate-left (str len)
+ "Truncate STR left side with max LEN characters, and pad with '…' if truncated."
+ (if (and (>= len 0) (> (length str) len))
+ (s-pad-left len "…" (s-right (- len 1) str))
+ str))
+
(defun ledger-reconcile-get-cleared-or-pending-balance (buffer account)
"Use BUFFER to Calculate the cleared or pending balance of the ACCOUNT."
@@ -359,12 +407,16 @@ POSTING is used in `ledger-clear-whole-transactions' is nil."
(ledger-reconcile-format-posting beg
where
fmt
- (format-time-string date-format (nth 2 xact)) ; date
- (if (nth 3 xact) (nth 3 xact) "") ; code
- (nth 3 posting) ; status
- (nth 4 xact) ; payee
- (nth 1 posting) ; account
- (nth 2 posting)))))) ; amount
+ (format-time-string date-format (nth 2 xact)) ; date
+ (if (nth 3 xact) (nth 3 xact) "") ; code
+ (nth 3 posting) ; status
+ (ledger-reconcile-truncate-right
+ (nth 4 xact) ; payee
+ ledger-reconcile-buffer-payee-max-chars)
+ (ledger-reconcile-truncate-left
+ (nth 1 posting) ; account
+ ledger-reconcile-buffer-account-max-chars)
+ (nth 2 posting)))))) ; amount
(defun ledger-do-reconcile (&optional sort)
"SORT the uncleared transactions in the account and display them in the *Reconcile* buffer.