Initial Commit
[packages] / xemacs-packages / calc / calc-trail.el
1 ;; Calculator for GNU Emacs, part II [calc-trail.el]
2 ;; Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
3 ;; Written by Dave Gillespie, daveg@synaptics.com.
4
5 ;; This file is part of GNU Emacs.
6
7 ;; GNU Emacs is distributed in the hope that it will be useful,
8 ;; but WITHOUT ANY WARRANTY.  No author or distributor
9 ;; accepts responsibility to anyone for the consequences of using it
10 ;; or for whether it serves any particular purpose or works at all,
11 ;; unless he says so in writing.  Refer to the GNU Emacs General Public
12 ;; License for full details.
13
14 ;; Everyone is granted permission to copy, modify and redistribute
15 ;; GNU Emacs, but only under the conditions described in the
16 ;; GNU Emacs General Public License.   A copy of this license is
17 ;; 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
19 ;; file named COPYING.  Among other things, the copyright notice
20 ;; and this notice must be preserved on all copies.
21
22
23
24 ;; This file is autoloaded from calc-ext.el.
25 (require 'calc-ext)
26
27 (require 'calc-macs)
28
29 (defun calc-Need-calc-trail () nil)
30
31
32 ;;; Trail commands.
33
34 (defun calc-trail-in ()
35   (interactive)
36   (let ((win (get-buffer-window (calc-trail-display t))))
37     (and win (select-window win)))
38 )
39
40 (defun calc-trail-out ()
41   (interactive)
42   (calc-select-buffer)
43   (let ((win (get-buffer-window (current-buffer))))
44     (if win
45         (progn
46           (select-window win)
47           (calc-align-stack-window))
48       (calc)))
49 )
50
51 (defun calc-trail-next (n)
52   (interactive "p")
53   (calc-with-trail-buffer
54    (forward-line n)
55    (calc-trail-here))
56 )
57
58 (defun calc-trail-previous (n)
59   (interactive "p")
60   (calc-with-trail-buffer
61    (forward-line (- n))
62    (calc-trail-here))
63 )
64
65 (defun calc-trail-first (n)
66   (interactive "p")
67   (calc-with-trail-buffer
68    (goto-char (point-min))
69    (forward-line n)
70    (calc-trail-here))
71 )
72
73 (defun calc-trail-last (n)
74   (interactive "p")
75   (calc-with-trail-buffer
76    (goto-char (point-max))
77    (forward-line (- n))
78    (calc-trail-here))
79 )
80
81 (defun calc-trail-scroll-left (n)
82   (interactive "P")
83   (let ((curwin (selected-window)))
84     (calc-with-trail-buffer
85      (unwind-protect
86          (progn
87            (select-window (get-buffer-window (current-buffer)))
88            (calc-scroll-left n))
89        (select-window curwin))))
90 )
91
92 (defun calc-trail-scroll-right (n)
93   (interactive "P")
94   (let ((curwin (selected-window)))
95     (calc-with-trail-buffer
96      (unwind-protect
97          (progn
98            (select-window (get-buffer-window (current-buffer)))
99            (calc-scroll-right n))
100        (select-window curwin))))
101 )
102
103 (defun calc-trail-forward (n)
104   (interactive "p")
105   (calc-with-trail-buffer
106    (forward-line (* n (1- (window-height))))
107    (calc-trail-here))
108 )
109
110 (defun calc-trail-backward (n)
111   (interactive "p")
112   (calc-with-trail-buffer
113    (forward-line (- (* n (1- (window-height)))))
114    (calc-trail-here))
115 )
116
117 (defun calc-trail-isearch-forward ()
118   (interactive)
119   (calc-with-trail-buffer
120    (save-window-excursion
121      (select-window (get-buffer-window (current-buffer)))
122      (let ((search-exit-char ?\r))
123        (isearch-forward)))
124    (calc-trail-here))
125 )
126
127 (defun calc-trail-isearch-backward ()
128   (interactive)
129   (calc-with-trail-buffer
130    (save-window-excursion
131      (select-window (get-buffer-window (current-buffer)))
132      (let ((search-exit-char ?\r))
133        (isearch-backward)))
134    (calc-trail-here))
135 )
136
137 (defun calc-trail-yank (arg)
138   (interactive "P")
139   (calc-wrapper
140    (or arg (calc-set-command-flag 'hold-trail))
141    (calc-enter-result 0 "yank"
142                       (calc-with-trail-buffer
143                        (if arg
144                            (forward-line (- (prefix-numeric-value arg))))
145                        (if (or (looking-at "Emacs Calc")
146                                (looking-at "----")
147                                (looking-at " ? ? ?[^ \n]* *$")
148                                (looking-at "..?.?$"))
149                            (error "Can't yank that line"))
150                        (if (looking-at ".*, \\.\\.\\., ")
151                            (error "Can't yank (vector was abbreviated)"))
152                        (forward-char 4)
153                        (search-forward " ")
154                        (let* ((next (save-excursion (forward-line 1) (point)))
155                               (str (buffer-substring (point) (1- next)))
156                               (val (save-excursion
157                                      (set-buffer save-buf)
158                                      (math-read-plain-expr str))))
159                          (if (eq (car-safe val) 'error)
160                              (error "Can't yank that line: %s" (nth 2 val))
161                            val)))))
162 )
163
164 (defun calc-trail-marker (str)
165   (interactive "sText to insert in trail: ")
166   (calc-with-trail-buffer
167    (forward-line 1)
168    (let ((buffer-read-only nil))
169      (insert "---- " str "\n"))
170    (forward-line -1)
171    (calc-trail-here))
172 )
173
174 (defun calc-trail-kill (n)
175   (interactive "p")
176   (calc-with-trail-buffer
177    (let ((buffer-read-only nil))
178      (save-restriction
179        (narrow-to-region   ; don't delete "Emacs Trail" header
180         (save-excursion
181           (goto-char (point-min))
182           (forward-line 1)
183           (point))
184         (point-max))
185        (kill-line n)))
186    (calc-trail-here))
187 )
188
189
190