ChangeLog fix for initial nxml import.
[emacs.git] / lisp / calc / calc-trail.el
blob9bbb4178fd300f4afd1c98c1f4f1a0e68761a7e4
1 ;;; calc-trail.el --- functions for manipulating the Calc "trail"
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
6 ;; Author: David Gillespie <daveg@synaptics.com>
7 ;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
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.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;; Commentary:
26 ;;; Code:
28 ;; This file is autoloaded from calc-ext.el.
30 (require 'calc-ext)
31 (require 'calc-macs)
33 ;;; Trail commands.
35 (defun calc-trail-in ()
36 (interactive)
37 (let ((win (get-buffer-window (calc-trail-display t))))
38 (and win (select-window win))))
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))))
50 (defun calc-trail-next (n)
51 (interactive "p")
52 (calc-with-trail-buffer
53 (forward-line n)
54 (calc-trail-here)))
56 (defun calc-trail-previous (n)
57 (interactive "p")
58 (calc-with-trail-buffer
59 (forward-line (- n))
60 (calc-trail-here)))
62 (defun calc-trail-first (n)
63 (interactive "p")
64 (calc-with-trail-buffer
65 (goto-char (point-min))
66 (forward-line n)
67 (calc-trail-here)))
69 (defun calc-trail-last (n)
70 (interactive "p")
71 (calc-with-trail-buffer
72 (goto-char (point-max))
73 (forward-line (- n))
74 (calc-trail-here)))
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))
84 (select-window curwin)))))
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))
94 (select-window curwin)))))
96 (defun calc-trail-forward (n)
97 (interactive "p")
98 (calc-with-trail-buffer
99 (forward-line (* n (1- (window-height))))
100 (calc-trail-here)))
102 (defun calc-trail-backward (n)
103 (interactive "p")
104 (calc-with-trail-buffer
105 (forward-line (- (* n (1- (window-height)))))
106 (calc-trail-here)))
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)))
115 (calc-trail-here)))
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)))
124 (calc-trail-here)))
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)))
145 (val (with-current-buffer save-buf
146 (math-read-plain-expr str))))
147 (if (eq (car-safe val) 'error)
148 (error "Can't yank that line: %s" (nth 2 val))
149 val))))))
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)
158 (calc-trail-here)))
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)))
172 (calc-trail-here)))
174 (provide 'calc-trail)
176 ;; arch-tag: 59b76655-d882-4aab-a3ee-b83870e530d0
177 ;;; calc-trail.el ends here