* 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.
This commit is contained in:
parent
423439b380
commit
0fac3f5532
8 changed files with 68 additions and 53 deletions
|
@ -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.
|
||||
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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.
|
||||
;; 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.
|
||||
;; 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.
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Add table
Reference in a new issue