From dda6730c44b82df6881baa083d78a87da4a916c6 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Thu, 3 May 2018 08:52:59 +0800 Subject: [PATCH] utilities.scm: centralize and modernize addto! (define-macro) is discouraged in most scheme forms. Change to (define-syntax), and centralize common macro to utilities.scm --- gnucash/report/business-reports/customer-summary.scm | 3 --- gnucash/report/business-reports/easy-invoice.scm | 4 +--- gnucash/report/business-reports/fancy-invoice.scm | 4 +--- gnucash/report/business-reports/invoice.scm | 4 +--- gnucash/report/business-reports/job-report.scm | 3 --- gnucash/report/business-reports/owner-report.scm | 3 --- gnucash/report/report-system/html-utilities.scm | 4 +++- gnucash/report/standard-reports/register.scm | 3 --- gnucash/report/standard-reports/transaction.scm | 5 +---- libgnucash/scm/utilities.scm | 5 +++++ 10 files changed, 12 insertions(+), 26 deletions(-) diff --git a/gnucash/report/business-reports/customer-summary.scm b/gnucash/report/business-reports/customer-summary.scm index 34ca9d56e3..376bc0ab76 100644 --- a/gnucash/report/business-reports/customer-summary.scm +++ b/gnucash/report/business-reports/customer-summary.scm @@ -97,9 +97,6 @@ ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(define-macro (addto! alist element) - `(set! ,alist (cons ,element ,alist))) - (define (set-last-row-style! table tag . rest) (let ((arg-list (cons table diff --git a/gnucash/report/business-reports/easy-invoice.scm b/gnucash/report/business-reports/easy-invoice.scm index 439e592ac3..eb294b0186 100644 --- a/gnucash/report/business-reports/easy-invoice.scm +++ b/gnucash/report/business-reports/easy-invoice.scm @@ -33,14 +33,12 @@ (use-modules (srfi srfi-1)) (use-modules (gnucash gnc-module)) (use-modules (gnucash gettext)) +(use-modules (gnucash utilities)) (gnc:module-load "gnucash/report/report-system" 0) (use-modules (gnucash report standard-reports)) (use-modules (gnucash report business-reports)) -(define-macro (addto! alist element) - `(set! ,alist (cons ,element ,alist))) - (define (set-last-row-style! table tag . rest) (let ((arg-list (cons table diff --git a/gnucash/report/business-reports/fancy-invoice.scm b/gnucash/report/business-reports/fancy-invoice.scm index 64c36c278f..ddb2794a90 100644 --- a/gnucash/report/business-reports/fancy-invoice.scm +++ b/gnucash/report/business-reports/fancy-invoice.scm @@ -51,14 +51,12 @@ (use-modules (srfi srfi-1)) (use-modules (gnucash gnc-module)) (use-modules (gnucash gettext)) +(use-modules (gnucash utilities)) (gnc:module-load "gnucash/report/report-system" 0) (use-modules (gnucash report standard-reports)) (use-modules (gnucash report business-reports)) -(define-macro (addto! alist element) - `(set! ,alist (cons ,element ,alist))) - (define (set-last-row-style! table tag . rest) (let ((arg-list (cons table diff --git a/gnucash/report/business-reports/invoice.scm b/gnucash/report/business-reports/invoice.scm index 71298497f7..6b6b22c3f5 100644 --- a/gnucash/report/business-reports/invoice.scm +++ b/gnucash/report/business-reports/invoice.scm @@ -27,14 +27,12 @@ (use-modules (srfi srfi-1)) (use-modules (gnucash gnc-module)) (use-modules (gnucash gettext)) +(use-modules (gnucash utilities)) (gnc:module-load "gnucash/report/report-system" 0) (use-modules (gnucash report standard-reports)) (use-modules (gnucash report business-reports)) -(define-macro (addto! alist element) - `(set! ,alist (cons ,element ,alist))) - (define (set-last-row-style! table tag . rest) (let ((arg-list (cons table diff --git a/gnucash/report/business-reports/job-report.scm b/gnucash/report/business-reports/job-report.scm index b377f94eb8..8eb55acfab 100644 --- a/gnucash/report/business-reports/job-report.scm +++ b/gnucash/report/business-reports/job-report.scm @@ -46,9 +46,6 @@ (define desc-header (N_ "Description")) (define amount-header (N_ "Amount")) -(define-macro (addto! alist element) - `(set! ,alist (cons ,element ,alist))) - (define (set-last-row-style! table tag . rest) (let ((arg-list (cons table diff --git a/gnucash/report/business-reports/owner-report.scm b/gnucash/report/business-reports/owner-report.scm index 39010d5264..89f48cd5c8 100644 --- a/gnucash/report/business-reports/owner-report.scm +++ b/gnucash/report/business-reports/owner-report.scm @@ -117,9 +117,6 @@ (else (_ "Vendor")))) -(define-macro (addto! alist element) - `(set! ,alist (cons ,element ,alist))) - (define (set-last-row-style! table tag . rest) (let ((arg-list (cons table diff --git a/gnucash/report/report-system/html-utilities.scm b/gnucash/report/report-system/html-utilities.scm index 6fbe9ce471..a701ff2bde 100644 --- a/gnucash/report/report-system/html-utilities.scm +++ b/gnucash/report/report-system/html-utilities.scm @@ -22,6 +22,8 @@ ;; Boston, MA 02110-1301, USA gnu@gnu.org ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(use-modules (gnucash utilities)) + ;; returns a list with n #f (empty cell) values (define (gnc:html-make-empty-cell) #f) (define (gnc:html-make-empty-cells n) @@ -854,7 +856,7 @@ (disp value)))) (if (not (or (equal? default-value value) (char=? (string-ref section 0) #\_))) - (set! render-list (cons retval render-list))))) + (addto! render-list retval)))) (gnc:options-for-each add-option-if-changed options) (if plaintext? (string-append diff --git a/gnucash/report/standard-reports/register.scm b/gnucash/report/standard-reports/register.scm index 029e9acac1..063b408a63 100644 --- a/gnucash/report/standard-reports/register.scm +++ b/gnucash/report/standard-reports/register.scm @@ -29,9 +29,6 @@ (gnc:module-load "gnucash/report/report-system" 0) -(define-macro (addto! alist element) - `(set! ,alist (cons ,element ,alist))) - (define (set-last-row-style! table tag . rest) (let ((arg-list (cons table diff --git a/gnucash/report/standard-reports/transaction.scm b/gnucash/report/standard-reports/transaction.scm index 016b3e12f6..26c3529622 100644 --- a/gnucash/report/standard-reports/transaction.scm +++ b/gnucash/report/standard-reports/transaction.scm @@ -40,7 +40,7 @@ (define-module (gnucash report standard-reports transaction)) -(use-modules (gnucash utilities)) +(use-modules (gnucash utilities)) (use-modules (srfi srfi-1)) (use-modules (srfi srfi-11)) (use-modules (srfi srfi-13)) @@ -50,9 +50,6 @@ (gnc:module-load "gnucash/report/report-system" 0) -(define-macro (addto! alist element) - `(set! ,alist (cons ,element ,alist))) - ;; Define the strings here to avoid typos and make changes easier. (define reportname (N_ "Transaction Report")) diff --git a/libgnucash/scm/utilities.scm b/libgnucash/scm/utilities.scm index 4a75c02a69..f34fbd99ce 100644 --- a/libgnucash/scm/utilities.scm +++ b/libgnucash/scm/utilities.scm @@ -42,6 +42,7 @@ (export gnc:error) (export gnc:msg) (export gnc:debug) +(export addto!) ;; Do this stuff very early -- but other than that, don't add any ;; executable code until the end of the file if you can help it. @@ -71,6 +72,10 @@ (define (gnc:debug . items) (gnc-scm-log-debug (strify items))) +(define-syntax addto! + (syntax-rules () + ((addto! alist element) + (set! alist (cons element alist))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; gnc:substring-replace