comparison lisp/calc/calc-prog.el @ 41271:fcd507927105

Change all toplevel `setq' forms to `defvar' forms, and move them before their first use. Use `when', `unless'. Remove trailing periods from error forms. Add description and headers suggested by Emacs Lisp coding conventions.
author Colin Walters <walters@gnu.org>
date Mon, 19 Nov 2001 07:43:43 +0000
parents 73f364fd8aaa
children 34ce7f0515d0
comparison
equal deleted inserted replaced
41270:711f18abaf57 41271:fcd507927105
1 ;; Calculator for GNU Emacs, part II [calc-prog.el] 1 ;;; calc-prog.el --- user programmability functions for Calc
2
2 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc. 3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc.
3 ;; Written by Dave Gillespie, daveg@synaptics.com. 4
5 ;; Author: David Gillespie <daveg@synaptics.com>
6 ;; Maintainer: Colin Walters <walters@debian.org>
4 7
5 ;; This file is part of GNU Emacs. 8 ;; This file is part of GNU Emacs.
6 9
7 ;; GNU Emacs is distributed in the hope that it will be useful, 10 ;; GNU Emacs is distributed in the hope that it will be useful,
8 ;; but WITHOUT ANY WARRANTY. No author or distributor 11 ;; but WITHOUT ANY WARRANTY. No author or distributor
17 ;; supposed to have been given to you along with GNU Emacs so you 20 ;; supposed to have been given to you along with GNU Emacs so you
18 ;; can know your rights and responsibilities. It should be in a 21 ;; can know your rights and responsibilities. It should be in a
19 ;; file named COPYING. Among other things, the copyright notice 22 ;; file named COPYING. Among other things, the copyright notice
20 ;; and this notice must be preserved on all copies. 23 ;; and this notice must be preserved on all copies.
21 24
25 ;;; Commentary:
26
27 ;;; Code:
22 28
23 29
24 ;; This file is autoloaded from calc-ext.el. 30 ;; This file is autoloaded from calc-ext.el.
25 (require 'calc-ext) 31 (require 'calc-ext)
26 32
100 (defun calc-timing (n) 106 (defun calc-timing (n)
101 (interactive "P") 107 (interactive "P")
102 (calc-wrapper 108 (calc-wrapper
103 (calc-change-mode 'calc-timing n nil t) 109 (calc-change-mode 'calc-timing n nil t)
104 (message (if calc-timing 110 (message (if calc-timing
105 "Reporting timing of slow commands in Trail." 111 "Reporting timing of slow commands in Trail"
106 "Not reporting timing of commands.")))) 112 "Not reporting timing of commands"))))
107 113
108 (defun calc-pass-errors () 114 (defun calc-pass-errors ()
109 (interactive) 115 (interactive)
110 ;; The following two cases are for the new, optimizing byte compiler 116 ;; The following two cases are for the new, optimizing byte compiler
111 ;; or the standard 18.57 byte compiler, respectively. 117 ;; or the standard 18.57 byte compiler, respectively.
114 (or (memq (car-safe (car-safe place)) '(error xxxerror)) 120 (or (memq (car-safe (car-safe place)) '(error xxxerror))
115 (setq place (aref (nth 2 (nth 2 (symbol-function 'calc-do))) 27))) 121 (setq place (aref (nth 2 (nth 2 (symbol-function 'calc-do))) 27)))
116 (or (memq (car (car place)) '(error xxxerror)) 122 (or (memq (car (car place)) '(error xxxerror))
117 (error "foo")) 123 (error "foo"))
118 (setcar (car place) 'xxxerror)) 124 (setcar (car place) 'xxxerror))
119 (error (error "The calc-do function has been modified; unable to patch.")))) 125 (error (error "The calc-do function has been modified; unable to patch"))))
120 126
121 (defun calc-user-define () 127 (defun calc-user-define ()
122 (interactive) 128 (interactive)
123 (message "Define user key: z-") 129 (message "Define user key: z-")
124 (let ((key (read-char))) 130 (let ((key (read-char)))
1104 (calc-wrapper 1110 (calc-wrapper
1105 (let ((cond (calc-top-n 1))) 1111 (let ((cond (calc-top-n 1)))
1106 (calc-pop-stack 1) 1112 (calc-pop-stack 1)
1107 (if (math-is-true cond) 1113 (if (math-is-true cond)
1108 (if defining-kbd-macro 1114 (if defining-kbd-macro
1109 (message "If true...")) 1115 (message "If true.."))
1110 (if defining-kbd-macro 1116 (if defining-kbd-macro
1111 (message "Condition is false; skipping to Z: or Z] ...")) 1117 (message "Condition is false; skipping to Z: or Z] ..."))
1112 (calc-kbd-skip-to-else-if t))))) 1118 (calc-kbd-skip-to-else-if t)))))
1113 1119
1114 (defun calc-kbd-else-if () 1120 (defun calc-kbd-else-if ()
1216 (and (not executing-kbd-macro) 1222 (and (not executing-kbd-macro)
1217 (= rpt-count 1000000) 1223 (= rpt-count 1000000)
1218 (null parts) 1224 (null parts)
1219 (null counter) 1225 (null counter)
1220 (progn 1226 (progn
1221 (message "Warning: Infinite loop! Not executing.") 1227 (message "Warning: Infinite loop! Not executing")
1222 (setq rpt-count 0))) 1228 (setq rpt-count 0)))
1223 (or (not initial) dir 1229 (or (not initial) dir
1224 (setq dir (math-compare final initial))) 1230 (setq dir (math-compare final initial)))
1225 (calc-wrapper 1231 (calc-wrapper
1226 (while (> rpt-count 0) 1232 (while (> rpt-count 0)
1264 (interactive) 1270 (interactive)
1265 (calc-wrapper 1271 (calc-wrapper
1266 (let ((cond (calc-top-n 1))) 1272 (let ((cond (calc-top-n 1)))
1267 (calc-pop-stack 1) 1273 (calc-pop-stack 1)
1268 (if (math-is-true cond) 1274 (if (math-is-true cond)
1269 (error "Keyboard macro aborted."))))) 1275 (error "Keyboard macro aborted")))))
1270 1276
1271 1277
1278 (defvar calc-kbd-push-level 0)
1272 (defun calc-kbd-push (arg) 1279 (defun calc-kbd-push (arg)
1273 (interactive "P") 1280 (interactive "P")
1274 (calc-wrapper 1281 (calc-wrapper
1275 (let* ((defs (and arg (> (prefix-numeric-value arg) 0))) 1282 (let* ((defs (and arg (> (prefix-numeric-value arg) 0)))
1276 (var-q0 (and (boundp 'var-q0) var-q0)) 1283 (var-q0 (and (boundp 'var-q0) var-q0))
1322 (let ((calc-kbd-push-level 0)) 1329 (let ((calc-kbd-push-level 0))
1323 (execute-kbd-macro (substring body 0 -2)))) 1330 (execute-kbd-macro (substring body 0 -2))))
1324 (let ((calc-kbd-push-level (1+ calc-kbd-push-level))) 1331 (let ((calc-kbd-push-level (1+ calc-kbd-push-level)))
1325 (message "Saving modes; type Z' to restore") 1332 (message "Saving modes; type Z' to restore")
1326 (recursive-edit)))))) 1333 (recursive-edit))))))
1327 (setq calc-kbd-push-level 0)
1328 1334
1329 (defun calc-kbd-pop () 1335 (defun calc-kbd-pop ()
1330 (interactive) 1336 (interactive)
1331 (if (> calc-kbd-push-level 0) 1337 (if (> calc-kbd-push-level 0)
1332 (progn 1338 (progn
1668 1674
1669 (defun calcFunc-istrue (a) 1675 (defun calcFunc-istrue (a)
1670 (if (math-is-true a) 1676 (if (math-is-true a)
1671 1 1677 1
1672 0)) 1678 0))
1673
1674 1679
1675 1680
1676 1681
1677 ;;;; User-programmability. 1682 ;;;; User-programmability.
1678 1683
2116 (defmacro math-while (head &rest body) 2121 (defmacro math-while (head &rest body)
2117 (let ((body (cons 'while (cons head body)))) 2122 (let ((body (cons 'while (cons head body))))
2118 (if (math-body-refers-to body 'math-break) 2123 (if (math-body-refers-to body 'math-break)
2119 (cons 'catch (cons '(quote math-break) (list body))) 2124 (cons 'catch (cons '(quote math-break) (list body)))
2120 body))) 2125 body)))
2121 2126 ;; (put 'math-while 'lisp-indent-hook 1)
2122 2127
2123 (defmacro math-for (head &rest body) 2128 (defmacro math-for (head &rest body)
2124 (let ((body (if head 2129 (let ((body (if head
2125 (math-handle-for head body) 2130 (math-handle-for head body)
2126 (cons 'while (cons t body))))) 2131 (cons 'while (cons t body)))))
2127 (if (math-body-refers-to body 'math-break) 2132 (if (math-body-refers-to body 'math-break)
2128 (cons 'catch (cons '(quote math-break) (list body))) 2133 (cons 'catch (cons '(quote math-break) (list body)))
2129 body))) 2134 body)))
2135 ;; (put 'math-for 'lisp-indent-hook 1)
2130 2136
2131 (defun math-handle-for (head body) 2137 (defun math-handle-for (head body)
2132 (let* ((var (nth 0 (car head))) 2138 (let* ((var (nth 0 (car head)))
2133 (init (nth 1 (car head))) 2139 (init (nth 1 (car head)))
2134 (limit (nth 2 (car head))) 2140 (limit (nth 2 (car head)))
2182 '+ 2188 '+
2183 'math-add) 2189 'math-add)
2184 var 2190 var
2185 save-step))))))))))) 2191 save-step)))))))))))
2186 2192
2187
2188 (defmacro math-foreach (head &rest body) 2193 (defmacro math-foreach (head &rest body)
2189 (let ((body (math-handle-foreach head body))) 2194 (let ((body (math-handle-foreach head body)))
2190 (if (math-body-refers-to body 'math-break) 2195 (if (math-body-refers-to body 'math-break)
2191 (cons 'catch (cons '(quote math-break) (list body))) 2196 (cons 'catch (cons '(quote math-break) (list body)))
2192 body))) 2197 body)))
2193 2198 ;; (put 'math-foreach 'lisp-indent-hook 1)
2194 2199
2195 (defun math-handle-foreach (head body) 2200 (defun math-handle-foreach (head body)
2196 (let ((var (nth 0 (car head))) 2201 (let ((var (nth 0 (car head)))
2197 (data (nth 1 (car head))) 2202 (data (nth 1 (car head)))
2198 (body (if (cdr head) 2203 (body (if (cdr head)