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