Mercurial > emacs
annotate lisp/calc/calc-incom.el @ 41509:aeb0c4a140d2
(lisp-indent-function): Add doc string.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 25 Nov 2001 19:32:53 +0000 |
parents | fcd507927105 |
children | f4d68f97221e |
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-incom.el --- complex data type input 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 |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 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
|
4 |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
5 ;; Author: David Gillespie <daveg@synaptics.com> |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
6 ;; Maintainer: Colin Walters <walters@debian.org> |
40785 | 7 |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is distributed in the hope that it will be useful, | |
11 ;; but WITHOUT ANY WARRANTY. No author or distributor | |
12 ;; accepts responsibility to anyone for the consequences of using it | |
13 ;; or for whether it serves any particular purpose or works at all, | |
14 ;; unless he says so in writing. Refer to the GNU Emacs General Public | |
15 ;; License for full details. | |
16 | |
17 ;; Everyone is granted permission to copy, modify and redistribute | |
18 ;; GNU Emacs, but only under the conditions described in the | |
19 ;; GNU Emacs General Public License. A copy of this license is | |
20 ;; supposed to have been given to you along with GNU Emacs so you | |
21 ;; can know your rights and responsibilities. It should be in a | |
22 ;; file named COPYING. Among other things, the copyright notice | |
23 ;; and this notice must be preserved on all copies. | |
24 | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
25 ;;; Commentary: |
40785 | 26 |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
27 ;;; Code: |
40785 | 28 |
29 ;; This file is autoloaded from calc-ext.el. | |
30 (require 'calc-ext) | |
31 | |
32 (require 'calc-macs) | |
33 | |
34 (defun calc-Need-calc-incom () nil) | |
35 | |
36 | |
37 ;;; Incomplete forms. | |
38 | |
39 (defun calc-begin-complex () | |
40 (interactive) | |
41 (calc-wrapper | |
42 (if (or calc-algebraic-mode calc-incomplete-algebraic-mode) | |
43 (calc-alg-entry "(") | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
44 (calc-push (list 'incomplete calc-complex-mode))))) |
40785 | 45 |
46 (defun calc-end-complex () | |
47 (interactive) | |
48 (calc-comma t) | |
49 (calc-wrapper | |
50 (let ((top (calc-top 1))) | |
51 (if (and (eq (car-safe top) 'incomplete) | |
52 (eq (nth 1 top) 'intv)) | |
53 (progn | |
54 (if (< (length top) 4) | |
55 (setq top (append top '((neg (var inf var-inf)))))) | |
56 (if (< (length top) 5) | |
57 (setq top (append top '((var inf var-inf))))) | |
58 (calc-enter-result 1 "..)" (cdr top))) | |
59 (if (not (and (eq (car-safe top) 'incomplete) | |
60 (memq (nth 1 top) '(cplx polar)))) | |
61 (error "Not entering a complex number")) | |
62 (while (< (length top) 4) | |
63 (setq top (append top '(0)))) | |
64 (if (not (and (math-realp (nth 2 top)) | |
65 (math-anglep (nth 3 top)))) | |
66 (error "Components must be real")) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
67 (calc-enter-result 1 "()" (cdr top)))))) |
40785 | 68 |
69 (defun calc-begin-vector () | |
70 (interactive) | |
71 (calc-wrapper | |
72 (if (or calc-algebraic-mode calc-incomplete-algebraic-mode) | |
73 (calc-alg-entry "[") | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
74 (calc-push '(incomplete vec))))) |
40785 | 75 |
76 (defun calc-end-vector () | |
77 (interactive) | |
78 (calc-comma t) | |
79 (calc-wrapper | |
80 (let ((top (calc-top 1))) | |
81 (if (and (eq (car-safe top) 'incomplete) | |
82 (eq (nth 1 top) 'intv)) | |
83 (progn | |
84 (if (< (length top) 4) | |
85 (setq top (append top '((neg (var inf var-inf)))))) | |
86 (if (< (length top) 5) | |
87 (setq top (append top '((var inf var-inf))))) | |
88 (setcar (cdr (cdr top)) (1+ (nth 2 top))) | |
89 (calc-enter-result 1 "..]" (cdr top))) | |
90 (if (not (and (eq (car-safe top) 'incomplete) | |
91 (eq (nth 1 top) 'vec))) | |
92 (error "Not entering a vector")) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
93 (calc-pop-push-record 1 "[]" (cdr top)))))) |
40785 | 94 |
95 (defun calc-comma (&optional allow-polar) | |
96 (interactive) | |
97 (calc-wrapper | |
98 (let ((num (calc-find-first-incomplete | |
99 (nthcdr calc-stack-top calc-stack) 1))) | |
100 (if (= num 0) | |
101 (error "Not entering a vector or complex number")) | |
102 (let* ((inc (calc-top num)) | |
103 (stuff (calc-top-list (1- num))) | |
104 (new (append inc stuff))) | |
105 (if (and (null stuff) | |
106 (not allow-polar) | |
107 (or (eq (nth 1 inc) 'vec) | |
108 (< (length new) 4))) | |
109 (setq new (append new | |
110 (if (= (length new) 2) | |
111 '(0) | |
112 (nthcdr (1- (length new)) new))))) | |
113 (or allow-polar | |
114 (if (eq (nth 1 new) 'polar) | |
115 (setq new (append '(incomplete cplx) (cdr (cdr new)))) | |
116 (if (eq (nth 1 new) 'intv) | |
117 (setq new (append '(incomplete cplx) | |
118 (cdr (cdr (cdr new)))))))) | |
119 (if (and (memq (nth 1 new) '(cplx polar)) | |
120 (> (length new) 4)) | |
121 (error "Too many components in complex number")) | |
122 (if (and (eq (nth 1 new) 'intv) | |
123 (> (length new) 5)) | |
124 (error "Too many components in interval form")) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
125 (calc-pop-push num new))))) |
40785 | 126 |
127 (defun calc-semi () | |
128 (interactive) | |
129 (calc-wrapper | |
130 (let ((num (calc-find-first-incomplete | |
131 (nthcdr calc-stack-top calc-stack) 1))) | |
132 (if (= num 0) | |
133 (error "Not entering a vector or complex number")) | |
134 (let ((inc (calc-top num)) | |
135 (stuff (calc-top-list (1- num)))) | |
136 (if (eq (nth 1 inc) 'cplx) | |
137 (setq inc (append '(incomplete polar) (cdr (cdr inc)))) | |
138 (if (eq (nth 1 inc) 'intv) | |
139 (setq inc (append '(incomplete polar) (cdr (cdr (cdr inc))))))) | |
140 (cond ((eq (nth 1 inc) 'polar) | |
141 (let ((new (append inc stuff))) | |
142 (if (> (length new) 4) | |
143 (error "Too many components in complex number") | |
144 (if (= (length new) 2) | |
145 (setq new (append new '(1))))) | |
146 (calc-pop-push num new))) | |
147 ((null stuff) | |
148 (if (> (length inc) 2) | |
149 (if (math-vectorp (nth 2 inc)) | |
150 (calc-comma) | |
151 (calc-pop-push 1 | |
152 (list 'incomplete 'vec (cdr (cdr inc))) | |
153 (list 'incomplete 'vec))))) | |
154 ((math-vectorp (car stuff)) | |
155 (calc-comma)) | |
156 ((eq (car-safe (car-safe (nth (+ num calc-stack-top) | |
157 calc-stack))) 'incomplete) | |
158 (calc-end-vector) | |
159 (calc-comma) | |
160 (let ((calc-algebraic-mode nil) | |
161 (calc-incomplete-algebraic-mode nil)) | |
162 (calc-begin-vector))) | |
163 ((or (= (length inc) 2) | |
164 (math-vectorp (nth 2 inc))) | |
165 (calc-pop-push num | |
166 (append inc (list (cons 'vec stuff))) | |
167 (list 'incomplete 'vec))) | |
168 (t | |
169 (calc-pop-push num | |
170 (list 'incomplete 'vec | |
171 (cons 'vec (append (cdr (cdr inc)) stuff))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
172 (list 'incomplete 'vec)))))))) |
40785 | 173 |
174 (defun calc-digit-dots () | |
175 (if (eq calc-prev-char ?.) | |
176 (progn | |
177 (delete-backward-char 1) | |
178 (if (calc-minibuffer-contains ".*\\.\\'") | |
179 (delete-backward-char 1)) | |
180 (setq calc-prev-char 'dots | |
181 last-command-char 32) | |
182 (if calc-prev-prev-char | |
183 (calcDigit-nondigit) | |
184 (setq calc-digit-value nil) | |
185 (erase-buffer) | |
186 (exit-minibuffer))) | |
187 ;; just ignore extra decimal point, anticipating ".." | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
188 (delete-backward-char 1))) |
40785 | 189 |
190 (defun calc-dots () | |
191 (interactive) | |
192 (calc-wrapper | |
193 (let ((num (calc-find-first-incomplete | |
194 (nthcdr calc-stack-top calc-stack) 1))) | |
195 (if (= num 0) | |
196 (error "Not entering an interval form")) | |
197 (let* ((inc (calc-top num)) | |
198 (stuff (calc-top-list (1- num))) | |
199 (new (append inc stuff))) | |
200 (if (not (eq (nth 1 new) 'intv)) | |
201 (setq new (append '(incomplete intv) | |
202 (if (eq (nth 1 new) 'vec) '(2) '(0)) | |
203 (cdr (cdr new))))) | |
204 (if (and (null stuff) | |
205 (= (length new) 3)) | |
206 (setq new (append new '((neg (var inf var-inf)))))) | |
207 (if (> (length new) 5) | |
208 (error "Too many components in interval form")) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
209 (calc-pop-push num new))))) |
40785 | 210 |
211 (defun calc-find-first-incomplete (stack n) | |
212 (cond ((null stack) | |
213 0) | |
214 ((eq (car-safe (car-safe (car stack))) 'incomplete) | |
215 n) | |
216 (t | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
217 (calc-find-first-incomplete (cdr stack) (1+ n))))) |
40785 | 218 |
219 (defun calc-incomplete-error (a) | |
220 (cond ((memq (nth 1 a) '(cplx polar)) | |
221 (error "Complex number is incomplete")) | |
222 ((eq (nth 1 a) 'vec) | |
223 (error "Vector is incomplete")) | |
224 ((eq (nth 1 a) 'intv) | |
225 (error "Interval form is incomplete")) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
226 (t (error "Object is incomplete")))) |
40785 | 227 |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
228 ;;; calc-incom.el ends here |