Avoid compiler warning in image.c on MS-Windows
[emacs.git] / lisp / calc / calc-trail.el
blob9417f7f3fb6c798d0856f341e4e3f8be94297c98
1 ;;; calc-trail.el --- functions for manipulating the Calc "trail"
3 ;; Copyright (C) 1990-1993, 2001-2015 Free Software Foundation, Inc.
5 ;; Author: David Gillespie <daveg@synaptics.com>
6 ;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
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.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;;; Code:
27 ;; This file is autoloaded from calc-ext.el.
29 (require 'calc-ext)
30 (require 'calc-macs)
32 ;;; Trail commands.
34 (defun calc-trail-in ()
35 (interactive)
36 (let ((win (get-buffer-window (calc-trail-display t))))
37 (and win (select-window win))))
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))
47 (calc))))
49 (defun calc-trail-next (n)
50 (interactive "p")
51 (calc-with-trail-buffer
52 (forward-line n)
53 (calc-trail-here)))
55 (defun calc-trail-previous (n)
56 (interactive "p")
57 (calc-with-trail-buffer
58 (forward-line (- n))
59 (calc-trail-here)))
61 (defun calc-trail-first (n)
62 (interactive "p")
63 (calc-with-trail-buffer
64 (goto-char (point-min))
65 (forward-line n)
66 (calc-trail-here)))
68 (defun calc-trail-last (n)
69 (interactive "p")
70 (calc-with-trail-buffer
71 (goto-char (point-max))
72 (forward-line (- n))
73 (calc-trail-here)))
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))
83 (select-window curwin)))))
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))
93 (select-window curwin)))))
95 (defun calc-trail-forward (n)
96 (interactive "p")
97 (calc-with-trail-buffer
98 (forward-line (* n (1- (window-height))))
99 (calc-trail-here)))
101 (defun calc-trail-backward (n)
102 (interactive "p")
103 (calc-with-trail-buffer
104 (forward-line (- (* n (1- (window-height)))))
105 (calc-trail-here)))
107 (defun calc-trail-isearch-forward ()
108 (interactive)
109 (calc-with-trail-buffer
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))))
120 (defun calc-trail-isearch-backward ()
121 (interactive)
122 (calc-with-trail-buffer
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))))
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)))
152 (val (with-current-buffer save-buf
153 (math-read-plain-expr str))))
154 (if (eq (car-safe val) 'error)
155 (error "Can't yank that line: %s" (nth 2 val))
156 val))))))
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)
165 (calc-trail-here)))
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)))
179 (calc-trail-here)))
181 (provide 'calc-trail)
183 ;;; calc-trail.el ends here