home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume24 / gnucalc / part30 < prev    next >
Encoding:
Text File  |  1991-10-31  |  55.2 KB  |  1,577 lines

  1. Newsgroups: comp.sources.misc
  2. From: daveg@synaptics.com (David Gillespie)
  3. Subject:  v24i078:  gnucalc - GNU Emacs Calculator, v2.00, Part30/56
  4. Message-ID: <1991Oct31.214347.2175@sparky.imd.sterling.com>
  5. X-Md4-Signature: cf8d2e12ed03bc78396f03a9c004e8e0
  6. Date: Thu, 31 Oct 1991 21:43:47 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: daveg@synaptics.com (David Gillespie)
  10. Posting-number: Volume 24, Issue 78
  11. Archive-name: gnucalc/part30
  12. Environment: Emacs
  13. Supersedes: gmcalc: Volume 13, Issue 27-45
  14.  
  15. ---- Cut Here and unpack ----
  16. #!/bin/sh
  17. # do not concatenate these parts, unpack them in order with /bin/sh
  18. # file calc-yank.el continued
  19. #
  20. if test ! -r _shar_seq_.tmp; then
  21.     echo 'Please unpack part 1 first!'
  22.     exit 1
  23. fi
  24. (read Scheck
  25.  if test "$Scheck" != 30; then
  26.     echo Please unpack part "$Scheck" next!
  27.     exit 1
  28.  else
  29.     exit 0
  30.  fi
  31. ) < _shar_seq_.tmp || exit 1
  32. if test ! -f _shar_wnt_.tmp; then
  33.     echo 'x - still skipping calc-yank.el'
  34. else
  35. echo 'x - continuing file calc-yank.el'
  36. sed 's/^X//' << 'SHAR_EOF' >> 'calc-yank.el' &&
  37. X    (setq calc-edit-handler handler)
  38. X    (make-local-variable 'calc-restore-trail)
  39. X    (setq calc-restore-trail (get-buffer-window (calc-trail-buffer)))
  40. X    (make-local-variable 'calc-allow-ret)
  41. X    (setq calc-allow-ret allow-ret)
  42. X    (erase-buffer)
  43. X    (insert (or title title "Calc Edit Mode")
  44. X        ".  Press "
  45. X        (if (eq (lookup-key (current-global-map) "\e#") 'calc-dispatch)
  46. X        "M-# M-# or C-c C-c"
  47. X          (if allow-ret "C-c C-c" "RET"))
  48. X        " to finish, "
  49. X        (if (eq (lookup-key (current-global-map) "\e#") 'calc-dispatch)
  50. X        "M-# x"
  51. X          "C-x k RET")
  52. X        " to cancel.\n"))
  53. )
  54. (put 'calc-edit-mode 'mode-class 'special)
  55. X
  56. (defun calc-show-edit-buffer ()
  57. X  (let ((buf (current-buffer)))
  58. X    (if (and (one-window-p t) pop-up-windows)
  59. X    (pop-to-buffer (get-buffer-create "*Calc Edit*"))
  60. X      (and calc-embedded-info (get-buffer-window (aref calc-embedded-info 1))
  61. X       (select-window (get-buffer-window (aref calc-embedded-info 1))))
  62. X      (switch-to-buffer (get-buffer-create "*Calc Edit*")))
  63. X    (setq calc-return-buffer buf)
  64. X    (if (and (< (window-width) (screen-width))
  65. X         calc-display-trail)
  66. X    (let ((win (get-buffer-window (calc-trail-buffer))))
  67. X      (if win
  68. X          (delete-window win))))
  69. X    (set-buffer-modified-p nil)
  70. X    (goto-char (point-min))
  71. X    (forward-line 1))
  72. )
  73. X
  74. (defun calc-edit-return ()
  75. X  (interactive)
  76. X  (if (and (boundp 'calc-allow-ret) calc-allow-ret)
  77. X      (newline)
  78. X    (calc-edit-finish))
  79. )
  80. X
  81. (defun calc-edit-finish (&optional keep)
  82. X  "Finish calc-edit mode.  Parse buffer contents and push them on the stack."
  83. X  (interactive "P")
  84. X  (message "Working...")
  85. X  (or (and (boundp 'calc-original-buffer)
  86. X       (boundp 'calc-return-buffer)
  87. X       (boundp 'calc-one-window)
  88. X       (boundp 'calc-edit-handler)
  89. X       (boundp 'calc-restore-trail)
  90. X       (eq major-mode 'calc-edit-mode))
  91. X      (error "This command is valid only in buffers created by calc-edit."))
  92. X  (let ((buf (current-buffer))
  93. X    (original calc-original-buffer)
  94. X    (return calc-return-buffer)
  95. X    (one-window calc-one-window)
  96. X    (disp-trail calc-restore-trail))
  97. X    (save-excursion
  98. X      (if (or (null (buffer-name original))
  99. X          (progn
  100. X        (set-buffer original)
  101. X        (not (eq major-mode 'calc-mode))))
  102. X      (error "Original calculator buffer has been corrupted.")))
  103. X    (goto-char (point-min))
  104. X    (if (looking-at "Calc Edit\\|Editing ")
  105. X    (forward-line 1))
  106. X    (if (buffer-modified-p)
  107. X    (eval calc-edit-handler))
  108. X    (if one-window
  109. X    (delete-window))
  110. X    (if (get-buffer-window return)
  111. X    (select-window (get-buffer-window return))
  112. X      (switch-to-buffer return))
  113. X    (if keep
  114. X    (bury-buffer buf)
  115. X      (kill-buffer buf))
  116. X    (if disp-trail
  117. X    (calc-wrapper
  118. X     (calc-trail-display 1 t)))
  119. X    (message ""))
  120. )
  121. X
  122. (defun calc-edit-cancel ()
  123. X  "Cancel calc-edit mode.  Ignore the Calc Edit buffer and don't change stack."
  124. X  (interactive)
  125. X  (let ((calc-edit-handler nil))
  126. X    (calc-edit-finish))
  127. X  (message "(Cancelled)")
  128. )
  129. X
  130. (defun calc-finish-stack-edit (num)
  131. X  (let ((buf (current-buffer))
  132. X    (str (buffer-substring (point) (point-max)))
  133. X    (start (point))
  134. X    pos)
  135. X    (if (and (integerp num) (> num 1))
  136. X    (while (setq pos (string-match "\n." str))
  137. X      (aset str pos ?\,)))
  138. X    (switch-to-buffer calc-original-buffer)
  139. X    (let ((vals (let ((calc-language nil)
  140. X              (math-expr-opers math-standard-opers))
  141. X          (and (string-match "[^\n\t ]" str)
  142. X               (math-read-exprs str)))))
  143. X      (if (eq (car-safe vals) 'error)
  144. X      (progn
  145. X        (switch-to-buffer buf)
  146. X        (goto-char (+ start (nth 1 vals)))
  147. X        (error (nth 2 vals))))
  148. X      (calc-wrapper
  149. X       (if (symbolp num)
  150. X       (progn
  151. X         (set num (car vals))
  152. X         (calc-refresh-evaltos num))
  153. X     (if disp-trail
  154. X         (calc-trail-display 1 t))
  155. X     (and vals
  156. X          (if (>= num 0)
  157. X          (calc-enter-result num "edit" vals)
  158. X        (calc-enter-result 1 "edit" vals (- num))))))))
  159. )
  160. X
  161. X
  162. X
  163. X
  164. SHAR_EOF
  165. echo 'File calc-yank.el is complete' &&
  166. chmod 0644 calc-yank.el ||
  167. echo 'restore of calc-yank.el failed'
  168. Wc_c="`wc -c < 'calc-yank.el'`"
  169. test 17330 -eq "$Wc_c" ||
  170.     echo 'calc-yank.el: original size 17330, current size' "$Wc_c"
  171. rm -f _shar_wnt_.tmp
  172. fi
  173. # ============= macedit.el ==============
  174. if test -f 'macedit.el' -a X"$1" != X"-c"; then
  175.     echo 'x - skipping macedit.el (File already exists)'
  176.     rm -f _shar_wnt_.tmp
  177. else
  178. > _shar_wnt_.tmp
  179. echo 'x - extracting macedit.el (Text)'
  180. sed 's/^X//' << 'SHAR_EOF' > 'macedit.el' &&
  181. ;; Keyboard macro editor for GNU Emacs.  Version 1.05.
  182. ;; Copyright (C) 1990, 1991 Free Software Foundation, Inc.
  183. ;; Written by Dave Gillespie, daveg@csvax.cs.caltech.edu.
  184. X
  185. ;; This file is part of GNU Emacs.
  186. X
  187. ;; GNU Emacs is distributed in the hope that it will be useful,
  188. ;; but WITHOUT ANY WARRANTY.  No author or distributor
  189. ;; accepts responsibility to anyone for the consequences of using it
  190. ;; or for whether it serves any particular purpose or works at all,
  191. ;; unless he says so in writing.  Refer to the GNU Emacs General Public
  192. ;; License for full details.
  193. X
  194. ;; Everyone is granted permission to copy, modify and redistribute
  195. ;; GNU Emacs, but only under the conditions described in the
  196. ;; GNU Emacs General Public License.   A copy of this license is
  197. ;; supposed to have been given to you along with GNU Emacs so you
  198. ;; can know your rights and responsibilities.  It should be in a
  199. ;; file named COPYING.  Among other things, the copyright notice
  200. ;; and this notice must be preserved on all copies.
  201. X
  202. ;; Installation:
  203. ;;   (autoload 'edit-kbd-macro "macedit" "Edit a named keyboard macro" t)
  204. ;;   (autoload 'edit-last-kbd-macro "macedit" "Edit a keyboard macro" t)
  205. ;;   (autoload 'read-kbd-macro "macedit" "Parse region as keyboard macro" t)
  206. X
  207. X
  208. X
  209. ;; To use, type `M-x edit-last-kbd-macro' to edit the most recently
  210. ;; defined keyboard macro.  If you have used `M-x name-last-kbd-macro'
  211. ;; to give a keyboard macro a name, type `M-x edit-kbd-macro' to edit
  212. ;; the macro by name.  When you are done editing, type `C-c C-c' to
  213. ;; record your changes back into the original keyboard macro.
  214. X
  215. X
  216. X
  217. X
  218. ;;; The user-level commands for editing macros.
  219. X
  220. ;;;###autoload
  221. (defun edit-last-kbd-macro (&optional prefix buffer hook)
  222. X  "Edit the most recently defined keyboard macro."
  223. X  (interactive "P")
  224. X  (MacEdit-edit-macro last-kbd-macro
  225. X              (function (lambda (x arg) (setq last-kbd-macro x)))
  226. X              prefix buffer hook)
  227. )
  228. X
  229. ;;;###autoload
  230. (defun edit-kbd-macro (cmd &optional prefix buffer hook in-hook out-hook)
  231. X  "Edit a keyboard macro which has been assigned a name by name-last-kbd-macro.
  232. \(See also edit-last-kbd-macro.)"
  233. X  (interactive "CCommand name: \nP")
  234. X  (and cmd
  235. X       (MacEdit-edit-macro (if in-hook
  236. X                   (funcall in-hook cmd)
  237. X                 (symbol-function cmd))
  238. X               (or out-hook
  239. X                   (list 'lambda '(x arg)
  240. X                     (list 'fset
  241. X                       (list 'quote cmd)
  242. X                       'x)))
  243. X               prefix buffer hook cmd))
  244. )
  245. X
  246. ;;;###autoload
  247. (defun read-kbd-macro (start &optional end)
  248. X  "Read the region as a keyboard macro definition.
  249. The region is interpreted as spelled-out keystrokes, e.g., `M-x abc RET'.
  250. The resulting macro is installed as the \"current\" keyboard macro.
  251. X
  252. Symbols:  RET, SPC, TAB, DEL, LFD, NUL; C-key; M-key.  (Must be uppercase.)
  253. X          REM marks the rest of a line as a comment.
  254. X          Whitespace is ignored; other characters are copied into the macro."
  255. X  (interactive "r")
  256. X  (if (stringp start)
  257. X      (setq last-kbd-macro (MacEdit-parse-keys start))
  258. X    (setq last-kbd-macro (MacEdit-parse-keys (buffer-substring start end)))
  259. X    (if (and (string-match "\\`\C-x(" last-kbd-macro)
  260. X         (string-match "\C-x)\\'" last-kbd-macro))
  261. X    (setq last-kbd-macro (substring last-kbd-macro 2 -2))))
  262. )
  263. X
  264. X
  265. X
  266. X
  267. ;;; Formatting a keyboard macro as human-readable text.
  268. X
  269. (defun MacEdit-print-macro (macro-str local-map)
  270. X  (let ((save-map (current-local-map))
  271. X    (print-escape-newlines t)
  272. X    key-symbol key-str key-last prefix-arg this-prefix)
  273. X    (unwind-protect
  274. X    (progn
  275. X      (use-local-map local-map)
  276. X      (while (MacEdit-peek-char)
  277. X        (MacEdit-read-key)
  278. X        (setq this-prefix prefix-arg)
  279. X        (or (memq key-symbol '(digit-argument
  280. X                   negative-argument
  281. X                   universal-argument))
  282. X        (null prefix-arg)
  283. X        (progn
  284. X          (cond ((consp prefix-arg)
  285. X             (insert (format "prefix-arg (%d)\n"
  286. X                     (car prefix-arg))))
  287. X            ((eq prefix-arg '-)
  288. X             (insert "prefix-arg -\n"))
  289. X            ((numberp prefix-arg)
  290. X             (insert (format "prefix-arg %d\n" prefix-arg))))
  291. X          (setq prefix-arg nil)))
  292. X        (cond ((null key-symbol)
  293. X           (insert "type \"")
  294. X           (MacEdit-insert-string macro-str)
  295. X           (insert "\"\n")
  296. X           (setq macro-str ""))
  297. X          ((stringp key-symbol)   ; key defined by another kbd macro
  298. X           (insert "type \"")
  299. X           (MacEdit-insert-string key-symbol)
  300. X           (insert "\"\n"))
  301. X          ((eq key-symbol 'digit-argument)
  302. X           (MacEdit-prefix-arg key-last nil prefix-arg))
  303. X          ((eq key-symbol 'negative-argument)
  304. X           (MacEdit-prefix-arg ?- nil prefix-arg))
  305. X          ((eq key-symbol 'universal-argument)
  306. X           (let* ((c-u 4) (argstartchar key-last)
  307. X              (char (MacEdit-read-char)))
  308. X             (while (= char argstartchar)
  309. X               (setq c-u (* 4 c-u)
  310. X                 char (MacEdit-read-char)))
  311. X             (MacEdit-prefix-arg char c-u nil)))
  312. X          ((eq key-symbol 'self-insert-command)
  313. X           (insert "insert ")
  314. X           (if (and (>= key-last 32) (<= key-last 126))
  315. X               (let ((str ""))
  316. X             (while (or (and (eq key-symbol
  317. X                         'self-insert-command)
  318. X                     (< (length str) 60)
  319. X                     (>= key-last 32)
  320. X                     (<= key-last 126))
  321. X                    (and (memq key-symbol
  322. X                           '(backward-delete-char
  323. X                         delete-backward-char
  324. X                         backward-delete-char-untabify))
  325. X                     (> (length str) 0)))
  326. X               (if (eq key-symbol 'self-insert-command)
  327. X                   (setq str (concat str
  328. X                         (char-to-string key-last)))
  329. X                 (setq str (substring str 0 -1)))
  330. X               (MacEdit-read-key))
  331. X             (insert "\"" str "\"\n")
  332. X             (MacEdit-unread-chars key-str))
  333. X             (insert "\"")
  334. X             (MacEdit-insert-string (char-to-string key-last))
  335. X             (insert "\"\n")))
  336. X          ((and (eq key-symbol 'quoted-insert)
  337. X            (MacEdit-peek-char))
  338. X           (insert "quoted-insert\n")
  339. X           (let ((ch (MacEdit-read-char))
  340. X             ch2)
  341. X             (if (and (>= ch ?0) (<= ch ?7))
  342. X             (progn
  343. X               (setq ch (- ch ?0)
  344. X                 ch2 (MacEdit-read-char))
  345. X               (if ch2
  346. X                   (if (and (>= ch2 ?0) (<= ch2 ?7))
  347. X                   (progn
  348. X                     (setq ch (+ (* ch 8) (- ch2 ?0))
  349. X                       ch2 (MacEdit-read-char))
  350. X                     (if ch2
  351. X                     (if (and (>= ch2 ?0) (<= ch2 ?7))
  352. X                         (setq ch (+ (* ch 8) (- ch2 ?0)))
  353. X                       (MacEdit-unread-chars ch2))))
  354. X                 (MacEdit-unread-chars ch2)))))
  355. X             (if (or (and (>= ch ?0) (<= ch ?7))
  356. X                 (< ch 32) (> ch 126))
  357. X             (insert (format "type \"\\%03o\"\n" ch))
  358. X               (insert "type \"" (char-to-string ch) "\"\n"))))
  359. X          ((memq key-symbol '(isearch-forward
  360. X                      isearch-backward
  361. X                      isearch-forward-regexp
  362. X                      isearch-backward-regexp))
  363. X           (insert (symbol-name key-symbol) "\n")
  364. X           (MacEdit-isearch-argument))
  365. X          ((eq key-symbol 'execute-extended-command)
  366. X           (MacEdit-read-argument obarray 'commandp))
  367. X          (t
  368. X           (let ((cust (get key-symbol 'MacEdit-print)))
  369. X             (if cust
  370. X             (funcall cust)
  371. X               (insert (symbol-name key-symbol))
  372. X               (indent-to 30)
  373. X               (insert " # ")
  374. X               (MacEdit-insert-string key-str)
  375. X               (insert "\n")
  376. X               (let ((int (MacEdit-get-interactive key-symbol)))
  377. X             (if (string-match "\\`\\*" int)
  378. X                 (setq int (substring int 1)))
  379. X             (while (> (length int) 0)
  380. X               (cond ((= (aref int 0) ?a)
  381. X                  (MacEdit-read-argument
  382. X                   obarray nil))
  383. X                 ((memq (aref int 0) '(?b ?B ?D ?f ?F ?n
  384. X                              ?s ?S ?x ?X))
  385. X                  (MacEdit-read-argument))
  386. X                 ((and (= (aref int 0) ?c)
  387. X                       (MacEdit-peek-char))
  388. X                  (insert "type \"")
  389. X                  (MacEdit-insert-string
  390. X                   (char-to-string
  391. X                    (MacEdit-read-char)))
  392. X                  (insert "\"\n"))
  393. X                 ((= (aref int 0) ?C)
  394. X                  (MacEdit-read-argument
  395. X                   obarray 'commandp))
  396. X                 ((= (aref int 0) ?k)
  397. X                  (MacEdit-read-key)
  398. X                  (if key-symbol
  399. X                      (progn
  400. X                    (insert "type \"")
  401. X                    (MacEdit-insert-string key-str)
  402. X                    (insert "\"\n"))
  403. X                    (MacEdit-unread-chars key-str)))
  404. X                 ((= (aref int 0) ?N)
  405. X                  (or this-prefix
  406. X                      (MacEdit-read-argument)))
  407. X                 ((= (aref int 0) ?v)
  408. X                  (MacEdit-read-argument
  409. X                   obarray 'user-variable-p)))
  410. X               (let ((nl (string-match "\n" int)))
  411. X                 (setq int (if nl
  412. X                       (substring int (1+ nl))
  413. X                     "")))))))))))
  414. X      (use-local-map save-map)))
  415. )
  416. X
  417. (defun MacEdit-prefix-arg (char c-u value)
  418. X  (let ((sign 1))
  419. X    (if (and (numberp value) (< value 0))
  420. X    (setq sign -1 value (- value)))
  421. X    (if (eq value '-)
  422. X    (setq sign -1 value nil))
  423. X    (while (and char (= ?- char))
  424. X      (setq sign (- sign) c-u nil)
  425. X      (setq char (MacEdit-read-char)))
  426. X    (while (and char (>= char ?0) (<= char ?9))
  427. X      (setq value (+ (* (if (numberp value) value 0) 10) (- char ?0)) c-u nil)
  428. X      (setq char (MacEdit-read-char)))
  429. X    (setq prefix-arg
  430. X      (cond (c-u (list c-u))
  431. X        ((numberp value) (* value sign))
  432. X        ((= sign -1) '-)))
  433. X    (MacEdit-unread-chars char))
  434. )
  435. X
  436. (defun MacEdit-insert-string (str)
  437. X  (let ((i 0) j ch)
  438. X    (while (< i (length str))
  439. X      (if (and (> (setq ch (aref str i)) 127)
  440. X           (< ch 160))
  441. X      (progn
  442. X        (setq ch (- ch 128))
  443. X        (insert "\\M-")))
  444. X      (if (< ch 32)
  445. X      (cond ((= ch 8)  (insert "\\b"))
  446. X        ((= ch 9)  (insert "\\t"))
  447. X        ((= ch 10) (insert "\\n"))
  448. X        ((= ch 13) (insert "\\r"))
  449. X        ((= ch 27) (insert "\\e"))
  450. X        (t (insert "\\C-" (char-to-string (downcase (+ ch 64))))))
  451. X    (if (< ch 127)
  452. X        (if (or (= ch 34) (= ch 92))
  453. X        (insert "\\" (char-to-string ch))
  454. X          (setq j i)
  455. X          (while (and (< (setq i (1+ i)) (length str))
  456. X              (>= (setq ch (aref str i)) 32)
  457. X              (/= ch 34) (/= ch 92)
  458. X              (< ch 127)))
  459. X          (insert (substring str j i))
  460. X          (setq i (1- i)))
  461. X      (if (memq ch '(127 255))
  462. X          (insert (format "\\%03o" ch))
  463. X        (insert "\\M-" (char-to-string (- ch 128))))))
  464. X      (setq i (1+ i))))
  465. )
  466. X
  467. (defun MacEdit-lookup-key (map)
  468. X  (let ((loc (and map (lookup-key map macro-str)))
  469. X    (glob (lookup-key (current-global-map) macro-str))
  470. X    (loc-str macro-str)
  471. X    (glob-str macro-str))
  472. X    (and (integerp loc)
  473. X     (setq loc-str (substring macro-str 0 loc)
  474. X           loc (lookup-key map loc-str)))
  475. X    (and (consp loc)
  476. X     (setq loc nil))
  477. X    (or loc
  478. X    (setq loc-str ""))
  479. X    (and (integerp glob)
  480. X     (setq glob-str (substring macro-str 0 glob)
  481. X           glob (lookup-key (current-global-map) glob-str)))
  482. X    (and (consp glob)
  483. X     (setq glob nil))
  484. X    (or glob
  485. X    (setq glob-str ""))
  486. X    (if (> (length glob-str) (length loc-str))
  487. X    (setq key-symbol glob
  488. X          key-str glob-str)
  489. X      (setq key-symbol loc
  490. X        key-str loc-str))
  491. X    (setq key-last (and (> (length key-str) 0)
  492. X            (logand (aref key-str (1- (length key-str))) 127)))
  493. X    key-symbol)
  494. )
  495. X
  496. (defun MacEdit-read-argument (&optional obarray pred)   ;; currently ignored
  497. X  (let ((str "")
  498. X    (min-bsp 0)
  499. X    (exec (eq key-symbol 'execute-extended-command))
  500. X    str-base)
  501. X    (while (progn
  502. X         (MacEdit-lookup-key (current-global-map))
  503. X         (or (and (eq key-symbol 'self-insert-command)
  504. X              (< (length str) 60))
  505. X         (memq key-symbol
  506. X                '(backward-delete-char
  507. X                  delete-backward-char
  508. X                  backward-delete-char-untabify))
  509. X         (eq key-last 9)))
  510. X      (setq macro-str (substring macro-str (length key-str)))
  511. X      (or (and (eq key-last 9)
  512. X           obarray
  513. X           (let ((comp (try-completion str obarray pred)))
  514. X         (and (stringp comp)
  515. X              (> (length comp) (length str))
  516. X              (setq str comp))))
  517. X      (if (or (eq key-symbol 'self-insert-command)
  518. X          (and (or (eq key-last 9)
  519. X               (<= (length str) min-bsp))
  520. X               (setq min-bsp (+ (length str) (length key-str)))))
  521. X          (setq str (concat str key-str))
  522. X        (setq str (substring str 0 -1)))))
  523. X    (setq str-base str
  524. X      str (concat str key-str)
  525. X      macro-str (substring macro-str (length key-str)))
  526. X    (if exec
  527. X    (let ((comp (try-completion str-base obarray pred)))
  528. X      (if (if (stringp comp)
  529. X          (and (commandp (intern comp))
  530. X               (setq str-base comp))
  531. X        (commandp (intern str-base)))
  532. X          (insert str-base "\n")
  533. X        (insert "execute-extended-command\n")
  534. X        (insert "type \"")
  535. X        (MacEdit-insert-string str)
  536. X        (insert "\"\n")))
  537. X      (if (> (length str) 0)
  538. X      (progn
  539. X        (insert "type \"")
  540. X        (MacEdit-insert-string str)
  541. X        (insert "\"\n")))))
  542. )
  543. X
  544. (defun MacEdit-isearch-argument ()
  545. X  (let ((str "")
  546. X    (min-bsp 0)
  547. X    ch)
  548. X    (while (and (setq ch (MacEdit-read-char))
  549. X        (or (<= ch 127) (not search-exit-option))
  550. X        (not (eq ch search-exit-char))
  551. X        (or (eq ch search-repeat-char)
  552. X            (eq ch search-reverse-char)
  553. X            (eq ch search-delete-char)
  554. X            (eq ch search-yank-word-char)
  555. X            (eq ch search-yank-line-char)
  556. X            (eq ch search-quote-char)
  557. X            (eq ch ?\r)
  558. X            (eq ch ?\t)
  559. X            (not search-exit-option)
  560. X            (and (/= ch 127) (>= ch 32))))
  561. X      (if (and (eq ch search-quote-char)
  562. X           (MacEdit-peek-char))
  563. X      (setq str (concat str (char-to-string ch)
  564. X                (char-to-string (MacEdit-read-char)))
  565. X        min-bsp (length str))
  566. X    (if (or (and (< ch 127) (>= ch 32))
  567. X        (eq ch search-yank-word-char)
  568. X        (eq ch search-yank-line-char)
  569. X        (and (or (not (eq ch search-delete-char))
  570. X             (<= (length str) min-bsp))
  571. X             (setq min-bsp (1+ (length str)))))
  572. X        (setq str (concat str (char-to-string ch)))
  573. X      (setq str (substring str 0 -1)))))
  574. X    (if (eq ch search-exit-char)
  575. X    (if (= (length str) 0)  ;; non-incremental search
  576. X        (progn
  577. X          (setq str (concat str (char-to-string ch)))
  578. X          (and (eq (MacEdit-peek-char) ?\C-w)
  579. X           (progn
  580. X             (setq str (concat str "\C-w"))
  581. X             (MacEdit-read-char)))
  582. X          (if (> (length str) 0)
  583. X          (progn
  584. X            (insert "type \"")
  585. X            (MacEdit-insert-string str)
  586. X            (insert "\"\n")))
  587. X          (MacEdit-read-argument)
  588. X          (setq str "")))
  589. X      (MacEdit-unread-chars ch))
  590. X    (if (> (length str) 0)
  591. X    (progn
  592. X      (insert "type \"")
  593. X      (MacEdit-insert-string str)
  594. X      (insert "\\e\"\n"))))
  595. )
  596. X
  597. ;;; Get the next keystroke-sequence from the input stream.
  598. ;;; Sets key-symbol, key-str, and key-last as a side effect.
  599. (defun MacEdit-read-key ()
  600. X  (MacEdit-lookup-key (current-local-map))
  601. X  (and key-symbol
  602. X       (setq macro-str (substring macro-str (length key-str))))
  603. )
  604. X
  605. (defun MacEdit-peek-char ()
  606. X  (and (> (length macro-str) 0)
  607. X       (aref macro-str 0))
  608. )
  609. X
  610. (defun MacEdit-read-char ()
  611. X  (and (> (length macro-str) 0)
  612. X       (prog1
  613. X       (aref macro-str 0)
  614. X     (setq macro-str (substring macro-str 1))))
  615. )
  616. X
  617. (defun MacEdit-unread-chars (chars)
  618. X  (and (integerp chars)
  619. X       (setq chars (char-to-string chars)))
  620. X  (and chars
  621. X       (setq macro-str (concat chars macro-str)))
  622. )
  623. X
  624. (defun MacEdit-dump (mac)
  625. X  (set-mark-command nil)
  626. X  (insert "\n\n")
  627. X  (MacEdit-print-macro mac (current-local-map))
  628. )
  629. X
  630. X
  631. X
  632. ;;; Parse a string of spelled-out keystrokes, as produced by key-description.
  633. X
  634. (defun MacEdit-parse-keys (str)
  635. X  (let ((pos 0)
  636. X    (mac "")
  637. X    part)
  638. X    (while (and (< pos (length str))
  639. X        (string-match "[^ \t\n]+" str pos))
  640. X      (setq pos (match-end 0)
  641. X        part (substring str (match-beginning 0) (match-end 0))
  642. X        mac (concat mac
  643. X            (if (and (> (length part) 2)
  644. X                 (= (aref part 1) ?-)
  645. X                 (= (aref part 0) ?M))
  646. X                (progn
  647. X                  (setq part (substring part 2))
  648. X                  "\e")
  649. X              (if (and (> (length part) 4)
  650. X                   (= (aref part 0) ?C)
  651. X                   (= (aref part 1) ?-)
  652. X                   (= (aref part 2) ?M)
  653. X                   (= (aref part 3) ?-))
  654. X                  (progn
  655. X                (setq part (concat "C-" (substring part 4)))
  656. X                "\e")
  657. X                ""))
  658. X            (or (cdr (assoc part '( ( "NUL" . "\0" )
  659. X                        ( "RET" . "\r" )
  660. X                        ( "LFD" . "\n" )
  661. X                        ( "TAB" . "\t" )
  662. X                        ( "ESC" . "\e" )
  663. X                        ( "SPC" . " " )
  664. X                        ( "DEL" . "\177" )
  665. X                        ( "C-?" . "\177" )
  666. X                        ( "C-2" . "\0" )
  667. X                        ( "C-SPC" . "\0") )))
  668. X                (and (equal part "REM")
  669. X                 (setq pos (or (string-match "\n" str pos)
  670. X                           (length str)))
  671. X                 "")
  672. X                (and (= (length part) 3)
  673. X                 (= (aref part 0) ?C)
  674. X                 (= (aref part 1) ?-)
  675. X                 (char-to-string (logand (aref part 2) 31)))
  676. X                part))))
  677. X    mac)
  678. )
  679. X
  680. X
  681. X
  682. X
  683. ;;; Parse a keyboard macro description in MacEdit-print-macro's format.
  684. X
  685. (defun MacEdit-read-macro (&optional map)
  686. X  (or map (setq map (current-local-map)))
  687. X  (let ((macro-str ""))
  688. X    (while (not (progn
  689. X          (skip-chars-forward " \t\n")
  690. X          (eobp)))
  691. X      (cond ((looking-at "#"))   ;; comment
  692. X        ((looking-at "prefix-arg[ \t]*-[ \t]*\n")
  693. X         (MacEdit-append-chars "\C-u-"))
  694. X        ((looking-at "prefix-arg[ \t]*\\(-?[0-9]+\\)[ \t]*\n")
  695. X         (MacEdit-append-chars (concat "\C-u" (MacEdit-match-string 1))))
  696. X        ((looking-at "prefix-arg[ \t]*(\\([0-9]+\\))[ \t]*\n")
  697. X         (let ((val (string-to-int (MacEdit-match-string 1))))
  698. X           (while (> val 1)
  699. X         (or (= (% val 4) 0)
  700. X             (error "Bad prefix argument value"))
  701. X         (MacEdit-append-chars "\C-u")
  702. X         (setq val (/ val 4)))))
  703. X        ((looking-at "prefix-arg")
  704. X         (error "Bad prefix argument syntax"))
  705. X        ((looking-at "insert ")
  706. X         (forward-char 7)
  707. X         (MacEdit-append-chars (read (current-buffer)))
  708. X         (if (< (current-column) 7)
  709. X         (forward-line -1)))
  710. X        ((looking-at "type ")
  711. X         (forward-char 5)
  712. X         (MacEdit-append-chars (read (current-buffer)))
  713. X         (if (< (current-column) 5)
  714. X         (forward-line -1)))
  715. X        ((looking-at "keys \\(.*\\)\n")
  716. X         (goto-char (1- (match-end 0)))
  717. X         (MacEdit-append-chars (MacEdit-parse-keys
  718. X                    (buffer-substring (match-beginning 1)
  719. X                              (match-end 1)))))
  720. X        ((looking-at "\\([-a-zA-z0-9_]+\\)[ \t]*\\(.*\\)\n")
  721. X         (let* ((func (intern (MacEdit-match-string 1)))
  722. X            (arg (MacEdit-match-string 2))
  723. X            (cust (get func 'MacEdit-read)))
  724. X           (if cust
  725. X           (funcall cust arg)
  726. X         (or (commandp func)
  727. X             (error "Not an Emacs command"))
  728. X         (or (equal arg "")
  729. X             (string-match "\\`#" arg)
  730. X             (error "Unexpected argument to command"))
  731. X         (let ((keys
  732. X            (or (where-is-internal func map t)
  733. X                (where-is-internal func (current-global-map) t))))
  734. X           (if keys
  735. X               (MacEdit-append-chars keys)
  736. X             (MacEdit-append-chars (concat "\ex"
  737. X                           (symbol-name func)
  738. X                           "\n")))))))
  739. X        (t (error "Syntax error")))
  740. X      (forward-line 1))
  741. X    macro-str)
  742. )
  743. X
  744. (defun MacEdit-append-chars (chars)
  745. X  (setq macro-str (concat macro-str chars))
  746. )
  747. X
  748. (defun MacEdit-match-string (n)
  749. X  (if (match-beginning n)
  750. X      (buffer-substring (match-beginning n) (match-end n))
  751. X    "")
  752. )
  753. X
  754. X
  755. X
  756. (defun MacEdit-get-interactive (func)
  757. X  (if (symbolp func)
  758. X      (let ((cust (get func 'MacEdit-interactive)))
  759. X    (if cust
  760. X        cust
  761. X      (MacEdit-get-interactive (symbol-function func))))
  762. X    (or (and (eq (car-safe func) 'lambda)
  763. X         (let ((int (if (consp (nth 2 func))
  764. X                (nth 2 func)
  765. X              (nth 3 func))))
  766. X           (and (eq (car-safe int) 'interactive)
  767. X            (stringp (nth 1 int))
  768. X            (nth 1 int))))
  769. X    ""))
  770. )
  771. X
  772. (put 'search-forward           'MacEdit-interactive "s")
  773. (put 'search-backward          'MacEdit-interactive "s")
  774. (put 'word-search-forward      'MacEdit-interactive "s")
  775. (put 'word-search-backward     'MacEdit-interactive "s")
  776. (put 're-search-forward        'MacEdit-interactive "s")
  777. (put 're-search-backward       'MacEdit-interactive "s")
  778. (put 'switch-to-buffer         'MacEdit-interactive "B")
  779. (put 'kill-buffer              'MacEdit-interactive "B")
  780. (put 'rename-buffer            'MacEdit-interactive "B\nB")
  781. (put 'goto-char                'MacEdit-interactive "N")
  782. (put 'global-set-key           'MacEdit-interactive "k\nC")
  783. (put 'global-unset-key         'MacEdit-interactive "k")
  784. (put 'local-set-key            'MacEdit-interactive "k\nC")
  785. (put 'local-unset-key          'MacEdit-interactive "k")
  786. X
  787. ;;; Think about kbd-macro-query
  788. X
  789. X
  790. X
  791. ;;; Edit a keyboard macro in another buffer.
  792. ;;; (Prefix argument is currently ignored.)
  793. X
  794. (defun MacEdit-edit-macro (mac repl &optional prefix buffer hook arg)
  795. X  (or (stringp mac)
  796. X      (error "Not a keyboard macro"))
  797. X  (let ((oldbuf (current-buffer))
  798. X    (from-calc (and (get-buffer-window "*Calculator*")
  799. X            (eq (lookup-key (current-global-map) "\e#")
  800. X                'calc-dispatch)))
  801. X    (local (current-local-map))
  802. X    (buf (get-buffer-create (or buffer "*Edit Macro*"))))
  803. X    (set-buffer buf)
  804. X    (kill-all-local-variables)
  805. X    (use-local-map MacEdit-mode-map)
  806. X    (setq buffer-read-only nil)
  807. X    (setq major-mode 'MacEdit-mode)
  808. X    (setq mode-name "Edit Macro")
  809. X    (make-local-variable 'MacEdit-original-buffer)
  810. X    (setq MacEdit-original-buffer oldbuf)
  811. X    (make-local-variable 'MacEdit-replace-function)
  812. X    (setq MacEdit-replace-function repl)
  813. X    (make-local-variable 'MacEdit-replace-argument)
  814. X    (setq MacEdit-replace-argument arg)
  815. X    (make-local-variable 'MacEdit-finish-hook)
  816. X    (setq MacEdit-finish-hook hook)
  817. X    (erase-buffer)
  818. X    (insert "# Keyboard Macro Editor.  Press "
  819. X        (if from-calc "M-# M-#" "C-c C-c")
  820. X        " to finish; press "
  821. X        (if from-calc "M-# x" "C-x k RET")
  822. X        " to cancel.\n")
  823. X    (insert "# Original keys: " (key-description mac) "\n\n")
  824. X    (message "Formatting keyboard macro...")
  825. X    (MacEdit-print-macro mac local)
  826. X    (switch-to-buffer buf)
  827. X    (goto-char (point-min))
  828. X    (forward-line 3)
  829. X    (recenter '(4))
  830. X    (set-buffer-modified-p nil)
  831. X    (message "Formatting keyboard macro...done")
  832. X    (run-hooks 'MacEdit-format-hook))
  833. )
  834. X
  835. (defun MacEdit-finish-edit ()
  836. X  (interactive)
  837. X  (or (and (boundp 'MacEdit-original-buffer)
  838. X       (boundp 'MacEdit-replace-function)
  839. X       (boundp 'MacEdit-replace-argument)
  840. X       (boundp 'MacEdit-finish-hook)
  841. X       (eq major-mode 'MacEdit-mode))
  842. X      (error "This command is valid only in buffers created by edit-kbd-macro."))
  843. X  (let ((buf (current-buffer))
  844. X    (str (buffer-string))
  845. X    (func MacEdit-replace-function)
  846. X    (arg MacEdit-replace-argument)
  847. X    (hook MacEdit-finish-hook))
  848. X    (goto-char (point-min))
  849. X    (and (buffer-modified-p)
  850. X     func
  851. X     (progn
  852. X       (message "Compiling keyboard macro...")
  853. X       (run-hooks 'MacEdit-compile-hook)
  854. X       (let ((mac (MacEdit-read-macro
  855. X               (and (buffer-name MacEdit-original-buffer)
  856. X                (save-excursion
  857. X                  (set-buffer MacEdit-original-buffer)
  858. X                  (current-local-map))))))
  859. X         (and (buffer-name MacEdit-original-buffer)
  860. X          (switch-to-buffer MacEdit-original-buffer))
  861. X         (funcall func mac arg))
  862. X       (message "Compiling keyboard macro...done")))
  863. X    (kill-buffer buf)
  864. X    (if hook
  865. X    (funcall hook arg)))
  866. )
  867. X
  868. (defun MacEdit-cancel-edit ()
  869. X  (interactive)
  870. X  (if (eq major-mode 'MacEdit-mode)
  871. X      (set-buffer-modified-p nil))
  872. X  (MacEdit-finish-edit)
  873. X  (message "(Cancelled)")
  874. )
  875. X
  876. (defun MacEdit-mode ()
  877. X  "Keyboard Macro Editing mode.  Press C-c C-c to save and exit.
  878. To abort the edit, just kill this buffer with C-x k RET.
  879. X
  880. The keyboard macro is represented as a series of M-x style command names.
  881. Keystrokes which do not correspond to simple M-x commands are written as
  882. \"type\" commands.  When you press C-c C-c, MacEdit converts each command
  883. back into a suitable keystroke sequence; \"type\" commands are converted
  884. directly back into keystrokes."
  885. X  (interactive)
  886. X  (error "This mode can be enabled only by edit-kbd-macro or edit-last-kbd-macro.")
  887. )
  888. (put 'MacEdit-mode 'mode-class 'special)
  889. X
  890. (defvar MacEdit-mode-map nil)
  891. (if MacEdit-mode-map
  892. X    ()
  893. X  (setq MacEdit-mode-map (make-sparse-keymap))
  894. X  (define-key MacEdit-mode-map "\C-c\C-c" 'MacEdit-finish-edit)
  895. )
  896. X
  897. SHAR_EOF
  898. chmod 0644 macedit.el ||
  899. echo 'restore of macedit.el failed'
  900. Wc_c="`wc -c < 'macedit.el'`"
  901. test 22571 -eq "$Wc_c" ||
  902.     echo 'macedit.el: original size 22571, current size' "$Wc_c"
  903. rm -f _shar_wnt_.tmp
  904. fi
  905. # ============= calc.texinfo ==============
  906. if test -f 'calc.texinfo' -a X"$1" != X"-c"; then
  907.     echo 'x - skipping calc.texinfo (File already exists)'
  908.     rm -f _shar_wnt_.tmp
  909. else
  910. > _shar_wnt_.tmp
  911. echo 'x - extracting calc.texinfo (Text)'
  912. sed 's/^X//' << 'SHAR_EOF' > 'calc.texinfo' &&
  913. \input texinfo                  @c -*-texinfo-*-
  914. @comment %**start of header (This is for running Texinfo on a region.)
  915. @c smallbook
  916. @setfilename calc.info
  917. @c [title]
  918. @settitle GNU Emacs Calc 2.00 Manual
  919. @setchapternewpage odd
  920. @comment %**end of header (This is for running Texinfo on a region.)
  921. X
  922. @tex
  923. % Some special kludges to make TeX formatting prettier.
  924. % Because makeinfo.c exists, we can't just define new commands.
  925. % So instead, we take over little-used existing commands.
  926. %
  927. % Redefine @cite{text} to act like $text$ in regular TeX.
  928. % Info will typeset this same as @samp{text}.
  929. \gdef\goodtex{\tex \let\rm\goodrm \let\t\ttfont \turnoffactive}
  930. \gdef\goodrm{\fam0\tenrm}
  931. \gdef\cite{\goodtex$\citexxx}
  932. \gdef\citexxx#1{#1$\Etex}
  933. %
  934. % Redefine @i{text} to be equivalent to @cite{text}, i.e., to use math mode.
  935. % This looks the same in TeX but omits the surrounding ` ' in Info.
  936. \global\let\i=\cite
  937. %
  938. % Redefine @c{tex-stuff} \n @whatever{info-stuff}.
  939. \gdef\c{\futurelet\next\mycxxx}
  940. \gdef\mycxxx{\ifx\next\bgroup\goodtex\let\next\mycxxy\else\let\next\comment\fi\next}
  941. \gdef\mycxxy#1#2{#1\Etex\mycxxz}
  942. \gdef\mycxxz#1{}
  943. @end tex
  944. X
  945. @c Fix some things to make math mode work properly.
  946. @iftex
  947. @textfont0=@tenrm
  948. @font@teni=cmmi10 scaled @magstephalf   @textfont1=@teni
  949. @font@seveni=cmmi7 scaled @magstephalf  @scriptfont1=@seveni
  950. @font@fivei=cmmi5 scaled @magstephalf   @scriptscriptfont1=@fivei
  951. @font@tensy=cmsy10 scaled @magstephalf  @textfont2=@tensy
  952. @font@sevensy=cmsy7 scaled @magstephalf @scriptfont2=@sevensy
  953. @font@fivesy=cmsy5 scaled @magstephalf  @scriptscriptfont2=@fivesy
  954. @font@tenex=cmex10 scaled @magstephalf  @textfont3=@tenex
  955. @scriptfont3=@tenex  @scriptscriptfont3=@tenex
  956. @textfont7=@tentt  @scriptfont7=@tentt  @scriptscriptfont7=@tentt
  957. @end iftex
  958. X
  959. @c Fix some other things specifically for this manual.
  960. @iftex
  961. @finalout
  962. @mathcode`@:=`@:  @c Make Calc fractions come out right in math mode
  963. @tocindent=.5pc   @c Indent subsections in table of contents less
  964. @rightskip=0pt plus 2pt  @c Favor short lines rather than overfull hboxes
  965. @tex
  966. \gdef\trademark{${}^{\rm TM}$}
  967. \gdef\group{\par\vskip2pt\begingroup
  968. \def\Egroup{\egroup\endgroup}%
  969. \let\aboveenvbreak=\relax  % so that nothing gets between vtop and first box
  970. \def\singlespace{\baselineskip=\singlespaceskip}%
  971. \vtop\bgroup}
  972. @end tex
  973. @ifx@turnoffactive@undefinedzzz@def@turnoffactive{}@fi
  974. @ifx@ninett@undefinedzzz@font@ninett=cmtt9@fi
  975. @catcode`@\=0 \catcode`\@=11
  976. \r@ggedbottomtrue
  977. \catcode`\@=0 @catcode`@\=@active
  978. @end iftex
  979. X
  980. @ifinfo
  981. This file documents Calc, the GNU Emacs calculator.
  982. X
  983. Copyright (C) 1990, 1991 Free Software Foundation, Inc.
  984. X
  985. Permission is granted to make and distribute verbatim copies of this
  986. manual provided the copyright notice and this permission notice are
  987. preserved on all copies.
  988. X
  989. @ignore
  990. Permission is granted to process this file through TeX and print the
  991. results, provided the printed document carries copying permission notice
  992. identical to this one except for the removal of this paragraph (this
  993. paragraph not being relevant to the printed manual).
  994. X
  995. @end ignore
  996. Permission is granted to copy and distribute modified versions of this
  997. manual under the conditions for verbatim copying, provided also that the
  998. section entitled ``GNU General Public License'' is included exactly as
  999. in the original, and provided that the entire resulting derived work is
  1000. distributed under the terms of a permission notice identical to this one.
  1001. X
  1002. Permission is granted to copy and distribute translations of this manual
  1003. into another language, under the above conditions for modified versions,
  1004. except that the section entitled ``GNU General Public License'' may be
  1005. included in a translation approved by the author instead of in the
  1006. original English.
  1007. @end ifinfo
  1008. X
  1009. @titlepage
  1010. @sp 6
  1011. @center @titlefont{Calc Manual}
  1012. @sp 4
  1013. @center GNU Emacs Calc Version 2.00
  1014. @c [volume]
  1015. @sp 1
  1016. @center October 1991
  1017. @sp 5
  1018. @center Dave Gillespie
  1019. @center daveg@@synaptics.com
  1020. @page
  1021. X
  1022. @vskip 0pt plus 1filll
  1023. Copyright @copyright{} 1990, 1991 Free Software Foundation, Inc.
  1024. X
  1025. Permission is granted to make and distribute verbatim copies of
  1026. this manual provided the copyright notice and this permission notice
  1027. are preserved on all copies.
  1028. X
  1029. @ignore
  1030. Permission is granted to process this file through TeX and print the
  1031. results, provided the printed document carries copying permission notice
  1032. identical to this one except for the removal of this paragraph (this
  1033. paragraph not being relevant to the printed manual).
  1034. X
  1035. @end ignore
  1036. Permission is granted to copy and distribute modified versions of this
  1037. manual under the conditions for verbatim copying, provided also that the
  1038. section entitled ``GNU General Public License'' is included exactly as
  1039. in the original, and provided that the entire resulting derived work is
  1040. distributed under the terms of a permission notice identical to this one.
  1041. X
  1042. Permission is granted to copy and distribute translations of this manual
  1043. into another language, under the above conditions for modified versions,
  1044. except that the section entitled ``GNU General Public License'' may be
  1045. included in a translation approved by the author instead of in the
  1046. original English.
  1047. @end titlepage
  1048. X
  1049. @c [begin]
  1050. @ifinfo
  1051. @node Top, Getting Started,, (dir)
  1052. @ichapter The GNU Emacs Calculator
  1053. X
  1054. @noindent
  1055. @dfn{Calc 2.00} is an advanced desk calculator and mathematical tool
  1056. that runs as part of the GNU Emacs environment.
  1057. X
  1058. This manual is divided into three major parts: "Getting Started," the
  1059. "Calc Tutorial," and the "Calc Reference."  The Tutorial introduces all
  1060. the major aspects of Calculator use in an easy, hands-on way.  The
  1061. remainder of the manual is a complete reference to the features of the
  1062. Calculator.
  1063. X
  1064. For help in the Emacs Info system (which you are using to read this
  1065. file), type @kbd{?}.  (You can also type @kbd{h} to run through a
  1066. longer Info tutorial.)
  1067. X
  1068. @end ifinfo
  1069. @menu
  1070. * Copying::               How you can copy and share Calc.
  1071. X
  1072. * Getting Started::       General description and overview.
  1073. * Tutorial::              A step-by-step introduction for beginners.
  1074. X
  1075. * Introduction::          Introduction to the Calc reference manual.
  1076. * Data Types::            Types of objects manipulated by Calc.
  1077. * Stack and Trail::       Manipulating the stack and trail buffers.
  1078. * Mode Settings::         Adjusting display format and other modes.
  1079. * Arithmetic::            Basic arithmetic functions.
  1080. * Scientific Functions::  Transcendentals and other scientific functions.
  1081. * Matrix Functions::      Operations on vectors and matrices.
  1082. * Algebra::               Manipulating expressions algebraically.
  1083. * Units::                 Operations on numbers with units.
  1084. * Store and Recall::      Storing and recalling variables.
  1085. * Graphics::              Commands for making graphs of data.
  1086. * Kill and Yank::         Moving data into and out of Calc.
  1087. * Embedded Mode::         Working with formulas embedded in a file.
  1088. * Programming::           Calc as a programmable calculator.
  1089. X
  1090. * Installation::          Installing Calc as a part of GNU Emacs.
  1091. * Reporting Bugs::        How to report bugs and make suggestions.
  1092. X
  1093. * Summary::               Summary of Calc commands and functions.
  1094. X
  1095. * Key Index::             The standard Calc key sequences.
  1096. * Command Index::         The interactive Calc commands.
  1097. * Function Index::        Functions (in algebraic formulas).
  1098. * Concept Index::         General concepts.
  1099. * Variable Index::        Variables used by Calc (both user and internal).
  1100. * Lisp Function Index::   Internal Lisp math functions.
  1101. @end menu
  1102. X
  1103. @node Copying, Getting Started, Top, Top
  1104. @unnumbered GNU GENERAL PUBLIC LICENSE
  1105. @center Version 1, February 1989
  1106. X
  1107. @display
  1108. Copyright @copyright{} 1989 Free Software Foundation, Inc.
  1109. 675 Mass Ave, Cambridge, MA 02139, USA
  1110. X
  1111. Everyone is permitted to copy and distribute verbatim copies
  1112. of this license document, but changing it is not allowed.
  1113. @end display
  1114. X
  1115. @unnumberedsec Preamble
  1116. X
  1117. X  The license agreements of most software companies try to keep users
  1118. at the mercy of those companies.  By contrast, our General Public
  1119. License is intended to guarantee your freedom to share and change free
  1120. software---to make sure the software is free for all its users.  The
  1121. General Public License applies to the Free Software Foundation's
  1122. software and to any other program whose authors commit to using it.
  1123. You can use it for your programs, too.
  1124. X
  1125. X  When we speak of free software, we are referring to freedom, not
  1126. price.  Specifically, the General Public License is designed to make
  1127. sure that you have the freedom to give away or sell copies of free
  1128. software, that you receive source code or can get it if you want it,
  1129. that you can change the software or use pieces of it in new free
  1130. programs; and that you know you can do these things.
  1131. X
  1132. X  To protect your rights, we need to make restrictions that forbid
  1133. anyone to deny you these rights or to ask you to surrender the rights.
  1134. These restrictions translate to certain responsibilities for you if you
  1135. distribute copies of the software, or if you modify it.
  1136. X
  1137. X  For example, if you distribute copies of a such a program, whether
  1138. gratis or for a fee, you must give the recipients all the rights that
  1139. you have.  You must make sure that they, too, receive or can get the
  1140. source code.  And you must tell them their rights.
  1141. X
  1142. X  We protect your rights with two steps: (1) copyright the software, and
  1143. (2) offer you this license which gives you legal permission to copy,
  1144. distribute and/or modify the software.
  1145. X
  1146. X  Also, for each author's protection and ours, we want to make certain
  1147. that everyone understands that there is no warranty for this free
  1148. software.  If the software is modified by someone else and passed on, we
  1149. want its recipients to know that what they have is not the original, so
  1150. that any problems introduced by others will not reflect on the original
  1151. authors' reputations.
  1152. X
  1153. X  The precise terms and conditions for copying, distribution and
  1154. modification follow.
  1155. X
  1156. @iftex
  1157. @unnumberedsec TERMS AND CONDITIONS
  1158. @end iftex
  1159. @ifinfo
  1160. @center TERMS AND CONDITIONS
  1161. @end ifinfo
  1162. X
  1163. @enumerate
  1164. @item
  1165. This License Agreement applies to any program or other work which
  1166. contains a notice placed by the copyright holder saying it may be
  1167. distributed under the terms of this General Public License.  The
  1168. ``Program'', below, refers to any such program or work, and a ``work based
  1169. on the Program'' means either the Program or any work containing the
  1170. Program or a portion of it, either verbatim or with modifications.  Each
  1171. licensee is addressed as ``you''.
  1172. X
  1173. @item
  1174. You may copy and distribute verbatim copies of the Program's source
  1175. code as you receive it, in any medium, provided that you conspicuously and
  1176. appropriately publish on each copy an appropriate copyright notice and
  1177. disclaimer of warranty; keep intact all the notices that refer to this
  1178. General Public License and to the absence of any warranty; and give any
  1179. other recipients of the Program a copy of this General Public License
  1180. along with the Program.  You may charge a fee for the physical act of
  1181. transferring a copy.
  1182. X
  1183. @item
  1184. You may modify your copy or copies of the Program or any portion of
  1185. it, and copy and distribute such modifications under the terms of Paragraph
  1186. 1 above, provided that you also do the following:
  1187. X
  1188. @itemize @bullet
  1189. @item
  1190. cause the modified files to carry prominent notices stating that
  1191. you changed the files and the date of any change; and
  1192. X
  1193. @item
  1194. cause the whole of any work that you distribute or publish, that
  1195. in whole or in part contains the Program or any part thereof, either
  1196. with or without modifications, to be licensed at no charge to all
  1197. third parties under the terms of this General Public License (except
  1198. that you may choose to grant warranty protection to some or all
  1199. third parties, at your option).
  1200. X
  1201. @item
  1202. If the modified program normally reads commands interactively when
  1203. run, you must cause it, when started running for such interactive use
  1204. in the simplest and most usual way, to print or display an
  1205. announcement including an appropriate copyright notice and a notice
  1206. that there is no warranty (or else, saying that you provide a
  1207. warranty) and that users may redistribute the program under these
  1208. conditions, and telling the user how to view a copy of this General
  1209. Public License.
  1210. X
  1211. @item
  1212. You may charge a fee for the physical act of transferring a
  1213. copy, and you may at your option offer warranty protection in
  1214. exchange for a fee.
  1215. @end itemize
  1216. X
  1217. Mere aggregation of another independent work with the Program (or its
  1218. derivative) on a volume of a storage or distribution medium does not bring
  1219. the other work under the scope of these terms.
  1220. X
  1221. @item
  1222. You may copy and distribute the Program (or a portion or derivative of
  1223. it, under Paragraph 2) in object code or executable form under the terms of
  1224. Paragraphs 1 and 2 above provided that you also do one of the following:
  1225. X
  1226. @itemize @bullet
  1227. @item
  1228. accompany it with the complete corresponding machine-readable
  1229. source code, which must be distributed under the terms of
  1230. Paragraphs 1 and 2 above; or,
  1231. X
  1232. @item
  1233. accompany it with a written offer, valid for at least three
  1234. years, to give any third party free (except for a nominal charge
  1235. for the cost of distribution) a complete machine-readable copy of the
  1236. corresponding source code, to be distributed under the terms of
  1237. Paragraphs 1 and 2 above; or,
  1238. X
  1239. @item
  1240. accompany it with the information you received as to where the
  1241. corresponding source code may be obtained.  (This alternative is
  1242. allowed only for noncommercial distribution and only if you
  1243. received the program in object code or executable form alone.)
  1244. @end itemize
  1245. X
  1246. Source code for a work means the preferred form of the work for making
  1247. modifications to it.  For an executable file, complete source code means
  1248. all the source code for all modules it contains; but, as a special
  1249. exception, it need not include source code for modules which are standard
  1250. libraries that accompany the operating system on which the executable
  1251. file runs, or for standard header files or definitions files that
  1252. accompany that operating system.
  1253. X
  1254. @item
  1255. You may not copy, modify, sublicense, distribute or transfer the
  1256. Program except as expressly provided under this General Public License.
  1257. Any attempt otherwise to copy, modify, sublicense, distribute or transfer
  1258. the Program is void, and will automatically terminate your rights to use
  1259. the Program under this License.  However, parties who have received
  1260. copies, or rights to use copies, from you under this General Public
  1261. License will not have their licenses terminated so long as such parties
  1262. remain in full compliance.
  1263. X
  1264. @item
  1265. By copying, distributing or modifying the Program (or any work based
  1266. on the Program) you indicate your acceptance of this license to do so,
  1267. and all its terms and conditions.
  1268. X
  1269. @item
  1270. Each time you redistribute the Program (or any work based on the
  1271. Program), the recipient automatically receives a license from the original
  1272. licensor to copy, distribute or modify the Program subject to these
  1273. terms and conditions.  You may not impose any further restrictions on the
  1274. recipients' exercise of the rights granted herein.
  1275. X
  1276. @item
  1277. The Free Software Foundation may publish revised and/or new versions
  1278. of the General Public License from time to time.  Such new versions will
  1279. be similar in spirit to the present version, but may differ in detail to
  1280. address new problems or concerns.
  1281. X
  1282. Each version is given a distinguishing version number.  If the Program
  1283. specifies a version number of the license which applies to it and ``any
  1284. later version'', you have the option of following the terms and conditions
  1285. either of that version or of any later version published by the Free
  1286. Software Foundation.  If the Program does not specify a version number of
  1287. the license, you may choose any version ever published by the Free Software
  1288. Foundation.
  1289. X
  1290. @item
  1291. If you wish to incorporate parts of the Program into other free
  1292. programs whose distribution conditions are different, write to the author
  1293. to ask for permission.  For software which is copyrighted by the Free
  1294. Software Foundation, write to the Free Software Foundation; we sometimes
  1295. make exceptions for this.  Our decision will be guided by the two goals
  1296. of preserving the free status of all derivatives of our free software and
  1297. of promoting the sharing and reuse of software generally.
  1298. X
  1299. @iftex
  1300. @heading NO WARRANTY
  1301. @end iftex
  1302. @ifinfo
  1303. @center NO WARRANTY
  1304. @end ifinfo
  1305. X
  1306. @item
  1307. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
  1308. FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
  1309. OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
  1310. PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
  1311. OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  1312. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
  1313. TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
  1314. PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
  1315. REPAIR OR CORRECTION.
  1316. X
  1317. @item
  1318. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL
  1319. ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
  1320. REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
  1321. INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
  1322. ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT
  1323. LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES
  1324. SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE
  1325. WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN
  1326. ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  1327. @end enumerate
  1328. X
  1329. @node Getting Started, Tutorial, Top, Top
  1330. @chapter Getting Started
  1331. X
  1332. @noindent
  1333. This chapter provides a general overview of Calc, the GNU Emacs
  1334. Calculator:  What it is, how to start it and how to exit from it,
  1335. and what are the various ways that it can be used.
  1336. X
  1337. @menu
  1338. * What is Calc::
  1339. * About This Manual::
  1340. * Notations Used in This Manual::
  1341. * Using Calc::
  1342. * Demonstration of Calc::
  1343. * New for Calc 2.00::
  1344. * History and Acknowledgements::
  1345. @end menu
  1346. X
  1347. @node What is Calc, About This Manual, Getting Started, Getting Started
  1348. @section What is Calc?
  1349. X
  1350. @noindent
  1351. @dfn{Calc} is an advanced calculator and mathematical tool that runs as
  1352. part of the GNU Emacs environment.  Very roughly based on the HP-28/48
  1353. series of calculators, its many features include:
  1354. X
  1355. @itemize @bullet
  1356. @item
  1357. Choice of algebraic or RPN (stack-based) entry of calculations.
  1358. X
  1359. @item
  1360. Arbitrary precision integers and floating-point numbers.
  1361. X
  1362. @item
  1363. Arithmetic on rational numbers, complex numbers (rectangular and polar),
  1364. error forms with standard deviations, open and closed intervals, vectors
  1365. and matrices, dates and times, infinities, sets, quantities with units,
  1366. and algebraic formulas.
  1367. X
  1368. @item
  1369. Mathematical operations such as logarithms and trigonometric functions.
  1370. X
  1371. @item
  1372. Programmer's features (bitwise operations, non-decimal numbers).
  1373. X
  1374. @item
  1375. Financial functions such as future value and internal rate of return.
  1376. X
  1377. @item
  1378. Number theoretical features such as prime factorization and arithmetic
  1379. modulo @i{M} for any @i{M}.
  1380. X
  1381. @item
  1382. Algebraic manipulation features, including symbolic calculus.
  1383. X
  1384. @item
  1385. Moving data to and from regular editing buffers.
  1386. X
  1387. @item
  1388. ``Embedded mode'' for manipulating Calc formulas and data directly
  1389. inside any editing buffer.
  1390. X
  1391. @item
  1392. Graphics using GNUPLOT, a versatile (and free) plotting program.
  1393. X
  1394. @item
  1395. Easy programming using keyboard macros, algebraic formulas,
  1396. algebraic rewrite rules, or extended Emacs Lisp.
  1397. @end itemize
  1398. X
  1399. Calc tries to include a little something for everyone; as a result it is
  1400. large and might be intimidating to the first-time user.  If you plan to
  1401. use Calc only as a traditional desk calculator, all you really need to
  1402. read is the ``Getting Started'' chapter of this manual and possibly the
  1403. first few sections of the tutorial.  As you become more comfortable with
  1404. the program you can learn its additional features.  In terms of efficiency,
  1405. scope and depth, Calc cannot replace a powerful tool like Mathematica@c{\trademark}
  1406. @asis{ (tm)}.
  1407. But Calc has the advantages of convenience, portability, and availability
  1408. of the source code.  And, of course, it's free!
  1409. X
  1410. @node About This Manual, Notations Used in This Manual, What is Calc, Getting Started
  1411. @section About This Manual
  1412. X
  1413. @ifinfo
  1414. @noindent
  1415. This manual is divided into three major sections:  The ``Getting
  1416. Started'' chapter you are reading now, the Calc tutorial (chapter 2),
  1417. and the Calc reference manual (the remaining chapters and appendices).
  1418. The printed version may be in two volumes, the Tutorial and the
  1419. Reference.  If so, both volumes will include a copy of the
  1420. ``getting started'' chapter.
  1421. @end ifinfo
  1422. @iftex
  1423. @noindent
  1424. This manual is divided into three major sections:  The ``Getting
  1425. Started'' chapter you are reading now, the Calc tutorial (chapter 2),
  1426. and the Calc reference manual (the remaining chapters and appendices).
  1427. @c [when-split]
  1428. @c This manual has been printed in two volumes, the @dfn{Tutorial} and the
  1429. @c @dfn{Reference}.  Both volumes include a copy of the ``Getting Started''
  1430. @c chapter.
  1431. @end iftex
  1432. X
  1433. At the end of the present chapter is a brief ``demonstration'' which
  1434. illustrates the major features of Calc in just a couple of pages.  If
  1435. you are in a hurry to use Calc, this will show you everything you need
  1436. to know to begin.
  1437. X
  1438. The tutorial chapter walks you through the various parts of Calc
  1439. with lots of hands-on examples and explanations.  If you are new
  1440. to Calc and you have some time, try going through at least the
  1441. beginning of the tutorial.  The tutorial includes over 50 exercises
  1442. with answers.  These exercises give you some guided practice with
  1443. Calc, as well as pointing out some interesting and unusual ways
  1444. to use Calc's features.
  1445. X
  1446. The reference section discusses Calc in complete depth.  The reference
  1447. can be read from start to finish if you want to learn every aspect
  1448. of Calc.  Or, you can look in the table of contents or the Concept
  1449. Index to find the parts of the manual that discuss the things you
  1450. need to know.
  1451. X
  1452. You can access this manual on-line at any time within Calc by
  1453. pressing the @kbd{h i} key sequence.  Outside of the Calc window,
  1454. you can press @kbd{M-# i} to read the manual on-line.  Also, you
  1455. can jump directly to the Tutorial by pressing @kbd{h t} or @kbd{M-# t},
  1456. or to the Summary by pressing @kbd{h s} or @kbd{M-# s}.  Within Calc,
  1457. you can also go to the part of the manual describing any Calc key,
  1458. function, or variable using @w{@kbd{h k}}, @kbd{h f}, or @kbd{h v},
  1459. respectively.
  1460. X
  1461. @node Notations Used in This Manual, Using Calc, About This Manual, Getting Started
  1462. @section Notations Used in This Manual
  1463. X
  1464. @noindent
  1465. This section describes the various notations that are used
  1466. throughout the Calc manual.
  1467. X
  1468. In keystroke sequences, uppercase letters mean you must hold down
  1469. the shift key while typing the letter.  Keys pressed with Control
  1470. held down are shown as @kbd{C-x}.  Keys pressed with Meta held down
  1471. are shown as @kbd{M-x}.  Other notations are @key{RET} for the
  1472. Return key, @key{SPC} for the space bar, @key{TAB} for the Tab key,
  1473. @key{DEL} for the Delete key, and @key{LFD} for the Line-Feed key
  1474. (@kbd{C-j} if you don't have this key on your keyboard).
  1475. X
  1476. Sometimes the @key{RET} key is not shown when it is ``obvious''
  1477. that you must press @kbd{RET} to proceed.  For example, the @key{RET}
  1478. is usually omitted in key sequences like @kbd{M-x calc-keypad @key{RET}}.
  1479. X
  1480. Commands are generally shown like this:  @kbd{p} (@code{calc-precision})
  1481. or @kbd{M-# k} (@code{calc-keypad}).  This means that the command is
  1482. normally used by pressing the @kbd{p} key or @kbd{M-# k} key sequence,
  1483. but it also has the full-name equivalent shown, e.g., @kbd{M-x calc-precision}.
  1484. X
  1485. Commands that correspond to functions in algebraic notation
  1486. are written:  @kbd{C} (@code{calc-cos}) [@code{cos}].  This means
  1487. the @kbd{C} key is equivalent to @kbd{M-x calc-cos}, and that
  1488. the corresponding function in an algebraic-style formula would
  1489. be @samp{cos(@var{x})}.
  1490. X
  1491. A few commands don't have key equivalents:  @code{calc-sincos}
  1492. [@code{sincos}].@refill
  1493. X
  1494. @node Using Calc, Demonstration of Calc, Notations Used in This Manual, Getting Started
  1495. @section Using Calc
  1496. X
  1497. @noindent
  1498. Calc has several user interfaces that are specialized for
  1499. different kinds of tasks.  As well as Calc's standard interface,
  1500. there are Quick Mode, Keypad Mode, and Embedded Mode.
  1501. X
  1502. @c [fix-ref Installation]
  1503. Calc must be @dfn{installed} before it can be used.  @xref{Installation},
  1504. for instructions on setting up and installing Calc.  We will assume
  1505. you or someone on your system has already installed Calc as described
  1506. there.
  1507. X
  1508. @menu
  1509. * Starting Calc::
  1510. * The Standard Interface::
  1511. * Quick Mode Overview::
  1512. * Keypad Mode Overview::
  1513. * Standalone Operation::
  1514. * Embedded Mode Overview::
  1515. * Other M-# Commands::
  1516. @end menu
  1517. X
  1518. @node Starting Calc, The Standard Interface, Using Calc, Using Calc
  1519. @subsection Starting Calc
  1520. X
  1521. @noindent
  1522. On most systems, you can type @kbd{M-#} to start the Calculator.
  1523. The notation @kbd{M-#} is short for @kbd{@key{META}-#}.  On most
  1524. keyboards this means holding down the @key{META} (or @key{ALT}) and
  1525. @key{SHIFT} keys while typing @kbd{3}.
  1526. X
  1527. @cindex META key
  1528. If you don't have a @key{META} key on your keyboard, you can type
  1529. @key{ESC} first, then @kbd{#}, to accomplish the same thing.  If you
  1530. don't even have an @key{ESC} key, you can fake it by holding down
  1531. @key{CTRL} or @key{CONTROL} while typing a left square bracket
  1532. (that's @kbd{C-[} in Emacs notation).@refill
  1533. X
  1534. @kbd{M-#} is a @dfn{prefix key}; when you press it, Emacs waits for
  1535. you to press a second key to complete the command.  In this case,
  1536. you will follow @kbd{M-#} with a letter (upper- or lower-case, it
  1537. doesn't matter for @kbd{M-#}) that says which Calc interface you
  1538. want to use.
  1539. X
  1540. To get Calc's standard interface, type @kbd{M-# c}.  To get
  1541. Keypad Mode, type @kbd{M-# k}.  Type @kbd{M-# ?} to get a brief
  1542. list of the available options, and type a second @kbd{?} to get
  1543. a complete list.
  1544. X
  1545. To ease typing, @kbd{M-# M-#} (or @kbd{M-# #} if that's easier)
  1546. also works to start Calc.  It starts the same interface (either
  1547. @kbd{M-# c} or @w{@kbd{M-# k}}) that you last used, selecting the
  1548. @kbd{M-# c} interface by default.  (If your installation has
  1549. a special function key set up to act like @kbd{M-#}, hitting that
  1550. function key twice is just like hitting @kbd{M-# M-#}.)
  1551. X
  1552. If @kbd{M-#} doesn't work for you, you can always type explicit
  1553. commands like @kbd{M-x calc} (for the standard user interface) or
  1554. @w{@kbd{M-x calc-keypad}} (for Keypad Mode).  First type @kbd{M-x}
  1555. (that's @key{META} with the letter @kbd{x}), then, at the prompt,
  1556. type the full command (like @kbd{calc-keypad}) and press Return.
  1557. X
  1558. If you type @kbd{M-x calc} and Emacs still doesn't recognize the
  1559. command (it will say @samp{[No match]} when you try to press
  1560. @key{RET}), then Calc has not been properly installed.
  1561. X
  1562. The same commands (like @kbd{M-# c} or @kbd{M-# M-#}) that start
  1563. the Calculator also turn it off if it is already on.
  1564. SHAR_EOF
  1565. true || echo 'restore of calc.texinfo failed'
  1566. fi
  1567. echo 'End of  part 30'
  1568. echo 'File calc.texinfo is continued in part 31'
  1569. echo 31 > _shar_seq_.tmp
  1570. exit 0
  1571. exit 0 # Just in case...
  1572. -- 
  1573. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  1574. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  1575. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  1576. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  1577.