Xref: utzoo gnu.emacs:3137 comp.emacs:8565 Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!sdd.hp.com!elroy.jpl.nasa.gov!cit-vax!daveg From: daveg@cit-vax.Caltech.Edu (David Gillespie) Newsgroups: gnu.emacs,comp.emacs Subject: Patch for GNU Emacs Calc, version 1.02 -> 1.03 Message-ID: <15426@cit-vax.Caltech.Edu> Date: 27 Jun 90 05:53:09 GMT Reply-To: daveg@csvax.caltech.edu (David Gillespie) Organization: California Institute of Technology Lines: 669 The following patches convert Calc version 1.02 into Calc version 1.03. To apply them automatically with Patch v2.0, first cd into your Calc distribution directory, then execute "patch -p0 = ch ?0) (<= ch ?9)) ! (memq ch '(?\. ?_))) (or (and (eq calc-language 'c) (string-match "0[xX][0-9a-fA-F]+" exp-str exp-pos)) (string-match "_?\\([0-9]+.?0*@ *\\)?\\([0-9]+.?0*' *\\)?\\([0-9]+\\(#\\|\\^\\^\\)[0-9a-zA-Z:]+\\|[0-9]+:[0-9:]+\\|[0-9.]+\\([eE][-+_]?[0-9]+\\)?\"?\\)?" exp-str exp-pos)) --- 3832,3842 ---- exp-data (math-restore-dashes (math-match-substring exp-str 0)))) ((or (and (>= ch ?0) (<= ch ?9)) ! (eq ch '?\.) ! (and (eq ch '?_) ! (or (not (eq calc-language 'tex)) ! (eq exp-pos 0) ! (memq (elt exp-str (1- exp-pos)) '(32 ?\())))) (or (and (eq calc-language 'c) (string-match "0[xX][0-9a-fA-F]+" exp-str exp-pos)) (string-match "_?\\([0-9]+.?0*@ *\\)?\\([0-9]+.?0*' *\\)?\\([0-9]+\\(#\\|\\^\\^\\)[0-9a-zA-Z:]+\\|[0-9]+:[0-9:]+\\|[0-9.]+\\([eE][-+_]?[0-9]+\\)?\"?\\)?" exp-str exp-pos)) *************** *** 4072,4078 **** (interactive "sBug Subject: ") (mail nil calc-bug-address topic) (goto-char (point-max)) ! (insert "\nIn Calc 1.02, Emacs " (emacs-version) "\n\n") (message (substitute-command-keys "Type \\[mail-send] to send bug report.")) ) --- 4106,4112 ---- (interactive "sBug Subject: ") (mail nil calc-bug-address topic) (goto-char (point-max)) ! (insert "\nIn Calc 1.03, Emacs " (emacs-version) "\n\n") (message (substitute-command-keys "Type \\[mail-send] to send bug report.")) ) *** calc-ext.el Wed Jun 13 11:27:16 1990 --- ../dist/calc-ext.el Tue Jun 26 17:02:21 1990 *************** *** 1,4 **** ! ;; Calculator for GNU Emacs, part II ;; Copyright (C) 1990 Dave Gillespie ;; This file is part of GNU Emacs. --- 1,4 ---- ! ;; Calculator for GNU Emacs version 1.03, part II ;; Copyright (C) 1990 Dave Gillespie ;; This file is part of GNU Emacs. *************** *** 1454,1466 **** (t s)) ) ! (defun calc-grab-region (top bot) "Parse the region as a matrix of numbers and push it on the Calculator stack. This is intended to be used in a non-Calculator buffer! If the start and the end of the region are in column zero, the contained lines are parsed into rows of the matrix. Otherwise, point and mark define a ! rectangle which is parsed into a matrix." ! (interactive "r") (and (memq major-mode '(calc-mode calc-trail-mode)) (error "This command works only in a regular text buffer.")) (let* ((col1 (save-excursion (goto-char top) (current-column))) --- 1454,1480 ---- (t s)) ) ! (defun calc-grab-region (top bot arg) "Parse the region as a matrix of numbers and push it on the Calculator stack. This is intended to be used in a non-Calculator buffer! If the start and the end of the region are in column zero, the contained lines are parsed into rows of the matrix. Otherwise, point and mark define a ! rectangle which is parsed into a matrix. ! ! With a positive numeric prefix N, each line is divided into columns of ! width N which become the elements of that row of the matrix. With a ! prefix of zero, each line is interpreted in its entirety as a formula ! which becomes a row of the (one-column) matrix. ! ! Otherwise, if a line contains a portion delimited by square brackets ! or curly braces (possibly surrounded by other ignored text), that portion ! is interpreted as a vector which becomes a row of the matrix. This can be ! suppressed by giving a negative numeric prefix argument. ! ! Otherwise, the entire contents of the line are parsed as if surrounded by ! brackets. If a stack-style line number (as in \"23: \") is present it is ! first removed." ! (interactive "r\nP") (and (memq major-mode '(calc-mode calc-trail-mode)) (error "This command works only in a regular text buffer.")) (let* ((col1 (save-excursion (goto-char top) (current-column))) *************** *** 1481,1505 **** (calc) (setq mat (list 'vec) lnum 0) (while data ! (if (string-match "[[{][^][{}]*[]}]" (car data)) ! (setq pos (match-beginning 0) ! vals (math-read-expr (math-match-substring (car data) 0))) ! (if (string-match "\\`\\([0-9]+:[ \t]\\)?\\(.*[^, \t]\\)[, \t]*\\'" (car data)) (setq pos -1 ! vals (math-read-expr (concat "[" ! (math-match-substring ! (car data) 2) ! "]"))) ! (setq pos -1 ! vals (math-read-expr (concat "[" (car data) "]"))))) (if (eq (car-safe vals) 'error) (progn (calc-quit) (switch-to-buffer from-buffer) (goto-char top) ! (next-line lnum) ! (forward-char (+ (nth 1 vals) pos)) (error (nth 2 vals)))) (setq mat (cons vals mat) data (cdr data) --- 1495,1540 ---- (calc) (setq mat (list 'vec) lnum 0) + (and arg + (setq arg (prefix-numeric-value arg))) (while data ! (if (natnump arg) ! (progn ! (if (= arg 0) ! (setq arg 1000000)) ! (setq pos 0 ! vals (list 'vec)) ! (let ((w (length (car data))) ! j v) ! (while (< pos w) ! (setq j (+ pos arg) ! v (if (>= j w) ! (math-read-expr (substring (car data) pos)) ! (math-read-expr (substring (car data) pos j)))) ! (if (eq (car-safe v) 'error) ! (setq vals v w 0) ! (setq vals (nconc vals (list v)) ! pos j))))) ! (if (and (null arg) ! (string-match "[[{][^][{}]*[]}]" (car data))) ! (setq pos (match-beginning 0) ! vals (math-read-expr (math-match-substring (car data) 0))) ! (if (string-match "\\`\\([0-9]+:[ \t]\\)?\\(.*[^, \t]\\)[, \t]*\\'" ! (car data)) ! (setq pos -1 ! vals (math-read-expr (concat "[" ! (math-match-substring ! (car data) 2) ! "]"))) (setq pos -1 ! vals (math-read-expr (concat "[" (car data) "]")))))) (if (eq (car-safe vals) 'error) (progn (calc-quit) (switch-to-buffer from-buffer) (goto-char top) ! (forward-line lnum) ! (forward-char (+ (nth 1 vals) (min col1 col2) pos)) (error (nth 2 vals)))) (setq mat (cons vals mat) data (cdr data) *************** *** 2860,2865 **** --- 2895,2901 ---- ( \\tan . calcFunc-tan ) ( \\sin . calcFunc-sin ) ( \\sinh . calcFunc-sinh ) + ( \\sqrt . calcFunc-sqrt ) ( \\tanh . calcFunc-tanh ) ( \\phi . calcFunc-totient ) ( \\mu . calcFunc-moebius ) *************** *** 9917,9923 **** (defun math-choose (n m) ; [I I I] [F F F] [Public] (cond ((and (integerp n) (integerp m) (<= m n) (>= m 0)) ! (math-choose-iter m n 1 1)) ((not (math-realp n)) (math-reject-arg n 'realp)) ((not (math-realp m)) --- 9953,9961 ---- (defun math-choose (n m) ; [I I I] [F F F] [Public] (cond ((and (integerp n) (integerp m) (<= m n) (>= m 0)) ! (if (> m (/ n 2)) ! (math-choose-iter (- n m) n 1 1) ! (math-choose-iter m n 1 1))) ((not (math-realp n)) (math-reject-arg n 'realp)) ((not (math-realp m)) *************** *** 10564,10570 **** (fset 'calcFunc-rsh (symbol-function 'math-rshift-binary)) (defun math-shift-binary (a &optional n w) ; [I I] [Public] ! (if (not (Math-negp n)) (math-lshift-binary a n w) (setq a (math-trunc a) n (if n (math-trunc n) 1)) --- 10602,10609 ---- (fset 'calcFunc-rsh (symbol-function 'math-rshift-binary)) (defun math-shift-binary (a &optional n w) ; [I I] [Public] ! (if (or (null n) ! (not (Math-negp n))) (math-lshift-binary a n w) (setq a (math-trunc a) n (if n (math-trunc n) 1)) *** calc.texinfo Tue Jun 26 16:34:50 1990 --- ../dist/calc.texinfo Tue Jun 26 17:02:30 1990 *************** *** 1,7 **** \input texinfo @c -*-texinfo-*- @comment %**start of header (This is for running Texinfo on a region.) @setfilename calc-info ! @settitle GNU Emacs Calc 1.02 Manual @setchapternewpage odd @comment %**end of header (This is for running Texinfo on a region.) --- 1,7 ---- \input texinfo @c -*-texinfo-*- @comment %**start of header (This is for running Texinfo on a region.) @setfilename calc-info ! @settitle GNU Emacs Calc 1.03 Manual @setchapternewpage odd @comment %**end of header (This is for running Texinfo on a region.) *************** *** 38,44 **** @sp 6 @center @titlefont{Calc Manual} @sp 4 ! @center GNU Emacs Calc Version 1.02 @sp 1 @center June 1990 @sp 5 --- 38,44 ---- @sp 6 @center @titlefont{Calc Manual} @sp 4 ! @center GNU Emacs Calc Version 1.03 @sp 1 @center June 1990 @sp 5 *************** *** 1450,1456 **** . 1: 10000. . . ! 2. RET 1e4 RET ^ @end example @end group --- 1450,1456 ---- . 1: 10000. . . ! 2.0 RET 1e4 RET ^ @end example @end group *************** *** 1497,1504 **** notation}. You get them by pressing @kbd{d n}, @kbd{d f}, @kbd{d s}, and @kbd{d e}, respectively. In each case, you can supply a numeric prefix argument which says how many digits ! should be displayed. As an example, put the following numbers ! onto the stack, then try some different display modes. First, use @kbd{M-0 DEL} to clear the stack, then enter the four numbers shown here: --- 1497,1504 ---- notation}. You get them by pressing @kbd{d n}, @kbd{d f}, @kbd{d s}, and @kbd{d e}, respectively. In each case, you can supply a numeric prefix argument which says how many digits ! should be displayed. As an example, let's put a few numbers ! onto the stack and try some different display modes. First, use @kbd{M-0 DEL} to clear the stack, then enter the four numbers shown here: *************** *** 2767,2773 **** @group @example ! 1: 8 +/- 0.2 2: 8 +/- 0.2 1: 0.266 +/- 0.011 1: 14.9 +/- 0.594 . 1: 30 +/- 1 . . . --- 2767,2773 ---- @group @example ! 1: 8 +/- 0.2 2: 8 +/- 0.2 1: 0.266 +/- 0.011 1: 14.93 +/- 0.594 . 1: 30 +/- 1 . . . *************** *** 8086,8109 **** The @kbd{M-#} key with a negative prefix argument (@kbd{M-- M-#}) is equivalent to @code{calc-grab-region}. ! Each line of the grabbed area must contain one or more numbers, ! separated by spaces and/or commas. Leading and trailing square ! brackets, curly braces and commas on the line are ignored. Leading ! line numbers (as found in the Calc stack) are also ignored. Thus, this ! command can generally read anything from a column of numbers in a ! spreadsheet to a matrix in one of Calc's own display formats. The ! grabbed values may actually be any Calc formulas, except that spaces ! not enclosed in parentheses will be interpreted as separating two ! separate formulas.@refill If a different language has been specified (@pxref{Language Modes}), the grabbed text will be interpreted according to the that language. ! Each line becomes a row of the matrix. The result will actually be a ! vector of vectors, which Calc will treat as a matrix only if every row ! contains the same number of values. @xref{Matrix Functions}, to see how ! to pull the matrix apart into its constituent rows and columns. (If it ! is a 1x1 matrix, just hit @kbd{v u} (@code{calc-unpack}) twice.) For example, suppose we have a column of numbers in a file which we wish to sum. Go to one corner of the column and press @kbd{C-@@} to --- 8086,8127 ---- The @kbd{M-#} key with a negative prefix argument (@kbd{M-- M-#}) is equivalent to @code{calc-grab-region}. ! Each line of the grabbed area becomes a row of the matrix. The result ! will actually be a vector of vectors, which Calc will treat as a matrix ! only if every row contains the same number of values. + If a line contains a portion surrounded by square brackets (or curly + braces), that portion is interpreted as a vector which becomes a row + of the matrix. Any text surrounding the bracketed portion on the line + is ignored. + + Otherwise, the entire line is interpreted as a row vector as if it + were surrounded by square brackets. Leading line numbers (in the + format used in the Calc stack buffer) are ignored. If you wish to + force this interpretation (even if the line contains bracketed + portions), give a negative numeric prefix argument to the + @code{calc-grab-region} command. + + If you give a numeric prefix argument of zero, each line is instead + interpreted as a single formula which is converted into a one-element + vector. Thus the result of @code{calc-grab-region} will be a one-column + matrix. For example, suppose one line of the data is the expression + @samp{2 a}. A plain @code{calc-grab-region} will interpret this as + @samp{[2 a]}, which in turn is read as a two-element vector. But + with a zero prefix argument, it will be interpreted as @samp{[2*a]}. + + If you give a positive numeric prefix argument @var{n}, then each line + will be split up into columns of width @var{n}; each column is parsed + separately as a matrix element. If a line contained @samp{2 +/- 3 4 +/- 5}, + then grabbing with a prefix argument of 8 would correctly split the + line into two error forms. + If a different language has been specified (@pxref{Language Modes}), the grabbed text will be interpreted according to the that language. ! @xref{Matrix Functions}, to see how to pull the matrix apart into its ! constituent rows and columns. (If it is a 1x1 matrix, just hit @kbd{v u} ! (@code{calc-unpack}) twice.) For example, suppose we have a column of numbers in a file which we wish to sum. Go to one corner of the column and press @kbd{C-@@} to *************** *** 10739,10744 **** --- 10757,10779 ---- The functions described here are responsible for parsing and formatting Calc numbers and formulas. + @defun calc-eval str sep arg1 arg2 @dots{} + This is the simplest interface to the Calculator from another Lisp program. + The algebraic expression(s) in @var{str} are parsed and evaluated; the + results are formatted as a string and returned. If @var{str} contains + several expressions the results are separated by string @var{sep}, or + by the string @samp{", "} if @var{sep} is omitted. If any additional + arguments are given, they are values (in Calc's internal format) to be + used for @kbd{$}, @kbd{$$}, and so on in the string. + + If the string @var{str} contains an error, the return value is instead + a list of two items: An integer index into @var{str} to show the + approximate position of the error, and an explanatory message string. + + This function uses the mode settings in the @code{*Calculator*} buffer. + If no such buffer exists, it will be created as a side-effect. + @end defun + @defun read-number str If string @var{str} contains a valid Calc number, either integer, fraction, float, or HMS form, this function parses and returns that *************** *** 10895,10900 **** --- 10930,10937 ---- (autoload 'calc ".../calc.elc" "Calculator Mode" t nil) (autoload 'calc-extensions ".../calc-ext.elc" nil nil nil) (autoload 'quick-calc ".../calc.elc" "Quick Calculator" t nil) + (autoload 'full-calc ".../calc.elc" "Full-screen Calculator" t nil) + (autoload 'calc-eval ".../calc.elc" "Call Calculator" nil nil) (autoload 'calc-grab-region ".../calc-ext.elc" nil t nil) (autoload 'defmath ".../calc-ext.elc" nil t t) @end example *************** *** 10909,10915 **** brings in the extensions module; Calc takes care to call the @code{calc-extensions} function (which doesn't actually do anything) before any operation that requires the extensions to be present. ! The other three @code{autoload} commands are for functions which might reasonably be used before the user has typed @kbd{M-x calc} for the first time. --- 10946,10952 ---- brings in the extensions module; Calc takes care to call the @code{calc-extensions} function (which doesn't actually do anything) before any operation that requires the extensions to be present. ! The other five @code{autoload} commands are for functions which might reasonably be used before the user has typed @kbd{M-x calc} for the first time. *************** *** 10978,10987 **** To test your installation of Calc, start a fresh Emacs and type @kbd{M-#} to make sure the autoload commands and key bindings work. Now, type @kbd{i} to make sure Calc can find its Info documentation. Press @kbd{q} ! to exit the Info system. Type @kbd{20 S} to compute the sine of ! 20 degrees; this will test the autoloading of the extensions module. ! The result should be 0.342020143326. Finally, press @kbd{M-#} again to ! make sure the Calculator can exit. (The above text is included in both the Calc documentation and the file INSTALL in the Calc distribution directory.) --- 11015,11024 ---- To test your installation of Calc, start a fresh Emacs and type @kbd{M-#} to make sure the autoload commands and key bindings work. Now, type @kbd{i} to make sure Calc can find its Info documentation. Press @kbd{q} ! to exit the Info system and @kbd{M-#} to re-enter the Calculator. ! Type @kbd{20 S} to compute the sine of 20 degrees; this will test the ! autoloading of the extensions module. The result should be 0.342020143326. ! Finally, press @kbd{M-#} again to make sure the Calculator can exit. (The above text is included in both the Calc documentation and the file INSTALL in the Calc distribution directory.)