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