-;; Calculator for GNU Emacs, part I [calc-aent.el]
+;;; calc-aent.el --- algebraic entry functions for Calc
+
;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc.
-;; Written by Dave Gillespie, daveg@synaptics.com.
+
+;; Author: Dave Gillespie <daveg@synaptics.com>
+;; Maintainers: D. Goel <deego@gnufans.org>
+;; Colin Walters <walters@debian.org>
;; This file is part of GNU Emacs.
;; file named COPYING. Among other things, the copyright notice
;; and this notice must be preserved on all copies.
+;;; Commentary:
+;;; Code:
;; This file is autoloaded from calc.el.
(require 'calc)
(calc-extensions)
(math-evaluate-expr x))))
entry)))
- (if (and (= (length alg-exp) 1)
- (eq (car-safe (car alg-exp)) 'calcFunc-assign)
- (= (length (car alg-exp)) 3)
- (eq (car-safe (nth 1 (car alg-exp))) 'var))
- (progn
- (calc-extensions)
- (set (nth 2 (nth 1 (car alg-exp))) (nth 2 (car alg-exp)))
- (calc-refresh-evaltos (nth 2 (nth 1 (car alg-exp))))
- (setq alg-exp (list (nth 2 (car alg-exp))))))
+ (when (and (= (length alg-exp) 1)
+ (eq (car-safe (car alg-exp)) 'calcFunc-assign)
+ (= (length (car alg-exp)) 3)
+ (eq (car-safe (nth 1 (car alg-exp))) 'var))
+ (calc-extensions)
+ (set (nth 2 (nth 1 (car alg-exp))) (nth 2 (car alg-exp)))
+ (calc-refresh-evaltos (nth 2 (nth 1 (car alg-exp))))
+ (setq alg-exp (list (nth 2 (car alg-exp)))))
(setq calc-quick-prev-results alg-exp
buf (mapconcat (function (lambda (x)
(math-format-value x 1000)))
(if (eq last-command-char 10)
(insert shortbuf)
(setq kill-ring (cons shortbuf kill-ring))
- (if (> (length kill-ring) kill-ring-max)
- (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil))
- (setq kill-ring-yank-pointer kill-ring))))
-)
+ (when (> (length kill-ring) kill-ring-max)
+ (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil))
+ (setq kill-ring-yank-pointer kill-ring)))))
(defun calc-do-calc-eval (str separator args)
(calc-check-defines)
(and buf (or separator ", "))
(math-format-value (car res) 1000))
res (cdr res)))
- buf))))))))
-)
+ buf)))))))))
(defun calc-eval-error (msg)
(if (and (boundp 'calc-eval-error)
(if (eq calc-eval-error 'string)
(nth 1 msg)
(error "%s" (nth 1 msg)))
- msg)
-)
+ msg))
;;;; Reading an expression in algebraic form.
(defun calc-auto-algebraic-entry (&optional prefix)
(interactive "P")
- (calc-algebraic-entry prefix t)
-)
+ (calc-algebraic-entry prefix t))
(defun calc-algebraic-entry (&optional prefix auto)
(interactive "P")
(calc-wrapper
(let ((calc-language (if prefix nil calc-language))
(math-expr-opers (if prefix math-standard-opers math-expr-opers)))
- (calc-alg-entry (and auto (char-to-string last-command-char)))))
-)
+ (calc-alg-entry (and auto (char-to-string last-command-char))))))
(defun calc-alg-entry (&optional initial prompt)
(let* ((sel-mode nil)
(setq alg-exp (cdr alg-exp)
nvals (cdr nvals)
calc-dollar-used 0)))
- (calc-handle-whys)))
-)
+ (calc-handle-whys))))
(defun calc-do-alg-entry (&optional initial prompt no-normalize)
(let* ((calc-buffer (current-buffer))
(blink-paren-function 'calcAlg-blink-matching-open)
(alg-exp 'error))
- (if (boundp 'calc-alg-ent-map)
- ()
+ (unless (boundp 'calc-alg-ent-map)
(setq calc-alg-ent-map (copy-keymap minibuffer-local-map))
(define-key calc-alg-ent-map "'" 'calcAlg-previous)
(define-key calc-alg-ent-map "`" 'calcAlg-edit)
(while (< i 127)
(aset calc-alg-ent-esc-map i 'calcAlg-escape)
(setq i (1+ i))))))
- (or calc-emacs-type-19
- (define-key calc-alg-ent-map "\e" nil))
+ (unless calc-emacs-type-19
+ (define-key calc-alg-ent-map "\e" nil))
(if (eq calc-algebraic-mode 'total)
(define-key calc-alg-ent-map "\e" calc-alg-ent-esc-map)
(define-key calc-alg-ent-map "\ep" 'calcAlg-plus-minus)
(let ((buf (read-from-minibuffer (or prompt "Algebraic: ")
(or initial "")
calc-alg-ent-map nil)))
- (if (eq alg-exp 'error)
- (if (eq (car-safe (setq alg-exp (math-read-exprs buf))) 'error)
- (setq alg-exp nil)))
+ (when (eq alg-exp 'error)
+ (when (eq (car-safe (setq alg-exp (math-read-exprs buf))) 'error)
+ (setq alg-exp nil)))
(setq calc-aborted-prefix "alg'")
(or no-normalize
(and alg-exp (setq alg-exp (mapcar 'calc-normalize alg-exp))))
- alg-exp))
-)
+ alg-exp)))
(defun calcAlg-plus-minus ()
(interactive)
(if (calc-minibuffer-contains ".* \\'")
(insert "+/- ")
- (insert " +/- "))
-)
+ (insert " +/- ")))
(defun calcAlg-mod ()
(interactive)
(if calc-previous-modulo
(insert (math-format-flat-expr calc-previous-modulo 0))
(beep))
- (insert "mod "))
-)
+ (insert "mod ")))
(defun calcAlg-previous ()
(interactive)
(if calc-previous-alg-entry
(insert calc-previous-alg-entry)
(beep))
- (insert "'"))
-)
+ (insert "'")))
(defun calcAlg-equals ()
(interactive)
(calcAlg-enter)
(if (consp alg-exp)
(progn (setq prefix-arg (length alg-exp))
- (calc-unread-command ?=))))
-)
+ (calc-unread-command ?=)))))
(defun calcAlg-escape ()
(interactive)
(save-excursion
(calc-select-buffer)
(use-local-map calc-mode-map))
- (calcAlg-enter)
-)
+ (calcAlg-enter))
+(defvar calc-plain-entry nil)
(defun calcAlg-edit ()
(interactive)
(if (or (not calc-plain-entry)
(insert "`")
(setq alg-exp (minibuffer-contents))
(and (> (length alg-exp) 0) (setq calc-previous-alg-entry alg-exp))
- (exit-minibuffer))
-)
-(setq calc-plain-entry nil)
+ (exit-minibuffer)))
(defun calcAlg-enter ()
(interactive)
'((incomplete vec))
exp))
(and (> (length str) 0) (setq calc-previous-alg-entry str))
- (exit-minibuffer)))
-)
+ (exit-minibuffer))))
(defun calcAlg-blink-matching-open ()
(let ((oldpos (point))
(lsh (char-after (1- oldpos)) 8)))
(blink-matching-open))
(aset (syntax-table) (char-after blinkpos) saved)))
- (blink-matching-open)))
-)
+ (blink-matching-open))))
(defun calc-alg-digit-entry ()
- (calc-alg-entry
+ (calc-alg-entry
(cond ((eq last-command-char ?e)
(if (> calc-number-radix 14) (format "%d.^" calc-number-radix) "1e"))
((eq last-command-char ?#) (format "%d#" calc-number-radix))
((eq last-command-char ?_) "-")
((eq last-command-char ?@) "0@ ")
- (t (char-to-string last-command-char))))
-)
+ (t (char-to-string last-command-char)))))
(defun calcDigit-algebraic ()
(interactive)
(if (calc-minibuffer-contains ".*[@oh] *[^'m ]+[^'m]*\\'")
(calcDigit-key)
(setq calc-digit-value (minibuffer-contents))
- (exit-minibuffer))
-)
+ (exit-minibuffer)))
(defun calcDigit-edit ()
(interactive)
(calc-unread-command)
(setq calc-digit-value (minibuffer-contents))
- (exit-minibuffer)
-)
+ (exit-minibuffer))
;;; Algebraic expression parsing. [Public]
(list 'error exp-old-pos val)
(if (equal exp-token 'end)
val
- (list 'error exp-old-pos "Syntax error")))))
-)
+ (list 'error exp-old-pos "Syntax error"))))))
(defun math-read-expr-list ()
(let* ((exp-keep-spaces nil)
(let ((rest (list (math-read-expr-level 0))))
(setcdr last rest)
(setq last rest)))
- val)
-)
+ val))
-(setq calc-user-parse-table nil)
-(setq calc-last-main-parse-table nil)
-(setq calc-last-lang-parse-table nil)
-(setq calc-user-tokens nil)
-(setq calc-user-token-chars nil)
+(defvar calc-user-parse-table nil)
+(defvar calc-last-main-parse-table nil)
+(defvar calc-last-lang-parse-table nil)
+(defvar calc-user-tokens nil)
+(defvar calc-user-token-chars nil)
(defun math-build-parse-table ()
(let ((mtab (cdr (assq nil calc-user-parse-tables)))
(length y)))))
"\\|")
calc-last-main-parse-table mtab
- calc-last-lang-parse-table ltab))))
-)
+ calc-last-lang-parse-table ltab)))))
(defun math-find-user-tokens (p) ; uses "toks"
(while p
(math-find-user-tokens (nth 1 (car p)))
(or (eq (car (car p)) '\?)
(math-find-user-tokens (nth 2 (car p))))))
- (setq p (cdr p)))
-)
+ (setq p (cdr p))))
(defun math-read-token ()
(if (>= exp-pos (length exp-str))
(setq ch ?\,))
(setq exp-token 'punc
exp-data (char-to-string ch)
- exp-pos (1+ exp-pos))))))
-)
+ exp-pos (1+ exp-pos)))))))
(defun math-read-expr-level (exp-prec &optional exp-term)
x
(math-read-expr-level (nth 3 op) exp-term))))
first nil))
- x)
-)
+ x))
(defun calc-check-user-syntax (&optional x prec)
(let ((p calc-user-parse-table)
exp-data save-exp-data
exp-pos save-exp-pos)))))))
(setq p (cdr p)))
- (and p match))
-)
+ (and p match)))
(defun calc-match-user-syntax (p &optional term)
(let ((matches nil)
exp-token save-exp-token
exp-data save-exp-data
matches "Failed"))
- matches)
-)
+ matches))
(defconst math-alg-inequalities
'(calcFunc-lt calcFunc-gt calcFunc-leq calcFunc-geq
(if (string-match "\\`\\(.*\\)-\\(.*\\)\\'" x)
(math-remove-dashes
(concat (math-match-substring x 1) "#" (math-match-substring x 2)))
- x)
-)
+ x))
(defun math-restore-dashes (x)
(if (string-match "\\`\\(.*\\)[#_]\\(.*\\)\\'" x)
(math-restore-dashes
(concat (math-match-substring x 1) "-" (math-match-substring x 2)))
- x)
-)
+ x))
(defun math-read-if (cond op)
(let ((then (math-read-expr-level 0)))
(or (equal exp-data ":")
(throw 'syntax "Expected ':'"))
(math-read-token)
- (list 'calcFunc-if cond then (math-read-expr-level (nth 3 op))))
-)
+ (list 'calcFunc-if cond then (math-read-expr-level (nth 3 op)))))
(defun math-factor-after ()
(let ((exp-pos exp-pos)
(and (assoc exp-data '(("-") ("+") ("!") ("|") ("/")))
(assoc (concat "u" exp-data) math-expr-opers))
(eq (nth 2 (assoc exp-data math-expr-opers)) -1)
- (assoc exp-data '(("(") ("[") ("{")))))
-)
+ (assoc exp-data '(("(") ("[") ("{"))))))
(defun math-read-factor ()
(let (op)
((equal exp-data "<")
(calc-extensions)
(math-read-angle-brackets))
- (t (throw 'syntax "Expected a number"))))
-)
-
-
+ (t (throw 'syntax "Expected a number")))))
+;;; arch-tag: 5599e45d-e51e-44bb-9a20-9f4ed8c96c32
+;;; calc-aent.el ends here