gnucash master: Multiple changes pushed

Christopher Lam clam at code.gnucash.org
Sat May 9 10:34:14 EDT 2020


Updated	 via  https://github.com/Gnucash/gnucash/commit/f1ff7896 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/8ffe7771 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/0c1b6c5a (commit)
	 via  https://github.com/Gnucash/gnucash/commit/9667a47d (commit)
	 via  https://github.com/Gnucash/gnucash/commit/010a0f15 (commit)
	from  https://github.com/Gnucash/gnucash/commit/4e6c497c (commit)



commit f1ff7896576cf67a6b4ba8b4e8413c9a6d209b0e
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat May 9 21:53:09 2020 +0800

    [balsheet-eg] don't use safe-cadr and safe-cdr
    
    they are safety hacks which indicate inability to deal with lists. use
    lists properly.

diff --git a/gnucash/report/eguile-utilities.scm b/gnucash/report/eguile-utilities.scm
index 8058d9ddb..09bb27a50 100644
--- a/gnucash/report/eguile-utilities.scm
+++ b/gnucash/report/eguile-utilities.scm
@@ -46,11 +46,13 @@
 ;; 'Safe' versions of cdr and cadr that don't crash
 ;; if the list is empty  (is there a better way?)
 (define-public safe-cdr
+  ;; deprecate
   (match-lambda
     ((_ . x) x)
     (_ '())))
 
 (define-public safe-cadr
+  ;; deprecate
   (match-lambda
     ((_ x . y) x)
     (_ '())))
diff --git a/gnucash/report/reports/standard/balsheet-eg.scm b/gnucash/report/reports/standard/balsheet-eg.scm
index 15f7d42c9..ee35e76f6 100644
--- a/gnucash/report/reports/standard/balsheet-eg.scm
+++ b/gnucash/report/reports/standard/balsheet-eg.scm
@@ -458,13 +458,12 @@
                       (>= (gnc-account-get-current-depth (car account-list))
                           curr-depth))
             (let* ((account (car account-list))
+                   (accrest (cdr account-list))
+                   (accnext (and (pair? accrest) (car accrest)))
                    (comm    (xaccAccountGetCommodity account))
                    (bal     (xaccAccountGetBalanceAsOfDate account opt-date))
                    (depth   (flattened-acc-depth account))
                    (treedepth 1)
-                   ;; Next account only qualifies as 'deeper' if we're not flattening
-                   (next-acc-deeper (and (not (null? (safe-cadr account-list)))
-                                         (> (flattened-acc-depth (safe-cadr account-list)) depth)))
                    (newacc (newaccrec-clean)))
               (accrec-set-account!      newacc account)
               (accrec-set-code!         newacc (xaccAccountGetCode account))
@@ -483,11 +482,11 @@
               (add-to-cc total-cc comm bal neg?)
               (add-to-cc (accrec-subtotal-cc newacc) comm bal neg?)
 
-              (if next-acc-deeper
+              ;; Next account only qualifies as 'deeper' if we're not flattening
+              (if (and accnext (> (flattened-acc-depth accnext) depth))
                   ;; recurse to deal with deeper level accounts,
                   ;; then store the resulting list
-                  (let* ((result-v (process-acc-list-r
-                                    (safe-cdr account-list) (1+ curr-depth) neg?))
+                  (let* ((result-v (process-acc-list-r accrest (1+ curr-depth) neg?))
                          (subtree (vector-ref result-v 0))
                          (subtotal-cc (vector-ref result-v 2))
                          (subtreedepth (vector-ref result-v 3))

commit 8ffe7771f19e264146a9cf650cff840eabcbc40f
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat May 9 21:51:50 2020 +0800

    [balsheet-eg] reindent process-acc-list-r

diff --git a/gnucash/report/reports/standard/balsheet-eg.scm b/gnucash/report/reports/standard/balsheet-eg.scm
index cbcc53aec..15f7d42c9 100644
--- a/gnucash/report/reports/standard/balsheet-eg.scm
+++ b/gnucash/report/reports/standard/balsheet-eg.scm
@@ -444,84 +444,84 @@
       ;; non-recursive wrapper around this:
       ;; Convert the account list to a tree structure for easier handling later
       (define (process-acc-list-r
-                account-list       ; list of accounts to process
-                curr-depth         ; set depth to 1 to start with
-                neg?)
+               account-list       ; list of accounts to process
+               curr-depth         ; set depth to 1 to start with
+               neg?)
         (let ((tree '())          ; gets tree of accounts from this depth down
               (maxdepth 0)        ; gets max depth of all at this level
               (any-non-zero? #f)  ; becomes true if any at this level are non-zero
-              (total-cc (gnc:make-commodity-collector)))        ; gets grand total of all accounts
-          ; at this level and below
-          ; loop until no more accounts, or next account is at higher level
+              (total-cc (gnc:make-commodity-collector)))
+
+          ;; at this level and below
+          ;; loop until no more accounts, or next account is at higher level
           (while (and (not (null? account-list))
-                      (>= (gnc-account-get-current-depth (car account-list)) curr-depth))
-                 (let* ((account (car account-list))
-                        (comm    (xaccAccountGetCommodity account))
-                        (bal     (xaccAccountGetBalanceAsOfDate account opt-date))
-                        (depth   (flattened-acc-depth account))
-                        (treedepth 1)
-                        ; Next account only qualifies as 'deeper' if we're not flattening
-                        (next-acc-deeper (and (not (null? (safe-cadr account-list)))
-                                              (> (flattened-acc-depth (safe-cadr account-list)) depth)))
-                        (newacc (newaccrec-clean)))
-                   (accrec-set-account!      newacc account)
-                   (accrec-set-code!         newacc (xaccAccountGetCode account))
-                   (accrec-set-placeholder?! newacc (xaccAccountGetPlaceholder account))
-                   (accrec-set-namelink!     newacc (account-link account))
-                   (accrec-set-commodity!    newacc comm) ;(xaccAccountGetCommodity account))
-                   (accrec-set-balance-num!  newacc
-                                             (if neg?
-                                               (gnc-numeric-neg bal)
-                                               bal))
-                   (accrec-set-depth!        newacc depth) ;(gnc-account-get-current-depth account))
-                   (accrec-set-non-zero?!    newacc (not (gnc-numeric-zero-p bal)))
-
-                   (if (>= depth opt-depth-limit)
-                     (accrec-set-summary?! newacc #t))
-                   (set! xlist (assoc-set! xlist comm #t)) ; even if not opt-show-foreign?
-
-                   (accrec-set-subtotal-cc! newacc (gnc:make-commodity-collector))
-                   (add-to-cc total-cc comm bal neg?)
-                   (add-to-cc (accrec-subtotal-cc newacc) comm bal neg?)
-
-                   (if next-acc-deeper
-                     ; recurse to deal with deeper level accounts,
-                     ; then store the resulting list
-                     (let* ((result-v (process-acc-list-r
-                                        (safe-cdr account-list) (1+ curr-depth) neg?))
-                            (subtree (vector-ref result-v 0))
-                            (subtotal-cc (vector-ref result-v 2))
-                            (subtreedepth (vector-ref result-v 3))
-                            (subnonzero?  (vector-ref result-v 4)))
-                       (set! account-list (vector-ref result-v 1))
-                       (if (not (null? subtree)); (it could be null if all sub-accounts were excluded)
-                         (begin
-                           ; add the sub-total from the recursion to the current level's total
-                           (total-cc 'merge subtotal-cc neg?)
-                           ((accrec-subtotal-cc newacc) 'merge subtotal-cc neg?)
-                           (if (< curr-depth opt-depth-limit)
-                             ; fix the subtree to the current tree
-                             ; but only if not beyond the limit
-                             (accrec-set-sublist! newacc subtree))
-                           ; add the subtree's depth to this level's
-                           (set! treedepth (1+ subtreedepth))
-                           (if subnonzero?
-                             (accrec-set-non-zero?! newacc #t)))))
-                     (begin  ; else -- same level -- just pop the account off the list
-                       (set! account-list (cdr account-list)))) ; end if next-acc-deeper
-
-                   (if (> treedepth maxdepth)
-                     (set! maxdepth treedepth))
-                   ;(display " =D=maxdepth=")(ddump maxdepth)
-                   (if (not (excluded-acc? newacc))
-                     (set! tree (append tree (list newacc))))
-                   (if (accrec-non-zero? newacc)
-                     (set! any-non-zero? #t))
-                   (accrec-set-treedepth!    newacc treedepth)
-                   )); end of while
-          ; next a/c (if any) is at higher level, so return what's
-          ; left of the account list, and the accumulated total
-          ;       0    1            2        3        4
+                      (>= (gnc-account-get-current-depth (car account-list))
+                          curr-depth))
+            (let* ((account (car account-list))
+                   (comm    (xaccAccountGetCommodity account))
+                   (bal     (xaccAccountGetBalanceAsOfDate account opt-date))
+                   (depth   (flattened-acc-depth account))
+                   (treedepth 1)
+                   ;; Next account only qualifies as 'deeper' if we're not flattening
+                   (next-acc-deeper (and (not (null? (safe-cadr account-list)))
+                                         (> (flattened-acc-depth (safe-cadr account-list)) depth)))
+                   (newacc (newaccrec-clean)))
+              (accrec-set-account!      newacc account)
+              (accrec-set-code!         newacc (xaccAccountGetCode account))
+              (accrec-set-placeholder?! newacc (xaccAccountGetPlaceholder account))
+              (accrec-set-namelink!     newacc (account-link account))
+              (accrec-set-commodity!    newacc comm)
+              (accrec-set-balance-num!  newacc (if neg? (- bal) bal))
+              (accrec-set-depth!        newacc depth)
+              (accrec-set-non-zero?!    newacc (not (zero? bal)))
+
+              (if (>= depth opt-depth-limit)
+                  (accrec-set-summary?! newacc #t))
+              (set! xlist (assoc-set! xlist comm #t)) ; even if not opt-show-foreign?
+
+              (accrec-set-subtotal-cc! newacc (gnc:make-commodity-collector))
+              (add-to-cc total-cc comm bal neg?)
+              (add-to-cc (accrec-subtotal-cc newacc) comm bal neg?)
+
+              (if next-acc-deeper
+                  ;; recurse to deal with deeper level accounts,
+                  ;; then store the resulting list
+                  (let* ((result-v (process-acc-list-r
+                                    (safe-cdr account-list) (1+ curr-depth) neg?))
+                         (subtree (vector-ref result-v 0))
+                         (subtotal-cc (vector-ref result-v 2))
+                         (subtreedepth (vector-ref result-v 3))
+                         (subnonzero?  (vector-ref result-v 4)))
+                    (set! account-list (vector-ref result-v 1))
+                    (unless (null? subtree)
+                      ;; (it could be null if all sub-accounts were excluded)
+                      ;; add the sub-total from the recursion to
+                      ;; the current level's total
+                      (total-cc 'merge subtotal-cc neg?)
+                      ((accrec-subtotal-cc newacc) 'merge subtotal-cc neg?)
+                      (when (< curr-depth opt-depth-limit)
+                        ;; fix the subtree to the current tree
+                        ;; but only if not beyond the limit
+                        (accrec-set-sublist! newacc subtree))
+                      ;; add the subtree's depth to this level's
+                      (set! treedepth (1+ subtreedepth))
+                      (when subnonzero?
+                        (accrec-set-non-zero?! newacc #t))))
+                  ;; else -- same level -- just pop the account off the list
+                  (set! account-list (cdr account-list)))
+
+              (when (> treedepth maxdepth)
+                (set! maxdepth treedepth))
+              ;;(display " =D=maxdepth=")(ddump maxdepth)
+              (unless (excluded-acc? newacc)
+                (set! tree (append tree (list newacc))))
+              (when (accrec-non-zero? newacc)
+                (set! any-non-zero? #t))
+              (accrec-set-treedepth!    newacc treedepth)))
+
+          ;; next a/c (if any) is at higher level, so return what's
+          ;; left of the account list, and the accumulated total
+          ;;       0    1            2        3        4
           (vector tree account-list total-cc maxdepth any-non-zero?)
           )); end of p-a-l-r
       (let* ((result-v (process-acc-list-r account-list 1 neg?))

commit 0c1b6c5a4faf7070fe06db4aebbec67528828e4d
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat May 9 21:34:38 2020 +0800

    [eguile-utilities] deprecate single-use function
    
    only used by balsheet-eg.scm

diff --git a/gnucash/report/eguile-utilities.scm b/gnucash/report/eguile-utilities.scm
index 611a5a900..8058d9ddb 100644
--- a/gnucash/report/eguile-utilities.scm
+++ b/gnucash/report/eguile-utilities.scm
@@ -39,7 +39,8 @@
 (define-public fmtnumeric fmtnumber)
 
 (define-public (gnc-monetary-neg? monetary)
-  ; return true if the monetary value is negative
+  ;; return true if the monetary value is negative
+  (issue-deprecated-warning "gnc-monetary-neg? is deprecated")
   (negative? (gnc:gnc-monetary-amount monetary)))
 
 ;; 'Safe' versions of cdr and cadr that don't crash

commit 9667a47da0f2ada90ccd1c5c3f5d87220ddff1ff
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sun Apr 5 20:33:56 2020 +0800

    [balsheet-eg] use "foreign" css class correctly
    
    5093a8fb1 had mistakenly disabled "foreign" class and used html
    formatting elements instead.
    
    also remove dead code

diff --git a/gnucash/report/reports/standard/balsheet-eg.scm b/gnucash/report/reports/standard/balsheet-eg.scm
index ebf34b154..cbcc53aec 100644
--- a/gnucash/report/reports/standard/balsheet-eg.scm
+++ b/gnucash/report/reports/standard/balsheet-eg.scm
@@ -391,8 +391,7 @@
 
     (define (foreignstyle item)
       ;; apply styling for amount in foreign currency
-        (string-append "<span class=\"foreign\">" item "</span>")
-        (string-append "<small><i>" item "</i></small>"))
+      (string-append "<span class=\"foreign\">" item "</span>"))
 
     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     ;;; accrec-related routines
@@ -592,11 +591,6 @@
       ;; Format the total value of a commodity collector
       (format-monetary (gnc:sum-collector-commodity cc opt-report-commodity exchange-fn)))
 
-    (define (fmtmoney2 mny)
-      ;; format a monetary amount in the given currency/commodity
-      ;; !! this takes a gnc-monetary
-      (nbsp (gnc:monetary->string (monetary-rounded mny))))
-
     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
     ;; Adjust options for convenience

commit 010a0f15868e1d7187d0e706945e02bdcbd95aca
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sun Apr 5 14:16:05 2020 +0800

    [eguile-gnc] don't catch errors in eguile-gnc
    
    With commit 9832fa397 the default report runner will now catch errors
    and show the backtrace in the report window. the eguile renderer
    doesn't need to catch errors anymore.

diff --git a/gnucash/report/eguile.scm b/gnucash/report/eguile.scm
index 1a05ab2af..828bcefcb 100644
--- a/gnucash/report/eguile.scm
+++ b/gnucash/report/eguile.scm
@@ -169,49 +169,6 @@
 
 ;end of (template->script)
 
-;; Evaluate input containing Scheme code, trapping errors
-;; e.g. (display "Text ")(display (+ x 2))(display ".") -> Text 42.
-;; Parameters:
-;;   env  - environment in which to do the evaluation;
-;;          if #f, (the-environment) will be used
-(define (script->output env)
-
-  ;; Placeholder for the error stack in case of an error
-  (define error-stack #f)
-  (define local-env (or env (the-environment)))
-
-  ;; Actual evaluation function. This is where the work happens.
-  (define (eval-input)
-    (let lp ((next (read)))
-      (cond
-       ((eof-object? next) #f)
-       (else
-        (local-eval next local-env)
-        (lp (read))))))
-
-  ;; Error handler to display any errors while evaluating the template
-  (define (error-handler key subr message args . rest)
-    (display "<p>")
-    (display (_ "An error occurred when processing the template:"))
-    (display "<br/><pre>")
-    (display
-     (gnc:html-string-sanitize
-      (with-output-to-string
-        (lambda ()
-          (display-backtrace error-stack (current-output-port))
-          (newline)
-          (display-error #f (current-output-port) subr message args rest)))))
-    (display "</pre><br/>"))
-
-  (define (pre-unwind-handler key . rest)
-    ;; Capture the stack here, cut the last 3 frames which are
-    ;; make-stack, this one, and the throw handler.
-    (set! error-stack (make-stack #t 3)))
-
-  (catch #t eval-input error-handler pre-unwind-handler))
-
-; end of (script->output)
-
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 ;; Process a template file and return the result as a string
@@ -223,11 +180,15 @@
     (let ((script (with-input-from-file infile
                     (lambda ()
                       (with-output-to-string template->script)))))
+      (define local-env (or environment (the-environment)))
       (with-output-to-string
         (lambda ()
           (with-input-from-string script
             (lambda ()
-              (script->output environment)))))))))
+              (let lp ((next (read)))
+                (unless (eof-object? next)
+                  (local-eval next local-env)
+                  (lp (read))))))))))))
 
 (export eguile-file-to-string)
 



Summary of changes:
 gnucash/report/eguile-utilities.scm             |   5 +-
 gnucash/report/eguile.scm                       |  49 +-------
 gnucash/report/reports/standard/balsheet-eg.scm | 155 +++++++++++-------------
 3 files changed, 83 insertions(+), 126 deletions(-)



More information about the gnucash-changes mailing list