annotate lisp/calc/calc-prog.el @ 110923:9246a8f688c5

* lisp/mail/mail-utils.el (mail-mbox-from): Also try return-path. (Per 8-year old observation: http://lists.gnu.org/archive/html/bug-gnu-emacs/2002-06/msg00176.html )
author Glenn Morris <rgm@gnu.org>
date Fri, 08 Oct 2010 17:41:03 -0700
parents 1d1d5d9bd884
children a141021cb63f 376148b31b5e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
1 ;;; calc-prog.el --- user programmability functions for Calc
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
2
64325
1db49616ce05 Update copyright information.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 62820
diff changeset
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004,
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 105792
diff changeset
4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
5
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
6 ;; Author: David Gillespie <daveg@synaptics.com>
77465
1154f082efd9 Update maintainer's address.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 76595
diff changeset
7 ;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com>
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
8
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
10
94654
6c9af2bfcfee Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
76595
497d17a80bb8 Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
94654
6c9af2bfcfee Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
13 ;; the Free Software Foundation, either version 3 of the License, or
6c9af2bfcfee Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
14 ;; (at your option) any later version.
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
15
76595
497d17a80bb8 Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
497d17a80bb8 Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
497d17a80bb8 Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
497d17a80bb8 Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
19 ;; GNU General Public License for more details.
497d17a80bb8 Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
20
497d17a80bb8 Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
21 ;; You should have received a copy of the GNU General Public License
94654
6c9af2bfcfee Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
23
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
24 ;;; Commentary:
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
25
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
26 ;;; Code:
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
27
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
28 ;; This file is autoloaded from calc-ext.el.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
29
58668
827d00badeb5 Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58614
diff changeset
30 (require 'calc-ext)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
31 (require 'calc-macs)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
32
86481
f7e3c30cc97d (edmacro-format-keys,edmacro-parse-keys)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82140
diff changeset
33 ;; Declare functions which are defined elsewhere.
f7e3c30cc97d (edmacro-format-keys,edmacro-parse-keys)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82140
diff changeset
34 (declare-function edmacro-format-keys "edmacro" (macro &optional verbose))
f7e3c30cc97d (edmacro-format-keys,edmacro-parse-keys)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82140
diff changeset
35 (declare-function edmacro-parse-keys "edmacro" (string &optional need-vector))
f7e3c30cc97d (edmacro-format-keys,edmacro-parse-keys)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82140
diff changeset
36 (declare-function math-read-expr-level "calc-aent" (exp-prec &optional exp-term))
f7e3c30cc97d (edmacro-format-keys,edmacro-parse-keys)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82140
diff changeset
37
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
38
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
39 (defun calc-equal-to (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
40 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
41 (calc-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
42 (if (and (integerp arg) (> arg 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
43 (calc-enter-result arg "eq" (cons 'calcFunc-eq (calc-top-list-n arg)))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
44 (calc-binary-op "eq" 'calcFunc-eq arg))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
45
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
46 (defun calc-remove-equal (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
47 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
48 (calc-wrapper
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
49 (calc-unary-op "rmeq" 'calcFunc-rmeq arg)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
50
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
51 (defun calc-not-equal-to (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
52 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
53 (calc-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
54 (if (and (integerp arg) (> arg 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
55 (calc-enter-result arg "neq" (cons 'calcFunc-neq (calc-top-list-n arg)))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
56 (calc-binary-op "neq" 'calcFunc-neq arg))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
57
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
58 (defun calc-less-than (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
59 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
60 (calc-wrapper
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
61 (calc-binary-op "lt" 'calcFunc-lt arg)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
62
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
63 (defun calc-greater-than (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
64 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
65 (calc-wrapper
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
66 (calc-binary-op "gt" 'calcFunc-gt arg)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
67
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
68 (defun calc-less-equal (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
69 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
70 (calc-wrapper
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
71 (calc-binary-op "leq" 'calcFunc-leq arg)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
72
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
73 (defun calc-greater-equal (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
74 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
75 (calc-wrapper
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
76 (calc-binary-op "geq" 'calcFunc-geq arg)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
77
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
78 (defun calc-in-set (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
79 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
80 (calc-wrapper
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
81 (calc-binary-op "in" 'calcFunc-in arg)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
82
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
83 (defun calc-logical-and (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
84 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
85 (calc-wrapper
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
86 (calc-binary-op "land" 'calcFunc-land arg 1)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
87
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
88 (defun calc-logical-or (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
89 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
90 (calc-wrapper
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
91 (calc-binary-op "lor" 'calcFunc-lor arg 0)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
92
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
93 (defun calc-logical-not (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
94 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
95 (calc-wrapper
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
96 (calc-unary-op "lnot" 'calcFunc-lnot arg)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
97
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
98 (defun calc-logical-if ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
99 (interactive)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
100 (calc-wrapper
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
101 (calc-enter-result 3 "if" (cons 'calcFunc-if (calc-top-list-n 3)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
102
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
103
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
104
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
105
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
106
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
107 (defun calc-timing (n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
108 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
109 (calc-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
110 (calc-change-mode 'calc-timing n nil t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
111 (message (if calc-timing
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
112 "Reporting timing of slow commands in Trail"
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
113 "Not reporting timing of commands"))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
114
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
115 (defun calc-pass-errors ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
116 (interactive)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
117 ;; The following two cases are for the new, optimizing byte compiler
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
118 ;; or the standard 18.57 byte compiler, respectively.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
119 (condition-case err
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
120 (let ((place (aref (nth 2 (nth 2 (symbol-function 'calc-do))) 15)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
121 (or (memq (car-safe (car-safe place)) '(error xxxerror))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
122 (setq place (aref (nth 2 (nth 2 (symbol-function 'calc-do))) 27)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
123 (or (memq (car (car place)) '(error xxxerror))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
124 (error "foo"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
125 (setcar (car place) 'xxxerror))
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
126 (error (error "The calc-do function has been modified; unable to patch"))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
127
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
128 (defun calc-user-define ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
129 (interactive)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
130 (message "Define user key: z-")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
131 (let ((key (read-char)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
132 (if (= (calc-user-function-classify key) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
133 (error "Can't redefine \"?\" key"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
134 (let ((func (intern (completing-read (concat "Set key z "
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
135 (char-to-string key)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
136 " to command: ")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
137 obarray
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
138 'commandp
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
139 t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
140 "calc-"))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
141 (let* ((kmap (calc-user-key-map))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
142 (old (assq key kmap)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
143 (if old
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
144 (setcdr old func)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
145 (setcdr kmap (cons (cons key func) (cdr kmap))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
146
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
147 (defun calc-user-undefine ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
148 (interactive)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
149 (message "Undefine user key: z-")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
150 (let ((key (read-char)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
151 (if (= (calc-user-function-classify key) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
152 (error "Can't undefine \"?\" key"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
153 (let* ((kmap (calc-user-key-map)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
154 (delq (or (assq key kmap)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
155 (assq (upcase key) kmap)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
156 (assq (downcase key) kmap)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
157 (error "No such user key is defined"))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
158 kmap))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
159
58390
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
160
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
161 ;; math-integral-cache-state is originally declared in calcalg2.el,
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
162 ;; it is used in calc-user-define-variable.
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
163 (defvar math-integral-cache-state)
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
164
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
165 ;; calc-user-formula-alist is local to calc-user-define-formula,
92025
038a958de82d Fix comment typo.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
166 ;; calc-user-define-composition and calc-finish-formula-edit,
58390
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
167 ;; but is used by calc-fix-user-formula.
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
168 (defvar calc-user-formula-alist)
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
169
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
170 (defun calc-user-define-formula ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
171 (interactive)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
172 (calc-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
173 (let* ((form (calc-top 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
174 (arglist nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
175 (is-lambda (and (eq (car-safe form) 'calcFunc-lambda)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
176 (>= (length form) 2)))
59184
a4aaaf92f7da (calc-user-define-formula): Put default values for function names in
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59183
diff changeset
177 odef key keyname cmd cmd-base cmd-base-default
a4aaaf92f7da (calc-user-define-formula): Put default values for function names in
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59183
diff changeset
178 func calc-user-formula-alist is-symb)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
179 (if is-lambda
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
180 (setq arglist (mapcar (function (lambda (x) (nth 1 x)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
181 (nreverse (cdr (reverse (cdr form)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
182 form (nth (1- (length form)) form))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
183 (calc-default-formula-arglist form)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
184 (setq arglist (sort arglist 'string-lessp)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
185 (message "Define user key: z-")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
186 (setq key (read-char))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
187 (if (= (calc-user-function-classify key) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
188 (error "Can't redefine \"?\" key"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
189 (setq key (and (not (memq key '(13 32))) key)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
190 keyname (and key
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
191 (if (or (and (<= ?0 key) (<= key ?9))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
192 (and (<= ?a key) (<= key ?z))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
193 (and (<= ?A key) (<= key ?Z)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
194 (char-to-string key)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
195 (format "%03d" key)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
196 odef (assq key (calc-user-key-map)))
59184
a4aaaf92f7da (calc-user-define-formula): Put default values for function names in
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59183
diff changeset
197 (unless keyname
a4aaaf92f7da (calc-user-define-formula): Put default values for function names in
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59183
diff changeset
198 (setq keyname (format "%05d" (abs (% (random) 10000)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
199 (while
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
200 (progn
59184
a4aaaf92f7da (calc-user-define-formula): Put default values for function names in
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59183
diff changeset
201 (setq cmd-base-default (concat "User-" keyname))
105022
af84e9739140 (arglist): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 101001
diff changeset
202 (setq cmd (completing-read
65680
ed770a0a7846 2005-09-24 Emilio C. Lopes <eclig@gmx.net>
Romain Francoise <romain@orebokech.com>
parents: 64325
diff changeset
203 (concat "Define M-x command name (default calc-"
59184
a4aaaf92f7da (calc-user-define-formula): Put default values for function names in
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59183
diff changeset
204 cmd-base-default
a4aaaf92f7da (calc-user-define-formula): Put default values for function names in
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59183
diff changeset
205 "): ")
a4aaaf92f7da (calc-user-define-formula): Put default values for function names in
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59183
diff changeset
206 obarray 'commandp nil
a4aaaf92f7da (calc-user-define-formula): Put default values for function names in
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59183
diff changeset
207 (if (and odef (symbolp (cdr odef)))
a4aaaf92f7da (calc-user-define-formula): Put default values for function names in
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59183
diff changeset
208 (symbol-name (cdr odef))
a4aaaf92f7da (calc-user-define-formula): Put default values for function names in
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59183
diff changeset
209 "calc-")))
a4aaaf92f7da (calc-user-define-formula): Put default values for function names in
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59183
diff changeset
210 (if (or (string-equal cmd "")
a4aaaf92f7da (calc-user-define-formula): Put default values for function names in
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59183
diff changeset
211 (string-equal cmd "calc-"))
a4aaaf92f7da (calc-user-define-formula): Put default values for function names in
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59183
diff changeset
212 (setq cmd (concat "calc-User-" keyname)))
a4aaaf92f7da (calc-user-define-formula): Put default values for function names in
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59183
diff changeset
213 (setq cmd-base (and (string-match "\\`calc-\\(.+\\)\\'" cmd)
a4aaaf92f7da (calc-user-define-formula): Put default values for function names in
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59183
diff changeset
214 (math-match-substring cmd 1)))
a4aaaf92f7da (calc-user-define-formula): Put default values for function names in
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59183
diff changeset
215 (setq cmd (intern cmd))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
216 (and cmd
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
217 (fboundp cmd)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
218 odef
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
219 (not
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
220 (y-or-n-p
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
221 (if (get cmd 'calc-user-defn)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
222 (concat "Replace previous definition for "
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
223 (symbol-name cmd) "? ")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
224 "That name conflicts with a built-in Emacs function. Replace this function? "))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
225 (while
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
226 (progn
105022
af84e9739140 (arglist): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 101001
diff changeset
227 (setq cmd-base-default
59184
a4aaaf92f7da (calc-user-define-formula): Put default values for function names in
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59183
diff changeset
228 (if cmd-base
a4aaaf92f7da (calc-user-define-formula): Put default values for function names in
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59183
diff changeset
229 (if (string-match
a4aaaf92f7da (calc-user-define-formula): Put default values for function names in
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59183
diff changeset
230 "\\`User-.+" cmd-base)
a4aaaf92f7da (calc-user-define-formula): Put default values for function names in
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59183
diff changeset
231 (concat
a4aaaf92f7da (calc-user-define-formula): Put default values for function names in
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59183
diff changeset
232 "User"
a4aaaf92f7da (calc-user-define-formula): Put default values for function names in
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59183
diff changeset
233 (substring cmd-base 5))
a4aaaf92f7da (calc-user-define-formula): Put default values for function names in
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59183
diff changeset
234 cmd-base)
a4aaaf92f7da (calc-user-define-formula): Put default values for function names in
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59183
diff changeset
235 (concat "User" keyname)))
105022
af84e9739140 (arglist): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 101001
diff changeset
236 (setq func
59183
f27d7a9c6f27 (calc-user-define-permanent, calc-user-define-composition)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58668
diff changeset
237 (concat "calcFunc-"
105022
af84e9739140 (arglist): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 101001
diff changeset
238 (completing-read
65680
ed770a0a7846 2005-09-24 Emilio C. Lopes <eclig@gmx.net>
Romain Francoise <romain@orebokech.com>
parents: 64325
diff changeset
239 (concat "Define algebraic function name (default "
59184
a4aaaf92f7da (calc-user-define-formula): Put default values for function names in
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59183
diff changeset
240 cmd-base-default "): ")
a4aaaf92f7da (calc-user-define-formula): Put default values for function names in
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59183
diff changeset
241 (mapcar (lambda (x) (substring x 9))
a4aaaf92f7da (calc-user-define-formula): Put default values for function names in
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59183
diff changeset
242 (all-completions "calcFunc-"
a4aaaf92f7da (calc-user-define-formula): Put default values for function names in
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59183
diff changeset
243 obarray))
105022
af84e9739140 (arglist): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 101001
diff changeset
244 (lambda (x)
af84e9739140 (arglist): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 101001
diff changeset
245 (fboundp
59184
a4aaaf92f7da (calc-user-define-formula): Put default values for function names in
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59183
diff changeset
246 (intern (concat "calcFunc-" x))))
a4aaaf92f7da (calc-user-define-formula): Put default values for function names in
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59183
diff changeset
247 nil)))
a4aaaf92f7da (calc-user-define-formula): Put default values for function names in
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59183
diff changeset
248 (setq func
a4aaaf92f7da (calc-user-define-formula): Put default values for function names in
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59183
diff changeset
249 (if (string-equal func "calcFunc-")
a4aaaf92f7da (calc-user-define-formula): Put default values for function names in
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59183
diff changeset
250 (intern (concat "calcFunc-" cmd-base-default))
a4aaaf92f7da (calc-user-define-formula): Put default values for function names in
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59183
diff changeset
251 (intern func)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
252 (and func
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
253 (fboundp func)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
254 (not (fboundp cmd))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
255 odef
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
256 (not
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
257 (y-or-n-p
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
258 (if (get func 'calc-user-defn)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
259 (concat "Replace previous definition for "
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
260 (symbol-name func) "? ")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
261 "That name conflicts with a built-in Emacs function. Replace this function? "))))))
59184
a4aaaf92f7da (calc-user-define-formula): Put default values for function names in
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59183
diff changeset
262
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
263 (if (not func)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
264 (setq func (intern (concat "calcFunc-User"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
265 (or keyname
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
266 (and cmd (symbol-name cmd))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
267 (format "%05d" (% (random) 10000)))))))
59184
a4aaaf92f7da (calc-user-define-formula): Put default values for function names in
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59183
diff changeset
268
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
269 (if is-lambda
58390
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
270 (setq calc-user-formula-alist arglist)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
271 (while
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
272 (progn
105022
af84e9739140 (arglist): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 101001
diff changeset
273 (setq calc-user-formula-alist
58390
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
274 (read-from-minibuffer "Function argument list: "
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
275 (if arglist
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
276 (prin1-to-string arglist)
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
277 "()")
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
278 minibuffer-local-map
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
279 t))
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
280 (and (not (calc-subsetp calc-user-formula-alist arglist))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
281 (not (y-or-n-p
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
282 "Okay for arguments that don't appear in formula to be ignored? "))))))
58390
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
283 (setq is-symb (and calc-user-formula-alist
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
284 func
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
285 (y-or-n-p
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
286 "Leave it symbolic for non-constant arguments? ")))
105022
af84e9739140 (arglist): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 101001
diff changeset
287 (setq calc-user-formula-alist
58390
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
288 (mapcar (function (lambda (x)
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
289 (or (cdr (assq x '((nil . arg-nil)
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
290 (t . arg-t))))
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
291 x))) calc-user-formula-alist))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
292 (if cmd
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
293 (progn
58614
eba1cd703531 (calc-user-define-formula, calc-do-defmath): Replace calc-need-macros by
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58390
diff changeset
294 (require 'calc-macs)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
295 (fset cmd
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
296 (list 'lambda
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
297 '()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
298 '(interactive)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
299 (list 'calc-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
300 (list 'calc-enter-result
58390
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
301 (length calc-user-formula-alist)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
302 (let ((name (symbol-name (or func cmd))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
303 (and (string-match
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
304 "\\([^-][^-]?[^-]?[^-]?\\)[^-]*\\'"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
305 name)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
306 (math-match-substring name 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
307 (list 'cons
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
308 (list 'quote func)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
309 (list 'calc-top-list-n
58390
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
310 (length calc-user-formula-alist)))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
311 (put cmd 'calc-user-defn t)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
312 (let ((body (list 'math-normalize (calc-fix-user-formula form))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
313 (fset func
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
314 (append
58390
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
315 (list 'lambda calc-user-formula-alist)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
316 (and is-symb
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
317 (mapcar (function (lambda (v)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
318 (list 'math-check-const v t)))
58390
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
319 calc-user-formula-alist))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
320 (list body))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
321 (put func 'calc-user-defn form)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
322 (setq math-integral-cache-state nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
323 (if key
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
324 (let* ((kmap (calc-user-key-map))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
325 (old (assq key kmap)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
326 (if old
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
327 (setcdr old cmd)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
328 (setcdr kmap (cons (cons key cmd) (cdr kmap)))))))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
329 (message "")))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
330
105022
af84e9739140 (arglist): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 101001
diff changeset
331 (defvar arglist) ; dynamically bound in all callers
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
332 (defun calc-default-formula-arglist (form)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
333 (if (consp form)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
334 (if (eq (car form) 'var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
335 (if (or (memq (nth 1 form) arglist)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
336 (math-const-var form))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
337 ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
338 (setq arglist (cons (nth 1 form) arglist)))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
339 (calc-default-formula-arglist-step (cdr form)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
340
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
341 (defun calc-default-formula-arglist-step (l)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
342 (and l
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
343 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
344 (calc-default-formula-arglist (car l))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
345 (calc-default-formula-arglist-step (cdr l)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
346
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
347 (defun calc-subsetp (a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
348 (or (null a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
349 (and (memq (car a) b)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
350 (calc-subsetp (cdr a) b))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
351
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
352 (defun calc-fix-user-formula (f)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
353 (if (consp f)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
354 (let (temp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
355 (cond ((and (eq (car f) 'var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
356 (memq (setq temp (or (cdr (assq (nth 1 f) '((nil . arg-nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
357 (t . arg-t))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
358 (nth 1 f)))
58390
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
359 calc-user-formula-alist))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
360 temp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
361 ((or (math-constp f) (eq (car f) 'var))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
362 (list 'quote f))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
363 ((and (eq (car f) 'calcFunc-eval)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
364 (= (length f) 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
365 (list 'let '((calc-simplify-mode nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
366 (list 'math-normalize (calc-fix-user-formula (nth 1 f)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
367 ((and (eq (car f) 'calcFunc-evalsimp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
368 (= (length f) 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
369 (list 'math-simplify (calc-fix-user-formula (nth 1 f))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
370 ((and (eq (car f) 'calcFunc-evalextsimp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
371 (= (length f) 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
372 (list 'math-simplify-extended
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
373 (calc-fix-user-formula (nth 1 f))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
374 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
375 (cons 'list
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
376 (cons (list 'quote (car f))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
377 (mapcar 'calc-fix-user-formula (cdr f)))))))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
378 f))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
379
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
380 (defun calc-user-define-composition ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
381 (interactive)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
382 (calc-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
383 (if (eq calc-language 'unform)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
384 (error "Can't define formats for unformatted mode"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
385 (let* ((comp (calc-top 1))
105022
af84e9739140 (arglist): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 101001
diff changeset
386 (func (intern
59183
f27d7a9c6f27 (calc-user-define-permanent, calc-user-define-composition)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58668
diff changeset
387 (concat "calcFunc-"
f27d7a9c6f27 (calc-user-define-permanent, calc-user-define-composition)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58668
diff changeset
388 (completing-read "Define format for which function: "
f27d7a9c6f27 (calc-user-define-permanent, calc-user-define-composition)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58668
diff changeset
389 (mapcar (lambda (x) (substring x 9))
f27d7a9c6f27 (calc-user-define-permanent, calc-user-define-composition)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58668
diff changeset
390 (all-completions "calcFunc-"
f27d7a9c6f27 (calc-user-define-permanent, calc-user-define-composition)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58668
diff changeset
391 obarray))
105022
af84e9739140 (arglist): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 101001
diff changeset
392 (lambda (x)
af84e9739140 (arglist): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 101001
diff changeset
393 (fboundp
59183
f27d7a9c6f27 (calc-user-define-permanent, calc-user-define-composition)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58668
diff changeset
394 (intern (concat "calcFunc-" x))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
395 (comps (get func 'math-compose-forms))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
396 entry entry2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
397 (arglist nil)
58390
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
398 (calc-user-formula-alist nil))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
399 (if (math-zerop comp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
400 (if (setq entry (assq calc-language comps))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
401 (put func 'math-compose-forms (delq entry comps)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
402 (calc-default-formula-arglist comp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
403 (setq arglist (sort arglist 'string-lessp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
404 (while
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
405 (progn
105022
af84e9739140 (arglist): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 101001
diff changeset
406 (setq calc-user-formula-alist
58390
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
407 (read-from-minibuffer "Composition argument list: "
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
408 (if arglist
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
409 (prin1-to-string arglist)
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
410 "()")
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
411 minibuffer-local-map
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
412 t))
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
413 (and (not (calc-subsetp calc-user-formula-alist arglist))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
414 (y-or-n-p
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
415 "Okay for arguments that don't appear in formula to be invisible? "))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
416 (or (setq entry (assq calc-language comps))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
417 (put func 'math-compose-forms
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
418 (cons (setq entry (list calc-language)) comps)))
58390
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
419 (or (setq entry2 (assq (length calc-user-formula-alist) (cdr entry)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
420 (setcdr entry
105022
af84e9739140 (arglist): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 101001
diff changeset
421 (cons (setq entry2
58390
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
422 (list (length calc-user-formula-alist))) (cdr entry))))
105022
af84e9739140 (arglist): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 101001
diff changeset
423 (setcdr entry2
58390
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
424 (list 'lambda calc-user-formula-alist (calc-fix-user-formula comp))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
425 (calc-pop-stack 1)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
426 (calc-do-refresh))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
427
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
428
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
429 (defun calc-user-define-kbd-macro (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
430 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
431 (or last-kbd-macro
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
432 (error "No keyboard macro defined"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
433 (message "Define last kbd macro on user key: z-")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
434 (let ((key (read-char)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
435 (if (= (calc-user-function-classify key) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
436 (error "Can't redefine \"?\" key"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
437 (let ((cmd (intern (completing-read "Full name for new command: "
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
438 obarray
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
439 'commandp
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
440 nil
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
441 (concat "calc-User-"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
442 (if (or (and (>= key ?a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
443 (<= key ?z))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
444 (and (>= key ?A)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
445 (<= key ?Z))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
446 (and (>= key ?0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
447 (<= key ?9)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
448 (char-to-string key)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
449 (format "%03d" key)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
450 (and (fboundp cmd)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
451 (not (let ((f (symbol-function cmd)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
452 (or (stringp f)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
453 (and (consp f)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
454 (eq (car-safe (nth 3 f))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
455 'calc-execute-kbd-macro)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
456 (error "Function %s is already defined and not a keyboard macro"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
457 cmd))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
458 (put cmd 'calc-user-defn t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
459 (fset cmd (if (< (prefix-numeric-value arg) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
460 last-kbd-macro
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
461 (list 'lambda
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
462 '(arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
463 '(interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
464 (list 'calc-execute-kbd-macro
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
465 (vector (key-description last-kbd-macro)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
466 last-kbd-macro)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
467 'arg
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
468 (format "z%c" key)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
469 (let* ((kmap (calc-user-key-map))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
470 (old (assq key kmap)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
471 (if old
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
472 (setcdr old cmd)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
473 (setcdr kmap (cons (cons key cmd) (cdr kmap))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
474
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
475
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
476 (defun calc-edit-user-syntax ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
477 (interactive)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
478 (calc-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
479 (let ((lang calc-language))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
480 (calc-edit-mode (list 'calc-finish-user-syntax-edit (list 'quote lang))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
481 t
59298
bcf56eea4fb8 (calc-edit-user-syntax): Change title to edit mode to match new
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59295
diff changeset
482 (format "Editing %s-Mode Syntax Table. "
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
483 (cond ((null lang) "Normal")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
484 ((eq lang 'tex) "TeX")
59812
fb44bc67721e (calc-edit-user-syntax, calc-fix-token-name)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59641
diff changeset
485 ((eq lang 'latex) "LaTeX")
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
486 (t (capitalize (symbol-name lang))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
487 (calc-write-parse-table (cdr (assq lang calc-user-parse-tables))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
488 lang)))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
489 (calc-show-edit-buffer))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
490
58390
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
491 (defvar calc-original-buffer)
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
492
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
493 (defun calc-finish-user-syntax-edit (lang)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
494 (let ((tab (calc-read-parse-table calc-original-buffer lang))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
495 (entry (assq lang calc-user-parse-tables)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
496 (if tab
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
497 (setcdr (or entry
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
498 (car (setq calc-user-parse-tables
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
499 (cons (list lang) calc-user-parse-tables))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
500 tab)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
501 (if entry
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
502 (setq calc-user-parse-tables
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
503 (delq entry calc-user-parse-tables)))))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
504 (switch-to-buffer calc-original-buffer))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
505
58390
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
506 ;; The variable calc-lang is local to calc-write-parse-table, but is
105022
af84e9739140 (arglist): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 101001
diff changeset
507 ;; used by calc-write-parse-table-part which is called by
af84e9739140 (arglist): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 101001
diff changeset
508 ;; calc-write-parse-table. The variable is also local to
58390
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
509 ;; calc-read-parse-table, but is used by calc-fix-token-name which
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
510 ;; is called (indirectly) by calc-read-parse-table.
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
511 (defvar calc-lang)
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
512
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
513 (defun calc-write-parse-table (tab calc-lang)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
514 (let ((p tab))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
515 (while p
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
516 (calc-write-parse-table-part (car (car p)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
517 (insert ":= "
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
518 (let ((math-format-hash-args t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
519 (math-format-flat-expr (cdr (car p)) 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
520 "\n")
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
521 (setq p (cdr p)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
522
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
523 (defun calc-write-parse-table-part (p)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
524 (while p
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
525 (cond ((stringp (car p))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
526 (let ((s (car p)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
527 (if (and (string-match "\\`\\\\dots\\>" s)
59983
d3632c99711e (calc-write-parse-table-part, calc-fix-token-name): Fix a check for
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59812
diff changeset
528 (not (memq calc-lang '(tex latex))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
529 (setq s (concat ".." (substring s 5))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
530 (if (or (and (string-match
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
531 "[a-zA-Z0-9\"{}]\\|\\`:=\\'\\|\\`#\\|\\`%%" s)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
532 (string-match "[^a-zA-Z0-9\\]" s))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
533 (and (assoc s '((")") ("]") (">")))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
534 (not (cdr p))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
535 (insert (prin1-to-string s) " ")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
536 (insert s " "))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
537 ((integerp (car p))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
538 (insert "#")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
539 (or (= (car p) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
540 (insert "/" (int-to-string (car p))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
541 (insert " "))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
542 ((and (eq (car (car p)) '\?) (equal (car (nth 2 (car p))) "$$"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
543 (insert (car (nth 1 (car p))) " "))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
544 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
545 (insert "{ ")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
546 (calc-write-parse-table-part (nth 1 (car p)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
547 (insert "}" (symbol-name (car (car p))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
548 (if (nth 2 (car p))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
549 (calc-write-parse-table-part (list (car (nth 2 (car p)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
550 (insert " "))))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
551 (setq p (cdr p))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
552
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
553 (defun calc-read-parse-table (calc-buf calc-lang)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
554 (let ((tab nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
555 (while (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
556 (skip-chars-forward "\n\t ")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
557 (not (eobp)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
558 (if (looking-at "%%")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
559 (end-of-line)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
560 (let ((pt (point))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
561 (p (calc-read-parse-table-part ":=[\n\t ]+" ":=")))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
562 (or (stringp (car p))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
563 (and (integerp (car p))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
564 (stringp (nth 1 p)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
565 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
566 (goto-char pt)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
567 (error "Malformed syntax rule")))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
568 (let ((pos (point)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
569 (end-of-line)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
570 (let* ((str (buffer-substring pos (point)))
105792
2c12fbae77c2 * calc/calc.el (calc, calc-refresh, calc-trail-buffer, calc-record)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 105275
diff changeset
571 (exp (with-current-buffer calc-buf
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
572 (let ((calc-user-parse-tables nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
573 (calc-language nil)
81471
46f072d4a30f (calc-read-parse-table): Let math-expr-opers equal the function
Jay Belanger <jay.p.belanger@gmail.com>
parents: 77465
diff changeset
574 (math-expr-opers (math-standard-ops))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
575 (calc-hashes-used 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
576 (math-read-expr
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
577 (if (string-match ",[ \t]*\\'" str)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
578 (substring str 0 (match-beginning 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
579 str))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
580 (if (eq (car-safe exp) 'error)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
581 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
582 (goto-char (+ pos (nth 1 exp)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
583 (error (nth 2 exp))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
584 (setq tab (nconc tab (list (cons p exp)))))))))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
585 tab))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
586
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
587 (defun calc-fix-token-name (name &optional unquoted)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
588 (cond ((string-match "\\`\\.\\." name)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
589 (concat "\\dots" (substring name 2)))
59812
fb44bc67721e (calc-edit-user-syntax, calc-fix-token-name)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59641
diff changeset
590 ((and (equal name "{") (memq calc-lang '(tex latex eqn)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
591 "(")
59812
fb44bc67721e (calc-edit-user-syntax, calc-fix-token-name)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59641
diff changeset
592 ((and (equal name "}") (memq calc-lang '(tex latex eqn)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
593 ")")
59983
d3632c99711e (calc-write-parse-table-part, calc-fix-token-name): Fix a check for
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59812
diff changeset
594 ((and (equal name "&") (memq calc-lang '(tex latex)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
595 ",")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
596 ((equal name "#")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
597 (search-backward "#")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
598 (error "Token '#' is reserved"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
599 ((and unquoted (string-match "#" name))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
600 (error "Tokens containing '#' must be quoted"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
601 ((not (string-match "[^ ]" name))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
602 (search-backward "\"" nil t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
603 (error "Blank tokens are not allowed"))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
604 (t name)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
605
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
606 (defun calc-read-parse-table-part (term eterm)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
607 (let ((part nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
608 (quoted nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
609 (while (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
610 (skip-chars-forward "\n\t ")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
611 (if (eobp) (error "Expected '%s'" eterm))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
612 (not (looking-at term)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
613 (cond ((looking-at "%%")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
614 (end-of-line))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
615 ((looking-at "{[\n\t ]")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
616 (forward-char 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
617 (let ((p (calc-read-parse-table-part "}" "}")))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
618 (or (looking-at "[+*?]")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
619 (error "Expected '+', '*', or '?'"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
620 (let ((sym (intern (buffer-substring (point) (1+ (point))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
621 (forward-char 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
622 (looking-at "[^\n\t ]*")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
623 (let ((sep (buffer-substring (point) (match-end 0))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
624 (goto-char (match-end 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
625 (and (eq sym '\?) (> (length sep) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
626 (not (equal sep "$")) (not (equal sep "."))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
627 (error "Separator not allowed with { ... }?"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
628 (if (string-match "\\`\"" sep)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
629 (setq sep (read-from-string sep)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
630 (setq sep (calc-fix-token-name sep))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
631 (setq part (nconc part
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
632 (list (list sym p
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
633 (and (> (length sep) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
634 (cons sep p))))))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
635 ((looking-at "}")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
636 (error "Too many }'s"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
637 ((looking-at "\"")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
638 (setq quoted (calc-fix-token-name (read (current-buffer)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
639 part (nconc part (list quoted))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
640 ((looking-at "#\\(\\(/[0-9]+\\)?\\)[\n\t ]")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
641 (setq part (nconc part (list (if (= (match-beginning 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
642 (match-end 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
643 0
62038
a5b38402e3e1 (calc-read-parse-table-part, calc-edit-macro-repeats): Replace
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60170
diff changeset
644 (string-to-number
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
645 (buffer-substring
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
646 (1+ (match-beginning 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
647 (match-end 1)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
648 (goto-char (match-end 0)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
649 ((looking-at ":=[\n\t ]")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
650 (error "Misplaced ':='"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
651 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
652 (looking-at "[^\n\t ]*")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
653 (let ((end (match-end 0)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
654 (setq part (nconc part (list (calc-fix-token-name
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
655 (buffer-substring
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
656 (point) end) t))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
657 (goto-char end)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
658 (goto-char (match-end 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
659 (let ((len (length part)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
660 (while (and (> len 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
661 (let ((last (nthcdr (setq len (1- len)) part)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
662 (and (assoc (car last) '((")") ("]") (">")))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
663 (not (eq (car last) quoted))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
664 (setcar last
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
665 (list '\? (list (car last)) '("$$"))))))))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
666 part))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
667
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
668 (defun calc-user-define-invocation ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
669 (interactive)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
670 (or last-kbd-macro
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
671 (error "No keyboard macro defined"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
672 (setq calc-invocation-macro last-kbd-macro)
67193
738cfb5e451f (calc-user-define-invokation): Update help message.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65680
diff changeset
673 (message "Use `C-x * Z' to invoke this macro"))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
674
59295
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
675 (defun calc-user-define-edit ()
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
676 (interactive) ; but no calc-wrapper!
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
677 (message "Edit definition of command: z-")
60170
259cc4e04cd1 (calc-user-define-edit): Add local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59983
diff changeset
678 (let* (cmdname
259cc4e04cd1 (calc-user-define-edit): Add local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59983
diff changeset
679 (key (read-char))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
680 (def (or (assq key (calc-user-key-map))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
681 (assq (upcase key) (calc-user-key-map))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
682 (assq (downcase key) (calc-user-key-map))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
683 (error "No command defined for that key")))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
684 (cmd (cdr def)))
59295
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
685 (when (symbolp cmd)
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
686 (setq cmdname (symbol-name cmd))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
687 (setq cmd (symbol-function cmd)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
688 (cond ((or (stringp cmd)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
689 (and (consp cmd)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
690 (eq (car-safe (nth 3 cmd)) 'calc-execute-kbd-macro)))
59295
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
691 (let* ((mac (elt (nth 1 (nth 3 cmd)) 1))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
692 (str (edmacro-format-keys mac t))
59298
bcf56eea4fb8 (calc-edit-user-syntax): Change title to edit mode to match new
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59295
diff changeset
693 (kys (nth 3 (nth 3 cmd))))
105022
af84e9739140 (arglist): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 101001
diff changeset
694 (calc-edit-mode
59298
bcf56eea4fb8 (calc-edit-user-syntax): Change title to edit mode to match new
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59295
diff changeset
695 (list 'calc-edit-macro-finish-edit cmdname kys)
105022
af84e9739140 (arglist): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 101001
diff changeset
696 t (format (concat
af84e9739140 (arglist): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 101001
diff changeset
697 "Editing keyboard macro (%s, bound to %s).\n"
59309
5a2b8e50c551 (calc-edit-macro-finish-edit, calc-finish-formula-edit)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59303
diff changeset
698 "Original keys: %s \n")
5a2b8e50c551 (calc-edit-macro-finish-edit, calc-finish-formula-edit)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59303
diff changeset
699 cmdname kys (elt (nth 1 (nth 3 cmd)) 0)))
59295
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
700 (insert str "\n")
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
701 (calc-edit-format-macro-buffer)
59309
5a2b8e50c551 (calc-edit-macro-finish-edit, calc-finish-formula-edit)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59303
diff changeset
702 (calc-show-edit-buffer)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
703 (t (let* ((func (calc-stack-command-p cmd))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
704 (defn (and func
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
705 (symbolp func)
59298
bcf56eea4fb8 (calc-edit-user-syntax): Change title to edit mode to match new
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59295
diff changeset
706 (get func 'calc-user-defn)))
bcf56eea4fb8 (calc-edit-user-syntax): Change title to edit mode to match new
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59295
diff changeset
707 (kys (concat "z" (char-to-string (car def))))
bcf56eea4fb8 (calc-edit-user-syntax): Change title to edit mode to match new
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59295
diff changeset
708 (intcmd (symbol-name (cdr def)))
62717
5aa3c60503e2 (calc-user-define-edit): Don't find substring of nil.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 62391
diff changeset
709 (algcmd (if func (substring (symbol-name func) 9) "")))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
710 (if (and defn (calc-valid-formula-func func))
59641
292caf631179 (calc-user-define-edit): Put original formula in formula editing buffer.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59631
diff changeset
711 (let ((niceexpr (math-format-nice-expr defn (frame-width))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
712 (calc-wrapper
105022
af84e9739140 (arglist): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 101001
diff changeset
713 (calc-edit-mode
59298
bcf56eea4fb8 (calc-edit-user-syntax): Change title to edit mode to match new
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59295
diff changeset
714 (list 'calc-finish-formula-edit (list 'quote func))
bcf56eea4fb8 (calc-edit-user-syntax): Change title to edit mode to match new
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59295
diff changeset
715 nil
59641
292caf631179 (calc-user-define-edit): Put original formula in formula editing buffer.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59631
diff changeset
716 (format (concat
292caf631179 (calc-user-define-edit): Put original formula in formula editing buffer.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59631
diff changeset
717 "Editing formula (%s, %s, bound to %s).\n"
292caf631179 (calc-user-define-edit): Put original formula in formula editing buffer.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59631
diff changeset
718 "Original formula: %s\n")
292caf631179 (calc-user-define-edit): Put original formula in formula editing buffer.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59631
diff changeset
719 intcmd algcmd kys niceexpr))
59303
603f6649f30b (calc-edit-user-formula, calc-finish-formula-edit): Handle extra line
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59298
diff changeset
720 (insert (math-showing-full-precision
59641
292caf631179 (calc-user-define-edit): Put original formula in formula editing buffer.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59631
diff changeset
721 niceexpr)
59303
603f6649f30b (calc-edit-user-formula, calc-finish-formula-edit): Handle extra line
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59298
diff changeset
722 "\n"))
59309
5a2b8e50c551 (calc-edit-macro-finish-edit, calc-finish-formula-edit)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59303
diff changeset
723 (calc-show-edit-buffer))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
724 (error "That command's definition cannot be edited")))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
725
59295
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
726 ;; Formatting the macro buffer
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
727
60170
259cc4e04cd1 (calc-user-define-edit): Add local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59983
diff changeset
728 (defvar calc-edit-top)
259cc4e04cd1 (calc-user-define-edit): Add local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59983
diff changeset
729
59295
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
730 (defun calc-edit-macro-repeats ()
59309
5a2b8e50c551 (calc-edit-macro-finish-edit, calc-finish-formula-edit)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59303
diff changeset
731 (goto-char calc-edit-top)
59295
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
732 (while
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
733 (re-search-forward "^\\([0-9]+\\)\\*" nil t)
62038
a5b38402e3e1 (calc-read-parse-table-part, calc-edit-macro-repeats): Replace
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60170
diff changeset
734 (let ((num (string-to-number (match-string 1)))
60170
259cc4e04cd1 (calc-user-define-edit): Add local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59983
diff changeset
735 (line (buffer-substring (point) (line-end-position))))
259cc4e04cd1 (calc-user-define-edit): Add local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59983
diff changeset
736 (goto-char (line-beginning-position))
259cc4e04cd1 (calc-user-define-edit): Add local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59983
diff changeset
737 (kill-line 1)
259cc4e04cd1 (calc-user-define-edit): Add local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59983
diff changeset
738 (while (> num 0)
259cc4e04cd1 (calc-user-define-edit): Add local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59983
diff changeset
739 (insert line "\n")
259cc4e04cd1 (calc-user-define-edit): Add local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59983
diff changeset
740 (setq num (1- num))))))
59295
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
741
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
742 (defun calc-edit-macro-adjust-buffer ()
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
743 (calc-edit-macro-repeats)
59309
5a2b8e50c551 (calc-edit-macro-finish-edit, calc-finish-formula-edit)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59303
diff changeset
744 (goto-char calc-edit-top)
59295
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
745 (while (re-search-forward "^RET$" nil t)
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
746 (delete-char 1))
59309
5a2b8e50c551 (calc-edit-macro-finish-edit, calc-finish-formula-edit)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59303
diff changeset
747 (goto-char calc-edit-top)
59295
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
748 (while (and (re-search-forward "^$" nil t)
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
749 (not (= (point) (point-max))))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
750 (delete-char 1)))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
751
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
752 (defun calc-edit-macro-command ()
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
753 "Return the command on the current line in a Calc macro editing buffer."
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
754 (let ((beg (line-beginning-position))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
755 (end (save-excursion
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
756 (if (search-forward ";;" (line-end-position) 1)
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
757 (forward-char -2))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
758 (skip-chars-backward " \t")
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
759 (point))))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
760 (buffer-substring beg end)))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
761
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
762 (defun calc-edit-macro-command-type ()
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
763 "Return the type of command on the current line in a Calc macro editing buffer."
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
764 (let ((beg (save-excursion
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
765 (if (search-forward ";;" (line-end-position) t)
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
766 (progn
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
767 (skip-chars-forward " \t")
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
768 (point)))))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
769 (end (save-excursion
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
770 (goto-char (line-end-position))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
771 (skip-chars-backward " \t")
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
772 (point))))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
773 (if beg
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
774 (buffer-substring beg end)
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
775 "")))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
776
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
777 (defun calc-edit-macro-combine-alg-ent ()
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
778 "Put an entire algebraic entry on a single line."
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
779 (let ((line (calc-edit-macro-command))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
780 (type (calc-edit-macro-command-type))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
781 curline
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
782 match)
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
783 (goto-char (line-beginning-position))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
784 (kill-line 1)
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
785 (setq curline (calc-edit-macro-command))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
786 (while (and curline
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
787 (not (string-equal "RET" curline))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
788 (not (setq match (string-match "<return>" curline))))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
789 (setq line (concat line curline))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
790 (kill-line 1)
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
791 (setq curline (calc-edit-macro-command)))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
792 (when match
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
793 (kill-line 1)
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
794 (setq line (concat line (substring curline 0 match))))
105022
af84e9739140 (arglist): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 101001
diff changeset
795 (setq line (replace-regexp-in-string "SPC" " SPC "
59295
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
796 (replace-regexp-in-string " " "" line)))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
797 (insert line "\t\t\t")
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
798 (if (> (current-column) 24)
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
799 (delete-char -1))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
800 (insert ";; " type "\n")
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
801 (if match
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
802 (insert "RET\t\t\t;; calc-enter\n"))))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
803
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
804 (defun calc-edit-macro-combine-ext-command ()
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
805 "Put an entire extended command on a single line."
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
806 (let ((cmdbeg (calc-edit-macro-command))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
807 (line "")
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
808 (type (calc-edit-macro-command-type))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
809 curline
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
810 match)
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
811 (goto-char (line-beginning-position))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
812 (kill-line 1)
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
813 (setq curline (calc-edit-macro-command))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
814 (while (and curline
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
815 (not (string-equal "RET" curline))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
816 (not (setq match (string-match "<return>" curline))))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
817 (setq line (concat line curline))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
818 (kill-line 1)
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
819 (setq curline (calc-edit-macro-command)))
105022
af84e9739140 (arglist): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 101001
diff changeset
820 (when match
59295
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
821 (kill-line 1)
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
822 (setq line (concat line (substring curline 0 match))))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
823 (setq line (replace-regexp-in-string " " "" line))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
824 (insert cmdbeg " " line "\t\t\t")
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
825 (if (> (current-column) 24)
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
826 (delete-char -1))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
827 (insert ";; " type "\n")
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
828 (if match
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
829 (insert "RET\t\t\t;; calc-enter\n"))))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
830
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
831 (defun calc-edit-macro-combine-var-name ()
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
832 "Put an entire variable name on a single line."
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
833 (let ((line (calc-edit-macro-command))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
834 curline
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
835 match)
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
836 (goto-char (line-beginning-position))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
837 (kill-line 1)
59298
bcf56eea4fb8 (calc-edit-user-syntax): Change title to edit mode to match new
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59295
diff changeset
838 (if (member line '("0" "1" "2" "3" "4" "5" "6" "7" "8" "9"))
59295
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
839 (insert line "\t\t\t;; calc quick variable\n")
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
840 (setq curline (calc-edit-macro-command))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
841 (while (and curline
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
842 (not (string-equal "RET" curline))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
843 (not (setq match (string-match "<return>" curline))))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
844 (setq line (concat line curline))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
845 (kill-line 1)
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
846 (setq curline (calc-edit-macro-command)))
105022
af84e9739140 (arglist): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 101001
diff changeset
847 (when match
59295
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
848 (kill-line 1)
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
849 (setq line (concat line (substring curline 0 match))))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
850 (setq line (replace-regexp-in-string " " "" line))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
851 (insert line "\t\t\t")
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
852 (if (> (current-column) 24)
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
853 (delete-char -1))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
854 (insert ";; calc variable\n")
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
855 (if match
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
856 (insert "RET\t\t\t;; calc-enter\n")))))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
857
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
858 (defun calc-edit-macro-combine-digits ()
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
859 "Put an entire sequence of digits on a single line."
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
860 (let ((line (calc-edit-macro-command))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
861 curline)
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
862 (goto-char (line-beginning-position))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
863 (kill-line 1)
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
864 (while (string-equal (calc-edit-macro-command-type) "calcDigit-start")
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
865 (setq line (concat line (calc-edit-macro-command)))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
866 (kill-line 1))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
867 (insert line "\t\t\t")
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
868 (if (> (current-column) 24)
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
869 (delete-char -1))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
870 (insert ";; calc digits\n")))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
871
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
872 (defun calc-edit-format-macro-buffer ()
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
873 "Rewrite the Calc macro editing buffer."
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
874 (calc-edit-macro-adjust-buffer)
59309
5a2b8e50c551 (calc-edit-macro-finish-edit, calc-finish-formula-edit)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59303
diff changeset
875 (goto-char calc-edit-top)
59295
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
876 (let ((type (calc-edit-macro-command-type)))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
877 (while (not (string-equal type ""))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
878 (cond
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
879 ((or
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
880 (string-equal type "calc-algebraic-entry")
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
881 (string-equal type "calc-auto-algebraic-entry"))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
882 (calc-edit-macro-combine-alg-ent))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
883 ((string-equal type "calc-execute-extended-command")
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
884 (calc-edit-macro-combine-ext-command))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
885 ((string-equal type "calcDigit-start")
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
886 (calc-edit-macro-combine-digits))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
887 ((or
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
888 (string-equal type "calc-store")
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
889 (string-equal type "calc-store-into")
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
890 (string-equal type "calc-store-neg")
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
891 (string-equal type "calc-store-plus")
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
892 (string-equal type "calc-store-minus")
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
893 (string-equal type "calc-store-div")
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
894 (string-equal type "calc-store-times")
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
895 (string-equal type "calc-store-power")
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
896 (string-equal type "calc-store-concat")
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
897 (string-equal type "calc-store-inv")
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
898 (string-equal type "calc-store-dec")
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
899 (string-equal type "calc-store-incr")
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
900 (string-equal type "calc-store-exchange")
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
901 (string-equal type "calc-unstore")
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
902 (string-equal type "calc-recall")
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
903 (string-equal type "calc-let")
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
904 (string-equal type "calc-permanent-variable"))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
905 (forward-line 1)
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
906 (calc-edit-macro-combine-var-name))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
907 ((or
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
908 (string-equal type "calc-copy-variable")
62391
65d4d337ea31 (calc-edit-format-macro-buffer): Add `calc-copy-special-constant'.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 62038
diff changeset
909 (string-equal type "calc-copy-special-constant")
59295
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
910 (string-equal type "calc-declare-variable"))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
911 (forward-line 1)
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
912 (calc-edit-macro-combine-var-name)
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
913 (calc-edit-macro-combine-var-name))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
914 (t (forward-line 1)))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
915 (setq type (calc-edit-macro-command-type))))
59309
5a2b8e50c551 (calc-edit-macro-finish-edit, calc-finish-formula-edit)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59303
diff changeset
916 (goto-char calc-edit-top))
59295
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
917
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
918 ;; Finish editing the macro
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
919
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
920 (defun calc-edit-macro-pre-finish-edit ()
59309
5a2b8e50c551 (calc-edit-macro-finish-edit, calc-finish-formula-edit)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59303
diff changeset
921 (goto-char calc-edit-top)
59295
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
922 (while (re-search-forward "\\(^\\| \\)RET\\($\\|\t\\| \\)" nil t)
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
923 (search-backward "RET")
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
924 (delete-char 3)
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
925 (insert "<return>")))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
926
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
927 (defun calc-edit-macro-finish-edit (cmdname key)
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
928 "Finish editing a Calc macro.
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
929 Redefine the corresponding command."
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
930 (interactive)
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
931 (let ((cmd (intern cmdname)))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
932 (calc-edit-macro-pre-finish-edit)
59309
5a2b8e50c551 (calc-edit-macro-finish-edit, calc-finish-formula-edit)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59303
diff changeset
933 (let* ((str (buffer-substring calc-edit-top (point-max)))
59295
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
934 (mac (edmacro-parse-keys str t)))
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
935 (if (= (length mac) 0)
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
936 (fmakunbound cmd)
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
937 (fset cmd
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
938 (list 'lambda '(arg)
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
939 '(interactive "P")
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
940 (list 'calc-execute-kbd-macro
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
941 (vector (key-description mac)
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
942 mac)
009c629ee755 (calc-finish-macro-edit): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59229
diff changeset
943 'arg key)))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
944
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
945 (defun calc-finish-formula-edit (func)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
946 (let ((buf (current-buffer))
59309
5a2b8e50c551 (calc-edit-macro-finish-edit, calc-finish-formula-edit)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59303
diff changeset
947 (str (buffer-substring calc-edit-top (point-max)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
948 (start (point))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
949 (body (calc-valid-formula-func func)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
950 (set-buffer calc-original-buffer)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
951 (let ((val (math-read-expr str)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
952 (if (eq (car-safe val) 'error)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
953 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
954 (set-buffer buf)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
955 (goto-char (+ start (nth 1 val)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
956 (error (nth 2 val))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
957 (setcar (cdr body)
58390
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
958 (let ((calc-user-formula-alist (nth 1 (symbol-function func))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
959 (calc-fix-user-formula val)))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
960 (put func 'calc-user-defn val))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
961
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
962 (defun calc-valid-formula-func (func)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
963 (let ((def (symbol-function func)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
964 (and (consp def)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
965 (eq (car def) 'lambda)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
966 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
967 (setq def (cdr (cdr def)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
968 (while (and def
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
969 (not (eq (car (car def)) 'math-normalize)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
970 (setq def (cdr def)))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
971 (car def)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
972
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
973
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
974 (defun calc-get-user-defn ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
975 (interactive)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
976 (calc-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
977 (message "Get definition of command: z-")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
978 (let* ((key (read-char))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
979 (def (or (assq key (calc-user-key-map))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
980 (assq (upcase key) (calc-user-key-map))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
981 (assq (downcase key) (calc-user-key-map))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
982 (error "No command defined for that key")))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
983 (cmd (cdr def)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
984 (if (symbolp cmd)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
985 (setq cmd (symbol-function cmd)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
986 (cond ((stringp cmd)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
987 (message "Keyboard macro: %s" cmd))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
988 (t (let* ((func (calc-stack-command-p cmd))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
989 (defn (and func
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
990 (symbolp func)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
991 (get func 'calc-user-defn))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
992 (if defn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
993 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
994 (and (calc-valid-formula-func func)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
995 (setq defn (append '(calcFunc-lambda)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
996 (mapcar 'math-build-var-name
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
997 (nth 1 (symbol-function
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
998 func)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
999 (list defn))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1000 (calc-enter-result 0 "gdef" defn))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1001 (error "That command is not defined by a formula"))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1002
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1003
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1004 (defun calc-user-define-permanent ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1005 (interactive)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1006 (calc-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1007 (message "Record in %s the command: z-" calc-settings-file)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1008 (let* ((key (read-char))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1009 (def (or (assq key (calc-user-key-map))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1010 (assq (upcase key) (calc-user-key-map))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1011 (assq (downcase key) (calc-user-key-map))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49263
diff changeset
1012 (and (eq key ?\')
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1013 (cons nil
59183
f27d7a9c6f27 (calc-user-define-permanent, calc-user-define-composition)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58668
diff changeset
1014 (intern
f27d7a9c6f27 (calc-user-define-permanent, calc-user-define-composition)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58668
diff changeset
1015 (concat "calcFunc-"
f27d7a9c6f27 (calc-user-define-permanent, calc-user-define-composition)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58668
diff changeset
1016 (completing-read
f27d7a9c6f27 (calc-user-define-permanent, calc-user-define-composition)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58668
diff changeset
1017 (format "Record in %s the algebraic function: "
f27d7a9c6f27 (calc-user-define-permanent, calc-user-define-composition)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58668
diff changeset
1018 calc-settings-file)
f27d7a9c6f27 (calc-user-define-permanent, calc-user-define-composition)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58668
diff changeset
1019 (mapcar (lambda (x) (substring x 9))
f27d7a9c6f27 (calc-user-define-permanent, calc-user-define-composition)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58668
diff changeset
1020 (all-completions "calcFunc-"
f27d7a9c6f27 (calc-user-define-permanent, calc-user-define-composition)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58668
diff changeset
1021 obarray))
105022
af84e9739140 (arglist): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 101001
diff changeset
1022 (lambda (x)
af84e9739140 (arglist): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 101001
diff changeset
1023 (fboundp
59183
f27d7a9c6f27 (calc-user-define-permanent, calc-user-define-composition)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58668
diff changeset
1024 (intern (concat "calcFunc-" x))))
f27d7a9c6f27 (calc-user-define-permanent, calc-user-define-composition)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58668
diff changeset
1025 t)))))
f27d7a9c6f27 (calc-user-define-permanent, calc-user-define-composition)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58668
diff changeset
1026 (and (eq key ?\M-x)
f27d7a9c6f27 (calc-user-define-permanent, calc-user-define-composition)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58668
diff changeset
1027 (cons nil
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1028 (intern (completing-read
59183
f27d7a9c6f27 (calc-user-define-permanent, calc-user-define-composition)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58668
diff changeset
1029 (format "Record in %s the command: "
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1030 calc-settings-file)
59183
f27d7a9c6f27 (calc-user-define-permanent, calc-user-define-composition)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58668
diff changeset
1031 obarray 'fboundp nil "calc-"))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1032 (error "No command defined for that key"))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1033 (set-buffer (find-file-noselect (substitute-in-file-name
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1034 calc-settings-file)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1035 (goto-char (point-max))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1036 (let* ((cmd (cdr def))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1037 (fcmd (and cmd (symbolp cmd) (symbol-function cmd)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1038 (func nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1039 (pt (point))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1040 (fill-column 70)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1041 (fill-prefix nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1042 str q-ok)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1043 (insert "\n;;; Definition stored by Calc on " (current-time-string)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1044 "\n(put 'calc-define '"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1045 (if (symbolp cmd) (symbol-name cmd) (format "key%d" key))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1046 " '(progn\n")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1047 (if (and fcmd
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1048 (eq (car-safe fcmd) 'lambda)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1049 (get cmd 'calc-user-defn))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1050 (let ((pt (point)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1051 (and (eq (car-safe (nth 3 fcmd)) 'calc-execute-kbd-macro)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1052 (vectorp (nth 1 (nth 3 fcmd)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1053 (progn (and (fboundp 'edit-kbd-macro)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1054 (edit-kbd-macro nil))
59218
644d716928bd (calc-user-define-edit, calc-finish-macro-edit)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59184
diff changeset
1055 (fboundp 'edmacro-parse-keys))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1056 (setq q-ok t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1057 (aset (nth 1 (nth 3 fcmd)) 1 nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1058 (insert (setq str (prin1-to-string
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1059 (cons 'defun (cons cmd (cdr fcmd)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1060 "\n")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1061 (or (and (string-match "\"" str) (not q-ok))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1062 (fill-region pt (point)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1063 (indent-rigidly pt (point) 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1064 (delete-region pt (1+ pt))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1065 (insert " (put '" (symbol-name cmd)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1066 " 'calc-user-defn '"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1067 (prin1-to-string (get cmd 'calc-user-defn))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1068 ")\n")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1069 (setq func (calc-stack-command-p cmd))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1070 (let ((ffunc (and func (symbolp func) (symbol-function func)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1071 (pt (point)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1072 (and ffunc
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1073 (eq (car-safe ffunc) 'lambda)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1074 (get func 'calc-user-defn)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1075 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1076 (insert (setq str (prin1-to-string
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1077 (cons 'defun (cons func
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1078 (cdr ffunc)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1079 "\n")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1080 (or (and (string-match "\"" str) (not q-ok))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1081 (fill-region pt (point)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1082 (indent-rigidly pt (point) 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1083 (delete-region pt (1+ pt))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1084 (setq pt (point))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1085 (insert "(put '" (symbol-name func)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1086 " 'calc-user-defn '"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1087 (prin1-to-string (get func 'calc-user-defn))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1088 ")\n")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1089 (fill-region pt (point))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1090 (indent-rigidly pt (point) 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1091 (delete-region pt (1+ pt))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1092 (and (stringp fcmd)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1093 (insert " (fset '" (prin1-to-string cmd)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1094 " " (prin1-to-string fcmd) ")\n")))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1095 (or func (setq func (and cmd (symbolp cmd) (fboundp cmd) cmd)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1096 (if (get func 'math-compose-forms)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1097 (let ((pt (point)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1098 (insert "(put '" (symbol-name cmd)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1099 " 'math-compose-forms '"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1100 (prin1-to-string (get func 'math-compose-forms))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1101 ")\n")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1102 (fill-region pt (point))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1103 (indent-rigidly pt (point) 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1104 (delete-region pt (1+ pt))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1105 (if (car def)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1106 (insert " (define-key calc-mode-map "
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1107 (prin1-to-string (concat "z" (char-to-string key)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1108 " '"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1109 (prin1-to-string cmd)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1110 ")\n")))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1111 (insert "))\n")
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1112 (save-buffer))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1113
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1114 (defun calc-stack-command-p (cmd)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1115 (if (and cmd (symbolp cmd))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1116 (and (fboundp cmd)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1117 (calc-stack-command-p (symbol-function cmd)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1118 (and (consp cmd)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1119 (eq (car cmd) 'lambda)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1120 (setq cmd (or (assq 'calc-wrapper cmd)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1121 (assq 'calc-slow-wrapper cmd)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1122 (setq cmd (assq 'calc-enter-result cmd))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1123 (memq (car (nth 3 cmd)) '(cons list))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1124 (eq (car (nth 1 (nth 3 cmd))) 'quote)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1125 (nth 1 (nth 1 (nth 3 cmd))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1126
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1127
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1128 (defun calc-call-last-kbd-macro (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1129 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1130 (and defining-kbd-macro
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1131 (error "Can't execute anonymous macro while defining one"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1132 (or last-kbd-macro
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1133 (error "No kbd macro has been defined"))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1134 (calc-execute-kbd-macro last-kbd-macro arg))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1135
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1136 (defun calc-execute-kbd-macro (mac arg &rest prefix)
59631
5f8090982771 (calc-execute-kbd-macro): Ignore calc-keep-arg-flag.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59309
diff changeset
1137 (if calc-keep-args-flag
5f8090982771 (calc-execute-kbd-macro): Ignore calc-keep-arg-flag.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59309
diff changeset
1138 (calc-keep-args))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1139 (if (and (vectorp mac) (> (length mac) 0) (stringp (aref mac 0)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1140 (setq mac (or (aref mac 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1141 (aset mac 1 (progn (and (fboundp 'edit-kbd-macro)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1142 (edit-kbd-macro nil))
59218
644d716928bd (calc-user-define-edit, calc-finish-macro-edit)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59184
diff changeset
1143 (edmacro-parse-keys (aref mac 0)))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1144 (if (< (prefix-numeric-value arg) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1145 (execute-kbd-macro mac (- (prefix-numeric-value arg)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1146 (if calc-executing-macro
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1147 (execute-kbd-macro mac arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1148 (calc-slow-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1149 (let ((old-stack-whole (copy-sequence calc-stack))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1150 (old-stack-top calc-stack-top)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1151 (old-buffer-size (buffer-size))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1152 (old-refresh-count calc-refresh-count))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1153 (unwind-protect
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1154 (let ((calc-executing-macro mac))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1155 (execute-kbd-macro mac arg))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1156 (calc-select-buffer)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1157 (let ((new-stack (reverse calc-stack))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1158 (old-stack (reverse old-stack-whole)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1159 (while (and new-stack old-stack
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1160 (equal (car new-stack) (car old-stack)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1161 (setq new-stack (cdr new-stack)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1162 old-stack (cdr old-stack)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1163 (or (equal prefix '(nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1164 (calc-record-list (if (> (length new-stack) 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1165 (mapcar 'car new-stack)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1166 '(""))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1167 (or (car prefix) "kmac")))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1168 (calc-record-undo (list 'set 'saved-stack-top old-stack-top))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1169 (and old-stack
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1170 (calc-record-undo (list 'pop 1 (mapcar 'car old-stack))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1171 (let ((calc-stack old-stack-whole)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1172 (calc-stack-top 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1173 (calc-cursor-stack-index (length old-stack)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1174 (if (and (= old-buffer-size (buffer-size))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1175 (= old-refresh-count calc-refresh-count))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1176 (let ((buffer-read-only nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1177 (delete-region (point) (point-max))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1178 (while new-stack
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1179 (calc-record-undo (list 'push 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1180 (insert (math-format-stack-value (car new-stack)) "\n")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1181 (setq new-stack (cdr new-stack)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1182 (calc-renumber-stack))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1183 (while new-stack
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1184 (calc-record-undo (list 'push 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1185 (setq new-stack (cdr new-stack)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1186 (calc-refresh))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1187 (calc-record-undo (list 'set 'saved-stack-top 0)))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1188
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1189 (defun calc-push-list-in-macro (vals m sels)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1190 (let ((entry (list (car vals) 1 (car sels)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1191 (mm (+ (or m 1) calc-stack-top)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1192 (if (> mm 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1193 (setcdr (nthcdr (- mm 2) calc-stack)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1194 (cons entry (nthcdr (1- mm) calc-stack)))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1195 (setq calc-stack (cons entry calc-stack)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1196
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1197 (defun calc-pop-stack-in-macro (n mm)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1198 (if (> mm 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1199 (setcdr (nthcdr (- mm 2) calc-stack)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1200 (nthcdr (+ n mm -1) calc-stack))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1201 (setq calc-stack (nthcdr n calc-stack))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1202
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1203
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1204 (defun calc-kbd-if ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1205 (interactive)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1206 (calc-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1207 (let ((cond (calc-top-n 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1208 (calc-pop-stack 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1209 (if (math-is-true cond)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1210 (if defining-kbd-macro
105275
b78ceb253d15 * speedbar.el (speedbar-item-delete):
Juanma Barranquero <lekktu@gmail.com>
parents: 105022
diff changeset
1211 (message "If true..."))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1212 (if defining-kbd-macro
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1213 (message "Condition is false; skipping to Z: or Z] ..."))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1214 (calc-kbd-skip-to-else-if t)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1215
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1216 (defun calc-kbd-else-if ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1217 (interactive)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1218 (calc-kbd-if))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1219
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1220 (defun calc-kbd-skip-to-else-if (else-okay)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1221 (let ((count 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1222 ch)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1223 (while (>= count 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1224 (setq ch (read-char))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1225 (if (= ch -1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1226 (error "Unterminated Z[ in keyboard macro"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1227 (if (= ch ?Z)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1228 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1229 (setq ch (read-char))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1230 (cond ((= ch ?\[)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1231 (setq count (1+ count)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1232 ((= ch ?\])
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1233 (setq count (1- count)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1234 ((= ch ?\:)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1235 (and (= count 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1236 else-okay
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1237 (setq count -1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1238 ((eq ch 7)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1239 (keyboard-quit))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1240 (and defining-kbd-macro
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1241 (if (= ch ?\:)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1242 (message "Else...")
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1243 (message "End-if...")))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1244
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1245 (defun calc-kbd-end-if ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1246 (interactive)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1247 (if defining-kbd-macro
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1248 (message "End-if...")))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1249
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1250 (defun calc-kbd-else ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1251 (interactive)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1252 (if defining-kbd-macro
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1253 (message "Else; skipping to Z] ..."))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1254 (calc-kbd-skip-to-else-if nil))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1255
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1256
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1257 (defun calc-kbd-repeat ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1258 (interactive)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1259 (let (count)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1260 (calc-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1261 (setq count (math-trunc (calc-top-n 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1262 (or (Math-integerp count)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1263 (error "Count must be an integer"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1264 (if (Math-integer-negp count)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1265 (setq count 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1266 (or (integerp count)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1267 (setq count 1000000))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1268 (calc-pop-stack 1))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1269 (calc-kbd-loop count)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1270
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1271 (defun calc-kbd-for (dir)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1272 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1273 (let (init final)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1274 (calc-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1275 (setq init (calc-top-n 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1276 final (calc-top-n 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1277 (or (and (math-anglep init) (math-anglep final))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1278 (error "Initial and final values must be real numbers"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1279 (calc-pop-stack 2))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1280 (calc-kbd-loop nil init final (and dir (prefix-numeric-value dir)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1281
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1282 (defun calc-kbd-loop (rpt-count &optional initial final dir)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1283 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1284 (setq rpt-count (if rpt-count (prefix-numeric-value rpt-count) 1000000))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1285 (let* ((count 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1286 (parts nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1287 (body "")
101001
14b421290b2f Replace last-command-char with last-command-event.
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
1288 (open last-command-event)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1289 (counter initial)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1290 ch)
40998
ee9c2872370b Use `frame-width' instead of `screen-width',
Eli Zaretskii <eliz@gnu.org>
parents: 40785
diff changeset
1291 (or executing-kbd-macro
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1292 (message "Reading loop body..."))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1293 (while (>= count 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1294 (setq ch (read-char))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1295 (if (= ch -1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1296 (error "Unterminated Z%c in keyboard macro" open))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1297 (if (= ch ?Z)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1298 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1299 (setq ch (read-char)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1300 body (concat body "Z" (char-to-string ch)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1301 (cond ((memq ch '(?\< ?\( ?\{))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1302 (setq count (1+ count)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1303 ((memq ch '(?\> ?\) ?\}))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1304 (setq count (1- count)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1305 ((and (= ch ?/)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1306 (= count 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1307 (setq parts (nconc parts (list (concat (substring body 0 -2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1308 "Z]")))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1309 body ""))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1310 ((eq ch 7)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1311 (keyboard-quit))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1312 (setq body (concat body (char-to-string ch)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1313 (if (/= ch (cdr (assq open '( (?\< . ?\>) (?\( . ?\)) (?\{ . ?\}) ))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1314 (error "Mismatched Z%c and Z%c in keyboard macro" open ch))
40998
ee9c2872370b Use `frame-width' instead of `screen-width',
Eli Zaretskii <eliz@gnu.org>
parents: 40785
diff changeset
1315 (or executing-kbd-macro
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1316 (message "Looping..."))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1317 (setq body (concat (substring body 0 -2) "Z]"))
40998
ee9c2872370b Use `frame-width' instead of `screen-width',
Eli Zaretskii <eliz@gnu.org>
parents: 40785
diff changeset
1318 (and (not executing-kbd-macro)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1319 (= rpt-count 1000000)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1320 (null parts)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1321 (null counter)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1322 (progn
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
1323 (message "Warning: Infinite loop! Not executing")
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1324 (setq rpt-count 0)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1325 (or (not initial) dir
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1326 (setq dir (math-compare final initial)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1327 (calc-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1328 (while (> rpt-count 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1329 (let ((part parts))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1330 (if counter
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1331 (if (cond ((eq dir 0) (Math-equal final counter))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1332 ((eq dir 1) (Math-lessp final counter))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1333 ((eq dir -1) (Math-lessp counter final)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1334 (setq rpt-count 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1335 (calc-push counter)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1336 (while (and part (> rpt-count 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1337 (execute-kbd-macro (car part))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1338 (if (math-is-true (calc-top-n 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1339 (setq rpt-count 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1340 (setq part (cdr part)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1341 (calc-pop-stack 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1342 (if (> rpt-count 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1343 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1344 (execute-kbd-macro body)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1345 (if counter
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1346 (let ((step (calc-top-n 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1347 (calc-pop-stack 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1348 (setq counter (calcFunc-add counter step)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1349 (setq rpt-count (1- rpt-count))))))))
40998
ee9c2872370b Use `frame-width' instead of `screen-width',
Eli Zaretskii <eliz@gnu.org>
parents: 40785
diff changeset
1350 (or executing-kbd-macro
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1351 (message "Looping...done"))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1352
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1353 (defun calc-kbd-end-repeat ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1354 (interactive)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1355 (error "Unbalanced Z> in keyboard macro"))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1356
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1357 (defun calc-kbd-end-for ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1358 (interactive)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1359 (error "Unbalanced Z) in keyboard macro"))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1360
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1361 (defun calc-kbd-end-loop ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1362 (interactive)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1363 (error "Unbalanced Z} in keyboard macro"))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1364
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1365 (defun calc-kbd-break ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1366 (interactive)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1367 (calc-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1368 (let ((cond (calc-top-n 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1369 (calc-pop-stack 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1370 (if (math-is-true cond)
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
1371 (error "Keyboard macro aborted")))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1372
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1373
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
1374 (defvar calc-kbd-push-level 0)
58390
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1375
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1376 ;; The variables var-q0 through var-q9 are the "quick" variables.
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1377 (defvar var-q0 nil)
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1378 (defvar var-q1 nil)
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1379 (defvar var-q2 nil)
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1380 (defvar var-q3 nil)
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1381 (defvar var-q4 nil)
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1382 (defvar var-q5 nil)
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1383 (defvar var-q6 nil)
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1384 (defvar var-q7 nil)
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1385 (defvar var-q8 nil)
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1386 (defvar var-q9 nil)
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1387
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1388 (defun calc-kbd-push (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1389 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1390 (calc-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1391 (let* ((defs (and arg (> (prefix-numeric-value arg) 0)))
58390
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1392 (var-q0 var-q0)
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1393 (var-q1 var-q1)
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1394 (var-q2 var-q2)
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1395 (var-q3 var-q3)
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1396 (var-q4 var-q4)
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1397 (var-q5 var-q5)
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1398 (var-q6 var-q6)
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1399 (var-q7 var-q7)
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1400 (var-q8 var-q8)
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1401 (var-q9 var-q9)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1402 (calc-internal-prec (if defs 12 calc-internal-prec))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1403 (calc-word-size (if defs 32 calc-word-size))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1404 (calc-angle-mode (if defs 'deg calc-angle-mode))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1405 (calc-simplify-mode (if defs nil calc-simplify-mode))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1406 (calc-algebraic-mode (if arg nil calc-algebraic-mode))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1407 (calc-incomplete-algebraic-mode (if arg nil
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1408 calc-incomplete-algebraic-mode))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1409 (calc-symbolic-mode (if defs nil calc-symbolic-mode))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1410 (calc-matrix-mode (if defs nil calc-matrix-mode))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1411 (calc-prefer-frac (if defs nil calc-prefer-frac))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1412 (calc-complex-mode (if defs nil calc-complex-mode))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1413 (calc-infinite-mode (if defs nil calc-infinite-mode))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1414 (count 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1415 (body "")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1416 ch)
40998
ee9c2872370b Use `frame-width' instead of `screen-width',
Eli Zaretskii <eliz@gnu.org>
parents: 40785
diff changeset
1417 (if (or executing-kbd-macro defining-kbd-macro)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1418 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1419 (if defining-kbd-macro
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1420 (message "Reading body..."))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1421 (while (>= count 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1422 (setq ch (read-char))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1423 (if (= ch -1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1424 (error "Unterminated Z` in keyboard macro"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1425 (if (= ch ?Z)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1426 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1427 (setq ch (read-char)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1428 body (concat body "Z" (char-to-string ch)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1429 (cond ((eq ch ?\`)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1430 (setq count (1+ count)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1431 ((eq ch ?\')
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1432 (setq count (1- count)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1433 ((eq ch 7)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1434 (keyboard-quit))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1435 (setq body (concat body (char-to-string ch)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1436 (if defining-kbd-macro
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1437 (message "Reading body...done"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1438 (let ((calc-kbd-push-level 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1439 (execute-kbd-macro (substring body 0 -2))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1440 (let ((calc-kbd-push-level (1+ calc-kbd-push-level)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1441 (message "Saving modes; type Z' to restore")
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1442 (recursive-edit))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1443
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1444 (defun calc-kbd-pop ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1445 (interactive)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1446 (if (> calc-kbd-push-level 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1447 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1448 (message "Mode settings restored")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1449 (exit-recursive-edit))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1450 (error "Unbalanced Z' in keyboard macro")))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1451
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1452
62819
3e8d22427034 (calc-kbd-report): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 62717
diff changeset
1453 ;; (defun calc-kbd-report (msg)
3e8d22427034 (calc-kbd-report): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 62717
diff changeset
1454 ;; (interactive "sMessage: ")
3e8d22427034 (calc-kbd-report): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 62717
diff changeset
1455 ;; (calc-wrapper
3e8d22427034 (calc-kbd-report): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 62717
diff changeset
1456 ;; (math-working msg (calc-top-n 1))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1457
62819
3e8d22427034 (calc-kbd-report): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 62717
diff changeset
1458 (defun calc-kbd-query ()
3e8d22427034 (calc-kbd-report): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 62717
diff changeset
1459 (interactive)
3e8d22427034 (calc-kbd-report): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 62717
diff changeset
1460 (let ((defining-kbd-macro nil)
3e8d22427034 (calc-kbd-report): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 62717
diff changeset
1461 (executing-kbd-macro nil)
3e8d22427034 (calc-kbd-report): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 62717
diff changeset
1462 (msg (calc-top 1)))
3e8d22427034 (calc-kbd-report): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 62717
diff changeset
1463 (if (not (eq (car-safe msg) 'vec))
62820
4d1d10306a3b (calc-kbd-query): Change error message.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 62819
diff changeset
1464 (error "No prompt string provided")
62819
3e8d22427034 (calc-kbd-report): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 62717
diff changeset
1465 (setq msg (math-vector-to-string msg))
3e8d22427034 (calc-kbd-report): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 62717
diff changeset
1466 (calc-wrapper
3e8d22427034 (calc-kbd-report): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 62717
diff changeset
1467 (calc-pop-stack 1)
3e8d22427034 (calc-kbd-report): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 62717
diff changeset
1468 (calc-alg-entry nil (and (not (equal msg "")) msg))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1469
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1470 ;;;; Logical operations.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1471
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1472 (defun calcFunc-eq (a b &rest more)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1473 (if more
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1474 (let* ((args (cons a (cons b (copy-sequence more))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1475 (res 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1476 (p args)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1477 p2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1478 (while (and (cdr p) (not (eq res 0)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1479 (setq p2 p)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1480 (while (and (setq p2 (cdr p2)) (not (eq res 0)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1481 (setq res (math-two-eq (car p) (car p2)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1482 (if (eq res 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1483 (setcdr p (delq (car p2) (cdr p)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1484 (setq p (cdr p)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1485 (if (eq res 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1486 0
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1487 (if (cdr args)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1488 (cons 'calcFunc-eq args)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1489 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1490 (or (math-two-eq a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1491 (if (and (or (math-looks-negp a) (math-zerop a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1492 (or (math-looks-negp b) (math-zerop b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1493 (list 'calcFunc-eq (math-neg a) (math-neg b))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1494 (list 'calcFunc-eq a b)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1495
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1496 (defun calcFunc-neq (a b &rest more)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1497 (if more
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1498 (let* ((args (cons a (cons b more)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1499 (res 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1500 (all t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1501 (p args)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1502 p2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1503 (while (and (cdr p) (not (eq res 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1504 (setq p2 p)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1505 (while (and (setq p2 (cdr p2)) (not (eq res 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1506 (setq res (math-two-eq (car p) (car p2)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1507 (or res (setq all nil)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1508 (setq p (cdr p)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1509 (if (eq res 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1510 0
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1511 (if all
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1512 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1513 (cons 'calcFunc-neq args))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1514 (or (cdr (assq (math-two-eq a b) '((0 . 1) (1 . 0))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1515 (if (and (or (math-looks-negp a) (math-zerop a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1516 (or (math-looks-negp b) (math-zerop b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1517 (list 'calcFunc-neq (math-neg a) (math-neg b))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1518 (list 'calcFunc-neq a b)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1519
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1520 (defun math-two-eq (a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1521 (if (eq (car-safe a) 'vec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1522 (if (eq (car-safe b) 'vec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1523 (if (= (length a) (length b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1524 (let ((res 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1525 (while (and (setq a (cdr a) b (cdr b)) (not (eq res 0)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1526 (if res
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1527 (setq res (math-two-eq (car a) (car b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1528 (if (eq (math-two-eq (car a) (car b)) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1529 (setq res 0))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1530 res)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1531 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1532 (if (Math-objectp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1533 0
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1534 nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1535 (if (eq (car-safe b) 'vec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1536 (if (Math-objectp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1537 0
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1538 nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1539 (let ((res (math-compare a b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1540 (if (= res 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1541 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1542 (if (and (= res 2) (not (and (Math-scalarp a) (Math-scalarp b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1543 nil
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1544 0))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1545
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1546 (defun calcFunc-lt (a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1547 (let ((res (math-compare a b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1548 (if (= res -1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1549 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1550 (if (= res 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1551 (if (and (or (math-looks-negp a) (math-zerop a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1552 (or (math-looks-negp b) (math-zerop b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1553 (list 'calcFunc-gt (math-neg a) (math-neg b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1554 (list 'calcFunc-lt a b))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1555 0))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1556
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1557 (defun calcFunc-gt (a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1558 (let ((res (math-compare a b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1559 (if (= res 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1560 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1561 (if (= res 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1562 (if (and (or (math-looks-negp a) (math-zerop a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1563 (or (math-looks-negp b) (math-zerop b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1564 (list 'calcFunc-lt (math-neg a) (math-neg b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1565 (list 'calcFunc-gt a b))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1566 0))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1567
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1568 (defun calcFunc-leq (a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1569 (let ((res (math-compare a b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1570 (if (= res 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1571 0
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1572 (if (= res 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1573 (if (and (or (math-looks-negp a) (math-zerop a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1574 (or (math-looks-negp b) (math-zerop b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1575 (list 'calcFunc-geq (math-neg a) (math-neg b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1576 (list 'calcFunc-leq a b))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1577 1))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1578
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1579 (defun calcFunc-geq (a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1580 (let ((res (math-compare a b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1581 (if (= res -1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1582 0
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1583 (if (= res 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1584 (if (and (or (math-looks-negp a) (math-zerop a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1585 (or (math-looks-negp b) (math-zerop b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1586 (list 'calcFunc-leq (math-neg a) (math-neg b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1587 (list 'calcFunc-geq a b))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1588 1))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1589
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1590 (defun calcFunc-rmeq (a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1591 (if (math-vectorp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1592 (math-map-vec 'calcFunc-rmeq a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1593 (if (assq (car-safe a) calc-tweak-eqn-table)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1594 (if (and (eq (car-safe (nth 2 a)) 'var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1595 (math-objectp (nth 1 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1596 (nth 1 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1597 (nth 2 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1598 (if (eq (car-safe a) 'calcFunc-assign)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1599 (nth 2 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1600 (if (eq (car-safe a) 'calcFunc-evalto)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1601 (nth 1 a)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1602 (list 'calcFunc-rmeq a))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1603
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1604 (defun calcFunc-land (a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1605 (cond ((Math-zerop a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1606 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1607 ((Math-zerop b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1608 b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1609 ((math-is-true a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1610 b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1611 ((math-is-true b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1612 a)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1613 (t (list 'calcFunc-land a b))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1614
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1615 (defun calcFunc-lor (a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1616 (cond ((Math-zerop a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1617 b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1618 ((Math-zerop b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1619 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1620 ((math-is-true a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1621 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1622 ((math-is-true b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1623 b)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1624 (t (list 'calcFunc-lor a b))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1625
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1626 (defun calcFunc-lnot (a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1627 (if (Math-zerop a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1628 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1629 (if (math-is-true a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1630 0
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1631 (let ((op (and (= (length a) 3)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1632 (assq (car a) calc-tweak-eqn-table))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1633 (if op
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1634 (cons (nth 2 op) (cdr a))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1635 (list 'calcFunc-lnot a))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1636
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1637 (defun calcFunc-if (c e1 e2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1638 (if (Math-zerop c)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1639 e2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1640 (if (and (math-is-true c) (not (Math-vectorp c)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1641 e1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1642 (or (and (Math-vectorp c)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1643 (math-constp c)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1644 (let ((ee1 (if (Math-vectorp e1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1645 (if (= (length c) (length e1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1646 (cdr e1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1647 (calc-record-why "*Dimension error" e1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1648 (list e1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1649 (ee2 (if (Math-vectorp e2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1650 (if (= (length c) (length e2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1651 (cdr e2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1652 (calc-record-why "*Dimension error" e2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1653 (list e2))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1654 (and ee1 ee2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1655 (cons 'vec (math-if-vector (cdr c) ee1 ee2)))))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1656 (list 'calcFunc-if c e1 e2)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1657
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1658 (defun math-if-vector (c e1 e2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1659 (and c
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1660 (cons (if (Math-zerop (car c)) (car e2) (car e1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1661 (math-if-vector (cdr c)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1662 (or (cdr e1) e1)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1663 (or (cdr e2) e2)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1664
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1665 (defun math-normalize-logical-op (a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1666 (or (and (eq (car a) 'calcFunc-if)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1667 (= (length a) 4)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1668 (let ((a1 (math-normalize (nth 1 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1669 (if (Math-zerop a1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1670 (math-normalize (nth 3 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1671 (if (Math-numberp a1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1672 (math-normalize (nth 2 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1673 (if (and (Math-vectorp (nth 1 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1674 (math-constp (nth 1 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1675 (calcFunc-if (nth 1 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1676 (math-normalize (nth 2 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1677 (math-normalize (nth 3 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1678 (let ((calc-simplify-mode 'none))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1679 (list 'calcFunc-if a1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1680 (math-normalize (nth 2 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1681 (math-normalize (nth 3 a)))))))))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1682 a))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1683
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1684 (defun calcFunc-in (a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1685 (or (and (eq (car-safe b) 'vec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1686 (let ((bb b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1687 (while (and (setq bb (cdr bb))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1688 (not (if (memq (car-safe (car bb)) '(vec intv))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1689 (eq (calcFunc-in a (car bb)) 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1690 (Math-equal a (car bb))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1691 (if bb 1 (and (math-constp a) (math-constp bb) 0))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1692 (and (eq (car-safe b) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1693 (let ((res (math-compare a (nth 2 b))) res2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1694 (cond ((= res -1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1695 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1696 ((and (= res 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1697 (or (/= (nth 1 b) 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1698 (Math-lessp (nth 2 b) (nth 3 b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1699 (if (memq (nth 1 b) '(2 3)) 1 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1700 ((= (setq res2 (math-compare a (nth 3 b))) 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1701 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1702 ((and (= res2 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1703 (or (/= (nth 1 b) 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1704 (Math-lessp (nth 2 b) (nth 3 b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1705 (if (memq (nth 1 b) '(1 3)) 1 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1706 ((/= res 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1707 nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1708 ((/= res2 -1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1709 nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1710 (t 1))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1711 (and (Math-equal a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1712 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1713 (and (math-constp a) (math-constp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1714 0)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1715 (list 'calcFunc-in a b)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1716
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1717 (defun calcFunc-typeof (a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1718 (cond ((Math-integerp a) 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1719 ((eq (car a) 'frac) 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1720 ((eq (car a) 'float) 3)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1721 ((eq (car a) 'hms) 4)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1722 ((eq (car a) 'cplx) 5)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1723 ((eq (car a) 'polar) 6)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1724 ((eq (car a) 'sdev) 7)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1725 ((eq (car a) 'intv) 8)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1726 ((eq (car a) 'mod) 9)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1727 ((eq (car a) 'date) (if (Math-integerp (nth 1 a)) 10 11))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1728 ((eq (car a) 'var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1729 (if (memq (nth 2 a) '(var-inf var-uinf var-nan)) 12 100))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1730 ((eq (car a) 'vec) (if (math-matrixp a) 102 101))
58390
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1731 (t (math-calcFunc-to-var (car a)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1732
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1733 (defun calcFunc-integer (a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1734 (if (Math-integerp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1735 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1736 (if (Math-objvecp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1737 0
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1738 (list 'calcFunc-integer a))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1739
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1740 (defun calcFunc-real (a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1741 (if (Math-realp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1742 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1743 (if (Math-objvecp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1744 0
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1745 (list 'calcFunc-real a))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1746
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1747 (defun calcFunc-constant (a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1748 (if (math-constp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1749 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1750 (if (Math-objvecp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1751 0
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1752 (list 'calcFunc-constant a))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1753
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1754 (defun calcFunc-refers (a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1755 (if (math-expr-contains a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1756 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1757 (if (eq (car-safe a) 'var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1758 (list 'calcFunc-refers a b)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1759 0)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1760
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1761 (defun calcFunc-negative (a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1762 (if (math-looks-negp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1763 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1764 (if (or (math-zerop a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1765 (math-posp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1766 0
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1767 (list 'calcFunc-negative a))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1768
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1769 (defun calcFunc-variable (a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1770 (if (eq (car-safe a) 'var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1771 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1772 (if (Math-objvecp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1773 0
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1774 (list 'calcFunc-variable a))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1775
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1776 (defun calcFunc-nonvar (a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1777 (if (eq (car-safe a) 'var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1778 (list 'calcFunc-nonvar a)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1779 1))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1780
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1781 (defun calcFunc-istrue (a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1782 (if (math-is-true a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1783 1
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1784 0))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1786
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1787
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1788 ;;;; User-programmability.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1789
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1790 ;;; Compiling Lisp-like forms to use the math library.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1791
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1792 (defun math-do-defmath (func args body)
58614
eba1cd703531 (calc-user-define-formula, calc-do-defmath): Replace calc-need-macros by
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58390
diff changeset
1793 (require 'calc-macs)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1794 (let* ((fname (intern (concat "calcFunc-" (symbol-name func))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1795 (doc (if (stringp (car body)) (list (car body))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1796 (clargs (mapcar 'math-clean-arg args))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1797 (body (math-define-function-body
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1798 (if (stringp (car body)) (cdr body) body)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1799 clargs)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1800 (list 'progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1801 (if (and (consp (car body))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1802 (eq (car (car body)) 'interactive))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1803 (let ((inter (car body)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1804 (setq body (cdr body))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1805 (if (or (> (length inter) 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1806 (integerp (nth 1 inter)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1807 (let ((hasprefix nil) (hasmulti nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1808 (if (stringp (nth 1 inter))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1809 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1810 (cond ((equal (nth 1 inter) "p")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1811 (setq hasprefix t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1812 ((equal (nth 1 inter) "m")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1813 (setq hasmulti t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1814 (t (error
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1815 "Can't handle interactive code string \"%s\""
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1816 (nth 1 inter))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1817 (setq inter (cdr inter))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1818 (if (not (integerp (nth 1 inter)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1819 (error
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1820 "Expected an integer in interactive specification"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1821 (append (list 'defun
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1822 (intern (concat "calc-"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1823 (symbol-name func)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1824 (if (or hasprefix hasmulti)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1825 '(&optional n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1826 ()))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1827 doc
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1828 (if (or hasprefix hasmulti)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1829 '((interactive "P"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1830 '((interactive)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1831 (list
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1832 (append
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1833 '(calc-slow-wrapper)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1834 (and hasmulti
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1835 (list
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1836 (list 'setq
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1837 'n
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1838 (list 'if
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1839 'n
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1840 (list 'prefix-numeric-value
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1841 'n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1842 (nth 1 inter)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1843 (list
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1844 (list 'calc-enter-result
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1845 (if hasmulti 'n (nth 1 inter))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1846 (nth 2 inter)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1847 (if hasprefix
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1848 (list 'append
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1849 (list 'quote (list fname))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1850 (list 'calc-top-list-n
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1851 (nth 1 inter))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1852 (list 'and
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1853 'n
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1854 (list
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1855 'list
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1856 (list
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1857 'math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1858 (list
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1859 'prefix-numeric-value
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1860 'n)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1861 (list 'cons
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1862 (list 'quote fname)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1863 (list 'calc-top-list-n
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1864 (if hasmulti
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1865 'n
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1866 (nth 1 inter)))))))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1867 (append (list 'defun
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1868 (intern (concat "calc-" (symbol-name func)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1869 args)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1870 doc
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1871 (list
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1872 inter
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1873 (cons 'calc-wrapper body))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1874 (append (list 'defun fname clargs)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1875 doc
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1876 (math-do-arg-list-check args nil nil)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1877 body))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1878
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1879 (defun math-clean-arg (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1880 (if (consp arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1881 (math-clean-arg (nth 1 arg))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1882 arg))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1883
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1884 (defun math-do-arg-check (arg var is-opt is-rest)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1885 (if is-opt
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1886 (let ((chk (math-do-arg-check arg var nil nil)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1887 (list (cons 'and
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1888 (cons var
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1889 (if (cdr chk)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1890 (setq chk (list (cons 'progn chk)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1891 chk)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1892 (and (consp arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1893 (let* ((rest (math-do-arg-check (nth 1 arg) var is-opt is-rest))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1894 (qual (car arg))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1895 (qqual (list 'quote qual))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1896 (qual-name (symbol-name qual))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1897 (chk (intern (concat "math-check-" qual-name))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1898 (if (fboundp chk)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1899 (append rest
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1900 (list
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1901 (if is-rest
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1902 (list 'setq var
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1903 (list 'mapcar (list 'quote chk) var))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1904 (list 'setq var (list chk var)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1905 (if (fboundp (setq chk (intern (concat "math-" qual-name))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1906 (append rest
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1907 (list
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1908 (if is-rest
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1909 (list 'mapcar
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1910 (list 'function
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1911 (list 'lambda '(x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1912 (list 'or
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1913 (list chk 'x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1914 (list 'math-reject-arg
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1915 'x qqual))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1916 var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1917 (list 'or
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1918 (list chk var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1919 (list 'math-reject-arg var qqual)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1920 (if (and (string-match "\\`not-\\(.*\\)\\'" qual-name)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1921 (fboundp (setq chk (intern
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1922 (concat "math-"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1923 (math-match-substring
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1924 qual-name 1))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1925 (append rest
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1926 (list
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1927 (if is-rest
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1928 (list 'mapcar
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1929 (list 'function
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1930 (list 'lambda '(x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1931 (list 'and
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1932 (list chk 'x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1933 (list 'math-reject-arg
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1934 'x qqual))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1935 var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1936 (list 'and
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1937 (list chk var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1938 (list 'math-reject-arg var qqual)))))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1939 (error "Unknown qualifier `%s'" qual-name))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1940
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1941 (defun math-do-arg-list-check (args is-opt is-rest)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1942 (cond ((null args) nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1943 ((consp (car args))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1944 (append (math-do-arg-check (car args)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1945 (math-clean-arg (car args))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1946 is-opt is-rest)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1947 (math-do-arg-list-check (cdr args) is-opt is-rest)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1948 ((eq (car args) '&optional)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1949 (math-do-arg-list-check (cdr args) t nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1950 ((eq (car args) '&rest)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1951 (math-do-arg-list-check (cdr args) nil t))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1952 (t (math-do-arg-list-check (cdr args) is-opt is-rest))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1953
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1954 (defconst math-prim-funcs
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1955 '( (~= . math-nearly-equal)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1956 (% . math-mod)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1957 (lsh . calcFunc-lsh)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1958 (ash . calcFunc-ash)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1959 (logand . calcFunc-and)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1960 (logandc2 . calcFunc-diff)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1961 (logior . calcFunc-or)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1962 (logxor . calcFunc-xor)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1963 (lognot . calcFunc-not)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1964 (equal . equal) ; need to leave these ones alone!
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1965 (eq . eq)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1966 (and . and)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1967 (or . or)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1968 (if . if)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1969 (^ . math-pow)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1970 (expt . math-pow)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1971 ))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1972
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1973 (defconst math-prim-vars
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1974 '( (nil . nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1975 (t . t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1976 (&optional . &optional)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1977 (&rest . &rest)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1978 ))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1979
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1980 (defun math-define-function-body (body env)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1981 (let ((body (math-define-body body env)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1982 (if (math-body-refers-to body 'math-return)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1983 (list (cons 'catch (cons '(quote math-return) body)))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1984 body)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1985
58390
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1986 ;; The variable math-exp-env is local to math-define-body, but is
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1987 ;; used by math-define-exp, which is called (indirectly) by
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1988 ;; by math-define-body.
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1989 (defvar math-exp-env)
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1990
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1991 (defun math-define-body (body math-exp-env)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
1992 (math-define-list body))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1993
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1994 (defun math-define-list (body &optional quote)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1995 (cond ((null body)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1996 nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1997 ((and (eq (car body) ':)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1998 (stringp (nth 1 body)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1999 (cons (let* ((math-read-expr-quotes t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2000 (exp (math-read-plain-expr (nth 1 body) t)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2001 (math-define-exp exp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2002 (math-define-list (cdr (cdr body)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2003 (quote
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2004 (cons (cond ((consp (car body))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2005 (math-define-list (cdr body) t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2006 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2007 (car body)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2008 (math-define-list (cdr body))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2009 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2010 (cons (math-define-exp (car body))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
2011 (math-define-list (cdr body))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2012
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2013 (defun math-define-exp (exp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2014 (cond ((consp exp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2015 (let ((func (car exp)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2016 (cond ((memq func '(quote function))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2017 (if (and (consp (nth 1 exp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2018 (eq (car (nth 1 exp)) 'lambda))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2019 (cons 'quote
58390
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
2020 (math-define-lambda (nth 1 exp) math-exp-env))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2021 exp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2022 ((memq func '(let let* for foreach))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2023 (let ((head (nth 1 exp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2024 (body (cdr (cdr exp))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2025 (if (memq func '(let let*))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2026 ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2027 (setq func (cdr (assq func '((for . math-for)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2028 (foreach . math-foreach)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2029 (if (not (listp (car head)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2030 (setq head (list head))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2031 (macroexpand
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2032 (cons func
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2033 (cons (math-define-let head)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2034 (math-define-body body
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2035 (nconc
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2036 (math-define-let-env head)
58390
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
2037 math-exp-env)))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2038 ((and (memq func '(setq setf))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2039 (math-complicated-lhs (cdr exp)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2040 (if (> (length exp) 3)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2041 (cons 'progn (math-define-setf-list (cdr exp)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2042 (math-define-setf (nth 1 exp) (nth 2 exp))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2043 ((eq func 'condition-case)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2044 (cons func
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2045 (cons (nth 1 exp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2046 (math-define-body (cdr (cdr exp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2047 (cons (nth 1 exp)
58390
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
2048 math-exp-env)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2049 ((eq func 'cond)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2050 (cons func
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2051 (math-define-cond (cdr exp))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2052 ((and (consp func) ; ('spam a b) == force use of plain spam
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2053 (eq (car func) 'quote))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2054 (cons func (math-define-list (cdr exp))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2055 ((symbolp func)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2056 (let ((args (math-define-list (cdr exp)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2057 (prim (assq func math-prim-funcs)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2058 (cond (prim
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2059 (cons (cdr prim) args))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2060 ((eq func 'floatp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2061 (list 'eq (car args) '(quote float)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2062 ((eq func '+)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2063 (math-define-binop 'math-add 0
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2064 (car args) (cdr args)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2065 ((eq func '-)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2066 (if (= (length args) 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2067 (cons 'math-neg args)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2068 (math-define-binop 'math-sub 0
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2069 (car args) (cdr args))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2070 ((eq func '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2071 (math-define-binop 'math-mul 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2072 (car args) (cdr args)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2073 ((eq func '/)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2074 (math-define-binop 'math-div 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2075 (car args) (cdr args)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2076 ((eq func 'min)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2077 (math-define-binop 'math-min 0
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2078 (car args) (cdr args)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2079 ((eq func 'max)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2080 (math-define-binop 'math-max 0
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2081 (car args) (cdr args)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2082 ((eq func '<)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2083 (if (and (math-numberp (nth 1 args))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2084 (math-zerop (nth 1 args)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2085 (list 'math-negp (car args))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2086 (cons 'math-lessp args)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2087 ((eq func '>)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2088 (if (and (math-numberp (nth 1 args))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2089 (math-zerop (nth 1 args)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2090 (list 'math-posp (car args))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2091 (list 'math-lessp (nth 1 args) (nth 0 args))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2092 ((eq func '<=)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2093 (list 'not
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2094 (if (and (math-numberp (nth 1 args))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2095 (math-zerop (nth 1 args)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2096 (list 'math-posp (car args))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2097 (list 'math-lessp
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2098 (nth 1 args) (nth 0 args)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2099 ((eq func '>=)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2100 (list 'not
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2101 (if (and (math-numberp (nth 1 args))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2102 (math-zerop (nth 1 args)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2103 (list 'math-negp (car args))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2104 (cons 'math-lessp args))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2105 ((eq func '=)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2106 (if (and (math-numberp (nth 1 args))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2107 (math-zerop (nth 1 args)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2108 (list 'math-zerop (nth 0 args))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2109 (if (and (integerp (nth 1 args))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2110 (/= (% (nth 1 args) 10) 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2111 (cons 'math-equal-int args)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2112 (cons 'math-equal args))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2113 ((eq func '/=)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2114 (list 'not
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2115 (if (and (math-numberp (nth 1 args))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2116 (math-zerop (nth 1 args)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2117 (list 'math-zerop (nth 0 args))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2118 (if (and (integerp (nth 1 args))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2119 (/= (% (nth 1 args) 10) 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2120 (cons 'math-equal-int args)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2121 (cons 'math-equal args)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2122 ((eq func '1+)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2123 (list 'math-add (car args) 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2124 ((eq func '1-)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2125 (list 'math-add (car args) -1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2126 ((eq func 'not) ; optimize (not (not x)) => x
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2127 (if (eq (car-safe args) func)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2128 (car (nth 1 args))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2129 (cons func args)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2130 ((and (eq func 'elt) (cdr (cdr args)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2131 (math-define-elt (car args) (cdr args)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2132 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2133 (macroexpand
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2134 (let* ((name (symbol-name func))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2135 (cfunc (intern (concat "calcFunc-" name)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2136 (mfunc (intern (concat "math-" name))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2137 (cond ((fboundp cfunc)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2138 (cons cfunc args))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2139 ((fboundp mfunc)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2140 (cons mfunc args))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2141 ((or (fboundp func)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2142 (string-match "\\`calcFunc-.*" name))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2143 (cons func args))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2144 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2145 (cons cfunc args)))))))))
58390
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
2146 (t (cons func (math-define-list (cdr exp))))))) ;;args
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2147 ((symbolp exp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2148 (let ((prim (assq exp math-prim-vars))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2149 (name (symbol-name exp)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2150 (cond (prim
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2151 (cdr prim))
58390
2c8f55b9ef8a (math-integral-cache-state, calc-lang)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
2152 ((memq exp math-exp-env)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2153 exp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2154 ((string-match "-" name)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2155 exp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2156 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2157 (intern (concat "var-" name))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2158 ((integerp exp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2159 (if (or (<= exp -1000000) (>= exp 1000000))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2160 (list 'quote (math-normalize exp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2161 exp))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
2162 (t exp)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2163
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2164 (defun math-define-cond (forms)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2165 (and forms
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2166 (cons (math-define-list (car forms))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
2167 (math-define-cond (cdr forms)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2168
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2169 (defun math-complicated-lhs (body)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2170 (and body
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2171 (or (not (symbolp (car body)))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
2172 (math-complicated-lhs (cdr (cdr body))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2173
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2174 (defun math-define-setf-list (body)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2175 (and body
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2176 (cons (math-define-setf (nth 0 body) (nth 1 body))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
2177 (math-define-setf-list (cdr (cdr body))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2178
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2179 (defun math-define-setf (place value)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2180 (setq place (math-define-exp place)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2181 value (math-define-exp value))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2182 (cond ((symbolp place)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2183 (list 'setq place value))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2184 ((eq (car-safe place) 'nth)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2185 (list 'setcar (list 'nthcdr (nth 1 place) (nth 2 place)) value))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2186 ((eq (car-safe place) 'elt)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2187 (list 'setcar (list 'nthcdr (nth 2 place) (nth 1 place)) value))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2188 ((eq (car-safe place) 'car)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2189 (list 'setcar (nth 1 place) value))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2190 ((eq (car-safe place) 'cdr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2191 (list 'setcdr (nth 1 place) value))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2192 (t
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
2193 (error "Bad place form for setf: %s" place))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2194
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2195 (defun math-define-binop (op ident arg1 rest)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2196 (if rest
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2197 (math-define-binop op ident
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2198 (list op arg1 (car rest))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2199 (cdr rest))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
2200 (or arg1 ident)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2201
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2202 (defun math-define-let (vlist)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2203 (and vlist
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2204 (cons (if (consp (car vlist))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2205 (cons (car (car vlist))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2206 (math-define-list (cdr (car vlist))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2207 (car vlist))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
2208 (math-define-let (cdr vlist)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2209
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2210 (defun math-define-let-env (vlist)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2211 (and vlist
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2212 (cons (if (consp (car vlist))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2213 (car (car vlist))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2214 (car vlist))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
2215 (math-define-let-env (cdr vlist)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2216
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2217 (defun math-define-lambda (exp exp-env)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2218 (nconc (list (nth 0 exp) ; 'lambda
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2219 (nth 1 exp)) ; arg list
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2220 (math-define-function-body (cdr (cdr exp))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
2221 (append (nth 1 exp) exp-env))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2222
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2223 (defun math-define-elt (seq idx)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2224 (if idx
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2225 (math-define-elt (list 'elt seq (car idx)) (cdr idx))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
2226 seq))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2227
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2228
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2229
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2230 ;;; Useful programming macros.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2231
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2232 (defmacro math-while (head &rest body)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2233 (let ((body (cons 'while (cons head body))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2234 (if (math-body-refers-to body 'math-break)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2235 (cons 'catch (cons '(quote math-break) (list body)))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
2236 body)))
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
2237 ;; (put 'math-while 'lisp-indent-hook 1)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2238
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2239 (defmacro math-for (head &rest body)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2240 (let ((body (if head
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2241 (math-handle-for head body)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2242 (cons 'while (cons t body)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2243 (if (math-body-refers-to body 'math-break)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2244 (cons 'catch (cons '(quote math-break) (list body)))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
2245 body)))
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
2246 ;; (put 'math-for 'lisp-indent-hook 1)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2247
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2248 (defun math-handle-for (head body)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2249 (let* ((var (nth 0 (car head)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2250 (init (nth 1 (car head)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2251 (limit (nth 2 (car head)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2252 (step (or (nth 3 (car head)) 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2253 (body (if (cdr head)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2254 (list (math-handle-for (cdr head) body))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2255 body))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2256 (all-ints (and (integerp init) (integerp limit) (integerp step)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2257 (const-limit (or (integerp limit)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2258 (and (eq (car-safe limit) 'quote)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2259 (math-realp (nth 1 limit)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2260 (const-step (or (integerp step)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2261 (and (eq (car-safe step) 'quote)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2262 (math-realp (nth 1 step)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2263 (save-limit (if const-limit limit (make-symbol "<limit>")))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2264 (save-step (if const-step step (make-symbol "<step>"))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2265 (cons 'let
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2266 (cons (append (if const-limit nil (list (list save-limit limit)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2267 (if const-step nil (list (list save-step step)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2268 (list (list var init)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2269 (list
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2270 (cons 'while
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2271 (cons (if all-ints
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2272 (if (> step 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2273 (list '<= var save-limit)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2274 (list '>= var save-limit))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2275 (list 'not
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2276 (if const-step
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2277 (if (or (math-posp step)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2278 (math-posp
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2279 (cdr-safe step)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2280 (list 'math-lessp
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2281 save-limit
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2282 var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2283 (list 'math-lessp
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2284 var
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2285 save-limit))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2286 (list 'if
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2287 (list 'math-posp
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2288 save-step)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2289 (list 'math-lessp
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2290 save-limit
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2291 var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2292 (list 'math-lessp
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2293 var
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2294 save-limit)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2295 (append body
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2296 (list (list 'setq
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2297 var
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2298 (list (if all-ints
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2299 '+
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2300 'math-add)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2301 var
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
2302 save-step)))))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2303
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2304 (defmacro math-foreach (head &rest body)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2305 (let ((body (math-handle-foreach head body)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2306 (if (math-body-refers-to body 'math-break)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2307 (cons 'catch (cons '(quote math-break) (list body)))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
2308 body)))
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
2309 ;; (put 'math-foreach 'lisp-indent-hook 1)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2310
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2311 (defun math-handle-foreach (head body)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2312 (let ((var (nth 0 (car head)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2313 (data (nth 1 (car head)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2314 (body (if (cdr head)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2315 (list (math-handle-foreach (cdr head) body))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2316 body)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2317 (cons 'let
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2318 (cons (list (list var data))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2319 (list
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2320 (cons 'while
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2321 (cons var
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2322 (append body
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2323 (list (list 'setq
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2324 var
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
2325 (list 'cdr var)))))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2326
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2327
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2328 (defun math-body-refers-to (body thing)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2329 (or (equal body thing)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2330 (and (consp body)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2331 (or (math-body-refers-to (car body) thing)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
2332 (math-body-refers-to (cdr body) thing)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2333
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2334 (defun math-break (&optional value)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
2335 (throw 'math-break value))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2336
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2337 (defun math-return (&optional value)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
2338 (throw 'math-return value))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2339
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2340
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2341
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2342
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2343
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2344 (defun math-composite-inequalities (x op)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2345 (if (memq (nth 1 op) '(calcFunc-eq calcFunc-neq))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2346 (if (eq (car x) (nth 1 op))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2347 (append x (list (math-read-expr-level (nth 3 op))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2348 (throw 'syntax "Syntax error"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2349 (list 'calcFunc-in
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2350 (nth 2 x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2351 (if (memq (nth 1 op) '(calcFunc-lt calcFunc-leq))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2352 (if (memq (car x) '(calcFunc-lt calcFunc-leq))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2353 (math-make-intv
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2354 (+ (if (eq (car x) 'calcFunc-leq) 2 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2355 (if (eq (nth 1 op) 'calcFunc-leq) 1 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2356 (nth 1 x) (math-read-expr-level (nth 3 op)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2357 (throw 'syntax "Syntax error"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2358 (if (memq (car x) '(calcFunc-gt calcFunc-geq))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2359 (math-make-intv
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2360 (+ (if (eq (nth 1 op) 'calcFunc-geq) 2 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2361 (if (eq (car x) 'calcFunc-geq) 1 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2362 (math-read-expr-level (nth 3 op)) (nth 1 x))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
2363 (throw 'syntax "Syntax error"))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2364
58668
827d00badeb5 Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58614
diff changeset
2365 (provide 'calc-prog)
827d00badeb5 Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58614
diff changeset
2366
93975
1e3a407766b9 Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92025
diff changeset
2367 ;; arch-tag: 4c5a183b-c9e5-4632-bb3f-e41a764518b0
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
2368 ;;; calc-prog.el ends here