summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2020-10-14 18:03:52 -0400
committerStefan Monnier <monnier@iro.umontreal.ca>2020-10-14 18:03:52 -0400
commit0fac3f55325cf33e797b33be9935bf39f344c7c9 (patch)
tree4fd9dc7fdace60642f3f179d75f54ba15489d6a9
parent423439b38067c4a428310edab24fba7da082027c (diff)
downloademacs-0fac3f55325cf33e797b33be9935bf39f344c7c9.tar.gz
* lisp/calc: Fix a few issues introduced by lexical scoping
Fix a few places I missed, where we incorrectly used lexical scoping on a var that needed dynamic scoping. These were detected thanks to a bit of footwork by Mattias EngdegÄrd! * lisp/calc/calc-ext.el (math-read-big-lines): Declare as dynbound. (math-read-big-bigp): Bind it inside a `let`. * lisp/calc/calc-graph.el (math-arglist): Declare as dynbound. * lisp/calc/calc-map.el (math-arglist): Declare as dynbound. * lisp/calc/calc-misc.el (math-trunc-prec): Declare as dynbound. (math-trunc): Bind it inside a `let`. (math-floor-prec): Declare as dynbound. (math-floor): Bind it inside a `let`. * lisp/calc/calc-nlfit.el (calc-curve-varnames, calc-curve-coefnames): Declare as dynbound. * lisp/calc/calc-sel.el (math-comp-sel-tag): Declare as dynbound. * lisp/calc/calcsel2.el (calc-sel-reselect): Declare as dynbound.
-rw-r--r--lisp/calc/calc-ext.el72
-rw-r--r--lisp/calc/calc-graph.el1
-rw-r--r--lisp/calc/calc-map.el2
-rw-r--r--lisp/calc/calc-misc.el21
-rw-r--r--lisp/calc/calc-nlfit.el2
-rw-r--r--lisp/calc/calc-sel.el4
-rw-r--r--lisp/calc/calcalg2.el20
-rw-r--r--lisp/calc/calcsel2.el1
8 files changed, 69 insertions, 54 deletions
diff --git a/lisp/calc/calc-ext.el b/lisp/calc/calc-ext.el
index fc0a2c88fea..c48d1595822 100644
--- a/lisp/calc/calc-ext.el
+++ b/lisp/calc/calc-ext.el
@@ -3094,6 +3094,7 @@ If X is not an error form, return 1."
(defvar math-read-big-baseline)
(defvar math-read-big-h2)
(defvar math-read-big-err-msg)
+(defvar math-read-big-lines)
(defun math-read-big-expr (str)
(and (> (length calc-left-label) 0)
@@ -3138,41 +3139,42 @@ If X is not an error form, return 1."
(defvar math-rb-h2)
-(defun math-read-big-bigp (math-read-big-lines)
- (and (cdr math-read-big-lines)
- (let ((matrix nil)
- (v 0)
- (height (if (> (length (car math-read-big-lines)) 0) 1 0)))
- (while (and (cdr math-read-big-lines)
- (let* ((i 0)
- j
- (l1 (car math-read-big-lines))
- (l2 (nth 1 math-read-big-lines))
- (len (min (length l1) (length l2))))
- (if (> (length l2) 0)
- (setq height (1+ height)))
- (while (and (< i len)
- (or (memq (aref l1 i) '(?\ ?\- ?\_))
- (memq (aref l2 i) '(?\ ?\-))
- (and (memq (aref l1 i) '(?\| ?\,))
- (= (aref l2 i) (aref l1 i)))
- (and (eq (aref l1 i) ?\[)
- (eq (aref l2 i) ?\[)
- (let ((math-rb-h2 (length l1)))
- (setq j (math-read-big-balance
- (1+ i) v "[")))
- (setq i (1- j)))))
- (setq i (1+ i)))
- (or (= i len)
- (and (eq (aref l1 i) ?\[)
- (eq (aref l2 i) ?\[)
- (setq matrix t)
- nil))))
- (setq math-read-big-lines (cdr math-read-big-lines)
- v (1+ v)))
- (or (and (> height 1)
- (not (cdr math-read-big-lines)))
- matrix))))
+(defun math-read-big-bigp (read-big-lines)
+ (when (cdr read-big-lines)
+ (let ((math-read-big-lines read-big-lines)
+ (matrix nil)
+ (v 0)
+ (height (if (> (length (car read-big-lines)) 0) 1 0)))
+ (while (and (cdr math-read-big-lines)
+ (let* ((i 0)
+ j
+ (l1 (car math-read-big-lines))
+ (l2 (nth 1 math-read-big-lines))
+ (len (min (length l1) (length l2))))
+ (if (> (length l2) 0)
+ (setq height (1+ height)))
+ (while (and (< i len)
+ (or (memq (aref l1 i) '(?\ ?\- ?\_))
+ (memq (aref l2 i) '(?\ ?\-))
+ (and (memq (aref l1 i) '(?\| ?\,))
+ (= (aref l2 i) (aref l1 i)))
+ (and (eq (aref l1 i) ?\[)
+ (eq (aref l2 i) ?\[)
+ (let ((math-rb-h2 (length l1)))
+ (setq j (math-read-big-balance
+ (1+ i) v "[")))
+ (setq i (1- j)))))
+ (setq i (1+ i)))
+ (or (= i len)
+ (and (eq (aref l1 i) ?\[)
+ (eq (aref l2 i) ?\[)
+ (setq matrix t)
+ nil))))
+ (setq math-read-big-lines (cdr math-read-big-lines)
+ v (1+ v)))
+ (or (and (> height 1)
+ (not (cdr math-read-big-lines)))
+ matrix))))
;;; Nontrivial "flat" formatting.
diff --git a/lisp/calc/calc-graph.el b/lisp/calc/calc-graph.el
index 82e93357164..829fa44ca4f 100644
--- a/lisp/calc/calc-graph.el
+++ b/lisp/calc/calc-graph.el
@@ -313,6 +313,7 @@
(defvar calc-graph-blank)
(defvar calc-graph-non-blank)
(defvar calc-graph-curve-num)
+(defvar math-arglist)
(defun calc-graph-plot (flag &optional printing)
(interactive "P")
diff --git a/lisp/calc/calc-map.el b/lisp/calc/calc-map.el
index 57483fc6590..0ee82826927 100644
--- a/lisp/calc/calc-map.el
+++ b/lisp/calc/calc-map.el
@@ -493,6 +493,8 @@
(defvar calc-get-operator-history nil
"History for calc-get-operator.")
+(defvar math-arglist)
+
(defun calc-get-operator (msg &optional nargs)
(setq calc-aborted-prefix nil)
(let ((inv nil) (hyp nil) (prefix nil) (forcenargs nil)
diff --git a/lisp/calc/calc-misc.el b/lisp/calc/calc-misc.el
index 7c97dc6a9a0..2db09e2b677 100644
--- a/lisp/calc/calc-misc.el
+++ b/lisp/calc/calc-misc.el
@@ -757,19 +757,21 @@ loaded and the keystroke automatically re-typed."
;; The variable math-trunc-prec is local to math-trunc, but used by
;; math-trunc-fancy in calc-arith.el, which is called by math-trunc.
+(defvar math-trunc-prec)
;;;###autoload
-(defun math-trunc (a &optional math-trunc-prec)
- (cond (math-trunc-prec
+(defun math-trunc (a &optional trunc-prec)
+ (cond (trunc-prec
(require 'calc-ext)
- (math-trunc-special a math-trunc-prec))
+ (math-trunc-special a trunc-prec))
((Math-integerp a) a)
((Math-looks-negp a)
(math-neg (math-trunc (math-neg a))))
((eq (car a) 'float)
(math-scale-int (nth 1 a) (nth 2 a)))
(t (require 'calc-ext)
- (math-trunc-fancy a))))
+ (let ((math-trunc-prec trunc-prec))
+ (math-trunc-fancy a)))))
;;;###autoload
(defalias 'calcFunc-trunc 'math-trunc)
@@ -777,12 +779,13 @@ loaded and the keystroke automatically re-typed."
;; The variable math-floor-prec is local to math-floor, but used by
;; math-floor-fancy in calc-arith.el, which is called by math-floor.
+(defvar math-floor-prec)
;;;###autoload
-(defun math-floor (a &optional math-floor-prec) ; [Public]
- (cond (math-floor-prec
+(defun math-floor (a &optional floor-prec) ; [Public]
+ (cond (floor-prec
(require 'calc-ext)
- (math-floor-special a math-floor-prec))
+ (math-floor-special a floor-prec))
((Math-integerp a) a)
((Math-messy-integerp a) (math-trunc a))
((Math-realp a)
@@ -790,7 +793,9 @@ loaded and the keystroke automatically re-typed."
(math-add (math-trunc a) -1)
(math-trunc a)))
(t (require 'calc-ext)
- (math-floor-fancy a))))
+ (let ((math-floor-prec floor-prec))
+ (math-floor-fancy a)))))
+
;;;###autoload
(defalias 'calcFunc-floor 'math-floor)
diff --git a/lisp/calc/calc-nlfit.el b/lisp/calc/calc-nlfit.el
index 6f2a601cd99..5ed85fe7cae 100644
--- a/lisp/calc/calc-nlfit.el
+++ b/lisp/calc/calc-nlfit.el
@@ -665,6 +665,8 @@
(calc-handle-whys))
(defvar calc-curve-nvars)
+(defvar calc-curve-varnames)
+(defvar calc-curve-coefnames)
(defun math-nlfit-fit-curve (fn grad solnexpr initparms &optional sdv)
(calc-slow-wrapper
diff --git a/lisp/calc/calc-sel.el b/lisp/calc/calc-sel.el
index d2944488870..23c0e01b527 100644
--- a/lisp/calc/calc-sel.el
+++ b/lisp/calc/calc-sel.el
@@ -419,6 +419,7 @@
;; The variable math-comp-sel-tag is local to calc-find-selected-part,
;; but is used by math-comp-sel-flat-term and math-comp-add-string-sel
;; in calccomp.el, which are called (indirectly) by calc-find-selected-part.
+(defvar math-comp-sel-tag)
(defun calc-find-selected-part ()
(let* ((math-comp-sel-hpos (- (current-column) calc-selection-cache-offset))
@@ -437,7 +438,8 @@
(current-indentation))
lcount (1+ lcount)))
(- lcount (math-comp-ascent
- calc-selection-cache-comp) -1))))
+ calc-selection-cache-comp)
+ -1))))
(math-comp-sel-cpos (- (point) toppt calc-selection-cache-offset
spaces lcount))
(math-comp-sel-tag nil))
diff --git a/lisp/calc/calcalg2.el b/lisp/calc/calcalg2.el
index 99d0549ca88..7894bd93015 100644
--- a/lisp/calc/calcalg2.el
+++ b/lisp/calc/calcalg2.el
@@ -3259,16 +3259,16 @@
(let ((math-solve-simplifying t))
(math-solve-system-rec exprs math-solve-vars nil)))))
-;;; The following backtracking solver works by choosing a variable
-;;; and equation, and trying to solve the equation for the variable.
-;;; If it succeeds it calls itself recursively with that variable and
-;;; equation removed from their respective lists, and with the solution
-;;; added to solns as well as being substituted into all existing
-;;; equations. The algorithm terminates when any solution path
-;;; manages to remove all the variables from var-list.
-
-;;; To support calcFunc-roots, entries in eqn-list and solns are
-;;; actually lists of equations.
+;; The following backtracking solver works by choosing a variable
+;; and equation, and trying to solve the equation for the variable.
+;; If it succeeds it calls itself recursively with that variable and
+;; equation removed from their respective lists, and with the solution
+;; added to solns as well as being substituted into all existing
+;; equations. The algorithm terminates when any solution path
+;; manages to remove all the variables from `var-list'.
+
+;; To support calcFunc-roots, entries in eqn-list and solns are
+;; actually lists of equations.
;; The variables math-solve-system-res and math-solve-system-vv are
;; local to math-solve-system-rec, but are used by math-solve-system-subst.
diff --git a/lisp/calc/calcsel2.el b/lisp/calc/calcsel2.el
index faec2309394..d6842aa7eee 100644
--- a/lisp/calc/calcsel2.el
+++ b/lisp/calc/calcsel2.el
@@ -34,6 +34,7 @@
;; The variable calc-sel-reselect is local to the methods below,
;; but is used by some functions in calc-sel.el which are called
;; by the functions below.
+(defvar calc-sel-reselect)
(defun calc-commute-left (arg)
(interactive "p")