gnucash maint: Multiple changes pushed

Christopher Lam clam at code.gnucash.org
Sat Jul 11 07:38:43 EDT 2020


Updated	 via  https://github.com/Gnucash/gnucash/commit/90c8a1e3 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/76fdbfc5 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/66c7a074 (commit)
	from  https://github.com/Gnucash/gnucash/commit/17727a7b (commit)



commit 90c8a1e3c2fffc56e7b8bc23c3c14ff1118fb2f3
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Jul 11 19:00:15 2020 +0800

    [balsheet-eg] remove unused functions

diff --git a/gnucash/report/reports/standard/balsheet-eg.scm b/gnucash/report/reports/standard/balsheet-eg.scm
index 5884a6332..40ccb80ae 100644
--- a/gnucash/report/reports/standard/balsheet-eg.scm
+++ b/gnucash/report/reports/standard/balsheet-eg.scm
@@ -338,21 +338,6 @@
 
          (html #f))
 
-    ;; end of all the lets.  time for some real code
-
-    ;; The following routines are defined inside
-    ;; the renderer to make options available:
-
-    ;; number formatting stuff
-    (define (fmtnumber n)
-      ;; format double n with as many decimal places as required
-      (number->string (if (integer? n) (inexact->exact n) n)))
-    (define (fmtnumeric n)
-      ;; format gnc-numeric n for printing
-      (fmtnumber (gnc-numeric-to-double n)))
-
-    ;; HTML-specific formatting
-
     (define (negstyle item)
       ;; apply styling for negative amounts
       (string-append "<span class=\"negative\">" item "</span>"))

commit 76fdbfc5fc10a6b434ac361cb0ac48a31199807b
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Jul 11 18:40:47 2020 +0800

    [balsheet-eg] modernize accrec to use srfi-9 record

diff --git a/gnucash/report/reports/standard/balsheet-eg.scm b/gnucash/report/reports/standard/balsheet-eg.scm
index c591acfe0..5884a6332 100644
--- a/gnucash/report/reports/standard/balsheet-eg.scm
+++ b/gnucash/report/reports/standard/balsheet-eg.scm
@@ -42,6 +42,7 @@
 
 (use-modules (ice-9 local-eval))  ; for the-environment
 (use-modules (srfi srfi-13)) ; for extra string functions
+(use-modules (srfi srfi-9))
 
 (define debugging? #f)
 
@@ -110,67 +111,31 @@
                                   (accrec-sublist accrec))
                                  (display "</ul>"))
                                (display "#f")))
