diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2020-10-10 16:00:51 -0400 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2020-10-10 16:00:51 -0400 |
commit | f342b7c96929dcb0324c6eded32be4d98a764708 (patch) | |
tree | ae0b3f20208f1f23e9a953957570488d48768544 /lisp/calc/calc-forms.el | |
parent | 46c0f28c0e4e212687e90ec0ecb239d994105a19 (diff) | |
download | emacs-f342b7c96929dcb0324c6eded32be4d98a764708.tar.gz emacs-f342b7c96929dcb0324c6eded32be4d98a764708.tar.bz2 emacs-f342b7c96929dcb0324c6eded32be4d98a764708.zip |
* lisp/calc/: Use lexical scoping in all the files
Includes the following pervasive changes:
- Move some defvars earlier in the file so they cover earlier let-bindings
- Change dynamically scoped `calc-FOO` or `math-FOO` function arguments
to just FOO and then let-bind the `calc-FOO` or `math-FOO` variable
explicitly in the body of the function. In some cases, the
beginning of the function was changed to refer to FOO so as to delay
the binding to a nearby `let` when I could ensure that it did
not make a difference.
- Add an underscore in front of unused vars or comment them out altogether.
- Replace unused `err` arg to `condition-case` with nil.
Plus the additional itemized changes below.
* lisp/calc/calc-map.el (calcFunc-reducer):
* lisp/calc/calc-arith.el (math-setup-declarations):
* lisp/calc/calc-help.el (calc-full-help, calc-help-index-entries)
(calc-full-help): Use `ignore-errors`.
* lisp/calc/calc-embed.el (calc-embedded-modes-change):
Declare `the-language` and `the-display-just` as dynamically scoped.
* lisp/calc/calc-forms.el (math-setup-year-holidays): Use `dolist`.
* lisp/calc/calc-graph.el (calc-graph-set-styles): Use `symbol-value`
rather than `eval.`
(calc-graph-delete-temps, calc-graph-set-styles): Use ignore-errors.
* lisp/calc/calc-macs.el (calc-with-trail-buffer): Add artificial use
of `save-buf` to silence compiler warnings in all the cases where
`body` doesn't make use of it.
* lisp/calc/calc-math.el (math-largest-emacs-expt)
(math-smallest-emacs-expt, math-use-emacs-fn): Use ignore-errors.
* lisp/calc/calc-mode.el (calc-total-algebraic-mode): Remove "P" from
interactive spec since it's not used anyway.
* lisp/calc/calc-rewr.el (calc-match): Simplify.
* lisp/calc/calc.el (calc-buffer): Give it a global nil value,
so it's automatically declared dynbound in any file that requires `calc`.
(calcDigit-nondigit): Adjust accordingly.
* lisp/calc/calcalg2.el (calcFunc-table): Declare `var-dummy` as dynbound.
(math-scan-for-limits): Comment out dead code.
* lisp/calc/calcalg3.el (math-general-fit): Declare `var-YVAL` and
`var-YVALX` as dynbound.
Diffstat (limited to 'lisp/calc/calc-forms.el')
-rw-r--r-- | lisp/calc/calc-forms.el | 56 |
1 files changed, 30 insertions, 26 deletions
diff --git a/lisp/calc/calc-forms.el b/lisp/calc/calc-forms.el index a2f66968665..465d4520b05 100644 --- a/lisp/calc/calc-forms.el +++ b/lisp/calc/calc-forms.el @@ -1,4 +1,4 @@ -;;; calc-forms.el --- data format conversion functions for Calc +;;; calc-forms.el --- data format conversion functions for Calc -*- lexical-binding:t -*- ;; Copyright (C) 1990-1993, 2001-2020 Free Software Foundation, Inc. @@ -678,10 +678,11 @@ in the Gregorian calendar." (defvar math-fd-isoweek) (defvar math-fd-isoweekday) -(defun math-format-date (math-fd-date) - (if (eq (car-safe math-fd-date) 'date) - (setq math-fd-date (nth 1 math-fd-date))) - (let ((entry (list math-fd-date calc-internal-prec calc-date-format))) +(defun math-format-date (fd-date) + (let* ((math-fd-date (if (eq (car-safe fd-date) 'date) + (nth 1 fd-date) + fd-date)) + (entry (list math-fd-date calc-internal-prec calc-date-format))) (or (cdr (assoc entry math-format-date-cache)) (let* ((math-fd-dt nil) (math-fd-iso-dt nil) @@ -914,15 +915,16 @@ to Jan 1, 1970 AD.") ;; which is called by math-parse-date and math-parse-standard-date. (defvar math-pd-str) -(defun math-parse-date (math-pd-str) +(defun math-parse-date (pd-str) (catch 'syntax - (or (math-parse-standard-date math-pd-str t) - (math-parse-standard-date math-pd-str nil) - (and (string-match "W[0-9][0-9]" math-pd-str) - (math-parse-iso-date math-pd-str)) - (and (string-match "\\`[^-+/0-9a-zA-Z]*\\([-+]?[0-9]+\\.?[0-9]*\\([eE][-+]?[0-9]+\\)?\\)[^-+/0-9a-zA-Z]*\\'" math-pd-str) - (list 'date (math-read-number (math-match-substring math-pd-str 1)))) + (or (math-parse-standard-date pd-str t) + (math-parse-standard-date pd-str nil) + (and (string-match "W[0-9][0-9]" pd-str) + (math-parse-iso-date pd-str)) + (and (string-match "\\`[^-+/0-9a-zA-Z]*\\([-+]?[0-9]+\\.?[0-9]*\\([eE][-+]?[0-9]+\\)?\\)[^-+/0-9a-zA-Z]*\\'" pd-str) + (list 'date (math-read-number (math-match-substring pd-str 1)))) (let ((case-fold-search t) + (math-pd-str pd-str) (year nil) (month nil) (day nil) (weekday nil) (hour nil) (minute nil) (second nil) (bc-flag nil) (a nil) (b nil) (c nil) (bigyear nil) temp) @@ -1128,8 +1130,9 @@ to Jan 1, 1970 AD.") (substring math-pd-str (match-end 0)))) n)))) -(defun math-parse-standard-date (math-pd-str with-time) - (let ((case-fold-search t) +(defun math-parse-standard-date (pd-str with-time) + (let ((math-pd-str pd-str) + (case-fold-search t) (okay t) num (fmt calc-date-format) this next (gnext nil) (isoyear nil) (isoweek nil) (isoweekday nil) @@ -1306,9 +1309,10 @@ to Jan 1, 1970 AD.") (setq day (math-add day (1- yearday)))) day)))))) -(defun math-parse-iso-date (math-pd-str) - "Parse MATH-PD-STR as an ISO week date, or return nil." - (let ((case-fold-search t) +(defun math-parse-iso-date (pd-str) + "Parse PD-STR as an ISO week date, or return nil." + (let ((math-pd-str pd-str) + (case-fold-search t) (isoyear nil) (isoweek nil) (isoweekday nil) (hour nil) (minute nil) (second nil)) ;; Extract the time, if any. @@ -1613,7 +1617,7 @@ and ends on the first Sunday of November at 2 a.m." (math-std-daylight-savings-old date dt zone bump) (math-std-daylight-savings-new date dt zone bump))) -(defun math-std-daylight-savings-new (date dt zone bump) +(defun math-std-daylight-savings-new (date dt _zone bump) "Standard North American daylight saving algorithm as of 2007. This implements the rules for the U.S. and Canada. Daylight saving begins on the second Sunday of March at 2 a.m., @@ -1634,7 +1638,7 @@ and ends on the first Sunday of November at 2 a.m." (t 0)))) (t 0))) -(defun math-std-daylight-savings-old (date dt zone bump) +(defun math-std-daylight-savings-old (date dt _zone bump) "Standard North American daylight saving algorithm before 2007. This implements the rules for the U.S. and Canada. Daylight saving begins on the first Sunday of April at 2 a.m., @@ -1657,7 +1661,7 @@ and ends on the last Sunday of October at 2 a.m." ;;; Compute the day (1-31) of the WDAY (0-6) on or preceding the given ;;; day of the given month. -(defun math-prev-weekday-in-month (date dt day wday) +(defun math-prev-weekday-in-month (date dt day _wday) (or day (setq day (nth 2 dt))) (if (> day (math-days-in-month (car dt) (nth 1 dt))) (setq day (math-days-in-month (car dt) (nth 1 dt)))) @@ -2036,18 +2040,18 @@ and ends on the last Sunday of October at 2 a.m." nil))) (or done (setq math-holidays-cache-tag t)))))) -(defun math-setup-year-holidays (math-sh-year) - (let ((exprs (nth 2 math-holidays-cache))) - (while exprs +(defun math-setup-year-holidays (sh-year) + (let ((math-sh-year sh-year)) + (dolist (expr (nth 2 math-holidays-cache)) + (defvar var-y) (defvar var-m) (let* ((var-y math-sh-year) (var-m nil) - (expr (math-evaluate-expr (car exprs)))) + (expr (math-evaluate-expr expr))) (if (math-expr-contains expr '(var m var-m)) (let ((var-m 0)) (while (<= (setq var-m (1+ var-m)) 12) (math-setup-add-holidays (math-evaluate-expr expr)))) - (math-setup-add-holidays expr))) - (setq exprs (cdr exprs))))) + (math-setup-add-holidays expr)))))) (defun math-setup-add-holidays (days) ; uses "math-sh-year" (cond ((eq (car-safe days) 'vec) |