annotate lisp/calc/calc-yank.el @ 104232:23230e6cbc19

*** empty log message ***
author Dmitry Dzhus <dima@sphinx.net.ru>
date Tue, 11 Aug 2009 10:48:56 +0000
parents 14b421290b2f
children 2c12fbae77c2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
1 ;;; calc-yank.el --- kill-ring functionality for Calc
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
2
64325
1db49616ce05 Update copyright information.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 62748
diff changeset
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004,
100908
a9dc0e7c3f2b Add 2009 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 95097
diff changeset
4 ;; 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
5
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
6 ;; Author: David Gillespie <daveg@synaptics.com>
77465
1154f082efd9 Update maintainer's address.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 76595
diff changeset
7 ;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com>
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
8
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
10
94654
6c9af2bfcfee Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93880
diff changeset
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
76595
497d17a80bb8 Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
94654
6c9af2bfcfee Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93880
diff changeset
13 ;; the Free Software Foundation, either version 3 of the License, or
6c9af2bfcfee Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93880
diff changeset
14 ;; (at your option) any later version.
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
15
76595
497d17a80bb8 Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
497d17a80bb8 Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
497d17a80bb8 Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
497d17a80bb8 Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
19 ;; GNU General Public License for more details.
497d17a80bb8 Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
20
497d17a80bb8 Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
21 ;; You should have received a copy of the GNU General Public License
94654
6c9af2bfcfee Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93880
diff changeset
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
23
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
24 ;;; Commentary:
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
25
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
26 ;;; Code:
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
27
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
28 ;; This file is autoloaded from calc-ext.el.
58679
9a7f5565091f Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58545
diff changeset
29
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
30 (require 'calc-ext)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
31 (require 'calc-macs)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
32
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
33 ;;; Kill ring commands.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
34
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
35 (defun calc-kill (nn &optional no-delete)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
36 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
37 (if (eq major-mode 'calc-mode)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
38 (calc-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
39 (calc-force-refresh)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
40 (calc-set-command-flag 'no-align)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
41 (let ((num (max (calc-locate-cursor-element (point)) 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
42 (n (prefix-numeric-value nn)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
43 (if (< n 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
44 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
45 (if (eobp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
46 (setq num (1- num)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
47 (setq num (- num n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
48 n (- n))))
95075
b39025681d99 (calc-kill): Make sure that only the stack is operated on.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 94654
diff changeset
49 (calc-check-stack num)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
50 (let ((stuff (calc-top-list n (- num n -1))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
51 (calc-cursor-stack-index num)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
52 (let ((first (point)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
53 (calc-cursor-stack-index (- num n))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
54 (if (null nn)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
55 (backward-char 1)) ; don't include newline for raw C-k
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
56 (copy-region-as-kill first (point))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
57 (if (not no-delete)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
58 (calc-pop-stack n (- num n -1))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
59 (setq calc-last-kill (cons (car kill-ring) stuff)))))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
60 (kill-line nn)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
61
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
62 (defun calc-force-refresh ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
63 (if (or calc-executing-macro calc-display-dirty)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
64 (let ((calc-executing-macro nil))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
65 (calc-refresh))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
66
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
67 (defun calc-locate-cursor-element (pt)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
68 (save-excursion
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
69 (goto-char (point-max))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
70 (calc-locate-cursor-scan (- calc-stack-top) calc-stack pt)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
71
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
72 (defun calc-locate-cursor-scan (n stack pt)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
73 (if (or (<= (point) pt)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
74 (null stack))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
75 n
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
76 (forward-line (- (nth 1 (car stack))))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
77 (calc-locate-cursor-scan (1+ n) (cdr stack) pt)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
78
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
79 (defun calc-kill-region (top bot &optional no-delete)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
80 (interactive "r")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
81 (if (eq major-mode 'calc-mode)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
82 (calc-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
83 (calc-force-refresh)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
84 (calc-set-command-flag 'no-align)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
85 (let* ((top-num (calc-locate-cursor-element top))
95075
b39025681d99 (calc-kill): Make sure that only the stack is operated on.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 94654
diff changeset
86 (top-pos (save-excursion
b39025681d99 (calc-kill): Make sure that only the stack is operated on.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 94654
diff changeset
87 (calc-cursor-stack-index top-num)
b39025681d99 (calc-kill): Make sure that only the stack is operated on.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 94654
diff changeset
88 (point)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
89 (bot-num (calc-locate-cursor-element (1- bot)))
95075
b39025681d99 (calc-kill): Make sure that only the stack is operated on.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 94654
diff changeset
90 (bot-pos (save-excursion
b39025681d99 (calc-kill): Make sure that only the stack is operated on.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 94654
diff changeset
91 (calc-cursor-stack-index (max 0 (1- bot-num)))
b39025681d99 (calc-kill): Make sure that only the stack is operated on.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 94654
diff changeset
92 (point)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
93 (num (- top-num bot-num -1)))
95075
b39025681d99 (calc-kill): Make sure that only the stack is operated on.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 94654
diff changeset
94 (copy-region-as-kill top-pos bot-pos)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
95 (setq calc-last-kill (cons (car kill-ring)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
96 (calc-top-list num bot-num)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
97 (if (not no-delete)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
98 (calc-pop-stack num bot-num))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
99 (if no-delete
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
100 (copy-region-as-kill top bot)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
101 (kill-region top bot))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
102
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
103 (defun calc-copy-as-kill (n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
104 (interactive "P")
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
105 (calc-kill n t))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
106
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
107 (defun calc-copy-region-as-kill (top bot)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
108 (interactive "r")
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
109 (calc-kill-region top bot t))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
110
93880
c6152337e4ad * calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
111 ;; This function uses calc-last-kill if possible to get an exact result,
c6152337e4ad * calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
112 ;; otherwise it just parses the yanked string.
c6152337e4ad * calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
113 ;; Modified to use Emacs 19 extended concept of kill-ring. -- daveg 12/15/96
c6152337e4ad * calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
114 ;;;###autoload
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
115 (defun calc-yank ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
116 (interactive)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
117 (calc-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
118 (calc-pop-push-record-list
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
119 0 "yank"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
120 (let ((thing (if (fboundp 'current-kill)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
121 (current-kill 0 t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
122 (car kill-ring-yank-pointer))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
123 (if (eq (car-safe calc-last-kill) thing)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
124 (cdr calc-last-kill)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
125 (if (stringp thing)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
126 (let ((val (math-read-exprs (calc-clean-newlines thing))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
127 (if (eq (car-safe val) 'error)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
128 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
129 (setq val (math-read-exprs thing))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
130 (if (eq (car-safe val) 'error)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
131 (error "Bad format in yanked data")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
132 val))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
133 val))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
134
95080
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
135 ;;; The Calc set- and get-register commands are modified versions of functions
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
136 ;;; in register.el
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
137
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
138 (defvar calc-register-alist nil
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
139 "Alist of elements (NAME . (TEXT . CALCVAL)).
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
140 NAME is a character (a number).
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
141 TEXT and CALCVAL are the TEXT and internal structure of stack entries.")
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
142
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
143 (defun calc-set-register (register text calcval)
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
144 "Set the contents of the Calc register REGISTER to (TEXT . CALCVAL),
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
145 as well as set the contents of the Emacs register REGISTER to TEXT."
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
146 (set-register register text)
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
147 (let ((aelt (assq register calc-register-alist)))
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
148 (if aelt
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
149 (setcdr aelt (cons text calcval))
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
150 (push (cons register (cons text calcval)) calc-register-alist))))
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
151
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
152 (defun calc-get-register (reg)
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
153 "Return the CALCVAL portion of the contents of the Calc register REG,
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
154 unless the TEXT portion doesn't match the contents of the Emacs register REG,
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
155 in which case either return the contents of the Emacs register (if it is
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
156 text) or `nil'."
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
157 (let ((cval (cdr (assq reg calc-register-alist)))
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
158 (val (cdr (assq reg register-alist))))
95097
f42ba0f30bed (calc-get-register): Fix problem when the Calc register is empty.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95080
diff changeset
159 (if (stringp val)
f42ba0f30bed (calc-get-register): Fix problem when the Calc register is empty.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95080
diff changeset
160 (if (and (stringp (car cval))
f42ba0f30bed (calc-get-register): Fix problem when the Calc register is empty.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95080
diff changeset
161 (string= (car cval) val))
95080
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
162 (cdr cval)
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
163 val))))
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
164
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
165 (defun calc-copy-to-register (register start end &optional delete-flag)
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
166 "Copy the lines in the region into register REGISTER.
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
167 With prefix arg, delete as well."
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
168 (interactive "cCopy to register: \nr\nP")
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
169 (if (eq major-mode 'calc-mode)
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
170 (let* ((top-num (calc-locate-cursor-element start))
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
171 (top-pos (save-excursion
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
172 (calc-cursor-stack-index top-num)
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
173 (point)))
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
174 (bot-num (calc-locate-cursor-element (1- end)))
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
175 (bot-pos (save-excursion
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
176 (calc-cursor-stack-index (max 0 (1- bot-num)))
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
177 (point)))
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
178 (num (- top-num bot-num -1))
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
179 (str (buffer-substring top-pos bot-pos)))
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
180 (calc-set-register register str (calc-top-list num bot-num))
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
181 (if delete-flag
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
182 (calc-wrapper
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
183 (calc-pop-stack num bot-num))))
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
184 (copy-to-register register start end delete-flag)))
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
185
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
186 (defun calc-insert-register (register)
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
187 "Insert the contents of register REGISTER."
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
188 (interactive "cInsert register: ")
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
189 (if (eq major-mode 'calc-mode)
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
190 (let ((val (calc-get-register register)))
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
191 (calc-wrapper
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
192 (calc-pop-push-record-list
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
193 0 "insr"
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
194 (if (not val)
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
195 (error "Bad format in register data")
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
196 (if (consp val)
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
197 val
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
198 (let ((nval (math-read-exprs (calc-clean-newlines val))))
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
199 (if (eq (car-safe nval) 'error)
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
200 (progn
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
201 (setq nval (math-read-exprs val))
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
202 (if (eq (car-safe nval) 'error)
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
203 (error "Bad format in register data")
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
204 nval))
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
205 nval)))))))
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
206 (insert-register register)))
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
207
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
208 (defun calc-add-to-register (register start end prepend delete-flag)
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
209 "Add the lines in the region to register REGISTER.
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
210 If PREPEND is non-nil, add them to the beginning of the register,
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
211 otherwise the end. If DELETE-FLAG is non-nil, also delete the region."
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
212 (let* ((top-num (calc-locate-cursor-element start))
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
213 (top-pos (save-excursion
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
214 (calc-cursor-stack-index top-num)
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
215 (point)))
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
216 (bot-num (calc-locate-cursor-element (1- end)))
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
217 (bot-pos (save-excursion
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
218 (calc-cursor-stack-index (max 0 (1- bot-num)))
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
219 (point)))
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
220 (num (- top-num bot-num -1))
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
221 (str (buffer-substring top-pos bot-pos))
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
222 (calcval (calc-top-list num bot-num))
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
223 (cval (cdr (assq register calc-register-alist))))
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
224 (if (not cval)
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
225 (calc-set-register register str calcval)
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
226 (if prepend
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
227 (calc-set-register
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
228 register
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
229 (concat str (car cval))
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
230 (append calcval (cdr cval)))
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
231 (calc-set-register
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
232 register
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
233 (concat (car cval) str)
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
234 (append (cdr cval) calcval))))
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
235 (if delete-flag
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
236 (calc-wrapper
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
237 (calc-pop-stack num bot-num)))))
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
238
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
239 (defun calc-append-to-register (register start end &optional delete-flag)
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
240 "Copy the lines in the region to the end of register REGISTER.
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
241 With prefix arg, also delete the region."
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
242 (interactive "cAppend to register: \nr\nP")
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
243 (if (eq major-mode 'calc-mode)
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
244 (calc-add-to-register register start end nil delete-flag)
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
245 (append-to-register register start end delete-flag)))
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
246
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
247 (defun calc-prepend-to-register (register start end &optional delete-flag)
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
248 "Copy the lines in the region to the beginning of register REGISTER.
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
249 With prefix arg, also delete the region."
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
250 (interactive "cPrepend to register: \nr\nP")
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
251 (if (eq major-mode 'calc-mode)
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
252 (calc-add-to-register register start end t delete-flag)
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
253 (prepend-to-register register start end delete-flag)))
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
254
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
255
5eb7d7d544f6 (calc-register-alist): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 95075
diff changeset
256
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
257 (defun calc-clean-newlines (s)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
258 (cond
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49263
diff changeset
259
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
260 ;; Omit leading/trailing whitespace
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
261 ((or (string-match "\\`[ \n\r]+\\([^\001]*\\)\\'" s)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
262 (string-match "\\`\\([^\001]*\\)[ \n\r]+\\'" s))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
263 (calc-clean-newlines (math-match-substring s 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
264
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
265 ;; Convert newlines to commas
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
266 ((string-match "\\`\\(.*\\)[\n\r]+\\([^\001]*\\)\\'" s)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
267 (calc-clean-newlines (concat (math-match-substring s 1) ","
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
268 (math-match-substring s 2))))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49263
diff changeset
269
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
270 (t s)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
271
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
272
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
273 (defun calc-do-grab-region (top bot arg)
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
274 (when (memq major-mode '(calc-mode calc-trail-mode))
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
275 (error "This command works only in a regular text buffer"))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
276 (let* ((from-buffer (current-buffer))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
277 (calc-was-started (get-buffer-window "*Calculator*"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
278 (single nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
279 data vals pos)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
280 (if arg
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
281 (if (consp arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
282 (setq single t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
283 (setq arg (prefix-numeric-value arg))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
284 (if (= arg 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
285 (save-excursion
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
286 (beginning-of-line)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
287 (setq top (point))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
288 (end-of-line)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
289 (setq bot (point)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
290 (save-excursion
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
291 (setq top (point))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
292 (forward-line arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
293 (if (> arg 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
294 (setq bot (point))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
295 (setq bot top
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
296 top (point)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
297 (setq data (buffer-substring top bot))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
298 (calc)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
299 (if single
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
300 (setq vals (math-read-expr data))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
301 (setq vals (math-read-expr (concat "[" data "]")))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
302 (and (eq (car-safe vals) 'vec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
303 (= (length vals) 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
304 (eq (car-safe (nth 1 vals)) 'vec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
305 (setq vals (nth 1 vals))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
306 (if (eq (car-safe vals) 'error)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
307 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
308 (if calc-was-started
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
309 (pop-to-buffer from-buffer)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
310 (calc-quit t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
311 (switch-to-buffer from-buffer))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
312 (goto-char top)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
313 (forward-char (+ (nth 1 vals) (if single 0 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
314 (error (nth 2 vals))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
315 (calc-slow-wrapper
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
316 (calc-enter-result 0 "grab" vals))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
317
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
318
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
319 (defun calc-do-grab-rectangle (top bot arg &optional reduce)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
320 (and (memq major-mode '(calc-mode calc-trail-mode))
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
321 (error "This command works only in a regular text buffer"))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
322 (let* ((col1 (save-excursion (goto-char top) (current-column)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
323 (col2 (save-excursion (goto-char bot) (current-column)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
324 (from-buffer (current-buffer))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
325 (calc-was-started (get-buffer-window "*Calculator*"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
326 data mat vals lnum pt pos)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
327 (if (= col1 col2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
328 (save-excursion
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
329 (unless (= col1 0)
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
330 (error "Point and mark must be at beginning of line, or define a rectangle"))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
331 (goto-char top)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
332 (while (< (point) bot)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
333 (setq pt (point))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
334 (forward-line 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
335 (setq data (cons (buffer-substring pt (1- (point))) data)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
336 (setq data (nreverse data)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
337 (setq data (extract-rectangle top bot)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
338 (calc)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
339 (setq mat (list 'vec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
340 lnum 0)
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
341 (when arg
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
342 (setq arg (if (consp arg) 0 (prefix-numeric-value arg))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
343 (while data
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
344 (if (natnump arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
345 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
346 (if (= arg 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
347 (setq arg 1000000))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
348 (setq pos 0
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
349 vals (list 'vec))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
350 (let ((w (length (car data)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
351 j v)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
352 (while (< pos w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
353 (setq j (+ pos arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
354 v (if (>= j w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
355 (math-read-expr (substring (car data) pos))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
356 (math-read-expr (substring (car data) pos j))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
357 (if (eq (car-safe v) 'error)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
358 (setq vals v w 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
359 (setq vals (nconc vals (list v))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
360 pos j)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
361 (if (string-match "\\` *-?[0-9][0-9]?[0-9]?[0-9]?[0-9]?[0-9]? *\\'"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
362 (car data))
62039
a17f83f2c421 (calc-do-grab-rectangle): Replace string-to-int by string-to-number.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61883
diff changeset
363 (setq vals (list 'vec (string-to-number (car data))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
364 (if (and (null arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
365 (string-match "[[{][^][{}]*[]}]" (car data)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
366 (setq pos (match-beginning 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
367 vals (math-read-expr (math-match-substring (car data) 0)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
368 (let ((s (if (string-match
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
369 "\\`\\([0-9]+:[ \t]\\)?\\(.*[^, \t]\\)[, \t]*\\'"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
370 (car data))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
371 (math-match-substring (car data) 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
372 (car data))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
373 (setq pos -1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
374 vals (math-read-expr (concat "[" s "]")))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
375 (if (eq (car-safe vals) 'error)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
376 (let ((v2 (math-read-expr s)))
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
377 (unless (eq (car-safe v2) 'error)
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
378 (setq vals (list 'vec v2)))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
379 (if (eq (car-safe vals) 'error)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
380 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
381 (if calc-was-started
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
382 (pop-to-buffer from-buffer)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
383 (calc-quit t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
384 (switch-to-buffer from-buffer))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
385 (goto-char top)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
386 (forward-line lnum)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
387 (forward-char (+ (nth 1 vals) (min col1 col2) pos))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
388 (error (nth 2 vals))))
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
389 (unless (equal vals '(vec))
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
390 (setq mat (cons vals mat)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
391 (setq data (cdr data)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
392 lnum (1+ lnum)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
393 (calc-slow-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
394 (if reduce
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
395 (calc-enter-result 0 "grb+" (list reduce '(var add var-add)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
396 (nreverse mat)))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
397 (calc-enter-result 0 "grab" (nreverse mat))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
398
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
399
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
400 (defun calc-copy-to-buffer (nn)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
401 "Copy the top of stack into an editing buffer."
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
402 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
403 (let ((thebuf (and (not (memq major-mode '(calc-mode calc-trail-mode)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
404 (current-buffer)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
405 (movept nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
406 oldbuf newbuf)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
407 (calc-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
408 (save-excursion
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
409 (calc-force-refresh)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
410 (let ((n (prefix-numeric-value nn))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
411 (eat-lnums calc-line-numbering)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
412 (big-offset (if (eq calc-language 'big) 1 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
413 top bot)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
414 (setq oldbuf (current-buffer)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
415 newbuf (or thebuf
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
416 (calc-find-writable-buffer (buffer-list) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
417 (calc-find-writable-buffer (buffer-list) 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
418 (error "No other buffer")))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
419 (cond ((and (or (null nn)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
420 (consp nn))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
421 (= (calc-substack-height 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
422 (- (1- (calc-substack-height 1)) big-offset)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
423 (calc-cursor-stack-index 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
424 (if (looking-at
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
425 (if calc-line-numbering "[0-9]+: *[^ \n]" " *[^ \n]"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
426 (goto-char (1- (match-end 0))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
427 (setq eat-lnums nil
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
428 top (point))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
429 (calc-cursor-stack-index 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
430 (setq bot (- (1- (point)) big-offset)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
431 ((> n 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
432 (calc-cursor-stack-index n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
433 (setq top (point))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
434 (calc-cursor-stack-index 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
435 (setq bot (- (point) big-offset)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
436 ((< n 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
437 (calc-cursor-stack-index (- n))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
438 (setq top (point))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
439 (calc-cursor-stack-index (1- (- n)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
440 (setq bot (point)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
441 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
442 (goto-char (point-min))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
443 (forward-line 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
444 (setq top (point))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
445 (calc-cursor-stack-index 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
446 (setq bot (point))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
447 (save-excursion
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
448 (set-buffer newbuf)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
449 (if (consp nn)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
450 (kill-region (region-beginning) (region-end)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
451 (push-mark (point) t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
452 (if (and overwrite-mode (not (consp nn)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
453 (calc-overwrite-string (save-excursion
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
454 (set-buffer oldbuf)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
455 (buffer-substring top bot))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
456 eat-lnums)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
457 (or (bolp) (setq eat-lnums nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
458 (insert-buffer-substring oldbuf top bot)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
459 (and eat-lnums
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
460 (let ((n 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
461 (while (and (> (point) (mark))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
462 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
463 (forward-line -1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
464 (>= (point) (mark))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
465 (delete-char 4)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
466 (setq n (1+ n)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
467 (forward-line n))))
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
468 (when thebuf
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
469 (setq movept (point)))
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
470 (when (get-buffer-window (current-buffer))
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
471 (set-window-point (get-buffer-window (current-buffer))
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
472 (point)))))))
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
473 (when movept
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
474 (goto-char movept))
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
475 (when (and (consp nn)
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
476 (not thebuf))
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
477 (calc-quit t)
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
478 (switch-to-buffer newbuf))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
479
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
480 (defun calc-overwrite-string (str eat-lnums)
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
481 (when (string-match "\n\\'" str)
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
482 (setq str (substring str 0 -1)))
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
483 (when eat-lnums
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
484 (setq str (substring str 4)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
485 (if (and (string-match "\\`[-+]?[0-9.]+\\(e-?[0-9]+\\)?\\'" str)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
486 (looking-at "[-+]?[0-9.]+\\(e-?[0-9]+\\)?"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
487 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
488 (delete-region (point) (match-end 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
489 (insert str))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
490 (let ((i 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
491 (while (< i (length str))
101001
14b421290b2f Replace last-command-char with last-command-event.
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
492 (if (= (setq last-command-event (aref str i)) ?\n)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
493 (or (= i (1- (length str)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
494 (let ((pt (point)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
495 (end-of-line)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
496 (delete-region pt (point))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
497 (if (eobp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
498 (insert "\n")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
499 (forward-char 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
500 (if eat-lnums (setq i (+ i 4)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
501 (self-insert-command 1))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
502 (setq i (1+ i))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
503
93880
c6152337e4ad * calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
504 ;; First, require that buffer is visible and does not begin with "*"
c6152337e4ad * calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
505 ;; Second, require only that it not begin with "*Calc"
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
506 (defun calc-find-writable-buffer (buf mode)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
507 (and buf
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
508 (if (or (string-match "\\`\\( .*\\|\\*Calc.*\\)"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
509 (buffer-name (car buf)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
510 (and (= mode 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
511 (or (string-match "\\`\\*.*" (buffer-name (car buf)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
512 (not (get-buffer-window (car buf))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
513 (calc-find-writable-buffer (cdr buf) mode)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
514 (car buf))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
515
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
516
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
517 (defun calc-edit (n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
518 (interactive "p")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
519 (calc-slow-wrapper
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
520 (when (eq n 0)
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
521 (setq n (calc-stack-size)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
522 (let* ((flag nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
523 (allow-ret (> n 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
524 (list (math-showing-full-precision
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
525 (mapcar (if (> n 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
526 (function (lambda (x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
527 (math-format-flat-expr x 0)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
528 (function
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
529 (lambda (x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
530 (if (math-vectorp x) (setq allow-ret t))
40998
ee9c2872370b Use `frame-width' instead of `screen-width',
Eli Zaretskii <eliz@gnu.org>
parents: 40785
diff changeset
531 (math-format-nice-expr x (frame-width)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
532 (if (> n 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
533 (calc-top-list n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
534 (calc-top-list 1 (- n)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
535 (calc-edit-mode (list 'calc-finish-stack-edit (or flag n)) allow-ret)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
536 (while list
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
537 (insert (car list) "\n")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
538 (setq list (cdr list)))))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
539 (calc-show-edit-buffer))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
540
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
541 (defun calc-alg-edit (str)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
542 (calc-edit-mode '(calc-finish-stack-edit 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
543 (calc-show-edit-buffer)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
544 (insert str "\n")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
545 (backward-char 1)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
546 (calc-set-command-flag 'do-edit))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
547
93880
c6152337e4ad * calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
548 (defvar calc-edit-mode-map
c6152337e4ad * calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
549 (let ((map (make-sparse-keymap)))
c6152337e4ad * calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
550 (define-key map "\n" 'calc-edit-finish)
c6152337e4ad * calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
551 (define-key map "\r" 'calc-edit-return)
c6152337e4ad * calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
552 (define-key map "\C-c\C-c" 'calc-edit-finish)
c6152337e4ad * calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
553 map)
c6152337e4ad * calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
554 "Keymap for use by the calc-edit command.")
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
555
58545
e4aa15831776 (calc-original-buffer, calc-return-buffer, calc-one-window)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58335
diff changeset
556 (defvar calc-original-buffer)
e4aa15831776 (calc-original-buffer, calc-return-buffer, calc-one-window)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58335
diff changeset
557 (defvar calc-return-buffer)
e4aa15831776 (calc-original-buffer, calc-return-buffer, calc-one-window)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58335
diff changeset
558 (defvar calc-one-window)
e4aa15831776 (calc-original-buffer, calc-return-buffer, calc-one-window)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58335
diff changeset
559 (defvar calc-edit-handler)
e4aa15831776 (calc-original-buffer, calc-return-buffer, calc-one-window)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58335
diff changeset
560 (defvar calc-restore-trail)
e4aa15831776 (calc-original-buffer, calc-return-buffer, calc-one-window)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58335
diff changeset
561 (defvar calc-allow-ret)
59306
c80fa806ab33 (calc-edit-top): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59305
diff changeset
562 (defvar calc-edit-top)
58545
e4aa15831776 (calc-original-buffer, calc-return-buffer, calc-one-window)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58335
diff changeset
563
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
564 (defun calc-edit-mode (&optional handler allow-ret title)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
565 "Calculator editing mode. Press RET, LFD, or C-c C-c to finish.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
566 To cancel the edit, simply kill the *Calc Edit* buffer."
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
567 (interactive)
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
568 (unless handler
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
569 (error "This command can be used only indirectly through calc-edit"))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
570 (let ((oldbuf (current-buffer))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
571 (buf (get-buffer-create "*Calc Edit*")))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
572 (set-buffer buf)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
573 (kill-all-local-variables)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
574 (use-local-map calc-edit-mode-map)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
575 (setq buffer-read-only nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
576 (setq truncate-lines nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
577 (setq major-mode 'calc-edit-mode)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
578 (setq mode-name "Calc Edit")
62748
8fd2f1761d1c (calc-edit-mode): Use run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents: 62039
diff changeset
579 (run-mode-hooks 'calc-edit-mode-hook)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
580 (make-local-variable 'calc-original-buffer)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
581 (setq calc-original-buffer oldbuf)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
582 (make-local-variable 'calc-return-buffer)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
583 (setq calc-return-buffer oldbuf)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
584 (make-local-variable 'calc-one-window)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
585 (setq calc-one-window (and (one-window-p t) pop-up-windows))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
586 (make-local-variable 'calc-edit-handler)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
587 (setq calc-edit-handler handler)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
588 (make-local-variable 'calc-restore-trail)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
589 (setq calc-restore-trail (get-buffer-window (calc-trail-buffer)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
590 (make-local-variable 'calc-allow-ret)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
591 (setq calc-allow-ret allow-ret)
59614
b883f279ae24 (calc-edit-mode): Inhibit read-only when erasing buffer.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59306
diff changeset
592 (let ((inhibit-read-only t))
b883f279ae24 (calc-edit-mode): Inhibit read-only when erasing buffer.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59306
diff changeset
593 (erase-buffer))
59232
6841983190b8 (calc-edit-mode): Mention C-cC-c as the way to finish, C-xk as the way
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58679
diff changeset
594 (add-hook 'kill-buffer-hook (lambda ()
6841983190b8 (calc-edit-mode): Mention C-cC-c as the way to finish, C-xk as the way
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58679
diff changeset
595 (let ((calc-edit-handler nil))
6841983190b8 (calc-edit-mode): Mention C-cC-c as the way to finish, C-xk as the way
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58679
diff changeset
596 (calc-edit-finish t))
6841983190b8 (calc-edit-mode): Mention C-cC-c as the way to finish, C-xk as the way
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58679
diff changeset
597 (message "(Cancelled)")) t t)
59305
f8fd85fc066a (calc-edit-mode): Make header in italic.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59302
diff changeset
598 (insert (propertize
f8fd85fc066a (calc-edit-mode): Make header in italic.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59302
diff changeset
599 (concat
f8fd85fc066a (calc-edit-mode): Make header in italic.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59302
diff changeset
600 (or title title "Calc Edit Mode. ")
f8fd85fc066a (calc-edit-mode): Make header in italic.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59302
diff changeset
601 "Press `C-c C-c'"
f8fd85fc066a (calc-edit-mode): Make header in italic.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59302
diff changeset
602 (if allow-ret "" " or RET")
f8fd85fc066a (calc-edit-mode): Make header in italic.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59302
diff changeset
603 " to finish, `C-x k RET' to cancel.\n\n")
59306
c80fa806ab33 (calc-edit-top): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59305
diff changeset
604 'font-lock-face 'italic 'read-only t 'rear-nonsticky t 'front-sticky t))
c80fa806ab33 (calc-edit-top): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59305
diff changeset
605 (make-local-variable 'calc-edit-top)
c80fa806ab33 (calc-edit-top): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59305
diff changeset
606 (setq calc-edit-top (point))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
607 (put 'calc-edit-mode 'mode-class 'special)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
608
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
609 (defun calc-show-edit-buffer ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
610 (let ((buf (current-buffer)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
611 (if (and (one-window-p t) pop-up-windows)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
612 (pop-to-buffer (get-buffer-create "*Calc Edit*"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
613 (and calc-embedded-info (get-buffer-window (aref calc-embedded-info 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
614 (select-window (get-buffer-window (aref calc-embedded-info 1))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
615 (switch-to-buffer (get-buffer-create "*Calc Edit*")))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
616 (setq calc-return-buffer buf)
40998
ee9c2872370b Use `frame-width' instead of `screen-width',
Eli Zaretskii <eliz@gnu.org>
parents: 40785
diff changeset
617 (if (and (< (window-width) (frame-width))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
618 calc-display-trail)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
619 (let ((win (get-buffer-window (calc-trail-buffer))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
620 (if win
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
621 (delete-window win))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
622 (set-buffer-modified-p nil)
59306
c80fa806ab33 (calc-edit-top): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59305
diff changeset
623 (goto-char calc-edit-top)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
624
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
625 (defun calc-edit-return ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
626 (interactive)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
627 (if (and (boundp 'calc-allow-ret) calc-allow-ret)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
628 (newline)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
629 (calc-edit-finish)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
630
58335
4e7e96bc6b95 (calc-edit-disp-trail): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
631 ;; The variable calc-edit-disp-trail is local to calc-edit finish, but
4e7e96bc6b95 (calc-edit-disp-trail): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
632 ;; is used by calc-finish-selection-edit and calc-finish-stack-edit.
4e7e96bc6b95 (calc-edit-disp-trail): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
633 (defvar calc-edit-disp-trail)
4e7e96bc6b95 (calc-edit-disp-trail): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
634
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
635 (defun calc-edit-finish (&optional keep)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
636 "Finish calc-edit mode. Parse buffer contents and push them on the stack."
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
637 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
638 (message "Working...")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
639 (or (and (boundp 'calc-original-buffer)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
640 (boundp 'calc-return-buffer)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
641 (boundp 'calc-one-window)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
642 (boundp 'calc-edit-handler)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
643 (boundp 'calc-restore-trail)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
644 (eq major-mode 'calc-edit-mode))
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
645 (error "This command is valid only in buffers created by calc-edit"))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
646 (let ((buf (current-buffer))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
647 (original calc-original-buffer)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
648 (return calc-return-buffer)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
649 (one-window calc-one-window)
58335
4e7e96bc6b95 (calc-edit-disp-trail): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
650 (calc-edit-disp-trail calc-restore-trail))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
651 (save-excursion
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
652 (when (or (null (buffer-name original))
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
653 (progn
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
654 (set-buffer original)
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
655 (not (eq major-mode 'calc-mode))))
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
656 (error "Original calculator buffer has been corrupted")))
59306
c80fa806ab33 (calc-edit-top): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59305
diff changeset
657 (goto-char calc-edit-top)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
658 (if (buffer-modified-p)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
659 (eval calc-edit-handler))
61883
6238d2f682a9 (calc-edit-finish): Make sure there is more than one window before
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59614
diff changeset
660 (if (and one-window (not (one-window-p t)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
661 (delete-window))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
662 (if (get-buffer-window return)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
663 (select-window (get-buffer-window return))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
664 (switch-to-buffer return))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
665 (if keep
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
666 (bury-buffer buf)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
667 (kill-buffer buf))
58335
4e7e96bc6b95 (calc-edit-disp-trail): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
668 (if calc-edit-disp-trail
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
669 (calc-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
670 (calc-trail-display 1 t)))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
671 (message "")))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
672
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
673 (defun calc-edit-cancel ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
674 "Cancel calc-edit mode. Ignore the Calc Edit buffer and don't change stack."
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
675 (interactive)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
676 (let ((calc-edit-handler nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
677 (calc-edit-finish))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
678 (message "(Cancelled)"))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
679
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
680 (defun calc-finish-stack-edit (num)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
681 (let ((buf (current-buffer))
59306
c80fa806ab33 (calc-edit-top): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59305
diff changeset
682 (str (buffer-substring calc-edit-top (point-max)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
683 (start (point))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
684 pos)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
685 (if (and (integerp num) (> num 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
686 (while (setq pos (string-match "\n." str))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
687 (aset str pos ?\,)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
688 (switch-to-buffer calc-original-buffer)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
689 (let ((vals (let ((calc-language nil)
81472
1ae3e881bf9c (calc-finish-stack-edit): Let math-expr-opers equal the function
Jay Belanger <jay.p.belanger@gmail.com>
parents: 77465
diff changeset
690 (math-expr-opers (math-standard-ops)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
691 (and (string-match "[^\n\t ]" str)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
692 (math-read-exprs str)))))
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
693 (when (eq (car-safe vals) 'error)
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
694 (switch-to-buffer buf)
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
695 (goto-char (+ start (nth 1 vals)))
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
696 (error (nth 2 vals)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
697 (calc-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
698 (if (symbolp num)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
699 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
700 (set num (car vals))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
701 (calc-refresh-evaltos num))
58335
4e7e96bc6b95 (calc-edit-disp-trail): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
702 (if calc-edit-disp-trail
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
703 (calc-trail-display 1 t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
704 (and vals
101001
14b421290b2f Replace last-command-char with last-command-event.
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
705 (let ((calc-simplify-mode (if (eq last-command-event ?\C-j)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
706 'none
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
707 calc-simplify-mode)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
708 (if (>= num 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
709 (calc-enter-result num "edit" vals)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
710 (calc-enter-result 1 "edit" vals (- num))))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
711
58679
9a7f5565091f Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58545
diff changeset
712 (provide 'calc-yank)
9a7f5565091f Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58545
diff changeset
713
93880
c6152337e4ad * calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
714 ;; Local variables:
c6152337e4ad * calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
715 ;; generated-autoload-file: "calc-loaddefs.el"
c6152337e4ad * calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
716 ;; End:
c6152337e4ad * calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
717
c6152337e4ad * calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
718 ;; arch-tag: ca61019e-caca-4daa-b32c-b6afe372d5b5
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40998
diff changeset
719 ;;; calc-yank.el ends here