-(define accrectype (make-record-type "accrecc"
-                                     '(account
-                                        code
-                                        placeholder?
-                                        namelink ; a/c name, as link if required
-                                        commodity
-                                        balance-num ; excluding sublist
-                                        depth
-                                        treedepth
-                                        non-zero?  ; #t if this or any sub-a/cs are non zero
-                                        summary?   ; #t if subaccounts summarised here
-                                        subtotal-cc ; of sublist plus this a/c
-                                        sublist)
-                                     accrec-printer))
-
-(define newaccrec-full (record-constructor accrectype))                ; requires all the fields
-(define (newaccrec-clean)
-  ;; Create a new accrec with 'clean' empty values, e.g. strings are "", not #f
-  (newaccrec-full #f         ; account
-                  ""         ; code
-                  #f         ; placeholder?
-                  ""         ; namelink
-                  (gnc-default-currency)         ; commodity
-                  (gnc-numeric-zero) ; balance-num
-                  0         ; depth
-                  0         ; treedepth
-                  #f         ; non-zero?
-                  #f        ; summary?
-                  (gnc:make-commodity-collector) ; subtotal-cc
-                  #f        ;'()        ; sublist
-                  ))
-(define accrec? (record-predicate accrectype))
-(define accrec-account      (record-accessor accrectype 'account))
-(define accrec-code         (record-accessor accrectype 'code))
-(define accrec-placeholder? (record-accessor accrectype 'placeholder?))
-(define accrec-namelink     (record-accessor accrectype 'namelink))
-(define accrec-commodity    (record-accessor accrectype 'commodity))
-(define accrec-balance-num  (record-accessor accrectype 'balance-num))
+
+(define-record-type <accrec>
+  (newaccrec-full account code placeholder? namelink commodity balance-num depth
+                  treedepth non-zero? summary? subtotal-cc sublist)
+  accrec?
+  (account accrec-account accrec-set-account!)
+  (code accrec-code accrec-set-code!)
+  (placeholder? accrec-placeholder? accrec-set-placeholder?!)
+  (namelink accrec-namelink accrec-set-namelink!)
+  (commodity accrec-commodity accrec-set-commodity!)
+  (balance-num accrec-balance-num accrec-set-balance-num!)
+  (depth accrec-depth accrec-set-depth!)
+  (treedepth accrec-treedepth accrec-set-treedepth!)
+  (non-zero? accrec-non-zero? accrec-set-non-zero?!)
+  (summary? accrec-summary? accrec-set-summary?!)
+  (subtotal-cc accrec-subtotal-cc accrec-set-subtotal-cc!)
+  (sublist accrec-sublist accrec-set-sublist!))
+
 (define (accrec-balance-mny accrec)
   (gnc:make-gnc-monetary (accrec-commodity accrec) (accrec-balance-num accrec)))
-(define accrec-depth        (record-accessor accrectype 'depth))
-(define accrec-treedepth    (record-accessor accrectype 'treedepth))
-(define accrec-non-zero?    (record-accessor accrectype 'non-zero?))
-(define accrec-summary?     (record-accessor accrectype 'summary?))
-(define accrec-subtotal-cc  (record-accessor accrectype 'subtotal-cc))
-(define accrec-sublist      (record-accessor accrectype 'sublist))
-(define accrec-set-account!      (record-modifier accrectype 'account))
-(define accrec-set-code!         (record-modifier accrectype 'code))
-(define accrec-set-placeholder?! (record-modifier accrectype 'placeholder?))
-(define accrec-set-namelink!     (record-modifier accrectype 'namelink))
-(define accrec-set-commodity!    (record-modifier accrectype 'commodity))
-(define accrec-set-balance-num!  (record-modifier accrectype 'balance-num))
-(define (accrec-set-balance-mny! accrec mny)
-  (accrec-set-commodity!   accrec (gnc:gnc-monetary-commodity mny))
-  (accrec-set-balance-num! accrec (gnc:gnc-monetary-amount    mny)))
-(define accrec-set-depth!        (record-modifier accrectype 'depth))
-(define accrec-set-treedepth!    (record-modifier accrectype 'treedepth))
-(define accrec-set-non-zero?!    (record-modifier accrectype 'non-zero?))
-(define accrec-set-summary?!     (record-modifier accrectype 'summary?))
-(define accrec-set-subtotal-cc!  (record-modifier accrectype 'subtotal-cc))
-(define accrec-set-sublist!      (record-modifier accrectype 'sublist))
+
+(define (newaccrec-clean)
+  (newaccrec-full #f "" #f "" (gnc-default-currency) 0 0 0 #f #f
+                  (gnc:make-commodity-collector) #f))
+
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; All the options stuff starts here

commit 66c7a0744ccd17fda31be41517ff017671f8f660
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Jul 11 13:25:54 2020 +0800

    [eguile reports] eradicate pythonic for loops, use for-each instead
    
    this syntax is pythonic rather than lispy, is not recognized by code
    highlighters, and is not necessary to seasoned schemers.

diff --git a/gnucash/report/eguile-utilities.scm b/gnucash/report/eguile-utilities.scm
index 3005777a2..e44c97e26 100644
--- a/gnucash/report/eguile-utilities.scm
+++ b/gnucash/report/eguile-utilities.scm
@@ -99,8 +99,11 @@
   ;; If no file is found, returns just 'fname' for use in error messages.
   (find-internal "templates" fname))
 
-; Define syntax for more readable for loops (the built-in for-each requires an
-; explicit lambda and has the list expression all the way at the end).
+;; Define syntax for more readable for loops (the built-in for-each
+;; requires an explicit lambda and has the list expression all the way
+;; at the end).  Note: deprecated in 4.x, removal in 5.x. this syntax
+;; is pythonic rather than lispy, is not recognized by code
+;; highlighters, and is not necessary to seasoned schemers.
 (export for)
 (define-syntax for
   (syntax-rules (for in do)
@@ -110,8 +113,12 @@
     ;; Note that this template must be defined before the
     ;; next one, since the template are evaluated in-order.
     ((for (<var> ...) in (<list> ...) do <expr> ...)
-     (for-each (lambda (<var> ...) <expr> ...) <list> ...))
+     (begin
+       (issue-deprecation-warning "for loops are deprecated. use for-each instead.")
+       (for-each (lambda (<var> ...) <expr> ...) <list> ...)))
 
     ;; Single variable and list. e.g.: (for a in lst do (display a))
     ((for <var> in <list> do <expr> ...)
-     (for-each (lambda (<var>) <expr> ...) <list>))))
+     (begin
+       (issue-deprecation-warning "for loops are deprecated. use for-each instead.")
+       (for-each (lambda (<var>) <expr> ...) <list>)))))
diff --git a/gnucash/report/reports/standard/balsheet-eg.scm b/gnucash/report/reports/standard/balsheet-eg.scm
index ee35e76f6..c591acfe0 100644
--- a/gnucash/report/reports/standard/balsheet-eg.scm
+++ b/gnucash/report/reports/standard/balsheet-eg.scm
@@ -46,12 +46,12 @@
 (define debugging? #f)
 
 (define (debug . args)
-  (if debugging?
-    (for arg in args do
-        (if (string? arg)
-          (display (string-append arg " "))
-          (display (string-append (dump arg) " "))))
-      ))
+  (when debugging?
+    (for-each
+     (lambda (arg)
+       (display (if (string? arg) arg (dump arg)))
+       (display " "))
+     args)))
 
 (define (hrule cols) ; in fact just puts in an empty row for spacing
   (display "<tr valign=\"center\"><td colspan=\"")
@@ -102,10 +102,12 @@
   (display " sublist: ")     (if (accrec-sublist accrec)
                                (begin
                                  (display "\n<ul>")
-                                 (for sub-accrec in (accrec-sublist accrec) do
+                                 (for-each
+                                  (lambda (sub-accrec)
                                      (display "\n<li>")
                                      (accrec-printer sub-accrec port)
                                      (display "</li>"))
+                                  (accrec-sublist accrec))
                                  (display "</ul>"))
                                (display "#f")))
 (define accrectype (make-record-type "accrecc"
@@ -122,6 +124,7 @@
                                         subtotal-cc ; of sublist plus this a/c
                                         sublist)
                                      accrec-printer))
+
 (define newaccrec-full (record-constructor accrectype))                ; requires all the fields
 (define (newaccrec-clean)
   ;; Create a new accrec with 'clean' empty values, e.g. strings are "", not #f
diff --git a/gnucash/report/reports/support/balsheet-eg.eguile.scm b/gnucash/report/reports/support/balsheet-eg.eguile.scm
index 17a62a56f..301962959 100644
--- a/gnucash/report/reports/support/balsheet-eg.eguile.scm
+++ b/gnucash/report/reports/support/balsheet-eg.eguile.scm
@@ -76,52 +76,46 @@
             onedepth1)
     ;; Recursively display the accounts table from the given tree
     ;; (as returned by process-acc-list)
-    (for accrec in tree do
-        (let ((rshift2 0)    ; adjust the amount column by this much
-              (showamt? #t)) ; whether to show the amount (e.g. not if zero)
-          (if (and (accrec-sublist accrec)
-                ;   (> (accrec-depth accrec) 0))
-                )
-            ; has sub-accounts: shift left to put balance in same column as sub-accounts
-            (set! rshift2 -1))
-          ; Don't show zero amount for a placeholder -- the value to
-          ; test for zero depends on whether or not this is a 'summary' value
-          ; (i.e. a total of sub-accounts that are not shown separately)
-          (if (and (accrec-placeholder? accrec)
-                   (if (accrec-summary? accrec)
-                     (not (accrec-non-zero? accrec))
-                     (gnc-numeric-zero-p (accrec-balance-num accrec))))
-            (set! showamt? #f))
-          (display-acc-row
+    (for-each
+     (lambda (accrec)
+       (display-acc-row
+        maxdepth
+        (accrec-depth accrec)
+        ;; has sub-accounts: shift left to put balance in same column
+        ;; as sub-accounts
+        (+ rshift (if (accrec-sublist accrec) -1 0))
+        (accrec-namelink accrec)
+        ;; Don't show zero amount for a placeholder -- the value to
+        ;; test for zero depends on whether or not this is a 'summary'
+        ;; value (i.e. a total of sub-accounts that are not shown
+        ;; separately)
+        (cond
+         ((and (accrec-placeholder? accrec)
+               (if (accrec-summary? accrec)
+                   (not (accrec-non-zero? accrec))
+                   (zero? (accrec-balance-num accrec))))
+          " ")
+         ((accrec-summary? accrec) (format-comm-coll (accrec-subtotal-cc accrec)))
+         (else (format-monetary (accrec-balance-mny accrec))))
+        (< (accrec-depth accrec) 1); total?
+        #f) ; leftoverrule?
+       (when (accrec-sublist accrec)
+         ;; recurse to deeper accounts...
+         (display-accounts-table-r
+          (accrec-sublist accrec) neg? maxdepth rshift onedepth1)
+         ;; ...and then display the total
+         ;; unless there is only one depth-1 account
+         (unless (and onedepth1 (= 1 (accrec-depth accrec)))
+           (display-acc-row
             maxdepth
             (accrec-depth accrec)
-            (+ rshift rshift2)
-            (accrec-namelink accrec)
-            (if showamt?
-              (if (accrec-summary? accrec)
-                (format-comm-coll (accrec-subtotal-cc accrec))
-                (format-monetary (accrec-balance-mny accrec)))
-              " "
-              )
-            (< (accrec-depth accrec) 1); total?
-            #f) ; leftoverrule?
-          (if (accrec-sublist accrec)
-            (begin
-              ; recurse to deeper accounts...
-              (display-accounts-table-r (accrec-sublist accrec) neg? maxdepth rshift onedepth1)
-              ; ...and then display the total
-              ; unless there is only one depth-1 account
-              (if (not (and onedepth1
-                            (= 1 (accrec-depth accrec))))
-                (display-acc-row
-                  maxdepth
-                  (accrec-depth accrec)
-                  (if (> (accrec-depth accrec) 1) rshift 0)
-                  (string-append (_ "Total") " " (accrec-namelink accrec))
-                  (format-comm-coll-total (accrec-subtotal-cc accrec))
-                  (<= (accrec-depth accrec) 1)        ; total?
-                  (> (accrec-depth accrec) 0)))))))   ; leftoverrule?
-      )
+            (if (> (accrec-depth accrec) 1) rshift 0)
+            (string-append (_ "Total") " " (accrec-namelink accrec))
+            (format-comm-coll-total (accrec-subtotal-cc accrec))
+            (<= (accrec-depth accrec) 1)        ; total?
+            (> (accrec-depth accrec) 0)))))   ; leftoverrule?
+
+     tree))
 ?>
 
 <!-- The HTML starts here... -->



Summary of changes:
 gnucash/report/eguile-utilities.scm                |  15 ++-
 gnucash/report/reports/standard/balsheet-eg.scm    | 113 ++++++---------------
 .../report/reports/support/balsheet-eg.eguile.scm  |  82 +++++++--------
 3 files changed, 82 insertions(+), 128 deletions(-)



More information about the gnucash-changes mailing list