Mercurial > emacs
annotate lisp/calc/calc-incom.el @ 98019:72564311fb7b
Add local variable setting for change-log-default-name.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Sat, 06 Sep 2008 02:55:23 +0000 |
parents | 6c9af2bfcfee |
children | a9dc0e7c3f2b |
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 |
64325
1db49616ce05
Update copyright information.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62442
diff
changeset
|
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004, |
79702 | 4 ;; 2005, 2006, 2007, 2008 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 | 8 |
9 ;; This file is part of GNU Emacs. | |
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 | 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 | 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: |
40785 | 25 |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
26 ;;; Code: |
40785 | 27 |
28 ;; This file is autoloaded from calc-ext.el. | |
58659
324e147417aa
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58550
diff
changeset
|
29 |
40785 | 30 (require 'calc-ext) |
31 (require 'calc-macs) | |
32 | |
33 ;;; Incomplete forms. | |
34 | |
35 (defun calc-begin-complex () | |
36 (interactive) | |
37 (calc-wrapper | |
38 (if (or calc-algebraic-mode calc-incomplete-algebraic-mode) | |
39 (calc-alg-entry "(") | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
40 (calc-push (list 'incomplete calc-complex-mode))))) |
40785 | 41 |
42 (defun calc-end-complex () | |
43 (interactive) | |
44 (calc-comma t) | |
45 (calc-wrapper | |
46 (let ((top (calc-top 1))) | |
47 (if (and (eq (car-safe top) 'incomplete) | |
48 (eq (nth 1 top) 'intv)) | |
49 (progn | |
50 (if (< (length top) 4) | |
51 (setq top (append top '((neg (var inf var-inf)))))) | |
52 (if (< (length top) 5) | |
53 (setq top (append top '((var inf var-inf))))) | |
54 (calc-enter-result 1 "..)" (cdr top))) | |
55 (if (not (and (eq (car-safe top) 'incomplete) | |
56 (memq (nth 1 top) '(cplx polar)))) | |
57 (error "Not entering a complex number")) | |
58 (while (< (length top) 4) | |
59 (setq top (append top '(0)))) | |
60 (if (not (and (math-realp (nth 2 top)) | |
61 (math-anglep (nth 3 top)))) | |
62 (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
|
63 (calc-enter-result 1 "()" (cdr top)))))) |
40785 | 64 |
65 (defun calc-begin-vector () | |
66 (interactive) | |
67 (calc-wrapper | |
68 (if (or calc-algebraic-mode calc-incomplete-algebraic-mode) | |
69 (calc-alg-entry "[") | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
70 (calc-push '(incomplete vec))))) |
40785 | 71 |
72 (defun calc-end-vector () | |
73 (interactive) | |
74 (calc-comma t) | |
75 (calc-wrapper | |
76 (let ((top (calc-top 1))) | |
77 (if (and (eq (car-safe top) 'incomplete) | |
78 (eq (nth 1 top) 'intv)) | |
79 (progn | |
80 (if (< (length top) 4) | |
81 (setq top (append top '((neg (var inf var-inf)))))) | |
82 (if (< (length top) 5) | |
83 (setq top (append top '((var inf var-inf))))) | |
84 (setcar (cdr (cdr top)) (1+ (nth 2 top))) | |
85 (calc-enter-result 1 "..]" (cdr top))) | |
86 (if (not (and (eq (car-safe top) 'incomplete) | |
87 (eq (nth 1 top) 'vec))) | |
88 (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
|
89 (calc-pop-push-record 1 "[]" (cdr top)))))) |
40785 | 90 |
91 (defun calc-comma (&optional allow-polar) | |
92 (interactive) | |
93 (calc-wrapper | |
94 (let ((num (calc-find-first-incomplete | |
95 (nthcdr calc-stack-top calc-stack) 1))) | |
96 (if (= num 0) | |
97 (error "Not entering a vector or complex number")) | |
98 (let* ((inc (calc-top num)) | |
99 (stuff (calc-top-list (1- num))) | |
100 (new (append inc stuff))) | |
101 (if (and (null stuff) | |
102 (not allow-polar) | |
103 (or (eq (nth 1 inc) 'vec) | |
104 (< (length new) 4))) | |
105 (setq new (append new | |
106 (if (= (length new) 2) | |
107 '(0) | |
108 (nthcdr (1- (length new)) new))))) | |
109 (or allow-polar | |
110 (if (eq (nth 1 new) 'polar) | |
111 (setq new (append '(incomplete cplx) (cdr (cdr new)))) | |
112 (if (eq (nth 1 new) 'intv) | |
113 (setq new (append '(incomplete cplx) | |
114 (cdr (cdr (cdr new)))))))) | |
115 (if (and (memq (nth 1 new) '(cplx polar)) | |
116 (> (length new) 4)) | |
117 (error "Too many components in complex number")) | |
118 (if (and (eq (nth 1 new) 'intv) | |
119 (> (length new) 5)) | |
120 (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
|
121 (calc-pop-push num new))))) |
40785 | 122 |
123 (defun calc-semi () | |
124 (interactive) | |
125 (calc-wrapper | |
126 (let ((num (calc-find-first-incomplete | |
127 (nthcdr calc-stack-top calc-stack) 1))) | |
128 (if (= num 0) | |
129 (error "Not entering a vector or complex number")) | |
130 (let ((inc (calc-top num)) | |
131 (stuff (calc-top-list (1- num)))) | |
132 (if (eq (nth 1 inc) 'cplx) | |
133 (setq inc (append '(incomplete polar) (cdr (cdr inc)))) | |
134 (if (eq (nth 1 inc) 'intv) | |
135 (setq inc (append '(incomplete polar) (cdr (cdr (cdr inc))))))) | |
136 (cond ((eq (nth 1 inc) 'polar) | |
137 (let ((new (append inc stuff))) | |
138 (if (> (length new) 4) | |
139 (error "Too many components in complex number") | |
140 (if (= (length new) 2) | |
141 (setq new (append new '(1))))) | |
142 (calc-pop-push num new))) | |
143 ((null stuff) | |
144 (if (> (length inc) 2) | |
145 (if (math-vectorp (nth 2 inc)) | |
146 (calc-comma) | |
147 (calc-pop-push 1 | |
148 (list 'incomplete 'vec (cdr (cdr inc))) | |
149 (list 'incomplete 'vec))))) | |
150 ((math-vectorp (car stuff)) | |
151 (calc-comma)) | |
152 ((eq (car-safe (car-safe (nth (+ num calc-stack-top) | |
153 calc-stack))) 'incomplete) | |
154 (calc-end-vector) | |
155 (calc-comma) | |
156 (let ((calc-algebraic-mode nil) | |
157 (calc-incomplete-algebraic-mode nil)) | |
158 (calc-begin-vector))) | |
159 ((or (= (length inc) 2) | |
160 (math-vectorp (nth 2 inc))) | |
161 (calc-pop-push num | |
162 (append inc (list (cons 'vec stuff))) | |
163 (list 'incomplete 'vec))) | |
164 (t | |
165 (calc-pop-push num | |
166 (list 'incomplete 'vec | |
167 (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
|
168 (list 'incomplete 'vec)))))))) |
40785 | 169 |
58550
938592e66a8e
(calc-prev-char, calc-prev-prev-char, calc-digit-value): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57691
diff
changeset
|
170 ;; The following variables are initially declared in calc.el, |
938592e66a8e
(calc-prev-char, calc-prev-prev-char, calc-digit-value): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57691
diff
changeset
|
171 ;; but are used by calc-digit-dots. |
938592e66a8e
(calc-prev-char, calc-prev-prev-char, calc-digit-value): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57691
diff
changeset
|
172 (defvar calc-prev-char) |
938592e66a8e
(calc-prev-char, calc-prev-prev-char, calc-digit-value): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57691
diff
changeset
|
173 (defvar calc-prev-prev-char) |
938592e66a8e
(calc-prev-char, calc-prev-prev-char, calc-digit-value): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57691
diff
changeset
|
174 (defvar calc-digit-value) |
938592e66a8e
(calc-prev-char, calc-prev-prev-char, calc-digit-value): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57691
diff
changeset
|
175 |
40785 | 176 (defun calc-digit-dots () |
177 (if (eq calc-prev-char ?.) | |
178 (progn | |
179 (delete-backward-char 1) | |
180 (if (calc-minibuffer-contains ".*\\.\\'") | |
181 (delete-backward-char 1)) | |
182 (setq calc-prev-char 'dots | |
183 last-command-char 32) | |
184 (if calc-prev-prev-char | |
185 (calcDigit-nondigit) | |
186 (setq calc-digit-value nil) | |
57691
8dc3dd828d67
(calc-digit-dots): Inhibit read-only before erasing minibuffer.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
187 (let ((inhibit-read-only t)) |
8dc3dd828d67
(calc-digit-dots): Inhibit read-only before erasing minibuffer.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
188 (erase-buffer)) |
40785 | 189 (exit-minibuffer))) |
190 ;; 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
|
191 (delete-backward-char 1))) |
40785 | 192 |
193 (defun calc-dots () | |
194 (interactive) | |
195 (calc-wrapper | |
196 (let ((num (calc-find-first-incomplete | |
197 (nthcdr calc-stack-top calc-stack) 1))) | |
198 (if (= num 0) | |
199 (error "Not entering an interval form")) | |
200 (let* ((inc (calc-top num)) | |
201 (stuff (calc-top-list (1- num))) | |
202 (new (append inc stuff))) | |
203 (if (not (eq (nth 1 new) 'intv)) | |
204 (setq new (append '(incomplete intv) | |
205 (if (eq (nth 1 new) 'vec) '(2) '(0)) | |
206 (cdr (cdr new))))) | |
207 (if (and (null stuff) | |
208 (= (length new) 3)) | |
209 (setq new (append new '((neg (var inf var-inf)))))) | |
210 (if (> (length new) 5) | |
211 (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
|
212 (calc-pop-push num new))))) |
40785 | 213 |
214 (defun calc-find-first-incomplete (stack n) | |
215 (cond ((null stack) | |
216 0) | |
217 ((eq (car-safe (car-safe (car stack))) 'incomplete) | |
218 n) | |
219 (t | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
220 (calc-find-first-incomplete (cdr stack) (1+ n))))) |
40785 | 221 |
222 (defun calc-incomplete-error (a) | |
223 (cond ((memq (nth 1 a) '(cplx polar)) | |
224 (error "Complex number is incomplete")) | |
225 ((eq (nth 1 a) 'vec) | |
226 (error "Vector is incomplete")) | |
227 ((eq (nth 1 a) 'intv) | |
228 (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
|
229 (t (error "Object is incomplete")))) |
40785 | 230 |
58659
324e147417aa
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58550
diff
changeset
|
231 (provide 'calc-incom) |
324e147417aa
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58550
diff
changeset
|
232 |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
79702
diff
changeset
|
233 ;; arch-tag: b8001270-4dc7-481b-a3e3-a952e19b390d |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
234 ;;; calc-incom.el ends here |