(latexenc-find-file-coding-system): Don't inherit the EOL part of the
[emacs.git] / lisp / calc / calc-incom.el
blob3fdec5a4b0691a91560bf9bcbf70d94a0edca531
1 ;;; calc-incom.el --- complex data type input functions for Calc
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2005 Free Software Foundation, Inc.
5 ;; Author: David Gillespie <daveg@synaptics.com>
6 ;; Maintainer: Jay Belanger <belanger@truman.edu>
8 ;; This file is part of GNU Emacs.
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.
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.
25 ;;; Commentary:
27 ;;; Code:
29 ;; This file is autoloaded from calc-ext.el.
31 (require 'calc-ext)
32 (require 'calc-macs)
34 ;;; Incomplete forms.
36 (defun calc-begin-complex ()
37 (interactive)
38 (calc-wrapper
39 (if (or calc-algebraic-mode calc-incomplete-algebraic-mode)
40 (calc-alg-entry "(")
41 (calc-push (list 'incomplete calc-complex-mode)))))
43 (defun calc-end-complex ()
44 (interactive)
45 (calc-comma t)
46 (calc-wrapper
47 (let ((top (calc-top 1)))
48 (if (and (eq (car-safe top) 'incomplete)
49 (eq (nth 1 top) 'intv))
50 (progn
51 (if (< (length top) 4)
52 (setq top (append top '((neg (var inf var-inf))))))
53 (if (< (length top) 5)
54 (setq top (append top '((var inf var-inf)))))
55 (calc-enter-result 1 "..)" (cdr top)))
56 (if (not (and (eq (car-safe top) 'incomplete)
57 (memq (nth 1 top) '(cplx polar))))
58 (error "Not entering a complex number"))
59 (while (< (length top) 4)
60 (setq top (append top '(0))))
61 (if (not (and (math-realp (nth 2 top))
62 (math-anglep (nth 3 top))))
63 (error "Components must be real"))
64 (calc-enter-result 1 "()" (cdr top))))))
66 (defun calc-begin-vector ()
67 (interactive)
68 (calc-wrapper
69 (if (or calc-algebraic-mode calc-incomplete-algebraic-mode)
70 (calc-alg-entry "[")
71 (calc-push '(incomplete vec)))))
73 (defun calc-end-vector ()
74 (interactive)
75 (calc-comma t)
76 (calc-wrapper
77 (let ((top (calc-top 1)))
78 (if (and (eq (car-safe top) 'incomplete)
79 (eq (nth 1 top) 'intv))
80 (progn
81 (if (< (length top) 4)
82 (setq top (append top '((neg (var inf var-inf))))))
83 (if (< (length top) 5)
84 (setq top (append top '((var inf var-inf)))))
85 (setcar (cdr (cdr top)) (1+ (nth 2 top)))
86 (calc-enter-result 1 "..]" (cdr top)))
87 (if (not (and (eq (car-safe top) 'incomplete)
88 (eq (nth 1 top) 'vec)))
89 (error "Not entering a vector"))
90 (calc-pop-push-record 1 "[]" (cdr top))))))
92 (defun calc-comma (&optional allow-polar)
93 (interactive)
94 (calc-wrapper
95 (let ((num (calc-find-first-incomplete
96 (nthcdr calc-stack-top calc-stack) 1)))
97 (if (= num 0)
98 (error "Not entering a vector or complex number"))
99 (let* ((inc (calc-top num))
100 (stuff (calc-top-list (1- num)))
101 (new (append inc stuff)))
102 (if (and (null stuff)
103 (not allow-polar)
104 (or (eq (nth 1 inc) 'vec)
105 (< (length new) 4)))
106 (setq new (append new
107 (if (= (length new) 2)
108 '(0)
109 (nthcdr (1- (length new)) new)))))
110 (or allow-polar
111 (if (eq (nth 1 new) 'polar)
112 (setq new (append '(incomplete cplx) (cdr (cdr new))))
113 (if (eq (nth 1 new) 'intv)
114 (setq new (append '(incomplete cplx)
115 (cdr (cdr (cdr new))))))))
116 (if (and (memq (nth 1 new) '(cplx polar))
117 (> (length new) 4))
118 (error "Too many components in complex number"))
119 (if (and (eq (nth 1 new) 'intv)
120 (> (length new) 5))
121 (error "Too many components in interval form"))
122 (calc-pop-push num new)))))
124 (defun calc-semi ()
125 (interactive)
126 (calc-wrapper
127 (let ((num (calc-find-first-incomplete
128 (nthcdr calc-stack-top calc-stack) 1)))
129 (if (= num 0)
130 (error "Not entering a vector or complex number"))
131 (let ((inc (calc-top num))
132 (stuff (calc-top-list (1- num))))
133 (if (eq (nth 1 inc) 'cplx)
134 (setq inc (append '(incomplete polar) (cdr (cdr inc))))
135 (if (eq (nth 1 inc) 'intv)
136 (setq inc (append '(incomplete polar) (cdr (cdr (cdr inc)))))))
137 (cond ((eq (nth 1 inc) 'polar)
138 (let ((new (append inc stuff)))
139 (if (> (length new) 4)
140 (error "Too many components in complex number")
141 (if (= (length new) 2)
142 (setq new (append new '(1)))))
143 (calc-pop-push num new)))
144 ((null stuff)
145 (if (> (length inc) 2)
146 (if (math-vectorp (nth 2 inc))
147 (calc-comma)
148 (calc-pop-push 1
149 (list 'incomplete 'vec (cdr (cdr inc)))
150 (list 'incomplete 'vec)))))
151 ((math-vectorp (car stuff))
152 (calc-comma))
153 ((eq (car-safe (car-safe (nth (+ num calc-stack-top)
154 calc-stack))) 'incomplete)
155 (calc-end-vector)
156 (calc-comma)
157 (let ((calc-algebraic-mode nil)
158 (calc-incomplete-algebraic-mode nil))
159 (calc-begin-vector)))
160 ((or (= (length inc) 2)
161 (math-vectorp (nth 2 inc)))
162 (calc-pop-push num
163 (append inc (list (cons 'vec stuff)))
164 (list 'incomplete 'vec)))
166 (calc-pop-push num
167 (list 'incomplete 'vec
168 (cons 'vec (append (cdr (cdr inc)) stuff)))
169 (list 'incomplete 'vec))))))))
171 ;; The following variables are initially declared in calc.el,
172 ;; but are used by calc-digit-dots.
173 (defvar calc-prev-char)
174 (defvar calc-prev-prev-char)
175 (defvar calc-digit-value)
177 (defun calc-digit-dots ()
178 (if (eq calc-prev-char ?.)
179 (progn
180 (delete-backward-char 1)
181 (if (calc-minibuffer-contains ".*\\.\\'")
182 (delete-backward-char 1))
183 (setq calc-prev-char 'dots
184 last-command-char 32)
185 (if calc-prev-prev-char
186 (calcDigit-nondigit)
187 (setq calc-digit-value nil)
188 (let ((inhibit-read-only t))
189 (erase-buffer))
190 (exit-minibuffer)))
191 ;; just ignore extra decimal point, anticipating ".."
192 (delete-backward-char 1)))
194 (defun calc-dots ()
195 (interactive)
196 (calc-wrapper
197 (let ((num (calc-find-first-incomplete
198 (nthcdr calc-stack-top calc-stack) 1)))
199 (if (= num 0)
200 (error "Not entering an interval form"))
201 (let* ((inc (calc-top num))
202 (stuff (calc-top-list (1- num)))
203 (new (append inc stuff)))
204 (if (not (eq (nth 1 new) 'intv))
205 (setq new (append '(incomplete intv)
206 (if (eq (nth 1 new) 'vec) '(2) '(0))
207 (cdr (cdr new)))))
208 (if (and (null stuff)
209 (= (length new) 3))
210 (setq new (append new '((neg (var inf var-inf))))))
211 (if (> (length new) 5)
212 (error "Too many components in interval form"))
213 (calc-pop-push num new)))))
215 (defun calc-find-first-incomplete (stack n)
216 (cond ((null stack)
218 ((eq (car-safe (car-safe (car stack))) 'incomplete)
221 (calc-find-first-incomplete (cdr stack) (1+ n)))))
223 (defun calc-incomplete-error (a)
224 (cond ((memq (nth 1 a) '(cplx polar))
225 (error "Complex number is incomplete"))
226 ((eq (nth 1 a) 'vec)
227 (error "Vector is incomplete"))
228 ((eq (nth 1 a) 'intv)
229 (error "Interval form is incomplete"))
230 (t (error "Object is incomplete"))))
232 (provide 'calc-incom)
234 ;;; arch-tag: b8001270-4dc7-481b-a3e3-a952e19b390d
235 ;;; calc-incom.el ends here