Commit | Line | Data |
---|---|---|
3132f345 CW |
1 | ;;; calc-trail.el --- functions for manipulating the Calc "trail" |
2 | ||
ab422c4d | 3 | ;; Copyright (C) 1990-1993, 2001-2013 Free Software Foundation, Inc. |
3132f345 CW |
4 | |
5 | ;; Author: David Gillespie <daveg@synaptics.com> | |
e8fff8ed | 6 | ;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com> |
136211a9 EZ |
7 | |
8 | ;; This file is part of GNU Emacs. | |
9 | ||
662c9c64 | 10 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
7c671b23 | 11 | ;; it under the terms of the GNU General Public License as published by |
662c9c64 GM |
12 | ;; the Free Software Foundation, either version 3 of the License, or |
13 | ;; (at your option) any later version. | |
7c671b23 | 14 | |
136211a9 | 15 | ;; GNU Emacs is distributed in the hope that it will be useful, |
7c671b23 GM |
16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | ;; GNU General Public License for more details. | |
19 | ||
20 | ;; You should have received a copy of the GNU General Public License | |
662c9c64 | 21 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
136211a9 | 22 | |
3132f345 | 23 | ;;; Commentary: |
136211a9 | 24 | |
3132f345 | 25 | ;;; Code: |
136211a9 EZ |
26 | |
27 | ;; This file is autoloaded from calc-ext.el. | |
136211a9 | 28 | |
07b7530a | 29 | (require 'calc-ext) |
136211a9 EZ |
30 | (require 'calc-macs) |
31 | ||
136211a9 EZ |
32 | ;;; Trail commands. |
33 | ||
34 | (defun calc-trail-in () | |
35 | (interactive) | |
36 | (let ((win (get-buffer-window (calc-trail-display t)))) | |
bf77c646 | 37 | (and win (select-window win)))) |
136211a9 EZ |
38 | |
39 | (defun calc-trail-out () | |
40 | (interactive) | |
41 | (calc-select-buffer) | |
42 | (let ((win (get-buffer-window (current-buffer)))) | |
43 | (if win | |
44 | (progn | |
45 | (select-window win) | |
46 | (calc-align-stack-window)) | |
bf77c646 | 47 | (calc)))) |
136211a9 EZ |
48 | |
49 | (defun calc-trail-next (n) | |
50 | (interactive "p") | |
51 | (calc-with-trail-buffer | |
52 | (forward-line n) | |
bf77c646 | 53 | (calc-trail-here))) |
136211a9 EZ |
54 | |
55 | (defun calc-trail-previous (n) | |
56 | (interactive "p") | |
57 | (calc-with-trail-buffer | |
58 | (forward-line (- n)) | |
bf77c646 | 59 | (calc-trail-here))) |
136211a9 EZ |
60 | |
61 | (defun calc-trail-first (n) | |
62 | (interactive "p") | |
63 | (calc-with-trail-buffer | |
64 | (goto-char (point-min)) | |
65 | (forward-line n) | |
bf77c646 | 66 | (calc-trail-here))) |
136211a9 EZ |
67 | |
68 | (defun calc-trail-last (n) | |
69 | (interactive "p") | |
70 | (calc-with-trail-buffer | |
71 | (goto-char (point-max)) | |
72 | (forward-line (- n)) | |
bf77c646 | 73 | (calc-trail-here))) |
136211a9 EZ |
74 | |
75 | (defun calc-trail-scroll-left (n) | |
76 | (interactive "P") | |
77 | (let ((curwin (selected-window))) | |
78 | (calc-with-trail-buffer | |
79 | (unwind-protect | |
80 | (progn | |
81 | (select-window (get-buffer-window (current-buffer))) | |
82 | (calc-scroll-left n)) | |
bf77c646 | 83 | (select-window curwin))))) |
136211a9 EZ |
84 | |
85 | (defun calc-trail-scroll-right (n) | |
86 | (interactive "P") | |
87 | (let ((curwin (selected-window))) | |
88 | (calc-with-trail-buffer | |
89 | (unwind-protect | |
90 | (progn | |
91 | (select-window (get-buffer-window (current-buffer))) | |
92 | (calc-scroll-right n)) | |
bf77c646 | 93 | (select-window curwin))))) |
136211a9 EZ |
94 | |
95 | (defun calc-trail-forward (n) | |
96 | (interactive "p") | |
97 | (calc-with-trail-buffer | |
98 | (forward-line (* n (1- (window-height)))) | |
bf77c646 | 99 | (calc-trail-here))) |
136211a9 EZ |
100 | |
101 | (defun calc-trail-backward (n) | |
102 | (interactive "p") | |
103 | (calc-with-trail-buffer | |
104 | (forward-line (- (* n (1- (window-height))))) | |
bf77c646 | 105 | (calc-trail-here))) |
136211a9 EZ |
106 | |
107 | (defun calc-trail-isearch-forward () | |
108 | (interactive) | |
109 | (calc-with-trail-buffer | |
134c2f29 JB |
110 | (let ((win (get-buffer-window (current-buffer))) |
111 | pos) | |
112 | (save-window-excursion | |
113 | (select-window win) | |
114 | (isearch-forward) | |
115 | (setq pos (point))) | |
116 | (goto-char pos) | |
117 | (set-window-point win pos) | |
118 | (calc-trail-here)))) | |
136211a9 EZ |
119 | |
120 | (defun calc-trail-isearch-backward () | |
121 | (interactive) | |
122 | (calc-with-trail-buffer | |
134c2f29 JB |
123 | (let ((win (get-buffer-window (current-buffer))) |
124 | pos) | |
125 | (save-window-excursion | |
126 | (select-window win) | |
127 | (isearch-backward) | |
128 | (setq pos (point))) | |
129 | (goto-char pos) | |
130 | (set-window-point win pos) | |
131 | (calc-trail-here)))) | |
136211a9 EZ |
132 | |
133 | (defun calc-trail-yank (arg) | |
134 | (interactive "P") | |
135 | (calc-wrapper | |
136 | (or arg (calc-set-command-flag 'hold-trail)) | |
137 | (calc-enter-result 0 "yank" | |
138 | (calc-with-trail-buffer | |
139 | (if arg | |
140 | (forward-line (- (prefix-numeric-value arg)))) | |
141 | (if (or (looking-at "Emacs Calc") | |
142 | (looking-at "----") | |
143 | (looking-at " ? ? ?[^ \n]* *$") | |
144 | (looking-at "..?.?$")) | |
145 | (error "Can't yank that line")) | |
146 | (if (looking-at ".*, \\.\\.\\., ") | |
147 | (error "Can't yank (vector was abbreviated)")) | |
148 | (forward-char 4) | |
149 | (search-forward " ") | |
150 | (let* ((next (save-excursion (forward-line 1) (point))) | |
151 | (str (buffer-substring (point) (1- next))) | |
6df9b6d7 | 152 | (val (with-current-buffer save-buf |
136211a9 EZ |
153 | (math-read-plain-expr str)))) |
154 | (if (eq (car-safe val) 'error) | |
155 | (error "Can't yank that line: %s" (nth 2 val)) | |
bf77c646 | 156 | val)))))) |
136211a9 EZ |
157 | |
158 | (defun calc-trail-marker (str) | |
159 | (interactive "sText to insert in trail: ") | |
160 | (calc-with-trail-buffer | |
161 | (forward-line 1) | |
162 | (let ((buffer-read-only nil)) | |
163 | (insert "---- " str "\n")) | |
164 | (forward-line -1) | |
bf77c646 | 165 | (calc-trail-here))) |
136211a9 EZ |
166 | |
167 | (defun calc-trail-kill (n) | |
168 | (interactive "p") | |
169 | (calc-with-trail-buffer | |
170 | (let ((buffer-read-only nil)) | |
171 | (save-restriction | |
172 | (narrow-to-region ; don't delete "Emacs Trail" header | |
173 | (save-excursion | |
174 | (goto-char (point-min)) | |
175 | (forward-line 1) | |
176 | (point)) | |
177 | (point-max)) | |
178 | (kill-line n))) | |
bf77c646 | 179 | (calc-trail-here))) |
136211a9 | 180 | |
07b7530a JB |
181 | (provide 'calc-trail) |
182 | ||
bf77c646 | 183 | ;;; calc-trail.el ends here |