Mercurial > emacs
annotate lisp/ses.el @ 87203:ecb9fe2736a4
D-Bus is not enabled by default.
author | Andreas Schwab <schwab@suse.de> |
---|---|
date | Sun, 09 Dec 2007 11:08:24 +0000 |
parents | d3e87ee5aa0e |
children | 107ccd98fa12 880960b70474 |
rev | line source |
---|---|
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1 ;;; ses.el -- Simple Emacs Spreadsheet -*- coding: utf-8 -*- |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2 |
75347 | 3 ;; Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
4 |
52042
c195b419ef52
Updated contact address.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
49573
diff
changeset
|
5 ;; Author: Jonathan Yavner <jyavner@member.fsf.org> |
c195b419ef52
Updated contact address.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
49573
diff
changeset
|
6 ;; Maintainer: Jonathan Yavner <jyavner@member.fsf.org> |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
7 ;; Keywords: spreadsheet |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
8 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
9 ;; This file is part of GNU Emacs. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
10 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
11 ;; GNU Emacs is free software; you can redistribute it and/or modify |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
12 ;; it under the terms of the GNU General Public License as published by |
78236
9355f9b7bbff
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
78200
diff
changeset
|
13 ;; the Free Software Foundation; either version 3, or (at your option) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
14 ;; any later version. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
15 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
16 ;; GNU Emacs is distributed in the hope that it will be useful, |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
19 ;; GNU General Public License for more details. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
20 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
21 ;; You should have received a copy of the GNU General Public License |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
64091 | 23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
24 ;; Boston, MA 02110-1301, USA. | |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
25 |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
26 ;;; Commentary: |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
27 |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
28 ;;; To-do list: |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
29 |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
30 ;; * Use $ or … for truncated fields |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
31 ;; * Add command to make a range of columns be temporarily invisible. |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
32 ;; * Allow paste of one cell to a range of cells -- copy formula to each. |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
33 ;; * Do something about control characters & octal codes in cell print |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
34 ;; areas. Use string-width? |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
35 ;; * Input validation functions. How specified? |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
36 ;; * Faces (colors & styles) in print cells. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
37 ;; * Move a column by dragging its letter in the header line. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
38 ;; * Left-margin column for row number. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
39 ;; * Move a row by dragging its number in the left-margin. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
40 |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
41 |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
42 ;;; Code: |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
43 |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
44 (require 'unsafep) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
45 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
46 |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
47 ;;---------------------------------------------------------------------------- |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
48 ;; User-customizable variables |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
49 ;;---------------------------------------------------------------------------- |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
50 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
51 (defgroup ses nil |
64020
463e088b8531
(ses): Finish `defgroup' description with period.
Juanma Barranquero <lekktu@gmail.com>
parents:
63622
diff
changeset
|
52 "Simple Emacs Spreadsheet." |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
53 :group 'applications |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
54 :prefix "ses-" |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
55 :version "21.1") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
56 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
57 (defcustom ses-initial-size '(1 . 1) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
58 "Initial size of a new spreadsheet, as a cons (NUMROWS . NUMCOLS)." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
59 :group 'ses |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
60 :type '(cons (integer :tag "numrows") (integer :tag "numcols"))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
61 |
53758
c503ef8bb300
Changes suggested by Stefan Monnier to truncate decimal places if print format too large for column width.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53746
diff
changeset
|
62 (defcustom ses-initial-column-width 7 |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
63 "Initial width of columns in a new spreadsheet." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
64 :group 'ses |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
65 :type '(integer :match (lambda (widget value) (> value 0)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
66 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
67 (defcustom ses-initial-default-printer "%.7g" |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
68 "Initial default printer for a new spreadsheet." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
69 :group 'ses |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
70 :type '(choice string |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
71 (list :tag "Parenthesized string" string) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
72 function)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
73 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
74 (defcustom ses-after-entry-functions '(forward-char) |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
75 "Things to do after entering a value into a cell. |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
76 An abnormal hook that usually runs a cursor-movement function. |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
77 Each function is called with ARG=1." |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
78 :group 'ses |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
79 :type 'hook |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
80 :options '(forward-char backward-char next-line previous-line)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
81 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
82 (defcustom ses-mode-hook nil |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
83 "Hook functions to be run upon entering SES mode." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
84 :group 'ses |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
85 :type 'hook) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
86 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
87 |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
88 ;;---------------------------------------------------------------------------- |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
89 ;; Global variables and constants |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
90 ;;---------------------------------------------------------------------------- |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
91 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
92 (defvar ses-read-cell-history nil |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
93 "List of formulas that have been typed in.") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
94 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
95 (defvar ses-read-printer-history nil |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
96 "List of printer functions that have been typed in.") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
97 |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
98 (easy-menu-define ses-header-line-menu nil |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
99 "Context menu when mouse-3 is used on the header-line in an SES buffer." |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
100 '("SES header row" |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
101 ["Set current row" ses-set-header-row t] |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
102 ["Unset row" ses-unset-header-row (> ses--header-row 0)])) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
103 |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
104 (defconst ses-mode-map |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
105 (let ((keys `("\C-c\M-\C-l" ses-reconstruct-all |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
106 "\C-c\C-l" ses-recalculate-all |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
107 "\C-c\C-n" ses-renarrow-buffer |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
108 "\C-c\C-c" ses-recalculate-cell |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
109 "\C-c\M-\C-s" ses-sort-column |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
110 "\C-c\M-\C-h" ses-set-header-row |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
111 "\C-c\C-t" ses-truncate-cell |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
112 "\C-c\C-j" ses-jump |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
113 "\C-c\C-p" ses-read-default-printer |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
114 "\M-\C-l" ses-reprint-all |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
115 [?\S-\C-l] ses-reprint-all |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
116 [header-line down-mouse-3] ,ses-header-line-menu |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
117 [header-line mouse-2] ses-sort-column-click)) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
118 (newmap (make-sparse-keymap))) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
119 (while keys |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
120 (define-key (1value newmap) (car keys) (cadr keys)) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
121 (setq keys (cddr keys))) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
122 newmap) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
123 "Local keymap for Simple Emacs Spreadsheet.") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
124 |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
125 (easy-menu-define ses-menu ses-mode-map |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
126 "Menu bar menu for SES." |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
127 '("SES" |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
128 ["Insert row" ses-insert-row (ses-in-print-area)] |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
129 ["Delete row" ses-delete-row (ses-in-print-area)] |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
130 ["Insert column" ses-insert-column (ses-in-print-area)] |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
131 ["Delete column" ses-delete-column (ses-in-print-area)] |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
132 ["Set column printer" ses-read-column-printer t] |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
133 ["Set column width" ses-set-column-width t] |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
134 ["Set default printer" ses-read-default-printer t] |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
135 ["Jump to cell" ses-jump t] |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
136 ["Set cell printer" ses-read-cell-printer t] |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
137 ["Recalculate cell" ses-recalculate-cell t] |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
138 ["Truncate cell display" ses-truncate-cell t] |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
139 ["Export values" ses-export-tsv t] |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
140 ["Export formulas" ses-export-tsf t])) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
141 |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
142 (defconst ses-mode-edit-map |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
143 (let ((keys '("\C-c\C-r" ses-insert-range |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
144 "\C-c\C-s" ses-insert-ses-range |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
145 [S-mouse-3] ses-insert-range-click |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
146 [C-S-mouse-3] ses-insert-ses-range-click |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
147 "\M-\C-i" lisp-complete-symbol)) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
148 (newmap (make-sparse-keymap))) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
149 (set-keymap-parent newmap minibuffer-local-map) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
150 (while keys |
68359
b9aec3e50e4f
(ses-read-cell): Provide a default value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65689
diff
changeset
|
151 (define-key newmap (pop keys) (pop keys))) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
152 newmap) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
153 "Local keymap for SES minibuffer cell-editing.") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
154 |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
155 ;Local keymap for SES print area |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
156 (defalias 'ses-mode-print-map |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
157 (let ((keys '([backtab] backward-char |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
158 [tab] ses-forward-or-insert |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
159 "\C-i" ses-forward-or-insert ;Needed for ses-coverage.el? |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
160 "\M-o" ses-insert-column |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
161 "\C-o" ses-insert-row |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
162 "\C-m" ses-edit-cell |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
163 "\M-k" ses-delete-column |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
164 "\M-y" ses-yank-pop |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
165 "\C-k" ses-delete-row |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
166 "\C-j" ses-append-row-jump-first-column |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
167 "\M-h" ses-mark-row |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
168 "\M-H" ses-mark-column |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
169 "\C-d" ses-clear-cell-forward |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
170 "\C-?" ses-clear-cell-backward |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
171 "(" ses-read-cell |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
172 "\"" ses-read-cell |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
173 "'" ses-read-symbol |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
174 "=" ses-edit-cell |
85644
3704b3bdbf49
Make `ses--symbolic-formulas' a safe local variable.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
78884
diff
changeset
|
175 "c" ses-recalculate-cell |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
176 "j" ses-jump |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
177 "p" ses-read-cell-printer |
85644
3704b3bdbf49
Make `ses--symbolic-formulas' a safe local variable.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
78884
diff
changeset
|
178 "t" ses-truncate-cell |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
179 "w" ses-set-column-width |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
180 "x" ses-export-keymap |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
181 "\M-p" ses-read-column-printer)) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
182 (repl '(;;We'll replace these wherever they appear in the keymap |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
183 clipboard-kill-region ses-kill-override |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
184 end-of-line ses-end-of-line |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
185 kill-line ses-delete-row |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
186 kill-region ses-kill-override |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
187 open-line ses-insert-row)) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
188 (numeric "0123456789.-") |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
189 (newmap (make-keymap))) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
190 ;;Get rid of printables |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
191 (suppress-keymap newmap t) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
192 ;;These keys insert themselves as the beginning of a numeric value |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
193 (dotimes (x (length numeric)) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
194 (define-key newmap (substring numeric x (1+ x)) 'ses-read-cell)) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
195 ;;Override these global functions wherever they're bound |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
196 (while repl |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
197 (substitute-key-definition (car repl) (cadr repl) newmap |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
198 (current-global-map)) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
199 (setq repl (cddr repl))) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
200 ;;Apparently substitute-key-definition doesn't catch this? |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
201 (define-key newmap [(menu-bar) edit cut] 'ses-kill-override) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
202 ;;Define our other local keys |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
203 (while keys |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
204 (define-key newmap (car keys) (cadr keys)) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
205 (setq keys (cddr keys))) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
206 newmap)) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
207 |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
208 ;;Helptext for ses-mode wants keymap as variable, not function |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
209 (defconst ses-mode-print-map (symbol-function 'ses-mode-print-map)) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
210 |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
211 ;;Key map used for 'x' key. |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
212 (defalias 'ses-export-keymap |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
213 (let ((map (make-sparse-keymap "SES export"))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
214 (define-key map "T" (cons " tab-formulas" 'ses-export-tsf)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
215 (define-key map "t" (cons " tab-values" 'ses-export-tsv)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
216 map)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
217 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
218 (defconst ses-print-data-boundary "\n\014\n" |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
219 "Marker string denoting the boundary between print area and data area.") |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
220 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
221 (defconst ses-initial-global-parameters |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
222 "\n( ;Global parameters (these are read first)\n 2 ;SES file-format\n 1 ;numrows\n 1 ;numcols\n)\n\n" |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
223 "Initial contents for the three-element list at the bottom of the data area.") |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
224 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
225 (defconst ses-initial-file-trailer |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
226 ";; Local Variables:\n;; mode: ses\n;; End:\n" |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
227 "Initial contents for the file-trailer area at the bottom of the file.") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
228 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
229 (defconst ses-initial-file-contents |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
230 (concat " \n" ;One blank cell in print area |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
231 ses-print-data-boundary |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
232 "(ses-cell A1 nil nil nil nil)\n" ;One blank cell in data area |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
233 "\n" ;End-of-row terminator for the one row in data area |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
234 "(ses-column-widths [7])\n" |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
235 "(ses-column-printers [nil])\n" |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
236 "(ses-default-printer \"%.7g\")\n" |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
237 "(ses-header-row 0)\n" |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
238 ses-initial-global-parameters |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
239 ses-initial-file-trailer) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
240 "The initial contents of an empty spreadsheet.") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
241 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
242 (defconst ses-box-prop '(:box (:line-width 2 :style released-button)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
243 "Display properties to create a raised box for cells in the header line.") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
244 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
245 (defconst ses-standard-printer-functions |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
246 '(ses-center ses-center-span ses-dashfill ses-dashfill-span |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
247 ses-tildefill-span) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
248 "List of print functions to be included in initial history of printer |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
249 functions. None of these standard-printer functions is suitable for use as a |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
250 column printer or a global-default printer because they invoke the column or |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
251 default printer and then modify its output.") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
252 |
73160
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
253 |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
254 ;;---------------------------------------------------------------------------- |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
255 ;; Local variables and constants |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
256 ;;---------------------------------------------------------------------------- |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
257 |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
258 (eval-and-compile |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
259 (defconst ses-localvars |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
260 '(ses--blank-line ses--cells ses--col-printers ses--col-widths ses--curcell |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
261 ses--curcell-overlay ses--default-printer ses--deferred-narrow |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
262 ses--deferred-recalc ses--deferred-write ses--file-format |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
263 ses--header-hscroll ses--header-row ses--header-string ses--linewidth |
73160
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
264 ses--numcols ses--numrows ses--symbolic-formulas ses--data-marker |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
265 ses--params-marker |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
266 ;;Global variables that we override |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
267 mode-line-process next-line-add-newlines transient-mark-mode) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
268 "Buffer-local variables used by SES.")) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
269 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
270 ;;When compiling, create all the buffer locals and give them values |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
271 (eval-when-compile |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
272 (dolist (x ses-localvars) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
273 (make-local-variable x) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
274 (set x nil))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
275 |
85644
3704b3bdbf49
Make `ses--symbolic-formulas' a safe local variable.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
78884
diff
changeset
|
276 ;;;This variable is documented as being permitted in file-locals: |
3704b3bdbf49
Make `ses--symbolic-formulas' a safe local variable.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
78884
diff
changeset
|
277 (put 'ses--symbolic-formulas 'safe-local-variable 'consp) |
3704b3bdbf49
Make `ses--symbolic-formulas' a safe local variable.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
78884
diff
changeset
|
278 |
73160
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
279 (defconst ses-paramlines-plist |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
280 '(ses--col-widths -5 ses--col-printers -4 ses--default-printer -3 |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
281 ses--header-row -2 ses--file-format 1 ses--numrows 2 |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
282 ses--numcols 3) |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
283 "Offsets from 'Global parameters' line to various parameter lines in the |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
284 data area of a spreadsheet.") |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
285 |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
286 |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
287 ;; |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
288 ;; "Side-effect variables". They are set in one function, altered in |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
289 ;; another as a side effect, then read back by the first, as a way of |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
290 ;; passing back more than one value. These declarations are just to make |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
291 ;; the compiler happy, and to conform to standard Emacs-Lisp practice (I |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
292 ;; think the make-local-variable trick above is cleaner). |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
293 ;; |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
294 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
295 (defvar ses-relocate-return nil |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
296 "Set by `ses-relocate-formula' and `ses-relocate-range', read by |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
297 `ses-relocate-all'. Set to 'delete if a cell-reference was deleted from a |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
298 formula--so the formula needs recalculation. Set to 'range if the size of a |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
299 `ses-range' was changed--so both the formula's value and list of dependents |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
300 need to be recalculated.") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
301 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
302 (defvar ses-call-printer-return nil |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
303 "Set to t if last cell printer invoked by `ses-call-printer' requested |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
304 left-justification of the result. Set to error-signal if ses-call-printer |
73910
e9b3186ac360
(ses-call-printer-return): Improve previous doc fix.
Glenn Morris <rgm@gnu.org>
parents:
73878
diff
changeset
|
305 encountered an error during printing. Otherwise nil.") |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
306 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
307 (defvar ses-start-time nil |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
308 "Time when current operation started. Used by `ses-time-check' to decide |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
309 when to emit a progress message.") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
310 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
311 |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
312 ;;---------------------------------------------------------------------------- |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
313 ;; Macros |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
314 ;;---------------------------------------------------------------------------- |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
315 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
316 (defmacro ses-get-cell (row col) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
317 "Return the cell structure that stores information about cell (ROW,COL)." |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
318 `(aref (aref ses--cells ,row) ,col)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
319 |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
320 ;; We might want to use defstruct here, but cells are explicitly used as |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
321 ;; arrays in ses-set-cell, so we'd need to fix this first. --Stef |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
322 (defsubst ses-make-cell (&optional symbol formula printer references) |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
323 (vector symbol formula printer references)) |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
324 |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
325 (defmacro ses-cell-symbol (row &optional col) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
326 "From a CELL or a pair (ROW,COL), get the symbol that names the local-variable holding its value. (0,0) => A1." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
327 `(aref ,(if col `(ses-get-cell ,row ,col) row) 0)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
328 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
329 (defmacro ses-cell-formula (row &optional col) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
330 "From a CELL or a pair (ROW,COL), get the function that computes its value." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
331 `(aref ,(if col `(ses-get-cell ,row ,col) row) 1)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
332 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
333 (defmacro ses-cell-printer (row &optional col) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
334 "From a CELL or a pair (ROW,COL), get the function that prints its value." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
335 `(aref ,(if col `(ses-get-cell ,row ,col) row) 2)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
336 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
337 (defmacro ses-cell-references (row &optional col) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
338 "From a CELL or a pair (ROW,COL), get the list of symbols for cells whose |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
339 functions refer to its value." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
340 `(aref ,(if col `(ses-get-cell ,row ,col) row) 3)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
341 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
342 (defmacro ses-cell-value (row &optional col) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
343 "From a CELL or a pair (ROW,COL), get the current value for that cell." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
344 `(symbol-value (ses-cell-symbol ,row ,col))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
345 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
346 (defmacro ses-col-width (col) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
347 "Return the width for column COL." |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
348 `(aref ses--col-widths ,col)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
349 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
350 (defmacro ses-col-printer (col) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
351 "Return the default printer for column COL." |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
352 `(aref ses--col-printers ,col)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
353 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
354 (defmacro ses-sym-rowcol (sym) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
355 "From a cell-symbol SYM, gets the cons (row . col). A1 => (0 . 0). Result |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
356 is nil if SYM is not a symbol that names a cell." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
357 `(and (symbolp ,sym) (get ,sym 'ses-cell))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
358 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
359 (defmacro ses-cell (sym value formula printer references) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
360 "Load a cell SYM from the spreadsheet file. Does not recompute VALUE from |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
361 FORMULA, does not reprint using PRINTER, does not check REFERENCES. This is a |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
362 macro to prevent propagate-on-load viruses. Safety-checking for FORMULA and |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
363 PRINTER are deferred until first use." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
364 (let ((rowcol (ses-sym-rowcol sym))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
365 (ses-formula-record formula) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
366 (ses-printer-record printer) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
367 (or (atom formula) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
368 (eq safe-functions t) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
369 (setq formula `(ses-safe-formula ,formula))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
370 (or (not printer) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
371 (stringp printer) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
372 (eq safe-functions t) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
373 (setq printer `(ses-safe-printer ,printer))) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
374 (aset (aref ses--cells (car rowcol)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
375 (cdr rowcol) |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
376 (ses-make-cell sym formula printer references))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
377 (set sym value) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
378 sym) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
379 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
380 (defmacro ses-column-widths (widths) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
381 "Load the vector of column widths from the spreadsheet file. This is a |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
382 macro to prevent propagate-on-load viruses." |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
383 (or (and (vectorp widths) (= (length widths) ses--numcols)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
384 (error "Bad column-width vector")) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
385 ;;To save time later, we also calculate the total width of each line in the |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
386 ;;print area (excluding the terminating newline) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
387 (setq ses--col-widths widths |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
388 ses--linewidth (apply '+ -1 (mapcar '1+ widths)) |
64020
463e088b8531
(ses): Finish `defgroup' description with period.
Juanma Barranquero <lekktu@gmail.com>
parents:
63622
diff
changeset
|
389 ses--blank-line (concat (make-string ses--linewidth ?\s) "\n")) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
390 t) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
391 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
392 (defmacro ses-column-printers (printers) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
393 "Load the vector of column printers from the spreadsheet file and checks |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
394 them for safety. This is a macro to prevent propagate-on-load viruses." |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
395 (or (and (vectorp printers) (= (length printers) ses--numcols)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
396 (error "Bad column-printers vector")) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
397 (dotimes (x ses--numcols) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
398 (aset printers x (ses-safe-printer (aref printers x)))) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
399 (setq ses--col-printers printers) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
400 (mapc 'ses-printer-record printers) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
401 t) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
402 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
403 (defmacro ses-default-printer (def) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
404 "Load the global default printer from the spreadsheet file and checks it |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
405 for safety. This is a macro to prevent propagate-on-load viruses." |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
406 (setq ses--default-printer (ses-safe-printer def)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
407 (ses-printer-record def) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
408 t) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
409 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
410 (defmacro ses-header-row (row) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
411 "Load the header row from the spreadsheet file and checks it |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
412 for safety. This is a macro to prevent propagate-on-load viruses." |
70964
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
413 (or (and (wholenump row) (or (zerop ses--numrows) (< row ses--numrows))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
414 (error "Bad header-row")) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
415 (setq ses--header-row row) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
416 t) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
417 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
418 (defmacro ses-dorange (curcell &rest body) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
419 "Execute BODY repeatedly, with the variables `row' and `col' set to each |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
420 cell in the range specified by CURCELL. The range is available in the |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
421 variables `minrow', `maxrow', `mincol', and `maxcol'." |
73160
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
422 (declare (indent defun) (debug (form body))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
423 (let ((cur (make-symbol "cur")) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
424 (min (make-symbol "min")) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
425 (max (make-symbol "max")) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
426 (r (make-symbol "r")) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
427 (c (make-symbol "c"))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
428 `(let* ((,cur ,curcell) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
429 (,min (ses-sym-rowcol (if (consp ,cur) (car ,cur) ,cur))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
430 (,max (ses-sym-rowcol (if (consp ,cur) (cdr ,cur) ,cur)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
431 (let ((minrow (car ,min)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
432 (maxrow (car ,max)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
433 (mincol (cdr ,min)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
434 (maxcol (cdr ,max)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
435 row col) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
436 (if (or (> minrow maxrow) (> mincol maxcol)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
437 (error "Empty range")) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
438 (dotimes (,r (- maxrow minrow -1)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
439 (setq row (+ ,r minrow)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
440 (dotimes (,c (- maxcol mincol -1)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
441 (setq col (+ ,c mincol)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
442 ,@body)))))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
443 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
444 ;;Support for coverage testing. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
445 (defmacro 1value (form) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
446 "For code-coverage testing, indicate that FORM is expected to always have |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
447 the same value." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
448 form) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
449 (defmacro noreturn (form) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
450 "For code-coverage testing, indicate that FORM will always signal an error." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
451 form) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
452 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
453 |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
454 ;;---------------------------------------------------------------------------- |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
455 ;; Utility functions |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
456 ;;---------------------------------------------------------------------------- |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
457 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
458 (defun ses-vector-insert (array idx new) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
459 "Create a new vector which is one larger than ARRAY and has NEW inserted |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
460 before element IDX." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
461 (let* ((len (length array)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
462 (result (make-vector (1+ len) new))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
463 (dotimes (x len) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
464 (aset result |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
465 (if (< x idx) x (1+ x)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
466 (aref array x))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
467 result)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
468 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
469 ;;Allow ARRAY to be a symbol for use in buffer-undo-list |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
470 (defun ses-vector-delete (array idx count) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
471 "Create a new vector which is a copy of ARRAY with COUNT objects removed |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
472 starting at element IDX. ARRAY is either a vector or a symbol whose value |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
473 is a vector--if a symbol, the new vector is assigned as the symbol's value." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
474 (let* ((a (if (arrayp array) array (symbol-value array))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
475 (len (- (length a) count)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
476 (result (make-vector len nil))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
477 (dotimes (x len) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
478 (aset result x (aref a (if (< x idx) x (+ x count))))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
479 (if (symbolp array) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
480 (set array result)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
481 result)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
482 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
483 (defun ses-delete-line (count) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
484 "Like `kill-line', but no kill ring." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
485 (let ((pos (point))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
486 (forward-line count) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
487 (delete-region pos (point)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
488 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
489 (defun ses-printer-validate (printer) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
490 "Signals an error if PRINTER is not a valid SES cell printer." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
491 (or (not printer) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
492 (stringp printer) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
493 (functionp printer) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
494 (and (stringp (car-safe printer)) (not (cdr printer))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
495 (error "Invalid printer function")) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
496 printer) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
497 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
498 (defun ses-printer-record (printer) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
499 "Add PRINTER to `ses-read-printer-history' if not already there, after first |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
500 checking that it is a valid printer function." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
501 (ses-printer-validate printer) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
502 ;;To speed things up, we avoid calling prin1 for the very common "nil" case. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
503 (if printer |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
504 (add-to-list 'ses-read-printer-history (prin1-to-string printer)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
505 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
506 (defun ses-formula-record (formula) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
507 "If FORMULA is of the form 'symbol, adds it to the list of symbolic formulas |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
508 for this spreadsheet." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
509 (when (and (eq (car-safe formula) 'quote) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
510 (symbolp (cadr formula))) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
511 (add-to-list 'ses--symbolic-formulas |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
512 (list (symbol-name (cadr formula)))))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
513 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
514 (defun ses-column-letter (col) |
85644
3704b3bdbf49
Make `ses--symbolic-formulas' a safe local variable.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
78884
diff
changeset
|
515 "Return the alphabetic name of column number COL. |
3704b3bdbf49
Make `ses--symbolic-formulas' a safe local variable.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
78884
diff
changeset
|
516 0-25 become A-Z; 26-701 become AA-ZZ, and so on." |
3704b3bdbf49
Make `ses--symbolic-formulas' a safe local variable.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
78884
diff
changeset
|
517 (let ((units (char-to-string (+ ?A (% col 26))))) |
3704b3bdbf49
Make `ses--symbolic-formulas' a safe local variable.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
78884
diff
changeset
|
518 (if (< col 26) |
3704b3bdbf49
Make `ses--symbolic-formulas' a safe local variable.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
78884
diff
changeset
|
519 units |
3704b3bdbf49
Make `ses--symbolic-formulas' a safe local variable.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
78884
diff
changeset
|
520 (concat (ses-column-letter (1- (/ col 26))) units)))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
521 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
522 (defun ses-create-cell-symbol (row col) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
523 "Produce a symbol that names the cell (ROW,COL). (0,0) => 'A1." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
524 (intern (concat (ses-column-letter col) (number-to-string (1+ row))))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
525 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
526 (defun ses-create-cell-variable-range (minrow maxrow mincol maxcol) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
527 "Create buffer-local variables for cells. This is undoable." |
59834
33c7409ff736
(ses-create-cell-variable-range)
Kim F. Storm <storm@cua.dk>
parents:
59787
diff
changeset
|
528 (push `(apply ses-destroy-cell-variable-range ,minrow ,maxrow ,mincol ,maxcol) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
529 buffer-undo-list) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
530 (let (sym xrow xcol) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
531 (dotimes (row (1+ (- maxrow minrow))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
532 (dotimes (col (1+ (- maxcol mincol))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
533 (setq xrow (+ row minrow) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
534 xcol (+ col mincol) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
535 sym (ses-create-cell-symbol xrow xcol)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
536 (put sym 'ses-cell (cons xrow xcol)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
537 (make-local-variable sym))))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
538 |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
539 ;;We do not delete the ses-cell properties for the cell-variables, in case a |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
540 ;;formula that refers to this cell is in the kill-ring and is later pasted |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
541 ;;back in. |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
542 (defun ses-destroy-cell-variable-range (minrow maxrow mincol maxcol) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
543 "Destroy buffer-local variables for cells. This is undoable." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
544 (let (sym) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
545 (dotimes (row (1+ (- maxrow minrow))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
546 (dotimes (col (1+ (- maxcol mincol))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
547 (setq sym (ses-create-cell-symbol (+ row minrow) (+ col mincol))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
548 (if (boundp sym) |
59834
33c7409ff736
(ses-create-cell-variable-range)
Kim F. Storm <storm@cua.dk>
parents:
59787
diff
changeset
|
549 (push `(apply ses-set-with-undo ,sym ,(symbol-value sym)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
550 buffer-undo-list)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
551 (kill-local-variable sym)))) |
59834
33c7409ff736
(ses-create-cell-variable-range)
Kim F. Storm <storm@cua.dk>
parents:
59787
diff
changeset
|
552 (push `(apply ses-create-cell-variable-range ,minrow ,maxrow ,mincol ,maxcol) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
553 buffer-undo-list)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
554 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
555 (defun ses-reset-header-string () |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
556 "Flags the header string for update. Upon undo, the header string will be |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
557 updated again." |
59834
33c7409ff736
(ses-create-cell-variable-range)
Kim F. Storm <storm@cua.dk>
parents:
59787
diff
changeset
|
558 (push '(apply ses-reset-header-string) buffer-undo-list) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
559 (setq ses--header-hscroll -1)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
560 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
561 ;;Split this code off into a function to avoid coverage-testing difficulties |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
562 (defun ses-time-check (format arg) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
563 "If `ses-start-time' is more than a second ago, call `message' with FORMAT |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
564 and (eval ARG) and reset `ses-start-time' to the current time." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
565 (when (> (- (float-time) ses-start-time) 1.0) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
566 (message format (eval arg)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
567 (setq ses-start-time (float-time))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
568 nil) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
569 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
570 |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
571 ;;---------------------------------------------------------------------------- |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
572 ;; The cells |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
573 ;;---------------------------------------------------------------------------- |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
574 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
575 (defun ses-set-cell (row col field val) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
576 "Install VAL as the contents for field FIELD (named by a quoted symbol) of |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
577 cell (ROW,COL). This is undoable. The cell's data will be updated through |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
578 `post-command-hook'." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
579 (let ((cell (ses-get-cell row col)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
580 (elt (plist-get '(value t symbol 0 formula 1 printer 2 references 3) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
581 field)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
582 change) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
583 (or elt (signal 'args-out-of-range nil)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
584 (setq change (if (eq elt t) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
585 (ses-set-with-undo (ses-cell-symbol cell) val) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
586 (ses-aset-with-undo cell elt val))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
587 (if change |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
588 (add-to-list 'ses--deferred-write (cons row col)))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
589 nil) ;Make coverage-tester happy |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
590 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
591 (defun ses-cell-set-formula (row col formula) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
592 "Store a new formula for (ROW . COL) and enqueues the cell for |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
593 recalculation via `post-command-hook'. Updates the reference lists for the |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
594 cells that this cell refers to. Does not update cell value or reprint the |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
595 cell. To avoid inconsistencies, this function is not interruptible, which |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
596 means Emacs will crash if FORMULA contains a circular list." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
597 (let* ((cell (ses-get-cell row col)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
598 (old (ses-cell-formula cell))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
599 (let ((sym (ses-cell-symbol cell)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
600 (oldref (ses-formula-references old)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
601 (newref (ses-formula-references formula)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
602 (inhibit-quit t) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
603 x xrow xcol) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
604 (add-to-list 'ses--deferred-recalc sym) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
605 ;;Delete old references from this cell. Skip the ones that are also |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
606 ;;in the new list. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
607 (dolist (ref oldref) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
608 (unless (memq ref newref) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
609 (setq x (ses-sym-rowcol ref) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
610 xrow (car x) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
611 xcol (cdr x)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
612 (ses-set-cell xrow xcol 'references |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
613 (delq sym (ses-cell-references xrow xcol))))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
614 ;;Add new ones. Skip ones left over from old list |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
615 (dolist (ref newref) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
616 (setq x (ses-sym-rowcol ref) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
617 xrow (car x) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
618 xcol (cdr x) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
619 x (ses-cell-references xrow xcol)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
620 (or (memq sym x) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
621 (ses-set-cell xrow xcol 'references (cons sym x)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
622 (ses-formula-record formula) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
623 (ses-set-cell row col 'formula formula)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
624 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
625 (defun ses-calculate-cell (row col force) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
626 "Calculate and print the value for cell (ROW,COL) using the cell's formula |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
627 function and print functions, if any. Result is nil for normal operation, or |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
628 the error signal if the formula or print function failed. The old value is |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
629 left unchanged if it was *skip* and the new value is nil. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
630 Any cells that depend on this cell are queued for update after the end of |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
631 processing for the current keystroke, unless the new value is the same as |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
632 the old and FORCE is nil." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
633 (let ((cell (ses-get-cell row col)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
634 formula-error printer-error) |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
635 (let ((oldval (ses-cell-value cell)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
636 (formula (ses-cell-formula cell)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
637 newval) |
78884
386417f6a905
(ses-calculate-cell): Don't evaluate unsafe formulae.
Glenn Morris <rgm@gnu.org>
parents:
78236
diff
changeset
|
638 (when (eq (car-safe formula) 'ses-safe-formula) |
386417f6a905
(ses-calculate-cell): Don't evaluate unsafe formulae.
Glenn Morris <rgm@gnu.org>
parents:
78236
diff
changeset
|
639 (setq formula (ses-safe-formula (cadr formula))) |
386417f6a905
(ses-calculate-cell): Don't evaluate unsafe formulae.
Glenn Morris <rgm@gnu.org>
parents:
78236
diff
changeset
|
640 (ses-set-cell row col 'formula formula)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
641 (condition-case sig |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
642 (setq newval (eval formula)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
643 (error |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
644 (setq formula-error sig |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
645 newval '*error*))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
646 (if (and (not newval) (eq oldval '*skip*)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
647 ;;Don't lose the *skip* - previous field spans this one |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
648 (setq newval '*skip*)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
649 (when (or force (not (eq newval oldval))) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
650 (add-to-list 'ses--deferred-write (cons row col)) ;In case force=t |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
651 (ses-set-cell row col 'value newval) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
652 (dolist (ref (ses-cell-references cell)) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
653 (add-to-list 'ses--deferred-recalc ref)))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
654 (setq printer-error (ses-print-cell row col)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
655 (or formula-error printer-error))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
656 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
657 (defun ses-clear-cell (row col) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
658 "Delete formula and printer for cell (ROW,COL)." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
659 (ses-set-cell row col 'printer nil) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
660 (ses-cell-set-formula row col nil)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
661 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
662 (defun ses-update-cells (list &optional force) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
663 "Recalculate cells in LIST, checking for dependency loops. Prints |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
664 progress messages every second. Dependent cells are not recalculated |
73160
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
665 if the cell's value is unchanged and FORCE is nil." |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
666 (let ((ses--deferred-recalc list) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
667 (nextlist list) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
668 (pos (point)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
669 curlist prevlist rowcol formula) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
670 (with-temp-message " " |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
671 (while (and ses--deferred-recalc (not (equal nextlist prevlist))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
672 ;;In each loop, recalculate cells that refer only to other cells that |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
673 ;;have already been recalculated or aren't in the recalculation |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
674 ;;region. Repeat until all cells have been processed or until the |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
675 ;;set of cells being worked on stops changing. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
676 (if prevlist |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
677 (message "Recalculating... (%d cells left)" |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
678 (length ses--deferred-recalc))) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
679 (setq curlist ses--deferred-recalc |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
680 ses--deferred-recalc nil |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
681 prevlist nextlist) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
682 (while curlist |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
683 (setq rowcol (ses-sym-rowcol (car curlist)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
684 formula (ses-cell-formula (car rowcol) (cdr rowcol))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
685 (or (catch 'ref |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
686 (dolist (ref (ses-formula-references formula)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
687 (when (or (memq ref curlist) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
688 (memq ref ses--deferred-recalc)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
689 ;;This cell refers to another that isn't done yet |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
690 (add-to-list 'ses--deferred-recalc (car curlist)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
691 (throw 'ref t)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
692 ;;ses-update-cells is called from post-command-hook, so |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
693 ;;inhibit-quit is implicitly bound to t. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
694 (when quit-flag |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
695 ;;Abort the recalculation. User will probably undo now. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
696 (error "Quit")) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
697 (ses-calculate-cell (car rowcol) (cdr rowcol) force)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
698 (setq curlist (cdr curlist))) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
699 (dolist (ref ses--deferred-recalc) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
700 (add-to-list 'nextlist ref)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
701 (setq nextlist (sort (copy-sequence nextlist) 'string<)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
702 (if (equal nextlist prevlist) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
703 ;;We'll go around the loop one more time. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
704 (add-to-list 'nextlist t))) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
705 (when ses--deferred-recalc |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
706 ;;Just couldn't finish these |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
707 (dolist (x ses--deferred-recalc) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
708 (let ((rowcol (ses-sym-rowcol x))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
709 (ses-set-cell (car rowcol) (cdr rowcol) 'value '*error*) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
710 (1value (ses-print-cell (car rowcol) (cdr rowcol))))) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
711 (error "Circular references: %s" ses--deferred-recalc)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
712 (message " ")) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
713 ;;Can't use save-excursion here: if the cell under point is |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
714 ;;updated, save-excusion's marker will move past the cell. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
715 (goto-char pos))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
716 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
717 |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
718 ;;---------------------------------------------------------------------------- |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
719 ;; The print area |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
720 ;;---------------------------------------------------------------------------- |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
721 |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
722 (defun ses-in-print-area () |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
723 "Returns t if point is in print area of spreadsheet." |
73160
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
724 (<= (point) ses--data-marker)) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
725 |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
726 ;;We turn off point-motion-hooks and explicitly position the cursor, in case |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
727 ;;the intangible properties have gotten screwed up (e.g., when |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
728 ;;ses-goto-print is called during a recursive ses-print-cell). |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
729 (defun ses-goto-print (row col) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
730 "Move point to print area for cell (ROW,COL)." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
731 (let ((inhibit-point-motion-hooks t)) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
732 (goto-char (point-min)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
733 (forward-line row) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
734 (dotimes (c col) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
735 (forward-char (1+ (ses-col-width c)))))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
736 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
737 (defun ses-set-curcell () |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
738 "Sets `ses--curcell' to the current cell symbol, or a cons (BEG,END) for a |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
739 region, or nil if cursor is not at a cell." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
740 (if (or (not mark-active) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
741 deactivate-mark |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
742 (= (region-beginning) (region-end))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
743 ;;Single cell |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
744 (setq ses--curcell (get-text-property (point) 'intangible)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
745 ;;Range |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
746 (let ((bcell (get-text-property (region-beginning) 'intangible)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
747 (ecell (get-text-property (1- (region-end)) 'intangible))) |
85644
3704b3bdbf49
Make `ses--symbolic-formulas' a safe local variable.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
78884
diff
changeset
|
748 (when (= (region-end) ses--data-marker) |
3704b3bdbf49
Make `ses--symbolic-formulas' a safe local variable.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
78884
diff
changeset
|
749 ;;Correct for overflow |
3704b3bdbf49
Make `ses--symbolic-formulas' a safe local variable.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
78884
diff
changeset
|
750 (setq ecell (get-text-property (- (region-end) 2) 'intangible))) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
751 (setq ses--curcell (if (and bcell ecell) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
752 (cons bcell ecell) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
753 nil)))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
754 nil) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
755 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
756 (defun ses-check-curcell (&rest args) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
757 "Signal an error if ses--curcell is inappropriate. The end marker is |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
758 appropriate if some argument is 'end. A range is appropriate if some |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
759 argument is 'range. A single cell is appropriate unless some argument is |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
760 'needrange." |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
761 (if (eq ses--curcell t) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
762 ;;curcell recalculation was postponed, but user typed ahead |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
763 (ses-set-curcell)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
764 (cond |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
765 ((not ses--curcell) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
766 (or (memq 'end args) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
767 (error "Not at cell"))) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
768 ((consp ses--curcell) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
769 (or (memq 'range args) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
770 (memq 'needrange args) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
771 (error "Can't use a range"))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
772 ((memq 'needrange args) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
773 (error "Need a range")))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
774 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
775 (defun ses-print-cell (row col) |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
776 "Format and print the value of cell (ROW,COL) to the print area. |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
777 Use the cell's printer function. If the cell's new print form is too wide, |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
778 it will spill over into the following cell, but will not run off the end of the |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
779 row or overwrite the next non-nil field. Result is nil for normal operation, |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
780 or the error signal if the printer function failed and the cell was formatted |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
781 with \"%s\". If the cell's value is *skip*, nothing is printed because the |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
782 preceding cell has spilled over." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
783 (catch 'ses-print-cell |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
784 (let* ((cell (ses-get-cell row col)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
785 (value (ses-cell-value cell)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
786 (printer (ses-cell-printer cell)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
787 (maxcol (1+ col)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
788 text sig startpos x) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
789 ;;Create the string to print |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
790 (cond |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
791 ((eq value '*skip*) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
792 ;;Don't print anything |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
793 (throw 'ses-print-cell nil)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
794 ((eq value '*error*) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
795 (setq text (make-string (ses-col-width col) ?#))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
796 (t |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
797 ;;Deferred safety-check on printer |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
798 (if (eq (car-safe printer) 'ses-safe-printer) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
799 (ses-set-cell row col 'printer |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
800 (setq printer (ses-safe-printer (cadr printer))))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
801 ;;Print the value |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
802 (setq text (ses-call-printer (or printer |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
803 (ses-col-printer col) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
804 ses--default-printer) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
805 value)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
806 (if (consp ses-call-printer-return) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
807 ;;Printer returned an error |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
808 (setq sig ses-call-printer-return)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
809 ;;Adjust print width to match column width |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
810 (let ((width (ses-col-width col)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
811 (len (length text))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
812 (cond |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
813 ((< len width) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
814 ;;Fill field to length with spaces |
64020
463e088b8531
(ses): Finish `defgroup' description with period.
Juanma Barranquero <lekktu@gmail.com>
parents:
63622
diff
changeset
|
815 (setq len (make-string (- width len) ?\s) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
816 text (if (eq ses-call-printer-return t) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
817 (concat text len) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
818 (concat len text)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
819 ((> len width) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
820 ;;Spill over into following cells, if possible |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
821 (let ((maxwidth width)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
822 (while (and (> len maxwidth) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
823 (< maxcol ses--numcols) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
824 (or (not (setq x (ses-cell-value row maxcol))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
825 (eq x '*skip*))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
826 (unless x |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
827 ;;Set this cell to '*skip* so it won't overwrite our spillover |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
828 (ses-set-cell row maxcol 'value '*skip*)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
829 (setq maxwidth (+ maxwidth (ses-col-width maxcol) 1) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
830 maxcol (1+ maxcol))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
831 (if (<= len maxwidth) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
832 ;;Fill to complete width of all the fields spanned |
64020
463e088b8531
(ses): Finish `defgroup' description with period.
Juanma Barranquero <lekktu@gmail.com>
parents:
63622
diff
changeset
|
833 (setq text (concat text (make-string (- maxwidth len) ?\s))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
834 ;;Not enough room to end of line or next non-nil field. Truncate |
53758
c503ef8bb300
Changes suggested by Stefan Monnier to truncate decimal places if print format too large for column width.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53746
diff
changeset
|
835 ;;if string or decimal; otherwise fill with error indicator |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
836 (setq sig `(error "Too wide" ,text)) |
53758
c503ef8bb300
Changes suggested by Stefan Monnier to truncate decimal places if print format too large for column width.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53746
diff
changeset
|
837 (cond |
c503ef8bb300
Changes suggested by Stefan Monnier to truncate decimal places if print format too large for column width.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53746
diff
changeset
|
838 ((stringp value) |
c503ef8bb300
Changes suggested by Stefan Monnier to truncate decimal places if print format too large for column width.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53746
diff
changeset
|
839 (setq text (substring text 0 maxwidth))) |
c503ef8bb300
Changes suggested by Stefan Monnier to truncate decimal places if print format too large for column width.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53746
diff
changeset
|
840 ((and (numberp value) |
c503ef8bb300
Changes suggested by Stefan Monnier to truncate decimal places if print format too large for column width.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53746
diff
changeset
|
841 (string-match "\\.[0-9]+" text) |
c503ef8bb300
Changes suggested by Stefan Monnier to truncate decimal places if print format too large for column width.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53746
diff
changeset
|
842 (>= 0 (setq width |
c503ef8bb300
Changes suggested by Stefan Monnier to truncate decimal places if print format too large for column width.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53746
diff
changeset
|
843 (- len maxwidth |
c503ef8bb300
Changes suggested by Stefan Monnier to truncate decimal places if print format too large for column width.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53746
diff
changeset
|
844 (- (match-end 0) (match-beginning 0)))))) |
c503ef8bb300
Changes suggested by Stefan Monnier to truncate decimal places if print format too large for column width.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53746
diff
changeset
|
845 ;; Turn 6.6666666666e+49 into 6.66e+49. Rounding is too hard! |
c503ef8bb300
Changes suggested by Stefan Monnier to truncate decimal places if print format too large for column width.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53746
diff
changeset
|
846 (setq text (concat (substring text |
c503ef8bb300
Changes suggested by Stefan Monnier to truncate decimal places if print format too large for column width.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53746
diff
changeset
|
847 0 |
c503ef8bb300
Changes suggested by Stefan Monnier to truncate decimal places if print format too large for column width.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53746
diff
changeset
|
848 (- (match-beginning 0) width)) |
c503ef8bb300
Changes suggested by Stefan Monnier to truncate decimal places if print format too large for column width.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53746
diff
changeset
|
849 (substring text (match-end 0))))) |
c503ef8bb300
Changes suggested by Stefan Monnier to truncate decimal places if print format too large for column width.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53746
diff
changeset
|
850 (t |
c503ef8bb300
Changes suggested by Stefan Monnier to truncate decimal places if print format too large for column width.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53746
diff
changeset
|
851 (setq text (make-string maxwidth ?#))))))))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
852 ;;Substitute question marks for tabs and newlines. Newlines are |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
853 ;;used as row-separators; tabs could confuse the reimport logic. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
854 (setq text (replace-regexp-in-string "[\t\n]" "?" text)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
855 (ses-goto-print row col) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
856 (setq startpos (point)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
857 ;;Install the printed result. This is not interruptible. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
858 (let ((inhibit-read-only t) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
859 (inhibit-quit t)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
860 (delete-char (1+ (length text))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
861 ;;We use concat instead of inserting separate strings in order to |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
862 ;;reduce the number of cells in the undo list. |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
863 (setq x (concat text (if (< maxcol ses--numcols) " " "\n"))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
864 ;;We use set-text-properties to prevent a wacky print function |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
865 ;;from inserting rogue properties, and to ensure that the keymap |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
866 ;;property is inherited (is it a bug that only unpropertied strings |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
867 ;;actually inherit from surrounding text?) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
868 (set-text-properties 0 (length x) nil x) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
869 (insert-and-inherit x) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
870 (put-text-property startpos (point) 'intangible |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
871 (ses-cell-symbol cell)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
872 (when (and (zerop row) (zerop col)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
873 ;;Reconstruct special beginning-of-buffer attributes |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
874 (put-text-property (point-min) (point) 'keymap 'ses-mode-print-map) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
875 (put-text-property (point-min) (point) 'read-only 'ses) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
876 (put-text-property (point-min) (1+ (point-min)) 'front-sticky t))) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
877 (if (= row (1- ses--header-row)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
878 ;;This line is part of the header - force recalc |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
879 (ses-reset-header-string)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
880 ;;If this cell (or a preceding one on the line) previously spilled over |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
881 ;;and has gotten shorter, redraw following cells on line recursively. |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
882 (when (and (< maxcol ses--numcols) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
883 (eq (ses-cell-value row maxcol) '*skip*)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
884 (ses-set-cell row maxcol 'value nil) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
885 (ses-print-cell row maxcol)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
886 ;;Return to start of cell |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
887 (goto-char startpos) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
888 sig))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
889 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
890 (defun ses-call-printer (printer &optional value) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
891 "Invokes PRINTER (a string or parenthesized string or function-symbol or |
77933
50f4b7448cfa
(ses-call-printer): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
76374
diff
changeset
|
892 lambda of one argument) on VALUE. Result is the printed cell as a string. |
50f4b7448cfa
(ses-call-printer): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
76374
diff
changeset
|
893 The variable `ses-call-printer-return' is set to t if the printer used |
50f4b7448cfa
(ses-call-printer): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
76374
diff
changeset
|
894 parenthesis to request left-justification, or the error-signal if the |
63622
85d4c02c56a6
(ses-call-printer): Fix spellings.
Juanma Barranquero <lekktu@gmail.com>
parents:
63422
diff
changeset
|
895 printer signaled one (and \"%s\" is used as the default printer), else nil." |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
896 (setq ses-call-printer-return nil) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
897 (unless value |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
898 (setq value "")) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
899 (condition-case signal |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
900 (cond |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
901 ((stringp printer) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
902 (format printer value)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
903 ((stringp (car-safe printer)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
904 (setq ses-call-printer-return t) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
905 (format (car printer) value)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
906 (t |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
907 (setq value (funcall printer value)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
908 (if (stringp value) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
909 value |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
910 (or (stringp (car-safe value)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
911 (error "Printer should return \"string\" or (\"string\")")) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
912 (setq ses-call-printer-return t) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
913 (car value)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
914 (error |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
915 (setq ses-call-printer-return signal) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
916 (prin1-to-string value t)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
917 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
918 (defun ses-adjust-print-width (col change) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
919 "Insert CHANGE spaces in front of column COL, or at end of line if |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
920 COL=NUMCOLS. Deletes characters if CHANGE < 0. Caller should bind |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
921 inhibit-quit to t." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
922 (let ((inhibit-read-only t) |
64020
463e088b8531
(ses): Finish `defgroup' description with period.
Juanma Barranquero <lekktu@gmail.com>
parents:
63622
diff
changeset
|
923 (blank (if (> change 0) (make-string change ?\s))) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
924 (at-end (= col ses--numcols))) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
925 (ses-set-with-undo 'ses--linewidth (+ ses--linewidth change)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
926 ;;ses-set-with-undo always returns t for strings. |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
927 (1value (ses-set-with-undo 'ses--blank-line |
64020
463e088b8531
(ses): Finish `defgroup' description with period.
Juanma Barranquero <lekktu@gmail.com>
parents:
63622
diff
changeset
|
928 (concat (make-string ses--linewidth ?\s) "\n"))) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
929 (dotimes (row ses--numrows) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
930 (ses-goto-print row col) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
931 (when at-end |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
932 ;;Insert new columns before newline |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
933 (let ((inhibit-point-motion-hooks t)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
934 (backward-char 1))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
935 (if blank |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
936 (insert blank) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
937 (delete-char (- change)))))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
938 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
939 (defun ses-print-cell-new-width (row col) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
940 "Same as ses-print-cell, except if the cell's value is *skip*, the preceding |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
941 nonskipped cell is reprinted. This function is used when the width of |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
942 cell (ROW,COL) has changed." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
943 (if (not (eq (ses-cell-value row col) '*skip*)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
944 (ses-print-cell row col) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
945 ;;Cell was skipped over - reprint previous |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
946 (ses-goto-print row col) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
947 (backward-char 1) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
948 (let ((rowcol (ses-sym-rowcol (get-text-property (point) 'intangible)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
949 (ses-print-cell (car rowcol) (cdr rowcol))))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
950 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
951 |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
952 ;;---------------------------------------------------------------------------- |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
953 ;; The data area |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
954 ;;---------------------------------------------------------------------------- |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
955 |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
956 (defun ses-narrowed-p () (/= (- (point-max) (point-min)) (buffer-size))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
957 |
70964
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
958 (defun ses-widen () |
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
959 "Turn off narrowing, to be reenabled at end of command loop." |
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
960 (if (ses-narrowed-p) |
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
961 (setq ses--deferred-narrow t)) |
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
962 (widen)) |
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
963 |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
964 (defun ses-goto-data (def &optional col) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
965 "Move point to data area for (DEF,COL). If DEF is a row |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
966 number, COL is the column number for a data cell -- otherwise DEF |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
967 is one of the symbols ses--col-widths, ses--col-printers, |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
968 ses--default-printer, ses--numrows, or ses--numcols." |
70964
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
969 (ses-widen) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
970 (let ((inhibit-point-motion-hooks t)) ;In case intangible attrs are wrong |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
971 (if col |
73160
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
972 ;;It's a cell |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
973 (progn |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
974 (goto-char ses--data-marker) |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
975 (forward-line (+ 1 (* def (1+ ses--numcols)) col))) |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
976 ;;Convert def-symbol to offset |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
977 (setq def (plist-get ses-paramlines-plist def)) |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
978 (or def (signal 'args-out-of-range nil)) |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
979 (goto-char ses--params-marker) |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
980 (forward-line def)))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
981 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
982 (defun ses-set-parameter (def value &optional elem) |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
983 "Set parameter DEF to VALUE (with undo) and write the value to the data area. |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
984 See `ses-goto-data' for meaning of DEF. Newlines in the data are escaped. |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
985 If ELEM is specified, it is the array subscript within DEF to be set to VALUE." |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
986 (save-excursion |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
987 ;;We call ses-goto-data early, using the old values of numrows and |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
988 ;;numcols in case one of them is being changed. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
989 (ses-goto-data def) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
990 (let ((inhibit-read-only t) |
55366
6956afbe5459
Typo fix: "ses--column-widths" => "ses--col-widths"
Jonathan Yavner <jyavner@member.fsf.org>
parents:
54571
diff
changeset
|
991 (fmt (plist-get '(ses--col-widths "(ses-column-widths %S)" |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
992 ses--col-printers "(ses-column-printers %S)" |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
993 ses--default-printer "(ses-default-printer %S)" |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
994 ses--header-row "(ses-header-row %S)" |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
995 ses--file-format " %S ;SES file-format" |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
996 ses--numrows " %S ;numrows" |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
997 ses--numcols " %S ;numcols") |
70964
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
998 def)) |
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
999 oldval) |
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
1000 (if elem |
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
1001 (progn |
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
1002 (setq oldval (aref (symbol-value def) elem)) |
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
1003 (aset (symbol-value def) elem value)) |
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
1004 (setq oldval (symbol-value def)) |
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
1005 (set def value)) |
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
1006 ;;Special undo since it's outside the narrowed buffer |
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
1007 (let (buffer-undo-list) |
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
1008 (delete-region (point) (line-end-position)) |
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
1009 (insert (format fmt (symbol-value def)))) |
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
1010 (push `(apply ses-set-parameter ,def ,oldval ,elem) buffer-undo-list)))) |
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
1011 |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1012 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1013 (defun ses-write-cells () |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1014 "Write cells in `ses--deferred-write' from local variables to data area. |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1015 Newlines in the data are escaped." |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1016 (let* ((inhibit-read-only t) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1017 (print-escape-newlines t) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1018 rowcol row col cell sym formula printer text) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1019 (setq ses-start-time (float-time)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1020 (with-temp-message " " |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1021 (save-excursion |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1022 (while ses--deferred-write |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1023 (ses-time-check "Writing... (%d cells left)" |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1024 '(length ses--deferred-write)) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1025 (setq rowcol (pop ses--deferred-write) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1026 row (car rowcol) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1027 col (cdr rowcol) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1028 cell (ses-get-cell row col) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1029 sym (ses-cell-symbol cell) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1030 formula (ses-cell-formula cell) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1031 printer (ses-cell-printer cell)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1032 (if (eq (car-safe formula) 'ses-safe-formula) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1033 (setq formula (cadr formula))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1034 (if (eq (car-safe printer) 'ses-safe-printer) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1035 (setq printer (cadr printer))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1036 ;;This is noticably faster than (format "%S %S %S %S %S") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1037 (setq text (concat "(ses-cell " |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1038 (symbol-name sym) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1039 " " |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1040 (prin1-to-string (symbol-value sym)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1041 " " |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1042 (prin1-to-string formula) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1043 " " |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1044 (prin1-to-string printer) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1045 " " |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1046 (if (atom (ses-cell-references cell)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1047 "nil" |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1048 (concat "(" |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1049 (mapconcat 'symbol-name |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1050 (ses-cell-references cell) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1051 " ") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1052 ")")) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1053 ")")) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1054 (ses-goto-data row col) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1055 (delete-region (point) (line-end-position)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1056 (insert text))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1057 (message " ")))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1058 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1059 |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1060 ;;---------------------------------------------------------------------------- |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1061 ;; Formula relocation |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1062 ;;---------------------------------------------------------------------------- |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1063 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1064 (defun ses-formula-references (formula &optional result-so-far) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1065 "Produce a list of symbols for cells that this formula's value |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1066 refers to. For recursive calls, RESULT-SO-FAR is the list being constructed, |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1067 or t to get a wrong-type-argument error when the first reference is found." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1068 (if (atom formula) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1069 (if (ses-sym-rowcol formula) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1070 ;;Entire formula is one symbol |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1071 (add-to-list 'result-so-far formula) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1072 ) ;;Ignore other atoms |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1073 (dolist (cur formula) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1074 (cond |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1075 ((ses-sym-rowcol cur) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1076 ;;Save this reference |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1077 (add-to-list 'result-so-far cur)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1078 ((eq (car-safe cur) 'ses-range) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1079 ;;All symbols in range are referenced |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1080 (dolist (x (cdr (macroexpand cur))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1081 (add-to-list 'result-so-far x))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1082 ((and (consp cur) (not (eq (car cur) 'quote))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1083 ;;Recursive call for subformulas |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1084 (setq result-so-far (ses-formula-references cur result-so-far))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1085 (t |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1086 ;;Ignore other stuff |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1087 )))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1088 result-so-far) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1089 |
73160
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
1090 (defsubst ses-relocate-symbol (sym rowcol startrow startcol rowincr colincr) |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
1091 "Relocate one symbol SYM, whichs corresponds to ROWCOL (a cons of ROW and |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
1092 COL). Cells starting at (STARTROW,STARTCOL) are being shifted |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
1093 by (ROWINCR,COLINCR)." |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
1094 (let ((row (car rowcol)) |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
1095 (col (cdr rowcol))) |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
1096 (if (or (< row startrow) (< col startcol)) |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
1097 sym |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
1098 (setq row (+ row rowincr) |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
1099 col (+ col colincr)) |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
1100 (if (and (>= row startrow) (>= col startcol) |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
1101 (< row ses--numrows) (< col ses--numcols)) |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
1102 ;;Relocate this variable |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
1103 (ses-create-cell-symbol row col) |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
1104 ;;Delete reference to a deleted cell |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
1105 nil)))) |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
1106 |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1107 (defun ses-relocate-formula (formula startrow startcol rowincr colincr) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1108 "Produce a copy of FORMULA where all symbols that refer to cells in row |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1109 STARTROW or above and col STARTCOL or above are altered by adding ROWINCR |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1110 and COLINCR. STARTROW and STARTCOL are 0-based. Example: |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1111 (ses-relocate-formula '(+ A1 B2 D3) 1 2 1 -1) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1112 => (+ A1 B2 C4) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1113 If ROWINCR or COLINCR is negative, references to cells being deleted are |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1114 removed. Example: |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1115 (ses-relocate-formula '(+ A1 B2 D3) 0 1 0 -1) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1116 => (+ A1 C3) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1117 Sets `ses-relocate-return' to 'delete if cell-references were removed." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1118 (let (rowcol result) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1119 (if (or (atom formula) (eq (car formula) 'quote)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1120 (if (setq rowcol (ses-sym-rowcol formula)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1121 (ses-relocate-symbol formula rowcol |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1122 startrow startcol rowincr colincr) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1123 formula) ;Pass through as-is |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1124 (dolist (cur formula) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1125 (setq rowcol (ses-sym-rowcol cur)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1126 (cond |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1127 (rowcol |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1128 (setq cur (ses-relocate-symbol cur rowcol |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1129 startrow startcol rowincr colincr)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1130 (if cur |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1131 (push cur result) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1132 ;;Reference to a deleted cell. Set a flag in ses-relocate-return. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1133 ;;don't change the flag if it's already 'range, since range |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1134 ;;implies 'delete. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1135 (unless ses-relocate-return |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1136 (setq ses-relocate-return 'delete)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1137 ((eq (car-safe cur) 'ses-range) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1138 (setq cur (ses-relocate-range cur startrow startcol rowincr colincr)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1139 (if cur |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1140 (push cur result))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1141 ((or (atom cur) (eq (car cur) 'quote)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1142 ;;Constants pass through unchanged |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1143 (push cur result)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1144 (t |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1145 ;;Recursively copy and alter subformulas |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1146 (push (ses-relocate-formula cur startrow startcol |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1147 rowincr colincr) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1148 result)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1149 (nreverse result)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1150 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1151 (defun ses-relocate-range (range startrow startcol rowincr colincr) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1152 "Relocate one RANGE, of the form '(ses-range min max). Cells starting |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1153 at (STARTROW,STARTCOL) are being shifted by (ROWINCR,COLINCR). Result is the |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1154 new range, or nil if the entire range is deleted. If new rows are being added |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1155 just beyond the end of a row range, or new columns just beyond a column range, |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1156 the new rows/columns will be added to the range. Sets `ses-relocate-return' |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1157 if the range was altered." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1158 (let* ((minorig (cadr range)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1159 (minrowcol (ses-sym-rowcol minorig)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1160 (min (ses-relocate-symbol minorig minrowcol |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1161 startrow startcol |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1162 rowincr colincr)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1163 (maxorig (nth 2 range)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1164 (maxrowcol (ses-sym-rowcol maxorig)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1165 (max (ses-relocate-symbol maxorig maxrowcol |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1166 startrow startcol |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1167 rowincr colincr)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1168 field) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1169 (cond |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1170 ((and (not min) (not max)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1171 (setq range nil)) ;;The entire range is deleted |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1172 ((zerop colincr) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1173 ;;Inserting or deleting rows |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1174 (setq field 'car) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1175 (if (not min) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1176 ;;Chopped off beginning of range |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1177 (setq min (ses-create-cell-symbol startrow (cdr minrowcol)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1178 ses-relocate-return 'range)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1179 (if (not max) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1180 (if (> rowincr 0) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1181 ;;Trying to insert a nonexistent row |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1182 (setq max (ses-create-cell-symbol (1- ses--numrows) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1183 (cdr minrowcol))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1184 ;;End of range is being deleted |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1185 (setq max (ses-create-cell-symbol (1- startrow) (cdr minrowcol)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1186 ses-relocate-return 'range)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1187 (and (> rowincr 0) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1188 (= (car maxrowcol) (1- startrow)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1189 (= (cdr minrowcol) (cdr maxrowcol)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1190 ;;Insert after ending row of vertical range - include it |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1191 (setq max (ses-create-cell-symbol (+ startrow rowincr -1) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1192 (cdr maxrowcol)))))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1193 (t |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1194 ;;Inserting or deleting columns |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1195 (setq field 'cdr) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1196 (if (not min) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1197 ;;Chopped off beginning of range |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1198 (setq min (ses-create-cell-symbol (car minrowcol) startcol) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1199 ses-relocate-return 'range)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1200 (if (not max) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1201 (if (> colincr 0) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1202 ;;Trying to insert a nonexistent column |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1203 (setq max (ses-create-cell-symbol (car maxrowcol) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1204 (1- ses--numcols))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1205 ;;End of range is being deleted |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1206 (setq max (ses-create-cell-symbol (car maxrowcol) (1- startcol)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1207 ses-relocate-return 'range)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1208 (and (> colincr 0) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1209 (= (cdr maxrowcol) (1- startcol)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1210 (= (car minrowcol) (car maxrowcol)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1211 ;;Insert after ending column of horizontal range - include it |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1212 (setq max (ses-create-cell-symbol (car maxrowcol) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1213 (+ startcol colincr -1))))))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1214 (when range |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1215 (if (/= (- (funcall field maxrowcol) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1216 (funcall field minrowcol)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1217 (- (funcall field (ses-sym-rowcol max)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1218 (funcall field (ses-sym-rowcol min)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1219 ;;This range has changed size |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1220 (setq ses-relocate-return 'range)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1221 (list 'ses-range min max)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1222 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1223 (defun ses-relocate-all (minrow mincol rowincr colincr) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1224 "Alter all cell values, symbols, formulas, and reference-lists to relocate |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1225 the rectangle (MINROW,MINCOL)..(NUMROWS,NUMCOLS) by adding ROWINCR and COLINCR |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1226 to each symbol." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1227 (let (reform) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1228 (let (mycell newval) |
59649
e57ef5d6d521
(ses-dotimes-msg): Remove macro. Use `dotimes-with-progress-reporter' instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59292
diff
changeset
|
1229 (dotimes-with-progress-reporter |
e57ef5d6d521
(ses-dotimes-msg): Remove macro. Use `dotimes-with-progress-reporter' instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59292
diff
changeset
|
1230 (row ses--numrows) "Relocating formulas..." |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1231 (dotimes (col ses--numcols) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1232 (setq ses-relocate-return nil |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1233 mycell (ses-get-cell row col) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1234 newval (ses-relocate-formula (ses-cell-formula mycell) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1235 minrow mincol rowincr colincr)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1236 (ses-set-cell row col 'formula newval) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1237 (if (eq ses-relocate-return 'range) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1238 ;;This cell contains a (ses-range X Y) where a cell has been |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1239 ;;inserted or deleted in the middle of the range. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1240 (push (cons row col) reform)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1241 (if ses-relocate-return |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1242 ;;This cell referred to a cell that's been deleted or is no |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1243 ;;longer part of the range. We can't fix that now because |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1244 ;;reference lists cells have been partially updated. |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1245 (add-to-list 'ses--deferred-recalc |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1246 (ses-create-cell-symbol row col))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1247 (setq newval (ses-relocate-formula (ses-cell-references mycell) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1248 minrow mincol rowincr colincr)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1249 (ses-set-cell row col 'references newval) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1250 (and (>= row minrow) (>= col mincol) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1251 (ses-set-cell row col 'symbol |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1252 (ses-create-cell-symbol row col)))))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1253 ;;Relocate the cell values |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1254 (let (oldval myrow mycol xrow xcol) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1255 (cond |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1256 ((and (<= rowincr 0) (<= colincr 0)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1257 ;;Deletion of rows and/or columns |
59649
e57ef5d6d521
(ses-dotimes-msg): Remove macro. Use `dotimes-with-progress-reporter' instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59292
diff
changeset
|
1258 (dotimes-with-progress-reporter |
e57ef5d6d521
(ses-dotimes-msg): Remove macro. Use `dotimes-with-progress-reporter' instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59292
diff
changeset
|
1259 (row (- ses--numrows minrow)) "Relocating variables..." |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1260 (setq myrow (+ row minrow)) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1261 (dotimes (col (- ses--numcols mincol)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1262 (setq mycol (+ col mincol) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1263 xrow (- myrow rowincr) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1264 xcol (- mycol colincr)) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1265 (if (and (< xrow ses--numrows) (< xcol ses--numcols)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1266 (setq oldval (ses-cell-value xrow xcol)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1267 ;;Cell is off the end of the array |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1268 (setq oldval (symbol-value (ses-create-cell-symbol xrow xcol)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1269 (ses-set-cell myrow mycol 'value oldval)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1270 ((and (wholenump rowincr) (wholenump colincr)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1271 ;;Insertion of rows and/or columns. Run the loop backwards. |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1272 (let ((disty (1- ses--numrows)) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1273 (distx (1- ses--numcols)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1274 myrow mycol) |
59649
e57ef5d6d521
(ses-dotimes-msg): Remove macro. Use `dotimes-with-progress-reporter' instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59292
diff
changeset
|
1275 (dotimes-with-progress-reporter |
e57ef5d6d521
(ses-dotimes-msg): Remove macro. Use `dotimes-with-progress-reporter' instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59292
diff
changeset
|
1276 (row (- ses--numrows minrow)) "Relocating variables..." |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1277 (setq myrow (- disty row)) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1278 (dotimes (col (- ses--numcols mincol)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1279 (setq mycol (- distx col) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1280 xrow (- myrow rowincr) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1281 xcol (- mycol colincr)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1282 (if (or (< xrow minrow) (< xcol mincol)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1283 ;;Newly-inserted value |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1284 (setq oldval nil) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1285 ;;Transfer old value |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1286 (setq oldval (ses-cell-value xrow xcol))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1287 (ses-set-cell myrow mycol 'value oldval))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1288 t)) ;Make testcover happy by returning non-nil here |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1289 (t |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1290 (error "ROWINCR and COLINCR must have the same sign")))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1291 ;;Reconstruct reference lists for cells that contain ses-ranges that |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1292 ;;have changed size. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1293 (when reform |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1294 (message "Fixing ses-ranges...") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1295 (let (row col) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1296 (setq ses-start-time (float-time)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1297 (while reform |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1298 (ses-time-check "Fixing ses-ranges... (%d left)" '(length reform)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1299 (setq row (caar reform) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1300 col (cdar reform) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1301 reform (cdr reform)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1302 (ses-cell-set-formula row col (ses-cell-formula row col)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1303 (message nil)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1304 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1305 |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1306 ;;---------------------------------------------------------------------------- |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1307 ;; Undo control |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1308 ;;---------------------------------------------------------------------------- |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1309 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1310 (defun ses-begin-change () |
59787
bc504fb813e7
(undo-more): defadvice deleted.
Richard M. Stallman <rms@gnu.org>
parents:
59649
diff
changeset
|
1311 "For undo, remember point before we start changing hidden stuff." |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1312 (let ((inhibit-read-only t)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1313 (insert-and-inherit "X") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1314 (delete-region (1- (point)) (point)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1315 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1316 (defun ses-set-with-undo (sym newval) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1317 "Like set, but undoable. Result is t if value has changed." |
70964
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
1318 ;;We try to avoid adding redundant entries to the undo list, but this is |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1319 ;;unavoidable for strings because equal ignores text properties and there's |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1320 ;;no easy way to get the whole property list to see if it's different! |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1321 (unless (and (boundp sym) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1322 (equal (symbol-value sym) newval) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1323 (not (stringp newval))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1324 (push (if (boundp sym) |
59834
33c7409ff736
(ses-create-cell-variable-range)
Kim F. Storm <storm@cua.dk>
parents:
59787
diff
changeset
|
1325 `(apply ses-set-with-undo ,sym ,(symbol-value sym)) |
33c7409ff736
(ses-create-cell-variable-range)
Kim F. Storm <storm@cua.dk>
parents:
59787
diff
changeset
|
1326 `(apply ses-unset-with-undo ,sym)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1327 buffer-undo-list) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1328 (set sym newval) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1329 t)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1330 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1331 (defun ses-unset-with-undo (sym) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1332 "Set SYM to be unbound. This is undoable." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1333 (when (1value (boundp sym)) ;;Always bound, except after a programming error |
59834
33c7409ff736
(ses-create-cell-variable-range)
Kim F. Storm <storm@cua.dk>
parents:
59787
diff
changeset
|
1334 (push `(apply ses-set-with-undo ,sym ,(symbol-value sym)) buffer-undo-list) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1335 (makunbound sym))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1336 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1337 (defun ses-aset-with-undo (array idx newval) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1338 "Like aset, but undoable. Result is t if element has changed" |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1339 (unless (equal (aref array idx) newval) |
59834
33c7409ff736
(ses-create-cell-variable-range)
Kim F. Storm <storm@cua.dk>
parents:
59787
diff
changeset
|
1340 (push `(apply ses-aset-with-undo ,array ,idx ,(aref array idx)) buffer-undo-list) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1341 (aset array idx newval) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1342 t)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1343 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1344 |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1345 ;;---------------------------------------------------------------------------- |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1346 ;; Startup for major mode |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1347 ;;---------------------------------------------------------------------------- |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1348 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1349 (defun ses-load () |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1350 "Parse the current buffer and sets up buffer-local variables. Does not |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1351 execute cell formulas or print functions." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1352 (widen) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1353 ;;Read our global parameters, which should be a 3-element list |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1354 (goto-char (point-max)) |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1355 (search-backward ";; Local Variables:\n" nil t) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1356 (backward-list 1) |
73160
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
1357 (setq ses--params-marker (point-marker)) |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1358 (let ((params (condition-case nil (read (current-buffer)) (error nil)))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1359 (or (and (= (safe-length params) 3) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1360 (numberp (car params)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1361 (numberp (cadr params)) |
70964
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
1362 (>= (cadr params) 0) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1363 (numberp (nth 2 params)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1364 (> (nth 2 params) 0)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1365 (error "Invalid SES file")) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1366 (setq ses--file-format (car params) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1367 ses--numrows (cadr params) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1368 ses--numcols (nth 2 params)) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1369 (when (= ses--file-format 1) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1370 (let (buffer-undo-list) ;This is not undoable |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1371 (ses-goto-data 'ses--header-row) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1372 (insert "(ses-header-row 0)\n") |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1373 (ses-set-parameter 'ses--file-format 2) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1374 (message "Upgrading from SES-1 file format"))) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1375 (or (= ses--file-format 2) |
63422
6c01c7e3e74f
(ses-load): Follow error conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
62738
diff
changeset
|
1376 (error "This file needs a newer version of the SES library code")) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1377 (ses-create-cell-variable-range 0 (1- ses--numrows) 0 (1- ses--numcols)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1378 ;;Initialize cell array |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1379 (setq ses--cells (make-vector ses--numrows nil)) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1380 (dotimes (row ses--numrows) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1381 (aset ses--cells row (make-vector ses--numcols nil)))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1382 ;;Skip over print area, which we assume is correct |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1383 (goto-char (point-min)) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1384 (forward-line ses--numrows) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1385 (or (looking-at ses-print-data-boundary) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1386 (error "Missing marker between print and data areas")) |
73160
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
1387 (forward-char 1) |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
1388 (setq ses--data-marker (point-marker)) |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
1389 (forward-char (1- (length ses-print-data-boundary))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1390 ;;Initialize printer and symbol lists |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1391 (mapc 'ses-printer-record ses-standard-printer-functions) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1392 (setq ses--symbolic-formulas nil) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1393 ;;Load cell definitions |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1394 (dotimes (row ses--numrows) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1395 (dotimes (col ses--numcols) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1396 (let* ((x (read (current-buffer))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1397 (rowcol (ses-sym-rowcol (car-safe (cdr-safe x))))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1398 (or (and (looking-at "\n") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1399 (eq (car-safe x) 'ses-cell) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1400 (eq row (car rowcol)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1401 (eq col (cdr rowcol))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1402 (error "Cell-def error")) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1403 (eval x))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1404 (or (looking-at "\n\n") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1405 (error "Missing blank line between rows"))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1406 ;;Load global parameters |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1407 (let ((widths (read (current-buffer))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1408 (n1 (char-after (point))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1409 (printers (read (current-buffer))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1410 (n2 (char-after (point))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1411 (def-printer (read (current-buffer))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1412 (n3 (char-after (point))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1413 (head-row (read (current-buffer))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1414 (n4 (char-after (point)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1415 (or (and (eq (car-safe widths) 'ses-column-widths) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1416 (= n1 ?\n) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1417 (eq (car-safe printers) 'ses-column-printers) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1418 (= n2 ?\n) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1419 (eq (car-safe def-printer) 'ses-default-printer) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1420 (= n3 ?\n) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1421 (eq (car-safe head-row) 'ses-header-row) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1422 (= n4 ?\n)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1423 (error "Invalid SES global parameters")) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1424 (1value (eval widths)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1425 (1value (eval def-printer)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1426 (1value (eval printers)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1427 (1value (eval head-row))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1428 ;;Should be back at global-params |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1429 (forward-char 1) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1430 (or (looking-at (replace-regexp-in-string "1" "[0-9]+" |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1431 ses-initial-global-parameters)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1432 (error "Problem with column-defs or global-params")) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1433 ;;Check for overall newline count in definitions area |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1434 (forward-line 3) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1435 (let ((start (point))) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1436 (ses-goto-data 'ses--numrows) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1437 (or (= (point) start) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1438 (error "Extraneous newlines someplace?")))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1439 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1440 (defun ses-setup () |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1441 "Set up for display of only the printed cell values. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1442 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1443 Narrows the buffer to show only the print area. Gives it `read-only' and |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1444 `intangible' properties. Sets up highlighting for current cell." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1445 (interactive) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1446 (let ((end (point-min)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1447 (inhibit-read-only t) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1448 (was-modified (buffer-modified-p)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1449 pos sym) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1450 (ses-goto-data 0 0) ;;Include marker between print-area and data-area |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1451 (set-text-properties (point) (point-max) nil) ;Delete garbage props |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1452 (mapc 'delete-overlay (overlays-in (point-min) (point-max))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1453 ;;The print area is read-only (except for our special commands) and uses a |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1454 ;;special keymap. |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1455 (put-text-property (point-min) (1- (point)) 'read-only 'ses) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1456 (put-text-property (point-min) (1- (point)) 'keymap 'ses-mode-print-map) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1457 ;;For the beginning of the buffer, we want the read-only and keymap |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1458 ;;attributes to be inherited from the first character |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1459 (put-text-property (point-min) (1+ (point-min)) 'front-sticky t) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1460 ;;Create intangible properties, which also indicate which cell the text |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1461 ;;came from. |
59649
e57ef5d6d521
(ses-dotimes-msg): Remove macro. Use `dotimes-with-progress-reporter' instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59292
diff
changeset
|
1462 (dotimes-with-progress-reporter (row ses--numrows) "Finding cells..." |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1463 (dotimes (col ses--numcols) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1464 (setq pos end |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1465 sym (ses-cell-symbol row col)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1466 ;;Include skipped cells following this one |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1467 (while (and (< col (1- ses--numcols)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1468 (eq (ses-cell-value row (1+ col)) '*skip*)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1469 (setq end (+ end (ses-col-width col) 1) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1470 col (1+ col))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1471 (setq end (+ end (ses-col-width col) 1)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1472 (put-text-property pos end 'intangible sym))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1473 ;;Adding these properties did not actually alter the text |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1474 (unless was-modified |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1475 (restore-buffer-modified-p nil) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1476 (buffer-disable-undo) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1477 (buffer-enable-undo))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1478 ;;Create the underlining overlay. It's impossible for (point) to be 2, |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1479 ;;because column A must be at least 1 column wide. |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1480 (setq ses--curcell-overlay (make-overlay (1+ (point-min)) (1+ (point-min)))) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1481 (overlay-put ses--curcell-overlay 'face 'underline)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1482 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1483 (defun ses-cleanup () |
78200
ece6179ee893
(ses-cleanup): Prevent Emacs from spuriously checking if the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
77933
diff
changeset
|
1484 "Cleanup when changing a buffer from SES mode to something else. |
ece6179ee893
(ses-cleanup): Prevent Emacs from spuriously checking if the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
77933
diff
changeset
|
1485 Delete overlays, remove special text properties." |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1486 (widen) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1487 (let ((inhibit-read-only t) |
78200
ece6179ee893
(ses-cleanup): Prevent Emacs from spuriously checking if the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
77933
diff
changeset
|
1488 ;; When reverting, hide the buffer name, otherwise Emacs will ask |
ece6179ee893
(ses-cleanup): Prevent Emacs from spuriously checking if the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
77933
diff
changeset
|
1489 ;; the user "the file is modified, do you really want to make |
ece6179ee893
(ses-cleanup): Prevent Emacs from spuriously checking if the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
77933
diff
changeset
|
1490 ;; modifications to this buffer", where the "modifications" refer to |
ece6179ee893
(ses-cleanup): Prevent Emacs from spuriously checking if the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
77933
diff
changeset
|
1491 ;; the irrelevant set-text-properties below. |
ece6179ee893
(ses-cleanup): Prevent Emacs from spuriously checking if the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
77933
diff
changeset
|
1492 (buffer-file-name nil) |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1493 (was-modified (buffer-modified-p))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1494 ;;Delete read-only, keymap, and intangible properties |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1495 (set-text-properties (point-min) (point-max) nil) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1496 ;;Delete overlay |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1497 (mapc 'delete-overlay (overlays-in (point-min) (point-max))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1498 (unless was-modified |
78200
ece6179ee893
(ses-cleanup): Prevent Emacs from spuriously checking if the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
77933
diff
changeset
|
1499 (restore-buffer-modified-p nil)))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1500 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1501 ;;;###autoload |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1502 (defun ses-mode () |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1503 "Major mode for Simple Emacs Spreadsheet. |
76374 | 1504 See \"ses-example.ses\" (in `data-directory') for more info. |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1505 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1506 Key definitions: |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1507 \\{ses-mode-map} |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1508 These key definitions are active only in the print area (the visible part): |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1509 \\{ses-mode-print-map} |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1510 These are active only in the minibuffer, when entering or editing a formula: |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1511 \\{ses-mode-edit-map}" |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1512 (interactive) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1513 (unless (and (boundp 'ses--deferred-narrow) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1514 (eq ses--deferred-narrow 'ses-mode)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1515 (kill-all-local-variables) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1516 (mapc 'make-local-variable ses-localvars) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1517 (setq major-mode 'ses-mode |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1518 mode-name "SES" |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1519 next-line-add-newlines nil |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1520 truncate-lines t |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1521 ;;SES deliberately puts lots of trailing whitespace in its buffer |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1522 show-trailing-whitespace nil |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1523 ;;Cell ranges do not work reasonably without this |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1524 transient-mark-mode t) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1525 (1value (add-hook 'change-major-mode-hook 'ses-cleanup nil t)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1526 (1value (add-hook 'before-revert-hook 'ses-cleanup nil t)) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1527 (setq ses--curcell nil |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1528 ses--deferred-recalc nil |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1529 ses--deferred-write nil |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1530 ses--header-hscroll -1 ;Flag for "initial recalc needed" |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1531 header-line-format '(:eval (progn |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1532 (when (/= (window-hscroll) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1533 ses--header-hscroll) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1534 ;;Reset ses--header-hscroll first, to |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1535 ;;avoid recursion problems when |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1536 ;;debugging ses-create-header-string |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1537 (setq ses--header-hscroll |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1538 (window-hscroll)) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1539 (ses-create-header-string)) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1540 ses--header-string))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1541 (let ((was-empty (zerop (buffer-size))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1542 (was-modified (buffer-modified-p))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1543 (save-excursion |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1544 (if was-empty |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1545 ;;Initialize buffer to contain one cell, for now |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1546 (insert ses-initial-file-contents)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1547 (ses-load) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1548 (ses-setup)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1549 (when was-empty |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1550 (unless (equal ses-initial-default-printer (1value ses--default-printer)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1551 (1value (ses-read-default-printer ses-initial-default-printer))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1552 (unless (= ses-initial-column-width (1value (ses-col-width 0))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1553 (1value (ses-set-column-width 0 ses-initial-column-width))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1554 (ses-set-curcell) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1555 (if (> (car ses-initial-size) (1value ses--numrows)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1556 (1value (ses-insert-row (1- (car ses-initial-size))))) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1557 (if (> (cdr ses-initial-size) (1value ses--numcols)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1558 (1value (ses-insert-column (1- (cdr ses-initial-size))))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1559 (ses-write-cells) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1560 (restore-buffer-modified-p was-modified) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1561 (buffer-disable-undo) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1562 (buffer-enable-undo) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1563 (goto-char (point-min)))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1564 (use-local-map ses-mode-map) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1565 ;;Set the deferred narrowing flag (we can't narrow until after |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1566 ;;after-find-file completes). If .ses is on the auto-load alist and the |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1567 ;;file has "mode: ses", our ses-mode function will be called twice! Use |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1568 ;;a special flag to detect this (will be reset by ses-command-hook). |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1569 ;;For find-alternate-file, post-command-hook doesn't get run for some |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1570 ;;reason, so use an idle timer to make sure. |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1571 (setq ses--deferred-narrow 'ses-mode) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1572 (1value (add-hook 'post-command-hook 'ses-command-hook nil t)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1573 (run-with-idle-timer 0.01 nil 'ses-command-hook) |
62738
d3fe76043df3
(ses-mode): Use run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
60179
diff
changeset
|
1574 (run-mode-hooks 'ses-mode-hook))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1575 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1576 (put 'ses-mode 'mode-class 'special) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1577 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1578 (defun ses-command-hook () |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1579 "Invoked from `post-command-hook'. If point has moved to a different cell, |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1580 moves the underlining overlay. Performs any recalculations or cell-data |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1581 writes that have been deferred. If buffer-narrowing has been deferred, |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1582 narrows the buffer now." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1583 (condition-case err |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1584 (when (eq major-mode 'ses-mode) ;Otherwise, not our buffer anymore |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1585 (when ses--deferred-recalc |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1586 ;;We reset the deferred list before starting on the recalc -- in case |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1587 ;;of error, we don't want to retry the recalc after every keystroke! |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1588 (let ((old ses--deferred-recalc)) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1589 (setq ses--deferred-recalc nil) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1590 (ses-update-cells old))) |
70964
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
1591 (when ses--deferred-write |
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
1592 ;;We don't reset the deferred list before starting -- the most |
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
1593 ;;likely error is keyboard-quit, and we do want to keep trying |
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
1594 ;;these writes after a quit. |
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
1595 (ses-write-cells) |
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
1596 (push '(apply ses-widen) buffer-undo-list)) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1597 (when ses--deferred-narrow |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1598 ;;We're not allowed to narrow the buffer until after-find-file has |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1599 ;;read the local variables at the end of the file. Now it's safe to |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1600 ;;do the narrowing. |
73160
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
1601 (narrow-to-region (point-min) ses--data-marker) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1602 (setq ses--deferred-narrow nil)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1603 ;;Update the modeline |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1604 (let ((oldcell ses--curcell)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1605 (ses-set-curcell) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1606 (unless (eq ses--curcell oldcell) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1607 (cond |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1608 ((not ses--curcell) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1609 (setq mode-line-process nil)) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1610 ((atom ses--curcell) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1611 (setq mode-line-process (list " cell " |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1612 (symbol-name ses--curcell)))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1613 (t |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1614 (setq mode-line-process (list " range " |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1615 (symbol-name (car ses--curcell)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1616 "-" |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1617 (symbol-name (cdr ses--curcell)))))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1618 (force-mode-line-update))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1619 ;;Use underline overlay for single-cells only, turn off otherwise |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1620 (if (listp ses--curcell) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1621 (move-overlay ses--curcell-overlay 2 2) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1622 (let ((next (next-single-property-change (point) 'intangible))) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1623 (move-overlay ses--curcell-overlay (point) (1- next)))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1624 (when (not (pos-visible-in-window-p)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1625 ;;Scrolling will happen later |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1626 (run-with-idle-timer 0.01 nil 'ses-command-hook) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1627 (setq ses--curcell t))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1628 ;;Prevent errors in this post-command-hook from silently erasing the hook! |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1629 (error |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1630 (unless executing-kbd-macro |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1631 (ding)) |
65582
4d1085b02d64
Message format spec fixes (1)
Deepak Goel <deego@gnufans.org>
parents:
64762
diff
changeset
|
1632 (message "%s" (error-message-string err)))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1633 nil) ;Make coverage-tester happy |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1634 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1635 (defun ses-create-header-string () |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1636 "Set up `ses--header-string' as the buffer's header line. |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1637 Based on the current set of columns and `window-hscroll' position." |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1638 (let ((totwidth (- (window-hscroll))) |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1639 result width x) |
49573
3261228348b4
Fix header-line when scrollbar is on left and/or fringe isn't one char wide.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
47667
diff
changeset
|
1640 ;;Leave room for the left-side fringe and scrollbar |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1641 (push (propertize " " 'display '((space :align-to 0))) result) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1642 (dotimes (col ses--numcols) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1643 (setq width (ses-col-width col) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1644 totwidth (+ totwidth width 1)) |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1645 (if (= totwidth 1) |
49573
3261228348b4
Fix header-line when scrollbar is on left and/or fringe isn't one char wide.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
47667
diff
changeset
|
1646 ;;Scrolled so intercolumn space is leftmost |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1647 (push " " result)) |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1648 (when (> totwidth 1) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1649 (if (> ses--header-row 0) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1650 (save-excursion |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1651 (ses-goto-print (1- ses--header-row) col) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1652 (setq x (buffer-substring-no-properties (point) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1653 (+ (point) width))) |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1654 ;; Strip trailing space. |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1655 (if (string-match "[ \t]+\\'" x) |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1656 (setq x (substring x 0 (match-beginning 0)))) |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1657 ;; Cut off excess text. |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1658 (if (>= (length x) totwidth) |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1659 (setq x (substring x 0 (- totwidth -1))))) |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1660 (setq x (ses-column-letter col))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1661 (push (propertize x 'face ses-box-prop) result) |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1662 (push (propertize "." |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1663 'display `((space :align-to ,(1- totwidth))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1664 'face ses-box-prop) |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1665 result) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1666 ;;Allow the following space to be squished to make room for the 3-D box |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1667 ;;Coverage test ignores properties, thinks this is always a space! |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1668 (push (1value (propertize " " 'display `((space :align-to ,totwidth)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1669 result))) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1670 (if (> ses--header-row 0) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1671 (push (propertize (format " [row %d]" ses--header-row) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1672 'display '((height (- 1)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1673 result)) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1674 (setq ses--header-string (apply 'concat (nreverse result))))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1675 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1676 |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1677 ;;---------------------------------------------------------------------------- |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1678 ;; Redisplay and recalculation |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1679 ;;---------------------------------------------------------------------------- |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1680 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1681 (defun ses-jump (sym) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1682 "Move point to cell SYM." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1683 (interactive "SJump to cell: ") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1684 (let ((rowcol (ses-sym-rowcol sym))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1685 (or rowcol (error "Invalid cell name")) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1686 (if (eq (symbol-value sym) '*skip*) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1687 (error "Cell is covered by preceding cell")) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1688 (ses-goto-print (car rowcol) (cdr rowcol)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1689 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1690 (defun ses-jump-safe (cell) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1691 "Like `ses-jump', but no error if invalid cell." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1692 (condition-case nil |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1693 (ses-jump cell) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1694 (error))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1695 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1696 (defun ses-reprint-all (&optional nonarrow) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1697 "Recreate the display area. Calls all printer functions. Narrows to |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1698 print area if NONARROW is nil." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1699 (interactive "*P") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1700 (widen) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1701 (unless nonarrow |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1702 (setq ses--deferred-narrow t)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1703 (let ((startcell (get-text-property (point) 'intangible)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1704 (inhibit-read-only t)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1705 (ses-begin-change) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1706 (goto-char (point-min)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1707 (search-forward ses-print-data-boundary) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1708 (backward-char (length ses-print-data-boundary)) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1709 (delete-region (point-min) (point)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1710 ;;Insert all blank lines before printing anything, so ses-print-cell can |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1711 ;;find the data area when inserting or deleting *skip* values for cells |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1712 (dotimes (row ses--numrows) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1713 (insert-and-inherit ses--blank-line)) |
59649
e57ef5d6d521
(ses-dotimes-msg): Remove macro. Use `dotimes-with-progress-reporter' instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59292
diff
changeset
|
1714 (dotimes-with-progress-reporter (row ses--numrows) "Reprinting..." |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1715 (if (eq (ses-cell-value row 0) '*skip*) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1716 ;;Column deletion left a dangling skip |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1717 (ses-set-cell row 0 'value nil)) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1718 (dotimes (col ses--numcols) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1719 (ses-print-cell row col)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1720 (beginning-of-line 2)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1721 (ses-jump-safe startcell))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1722 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1723 (defun ses-recalculate-cell () |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1724 "Recalculate and reprint the current cell or range. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1725 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1726 For an individual cell, shows the error if the formula or printer |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1727 signals one, or otherwise shows the cell's complete value. For a range, the |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1728 cells are recalculated in \"natural\" order, so cells that other cells refer |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1729 to are recalculated first." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1730 (interactive "*") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1731 (ses-check-curcell 'range) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1732 (ses-begin-change) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1733 (let (sig) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1734 (setq ses-start-time (float-time)) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1735 (if (atom ses--curcell) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1736 (setq sig (ses-sym-rowcol ses--curcell) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1737 sig (ses-calculate-cell (car sig) (cdr sig) t)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1738 ;;First, recalculate all cells that don't refer to other cells and |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1739 ;;produce a list of cells with references. |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1740 (ses-dorange ses--curcell |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1741 (ses-time-check "Recalculating... %s" '(ses-cell-symbol row col)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1742 (condition-case nil |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1743 (progn |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1744 ;;The t causes an error if the cell has references. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1745 ;;If no references, the t will be the result value. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1746 (1value (ses-formula-references (ses-cell-formula row col) t)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1747 (setq sig (ses-calculate-cell row col t))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1748 (wrong-type-argument |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1749 ;;The formula contains a reference |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1750 (add-to-list 'ses--deferred-recalc (ses-cell-symbol row col)))))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1751 ;;Do the update now, so we can force recalculation |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1752 (let ((x ses--deferred-recalc)) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1753 (setq ses--deferred-recalc nil) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1754 (condition-case hold |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1755 (ses-update-cells x t) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1756 (error (setq sig hold)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1757 (cond |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1758 (sig |
65582
4d1085b02d64
Message format spec fixes (1)
Deepak Goel <deego@gnufans.org>
parents:
64762
diff
changeset
|
1759 (message "%s" (error-message-string sig))) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1760 ((consp ses--curcell) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1761 (message " ")) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1762 (t |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1763 (princ (symbol-value ses--curcell)))))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1764 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1765 (defun ses-recalculate-all () |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1766 "Recalculate and reprint all cells." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1767 (interactive "*") |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1768 (let ((startcell (get-text-property (point) 'intangible)) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1769 (ses--curcell (cons 'A1 (ses-cell-symbol (1- ses--numrows) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1770 (1- ses--numcols))))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1771 (ses-recalculate-cell) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1772 (ses-jump-safe startcell))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1773 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1774 (defun ses-truncate-cell () |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1775 "Reprint current cell, but without spillover into any following blank |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1776 cells." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1777 (interactive "*") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1778 (ses-check-curcell) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1779 (let* ((rowcol (ses-sym-rowcol ses--curcell)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1780 (row (car rowcol)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1781 (col (cdr rowcol))) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1782 (when (and (< col (1- ses--numcols)) ;;Last column can't spill over, anyway |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1783 (eq (ses-cell-value row (1+ col)) '*skip*)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1784 ;;This cell has spill-over. We'll momentarily pretend the following |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1785 ;;cell has a `t' in it. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1786 (eval `(let ((,(ses-cell-symbol row (1+ col)) t)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1787 (ses-print-cell row col))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1788 ;;Now remove the *skip*. ses-print-cell is always nil here |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1789 (ses-set-cell row (1+ col) 'value nil) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1790 (1value (ses-print-cell row (1+ col)))))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1791 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1792 (defun ses-reconstruct-all () |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1793 "Reconstruct buffer based on cell data stored in Emacs variables." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1794 (interactive "*") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1795 (ses-begin-change) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1796 ;;Reconstruct reference lists. |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1797 (let (x yrow ycol) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1798 ;;Delete old reference lists |
59649
e57ef5d6d521
(ses-dotimes-msg): Remove macro. Use `dotimes-with-progress-reporter' instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59292
diff
changeset
|
1799 (dotimes-with-progress-reporter |
e57ef5d6d521
(ses-dotimes-msg): Remove macro. Use `dotimes-with-progress-reporter' instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59292
diff
changeset
|
1800 (row ses--numrows) "Deleting references..." |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1801 (dotimes (col ses--numcols) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1802 (ses-set-cell row col 'references nil))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1803 ;;Create new reference lists |
59649
e57ef5d6d521
(ses-dotimes-msg): Remove macro. Use `dotimes-with-progress-reporter' instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59292
diff
changeset
|
1804 (dotimes-with-progress-reporter |
e57ef5d6d521
(ses-dotimes-msg): Remove macro. Use `dotimes-with-progress-reporter' instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59292
diff
changeset
|
1805 (row ses--numrows) "Computing references..." |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1806 (dotimes (col ses--numcols) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1807 (dolist (ref (ses-formula-references (ses-cell-formula row col))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1808 (setq x (ses-sym-rowcol ref) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1809 yrow (car x) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1810 ycol (cdr x)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1811 (ses-set-cell yrow ycol 'references |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1812 (cons (ses-cell-symbol row col) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1813 (ses-cell-references yrow ycol))))))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1814 ;;Delete everything and reconstruct basic data area |
70964
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
1815 (ses-widen) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1816 (let ((inhibit-read-only t)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1817 (goto-char (point-max)) |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1818 (if (search-backward ";; Local Variables:\n" nil t) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1819 (delete-region (point-min) (point)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1820 ;;Buffer is quite screwed up - can't even save the user-specified locals |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1821 (delete-region (point-min) (point-max)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1822 (insert ses-initial-file-trailer) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1823 (goto-char (point-min))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1824 ;;Create a blank display area |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1825 (dotimes (row ses--numrows) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1826 (insert ses--blank-line)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1827 (insert ses-print-data-boundary) |
73160
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
1828 (backward-char (1- (length ses-print-data-boundary))) |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
1829 (setq ses--data-marker (point-marker)) |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
1830 (forward-char (1- (length ses-print-data-boundary))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1831 ;;Placeholders for cell data |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1832 (insert (make-string (* ses--numrows (1+ ses--numcols)) ?\n)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1833 ;;Placeholders for col-widths, col-printers, default-printer, header-row |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1834 (insert "\n\n\n\n") |
73160
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
1835 (insert ses-initial-global-parameters) |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
1836 (backward-char (1- (length ses-initial-global-parameters))) |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
1837 (setq ses--params-marker (point-marker)) |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
1838 (forward-char (1- (length ses-initial-global-parameters)))) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1839 (ses-set-parameter 'ses--col-widths ses--col-widths) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1840 (ses-set-parameter 'ses--col-printers ses--col-printers) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1841 (ses-set-parameter 'ses--default-printer ses--default-printer) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1842 (ses-set-parameter 'ses--header-row ses--header-row) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1843 (ses-set-parameter 'ses--numrows ses--numrows) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1844 (ses-set-parameter 'ses--numcols ses--numcols) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1845 ;;Keep our old narrowing |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1846 (ses-setup) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1847 (ses-recalculate-all) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1848 (goto-char (point-min))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1849 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1850 |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1851 ;;---------------------------------------------------------------------------- |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1852 ;; Input of cell formulas |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1853 ;;---------------------------------------------------------------------------- |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1854 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1855 (defun ses-edit-cell (row col newval) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1856 "Display current cell contents in minibuffer, for editing. Returns nil if |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1857 cell formula was unsafe and user declined confirmation." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1858 (interactive |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1859 (progn |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1860 (barf-if-buffer-read-only) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1861 (ses-check-curcell) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1862 (let* ((rowcol (ses-sym-rowcol ses--curcell)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1863 (row (car rowcol)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1864 (col (cdr rowcol)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1865 (formula (ses-cell-formula row col)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1866 initial) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1867 (if (eq (car-safe formula) 'ses-safe-formula) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1868 (setq formula (cadr formula))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1869 (if (eq (car-safe formula) 'quote) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1870 (setq initial (format "'%S" (cadr formula))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1871 (setq initial (prin1-to-string formula))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1872 (if (stringp formula) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1873 ;;Position cursor inside close-quote |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1874 (setq initial (cons initial (length initial)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1875 (list row col |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1876 (read-from-minibuffer (format "Cell %s: " ses--curcell) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1877 initial |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1878 ses-mode-edit-map |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1879 t ;Convert to Lisp object |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1880 'ses-read-cell-history))))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1881 (when (ses-warn-unsafe newval 'unsafep) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1882 (ses-begin-change) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1883 (ses-cell-set-formula row col newval) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1884 t)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1885 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1886 (defun ses-read-cell (row col newval) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1887 "Self-insert for initial character of cell function." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1888 (interactive |
68359
b9aec3e50e4f
(ses-read-cell): Provide a default value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65689
diff
changeset
|
1889 (let* ((initial (this-command-keys)) |
b9aec3e50e4f
(ses-read-cell): Provide a default value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65689
diff
changeset
|
1890 (rowcol (progn (ses-check-curcell) (ses-sym-rowcol ses--curcell))) |
b9aec3e50e4f
(ses-read-cell): Provide a default value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65689
diff
changeset
|
1891 (curval (ses-cell-formula (car rowcol) (cdr rowcol)))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1892 (barf-if-buffer-read-only) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1893 (list (car rowcol) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1894 (cdr rowcol) |
68359
b9aec3e50e4f
(ses-read-cell): Provide a default value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65689
diff
changeset
|
1895 (read-from-minibuffer |
b9aec3e50e4f
(ses-read-cell): Provide a default value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65689
diff
changeset
|
1896 (format "Cell %s: " ses--curcell) |
b9aec3e50e4f
(ses-read-cell): Provide a default value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65689
diff
changeset
|
1897 (cons (if (equal initial "\"") "\"\"" |
b9aec3e50e4f
(ses-read-cell): Provide a default value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65689
diff
changeset
|
1898 (if (equal initial "(") "()" initial)) 2) |
b9aec3e50e4f
(ses-read-cell): Provide a default value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65689
diff
changeset
|
1899 ses-mode-edit-map |
b9aec3e50e4f
(ses-read-cell): Provide a default value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65689
diff
changeset
|
1900 t ;Convert to Lisp object |
b9aec3e50e4f
(ses-read-cell): Provide a default value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65689
diff
changeset
|
1901 'ses-read-cell-history |
70964
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
1902 (prin1-to-string (if (eq (car-safe curval) 'ses-safe-formula) |
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
1903 (cadr curval) |
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
1904 curval)))))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1905 (when (ses-edit-cell row col newval) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1906 (ses-command-hook) ;Update cell widths before movement |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1907 (dolist (x ses-after-entry-functions) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1908 (funcall x 1)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1909 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1910 (defun ses-read-symbol (row col symb) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1911 "Self-insert for a symbol as a cell formula. The set of all symbols that |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1912 have been used as formulas in this spreadsheet is available for completions." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1913 (interactive |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1914 (let ((rowcol (progn (ses-check-curcell) (ses-sym-rowcol ses--curcell))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1915 newval) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1916 (barf-if-buffer-read-only) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1917 (setq newval (completing-read (format "Cell %s ': " ses--curcell) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1918 ses--symbolic-formulas)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1919 (list (car rowcol) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1920 (cdr rowcol) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1921 (if (string= newval "") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1922 nil ;Don't create zero-length symbols! |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1923 (list 'quote (intern newval)))))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1924 (when (ses-edit-cell row col symb) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1925 (ses-command-hook) ;Update cell widths before movement |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1926 (dolist (x ses-after-entry-functions) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1927 (funcall x 1)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1928 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1929 (defun ses-clear-cell-forward (count) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1930 "Delete formula and printer for current cell and then move to next cell. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1931 With prefix, deletes several cells." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1932 (interactive "*p") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1933 (if (< count 0) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1934 (1value (ses-clear-cell-backward (- count))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1935 (ses-check-curcell) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1936 (ses-begin-change) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1937 (dotimes (x count) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1938 (ses-set-curcell) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1939 (let ((rowcol (ses-sym-rowcol ses--curcell))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1940 (or rowcol (signal 'end-of-buffer nil)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1941 (ses-clear-cell (car rowcol) (cdr rowcol))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1942 (forward-char 1)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1943 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1944 (defun ses-clear-cell-backward (count) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1945 "Move to previous cell and then delete it. With prefix, deletes several |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1946 cells." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1947 (interactive "*p") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1948 (if (< count 0) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1949 (1value (ses-clear-cell-forward (- count))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1950 (ses-check-curcell 'end) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1951 (ses-begin-change) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1952 (dotimes (x count) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1953 (backward-char 1) ;Will signal 'beginning-of-buffer if appropriate |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1954 (ses-set-curcell) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
1955 (let ((rowcol (ses-sym-rowcol ses--curcell))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1956 (ses-clear-cell (car rowcol) (cdr rowcol)))))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1957 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1958 |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1959 ;;---------------------------------------------------------------------------- |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1960 ;; Input of cell-printer functions |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
1961 ;;---------------------------------------------------------------------------- |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1962 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1963 (defun ses-read-printer (prompt default) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1964 "Common code for `ses-read-cell-printer', `ses-read-column-printer', and `ses-read-default-printer'. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1965 PROMPT should end with \": \". Result is t if operation was cancelled." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1966 (barf-if-buffer-read-only) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1967 (if (eq default t) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1968 (setq default "") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1969 (setq prompt (format "%s [currently %S]: " |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1970 (substring prompt 0 -2) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1971 default))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1972 (let ((new (read-from-minibuffer prompt |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1973 nil ;Initial contents |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1974 ses-mode-edit-map |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1975 t ;Evaluate the result |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1976 'ses-read-printer-history |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1977 (prin1-to-string default)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1978 (if (equal new default) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1979 ;;User changed mind, decided not to change printer |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1980 (setq new t) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1981 (ses-printer-validate new) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1982 (or (not new) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1983 (stringp new) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1984 (stringp (car-safe new)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1985 (ses-warn-unsafe new 'unsafep-function) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1986 (setq new t))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1987 new)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1988 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1989 (defun ses-read-cell-printer (newval) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1990 "Set the printer function for the current cell or range. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1991 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1992 A printer function is either a string (a format control-string with one |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1993 %-sequence -- result from format will be right-justified), or a list of one |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1994 string (result from format will be left-justified), or a lambda-expression of |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1995 one argument, or a symbol that names a function of one argument. In the |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1996 latter two cases, the function's result should be either a string (will be |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1997 right-justified) or a list of one string (will be left-justified)." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1998 (interactive |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
1999 (let ((default t) |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
2000 x) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2001 (ses-check-curcell 'range) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2002 ;;Default is none if not all cells in range have same printer |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2003 (catch 'ses-read-cell-printer |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2004 (ses-dorange ses--curcell |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2005 (setq x (ses-cell-printer row col)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2006 (if (eq (car-safe x) 'ses-safe-printer) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2007 (setq x (cadr x))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2008 (if (eq default t) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2009 (setq default x) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2010 (unless (equal default x) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2011 ;;Range contains differing printer functions |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2012 (setq default t) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2013 (throw 'ses-read-cell-printer t))))) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2014 (list (ses-read-printer (format "Cell %S printer: " ses--curcell) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2015 default)))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2016 (unless (eq newval t) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2017 (ses-begin-change) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2018 (ses-dorange ses--curcell |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2019 (ses-set-cell row col 'printer newval) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2020 (ses-print-cell row col)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2021 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2022 (defun ses-read-column-printer (col newval) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2023 "Set the printer function for the current column. See |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2024 `ses-read-cell-printer' for input forms." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2025 (interactive |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2026 (let ((col (cdr (ses-sym-rowcol ses--curcell)))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2027 (ses-check-curcell) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2028 (list col (ses-read-printer (format "Column %s printer: " |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2029 (ses-column-letter col)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2030 (ses-col-printer col))))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2031 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2032 (unless (eq newval t) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2033 (ses-begin-change) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2034 (ses-set-parameter 'ses--col-printers newval col) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2035 (save-excursion |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2036 (dotimes (row ses--numrows) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2037 (ses-print-cell row col))))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2038 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2039 (defun ses-read-default-printer (newval) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2040 "Set the default printer function for cells that have no other. See |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2041 `ses-read-cell-printer' for input forms." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2042 (interactive |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2043 (list (ses-read-printer "Default printer: " ses--default-printer))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2044 (unless (eq newval t) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2045 (ses-begin-change) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2046 (ses-set-parameter 'ses--default-printer newval) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2047 (ses-reprint-all t))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2048 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2049 |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
2050 ;;---------------------------------------------------------------------------- |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
2051 ;; Spreadsheet size adjustments |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
2052 ;;---------------------------------------------------------------------------- |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2053 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2054 (defun ses-insert-row (count) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2055 "Insert a new row before the current one. With prefix, insert COUNT rows |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2056 before current one." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2057 (interactive "*p") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2058 (ses-check-curcell 'end) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2059 (or (> count 0) (signal 'args-out-of-range nil)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2060 (ses-begin-change) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2061 (let ((inhibit-quit t) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2062 (inhibit-read-only t) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2063 (row (or (car (ses-sym-rowcol ses--curcell)) ses--numrows)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2064 newrow) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2065 ;;Create a new set of cell-variables |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2066 (ses-create-cell-variable-range ses--numrows (+ ses--numrows count -1) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2067 0 (1- ses--numcols)) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2068 (ses-set-parameter 'ses--numrows (+ ses--numrows count)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2069 ;;Insert each row |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2070 (ses-goto-print row 0) |
59649
e57ef5d6d521
(ses-dotimes-msg): Remove macro. Use `dotimes-with-progress-reporter' instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59292
diff
changeset
|
2071 (dotimes-with-progress-reporter (x count) "Inserting row..." |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2072 ;;Create a row of empty cells. The `symbol' fields will be set by |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2073 ;;the call to ses-relocate-all. |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2074 (setq newrow (make-vector ses--numcols nil)) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2075 (dotimes (col ses--numcols) |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
2076 (aset newrow col (ses-make-cell))) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2077 (setq ses--cells (ses-vector-insert ses--cells row newrow)) |
59834
33c7409ff736
(ses-create-cell-variable-range)
Kim F. Storm <storm@cua.dk>
parents:
59787
diff
changeset
|
2078 (push `(apply ses-vector-delete ses--cells ,row 1) buffer-undo-list) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2079 (insert ses--blank-line)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2080 ;;Insert empty lines in cell data area (will be replaced by |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2081 ;;ses-relocate-all) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2082 (ses-goto-data row 0) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2083 (insert (make-string (* (1+ ses--numcols) count) ?\n)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2084 (ses-relocate-all row 0 count 0) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2085 ;;If any cell printers insert constant text, insert that text |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2086 ;;into the line. |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2087 (let ((cols (mapconcat #'ses-call-printer ses--col-printers nil)) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2088 (global (ses-call-printer ses--default-printer))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2089 (if (or (> (length cols) 0) (> (length global) 0)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2090 (dotimes (x count) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2091 (dotimes (col ses--numcols) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2092 ;;These cells are always nil, only constant formatting printed |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2093 (1value (ses-print-cell (+ x row) col)))))) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2094 (when (> ses--header-row row) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2095 ;;Inserting before header |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2096 (ses-set-parameter 'ses--header-row (+ ses--header-row count)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2097 (ses-reset-header-string))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2098 ;;Reconstruct text attributes |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2099 (ses-setup) |
70964
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
2100 ;;Prepare for undo |
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
2101 (push '(apply ses-widen) buffer-undo-list) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2102 ;;Return to current cell |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2103 (if ses--curcell |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2104 (ses-jump-safe ses--curcell) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2105 (ses-goto-print (1- ses--numrows) 0))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2106 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2107 (defun ses-delete-row (count) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2108 "Delete the current row. With prefix, Deletes COUNT rows starting from the |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2109 current one." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2110 (interactive "*p") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2111 (ses-check-curcell) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2112 (or (> count 0) (signal 'args-out-of-range nil)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2113 (let ((inhibit-quit t) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2114 (inhibit-read-only t) |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
2115 (row (car (ses-sym-rowcol ses--curcell)))) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2116 (setq count (min count (- ses--numrows row))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2117 (ses-begin-change) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2118 (ses-set-parameter 'ses--numrows (- ses--numrows count)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2119 ;;Delete lines from print area |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2120 (ses-goto-print row 0) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2121 (ses-delete-line count) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2122 ;;Delete lines from cell data area |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2123 (ses-goto-data row 0) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2124 (ses-delete-line (* count (1+ ses--numcols))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2125 ;;Relocate variables and formulas |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2126 (ses-set-with-undo 'ses--cells (ses-vector-delete ses--cells row count)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2127 (ses-relocate-all row 0 (- count) 0) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2128 (ses-destroy-cell-variable-range ses--numrows (+ ses--numrows count -1) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2129 0 (1- ses--numcols)) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2130 (when (> ses--header-row row) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2131 (if (<= ses--header-row (+ row count)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2132 ;;Deleting the header row |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2133 (ses-set-parameter 'ses--header-row 0) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2134 (ses-set-parameter 'ses--header-row (- ses--header-row count))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2135 (ses-reset-header-string))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2136 ;;Reconstruct attributes |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2137 (ses-setup) |
70964
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
2138 ;;Prepare for undo |
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
2139 (push '(apply ses-widen) buffer-undo-list) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2140 (ses-jump-safe ses--curcell)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2141 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2142 (defun ses-insert-column (count &optional col width printer) |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
2143 "Insert a new column before COL (default is the current one). |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
2144 With prefix, insert COUNT columns before current one. |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
2145 If COL is specified, the new column(s) get the specified WIDTH and PRINTER |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
2146 \(otherwise they're taken from the current column)." |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2147 (interactive "*p") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2148 (ses-check-curcell) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2149 (or (> count 0) (signal 'args-out-of-range nil)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2150 (or col |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2151 (setq col (cdr (ses-sym-rowcol ses--curcell)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2152 width (ses-col-width col) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2153 printer (ses-col-printer col))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2154 (ses-begin-change) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2155 (let ((inhibit-quit t) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2156 (inhibit-read-only t) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2157 (widths ses--col-widths) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2158 (printers ses--col-printers) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2159 has-skip) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2160 ;;Create a new set of cell-variables |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2161 (ses-create-cell-variable-range 0 (1- ses--numrows) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2162 ses--numcols (+ ses--numcols count -1)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2163 ;;Insert each column. |
59649
e57ef5d6d521
(ses-dotimes-msg): Remove macro. Use `dotimes-with-progress-reporter' instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59292
diff
changeset
|
2164 (dotimes-with-progress-reporter (x count) "Inserting column..." |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2165 ;;Create a column of empty cells. The `symbol' fields will be set by |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2166 ;;the call to ses-relocate-all. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2167 (ses-adjust-print-width col (1+ width)) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2168 (ses-set-parameter 'ses--numcols (1+ ses--numcols)) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2169 (dotimes (row ses--numrows) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2170 (and (< (1+ col) ses--numcols) (eq (ses-cell-value row col) '*skip*) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2171 ;;Inserting in the middle of a spill-over |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2172 (setq has-skip t)) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2173 (ses-aset-with-undo ses--cells row |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2174 (ses-vector-insert (aref ses--cells row) |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
2175 col (ses-make-cell))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2176 ;;Insert empty lines in cell data area (will be replaced by |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2177 ;;ses-relocate-all) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2178 (ses-goto-data row col) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2179 (insert ?\n)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2180 ;;Insert column width and printer |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2181 (setq widths (ses-vector-insert widths col width) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2182 printers (ses-vector-insert printers col printer))) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2183 (ses-set-parameter 'ses--col-widths widths) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2184 (ses-set-parameter 'ses--col-printers printers) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2185 (ses-reset-header-string) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2186 (ses-relocate-all 0 col 0 count) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2187 (if has-skip |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2188 (ses-reprint-all t) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2189 (when (or (> (length (ses-call-printer printer)) 0) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2190 (> (length (ses-call-printer ses--default-printer)) 0)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2191 ;;Either column printer or global printer inserts some constant text |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2192 ;;Reprint the new columns to insert that text. |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2193 (dotimes (x ses--numrows) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2194 (dotimes (y count) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2195 ;Always nil here - this is a blank column |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2196 (1value (ses-print-cell-new-width x (+ y col)))))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2197 (ses-setup))) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2198 (ses-jump-safe ses--curcell)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2199 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2200 (defun ses-delete-column (count) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2201 "Delete the current column. With prefix, Deletes COUNT columns starting |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2202 from the current one." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2203 (interactive "*p") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2204 (ses-check-curcell) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2205 (or (> count 0) (signal 'args-out-of-range nil)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2206 (let ((inhibit-quit t) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2207 (inhibit-read-only t) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2208 (rowcol (ses-sym-rowcol ses--curcell)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2209 (width 0) |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
2210 col origrow has-skip) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2211 (setq origrow (car rowcol) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2212 col (cdr rowcol) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2213 count (min count (- ses--numcols col))) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2214 (if (= count ses--numcols) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2215 (error "Can't delete all columns!")) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2216 ;;Determine width of column(s) being deleted |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2217 (dotimes (x count) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2218 (setq width (+ width (ses-col-width (+ col x)) 1))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2219 (ses-begin-change) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2220 (ses-set-parameter 'ses--numcols (- ses--numcols count)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2221 (ses-adjust-print-width col (- width)) |
59649
e57ef5d6d521
(ses-dotimes-msg): Remove macro. Use `dotimes-with-progress-reporter' instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59292
diff
changeset
|
2222 (dotimes-with-progress-reporter (row ses--numrows) "Deleting column..." |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2223 ;;Delete lines from cell data area |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2224 (ses-goto-data row col) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2225 (ses-delete-line count) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2226 ;;Delete cells. Check if deletion area begins or ends with a skip. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2227 (if (or (eq (ses-cell-value row col) '*skip*) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2228 (and (< col ses--numcols) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2229 (eq (ses-cell-value row (+ col count)) '*skip*))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2230 (setq has-skip t)) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2231 (ses-aset-with-undo ses--cells row |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2232 (ses-vector-delete (aref ses--cells row) col count))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2233 ;;Update globals |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2234 (ses-set-parameter 'ses--col-widths |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2235 (ses-vector-delete ses--col-widths col count)) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2236 (ses-set-parameter 'ses--col-printers |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2237 (ses-vector-delete ses--col-printers col count)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2238 (ses-reset-header-string) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2239 ;;Relocate variables and formulas |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2240 (ses-relocate-all 0 col 0 (- count)) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2241 (ses-destroy-cell-variable-range 0 (1- ses--numrows) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2242 ses--numcols (+ ses--numcols count -1)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2243 (if has-skip |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2244 (ses-reprint-all t) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2245 (ses-setup)) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2246 (if (>= col ses--numcols) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2247 (setq col (1- col))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2248 (ses-goto-print origrow col))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2249 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2250 (defun ses-forward-or-insert (&optional count) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2251 "Move to next cell in row, or inserts a new cell if already in last one, or |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2252 inserts a new row if at bottom of print area. Repeat COUNT times." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2253 (interactive "p") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2254 (ses-check-curcell 'end) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2255 (setq deactivate-mark t) ;Doesn't combine well with ranges |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2256 (dotimes (x count) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2257 (ses-set-curcell) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2258 (if (not ses--curcell) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2259 (progn ;At bottom of print area |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2260 (barf-if-buffer-read-only) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2261 (ses-insert-row 1)) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2262 (let ((col (cdr (ses-sym-rowcol ses--curcell)))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2263 (when (/= 32 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2264 (char-before (next-single-property-change (point) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2265 'intangible))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2266 ;;We're already in last nonskipped cell on line. Need to create a |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2267 ;;new column. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2268 (barf-if-buffer-read-only) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2269 (ses-insert-column (- count x) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2270 ses--numcols |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2271 (ses-col-width col) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2272 (ses-col-printer col))))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2273 (forward-char))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2274 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2275 (defun ses-append-row-jump-first-column () |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2276 "Insert a new row after current one and jumps to its first column." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2277 (interactive "*") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2278 (ses-check-curcell) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2279 (ses-begin-change) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2280 (beginning-of-line 2) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2281 (ses-set-curcell) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2282 (ses-insert-row 1)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2283 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2284 (defun ses-set-column-width (col newwidth) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2285 "Set the width of the current column." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2286 (interactive |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2287 (let ((col (cdr (progn (ses-check-curcell) (ses-sym-rowcol ses--curcell))))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2288 (barf-if-buffer-read-only) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2289 (list col |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2290 (if current-prefix-arg |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2291 (prefix-numeric-value current-prefix-arg) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2292 (read-from-minibuffer (format "Column %s width [currently %d]: " |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2293 (ses-column-letter col) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2294 (ses-col-width col)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2295 nil ;No initial contents |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2296 nil ;No override keymap |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2297 t ;Convert to Lisp object |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2298 nil ;No history |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2299 (number-to-string |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2300 (ses-col-width col))))))) ;Default value |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2301 (if (< newwidth 1) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2302 (error "Invalid column width")) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2303 (ses-begin-change) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2304 (ses-reset-header-string) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2305 (save-excursion |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2306 (let ((inhibit-quit t)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2307 (ses-adjust-print-width col (- newwidth (ses-col-width col))) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2308 (ses-set-parameter 'ses--col-widths newwidth col)) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2309 (dotimes (row ses--numrows) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2310 (ses-print-cell-new-width row col)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2311 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2312 |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
2313 ;;---------------------------------------------------------------------------- |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
2314 ;; Cut and paste, import and export |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
2315 ;;---------------------------------------------------------------------------- |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2316 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2317 (defadvice copy-region-as-kill (around ses-copy-region-as-kill |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2318 activate preactivate) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2319 "It doesn't make sense to copy read-only or intangible attributes into the |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2320 kill ring. It probably doesn't make sense to copy keymap properties. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2321 We'll assume copying front-sticky properties doesn't make sense, either. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2322 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2323 This advice also includes some SES-specific code because otherwise it's too |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2324 hard to override how mouse-1 works." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2325 (when (> beg end) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2326 (let ((temp beg)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2327 (setq beg end |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2328 end temp))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2329 (if (not (and (eq major-mode 'ses-mode) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2330 (eq (get-text-property beg 'read-only) 'ses) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2331 (eq (get-text-property (1- end) 'read-only) 'ses))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2332 ad-do-it ;Normal copy-region-as-kill |
59292
c8adcd0d5e2e
(copy-region-as-kill): Deactivate mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
58409
diff
changeset
|
2333 (kill-new (ses-copy-region beg end)) |
c8adcd0d5e2e
(copy-region-as-kill): Deactivate mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
58409
diff
changeset
|
2334 (if transient-mark-mode |
c8adcd0d5e2e
(copy-region-as-kill): Deactivate mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
58409
diff
changeset
|
2335 (setq deactivate-mark t)) |
c8adcd0d5e2e
(copy-region-as-kill): Deactivate mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
58409
diff
changeset
|
2336 nil)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2337 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2338 (defun ses-copy-region (beg end) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2339 "Treat the region as rectangular. Convert the intangible attributes to |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2340 SES attributes recording the contents of the cell as of the time of copying." |
85644
3704b3bdbf49
Make `ses--symbolic-formulas' a safe local variable.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
78884
diff
changeset
|
2341 (when (= end ses--data-marker) |
3704b3bdbf49
Make `ses--symbolic-formulas' a safe local variable.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
78884
diff
changeset
|
2342 ;;Avoid overflow situation |
3704b3bdbf49
Make `ses--symbolic-formulas' a safe local variable.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
78884
diff
changeset
|
2343 (setq end (1- ses--data-marker))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2344 (let* ((inhibit-point-motion-hooks t) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2345 (x (mapconcat 'ses-copy-region-helper |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2346 (extract-rectangle beg (1- end)) "\n"))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2347 (remove-text-properties 0 (length x) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2348 '(read-only t |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2349 intangible t |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2350 keymap t |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2351 front-sticky t) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2352 x) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2353 x)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2354 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2355 (defun ses-copy-region-helper (line) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2356 "Converts one line (of a rectangle being extracted from a spreadsheet) to |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2357 external form by attaching to each print cell a 'ses attribute that records |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2358 the corresponding data cell." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2359 (or (> (length line) 1) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2360 (error "Empty range")) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2361 (let ((inhibit-read-only t) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2362 (pos 0) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2363 mycell next sym rowcol) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2364 (while pos |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2365 (setq sym (get-text-property pos 'intangible line) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2366 next (next-single-property-change pos 'intangible line) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2367 rowcol (ses-sym-rowcol sym) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2368 mycell (ses-get-cell (car rowcol) (cdr rowcol))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2369 (put-text-property pos (or next (length line)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2370 'ses |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2371 (list (ses-cell-symbol mycell) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2372 (ses-cell-formula mycell) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2373 (ses-cell-printer mycell)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2374 line) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2375 (setq pos next))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2376 line) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2377 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2378 (defun ses-kill-override (beg end) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2379 "Generic override for any commands that kill text. We clear the killed |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2380 cells instead of deleting them." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2381 (interactive "r") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2382 (ses-check-curcell 'needrange) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2383 ;;For some reason, the text-read-only error is not caught by |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2384 ;;`delete-region', so we have to use subterfuge. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2385 (let ((buffer-read-only t)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2386 (1value (condition-case x |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2387 (noreturn (funcall (lookup-key (current-global-map) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2388 (this-command-keys)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2389 beg end)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2390 (buffer-read-only nil)))) ;The expected error |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2391 ;;Because the buffer was marked read-only, the kill command turned itself |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2392 ;;into a copy. Now we clear the cells or signal the error. First we |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2393 ;;check whether the buffer really is read-only. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2394 (barf-if-buffer-read-only) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2395 (ses-begin-change) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2396 (ses-dorange ses--curcell |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2397 (ses-clear-cell row col)) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2398 (ses-jump (car ses--curcell))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2399 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2400 (defadvice yank (around ses-yank activate preactivate) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2401 "In SES mode, the yanked text is inserted as cells. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2402 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2403 If the text contains 'ses attributes (meaning it went to the kill-ring from a |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2404 SES buffer), the formulas and print functions are restored for the cells. If |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2405 the text contains tabs, this is an insertion of tab-separated formulas. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2406 Otherwise the text is inserted as the formula for the current cell. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2407 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2408 When inserting cells, the formulas are usually relocated to keep the same |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2409 relative references to neighboring cells. This is best if the formulas |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2410 generally refer to other cells within the yanked text. You can use the C-u |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2411 prefix to specify insertion without relocation, which is best when the |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2412 formulas refer to cells outsite the yanked text. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2413 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2414 When inserting formulas, the text is treated as a string constant if it doesn't |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2415 make sense as a sexp or would otherwise be considered a symbol. Use 'sym to |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2416 explicitly insert a symbol, or use the C-u prefix to treat all unmarked words |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2417 as symbols." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2418 (if (not (and (eq major-mode 'ses-mode) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2419 (eq (get-text-property (point) 'keymap) 'ses-mode-print-map))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2420 ad-do-it ;Normal non-SES yank |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2421 (ses-check-curcell 'end) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2422 (push-mark (point)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2423 (let ((text (current-kill (cond |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2424 ((listp arg) 0) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2425 ((eq arg '-) -1) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2426 (t (1- arg)))))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2427 (or (ses-yank-cells text arg) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2428 (ses-yank-tsf text arg) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2429 (ses-yank-one (ses-yank-resize 1 1) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2430 text |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2431 0 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2432 (if (memq (aref text (1- (length text))) '(?\t ?\n)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2433 ;;Just one cell - delete final tab or newline |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2434 (1- (length text))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2435 arg))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2436 (if (consp arg) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2437 (exchange-point-and-mark)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2438 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2439 (defun ses-yank-pop (arg) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2440 "Replace just-yanked stretch of killed text with a different stretch. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2441 This command is allowed only immediately after a `yank' or a `yank-pop', when |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2442 the region contains a stretch of reinserted previously-killed text. We |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2443 replace it with a different stretch of killed text. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2444 Unlike standard `yank-pop', this function uses `undo' to delete the |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2445 previous insertion." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2446 (interactive "*p") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2447 (or (eq last-command 'yank) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2448 ;;Use noreturn here just to avoid a "poor-coverage" warning in its |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2449 ;;macro definition. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2450 (noreturn (error "Previous command was not a yank"))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2451 (undo) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2452 (ses-set-curcell) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2453 (yank (1+ (or arg 1))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2454 (setq this-command 'yank)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2455 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2456 (defun ses-yank-cells (text arg) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2457 "If the TEXT has a proper set of 'ses attributes, inserts the text as |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2458 cells, else return nil. The cells are reprinted--the supplied text is |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2459 ignored because the column widths, default printer, etc. at yank time might |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2460 be different from those at kill-time. ARG is a list to indicate that |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2461 formulas are to be inserted without relocation." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2462 (let ((first (get-text-property 0 'ses text)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2463 (last (get-text-property (1- (length text)) 'ses text))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2464 (when (and first last) ;;Otherwise not proper set of attributes |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2465 (setq first (ses-sym-rowcol (car first)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2466 last (ses-sym-rowcol (car last))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2467 (let* ((needrows (- (car last) (car first) -1)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2468 (needcols (- (cdr last) (cdr first) -1)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2469 (rowcol (ses-yank-resize needrows needcols)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2470 (rowincr (- (car rowcol) (car first))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2471 (colincr (- (cdr rowcol) (cdr first))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2472 (pos 0) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2473 myrow mycol x) |
59649
e57ef5d6d521
(ses-dotimes-msg): Remove macro. Use `dotimes-with-progress-reporter' instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59292
diff
changeset
|
2474 (dotimes-with-progress-reporter (row needrows) "Yanking..." |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2475 (setq myrow (+ row (car rowcol))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2476 (dotimes (col needcols) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2477 (setq mycol (+ col (cdr rowcol)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2478 last (get-text-property pos 'ses text) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2479 pos (next-single-property-change pos 'ses text) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2480 x (ses-sym-rowcol (car last))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2481 (if (not last) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2482 ;;Newline - all remaining cells on row are skipped |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2483 (setq x (cons (- myrow rowincr) (+ needcols colincr -1)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2484 last (list nil nil nil) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2485 pos (1- pos))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2486 (if (/= (car x) (- myrow rowincr)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2487 (error "Cell row error")) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2488 (if (< (- mycol colincr) (cdr x)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2489 ;;Some columns were skipped |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2490 (let ((oldcol mycol)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2491 (while (< (- mycol colincr) (cdr x)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2492 (ses-clear-cell myrow mycol) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2493 (setq col (1+ col) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2494 mycol (1+ mycol))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2495 (ses-print-cell myrow (1- oldcol)))) ;;This inserts *skip* |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2496 (when (car last) ;Skip this for *skip* cells |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2497 (setq x (nth 2 last)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2498 (unless (equal x (ses-cell-printer myrow mycol)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2499 (or (not x) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2500 (stringp x) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2501 (eq (car-safe x) 'ses-safe-printer) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2502 (setq x `(ses-safe-printer ,x))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2503 (ses-set-cell myrow mycol 'printer x)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2504 (setq x (cadr last)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2505 (if (atom arg) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2506 (setq x (ses-relocate-formula x 0 0 rowincr colincr))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2507 (or (atom x) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2508 (eq (car-safe x) 'ses-safe-formula) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2509 (setq x `(ses-safe-formula ,x))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2510 (ses-cell-set-formula myrow mycol x))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2511 (when pos |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2512 (if (get-text-property pos 'ses text) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2513 (error "Missing newline between rows")) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2514 (setq pos (next-single-property-change pos 'ses text)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2515 t)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2516 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2517 (defun ses-yank-one (rowcol text from to arg) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2518 "Insert the substring [FROM,TO] of TEXT as the formula for cell ROWCOL (a |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2519 cons of ROW and COL). Treat plain symbols as strings unless ARG is a list." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2520 (let ((val (condition-case nil |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2521 (read-from-string text from to) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2522 (error (cons nil from))))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2523 (cond |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2524 ((< (cdr val) (or to (length text))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2525 ;;Invalid sexp - leave it as a string |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2526 (setq val (substring text from to))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2527 ((and (car val) (symbolp (car val))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2528 (if (consp arg) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2529 (setq val (list 'quote (car val))) ;Keep symbol |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2530 (setq val (substring text from to)))) ;Treat symbol as text |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2531 (t |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2532 (setq val (car val)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2533 (let ((row (car rowcol)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2534 (col (cdr rowcol))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2535 (or (atom val) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2536 (setq val `(ses-safe-formula ,val))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2537 (ses-cell-set-formula row col val)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2538 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2539 (defun ses-yank-tsf (text arg) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2540 "If TEXT contains tabs and/or newlines, treats the tabs as |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2541 column-separators and the newlines as row-separators and inserts the text as |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2542 cell formulas--else return nil. Treat plain symbols as strings unless ARG |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2543 is a list. Ignore a final newline." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2544 (if (or (not (string-match "[\t\n]" text)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2545 (= (match-end 0) (length text))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2546 ;;Not TSF format |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2547 nil |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2548 (if (/= (aref text (1- (length text))) ?\n) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2549 (setq text (concat text "\n"))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2550 (let ((pos -1) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2551 (spots (list -1)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2552 (cols 0) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2553 (needrows 0) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2554 needcols rowcol) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2555 ;;Find all the tabs and newlines |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2556 (while (setq pos (string-match "[\t\n]" text (1+ pos))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2557 (push pos spots) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2558 (setq cols (1+ cols)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2559 (when (eq (aref text pos) ?\n) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2560 (if (not needcols) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2561 (setq needcols cols) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2562 (or (= needcols cols) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2563 (error "Inconsistent row lengths"))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2564 (setq cols 0 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2565 needrows (1+ needrows)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2566 ;;Insert the formulas |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2567 (setq rowcol (ses-yank-resize needrows needcols)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2568 (dotimes (row needrows) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2569 (dotimes (col needcols) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2570 (ses-yank-one (cons (+ (car rowcol) needrows (- row) -1) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2571 (+ (cdr rowcol) needcols (- col) -1)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2572 text (1+ (cadr spots)) (car spots) arg) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2573 (setq spots (cdr spots)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2574 (ses-goto-print (+ (car rowcol) needrows -1) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2575 (+ (cdr rowcol) needcols -1)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2576 t))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2577 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2578 (defun ses-yank-resize (needrows needcols) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2579 "If this yank will require inserting rows and/or columns, asks for |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2580 confirmation and then inserts them. Result is (row,col) for top left of yank |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2581 spot, or error signal if user requests cancel." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2582 (ses-begin-change) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2583 (let ((rowcol (if ses--curcell |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2584 (ses-sym-rowcol ses--curcell) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2585 (cons ses--numrows 0))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2586 rowbool colbool) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2587 (setq needrows (- (+ (car rowcol) needrows) ses--numrows) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2588 needcols (- (+ (cdr rowcol) needcols) ses--numcols) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2589 rowbool (> needrows 0) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2590 colbool (> needcols 0)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2591 (when (or rowbool colbool) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2592 ;;Need to insert. Get confirm |
65689
96187e7edd1b
2005-09-25 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents:
65582
diff
changeset
|
2593 (or (y-or-n-p (format "Yank will insert %s%s%s. Continue? " |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2594 (if rowbool (format "%d rows" needrows) "") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2595 (if (and rowbool colbool) " and " "") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2596 (if colbool (format "%d columns" needcols) ""))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2597 (error "Cancelled")) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2598 (when rowbool |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2599 (let (ses--curcell) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2600 (save-excursion |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2601 (ses-goto-print ses--numrows 0) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2602 (ses-insert-row needrows)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2603 (when colbool |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2604 (ses-insert-column needcols |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2605 ses--numcols |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2606 (ses-col-width (1- ses--numcols)) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2607 (ses-col-printer (1- ses--numcols))))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2608 rowcol)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2609 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2610 (defun ses-export-tsv (beg end) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2611 "Export values from the current range, with tabs between columns and |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2612 newlines between rows. Result is placed in kill ring." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2613 (interactive "r") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2614 (ses-export-tab nil)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2615 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2616 (defun ses-export-tsf (beg end) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2617 "Export formulas from the current range, with tabs between columns and |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2618 newlines between rows. Result is placed in kill ring." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2619 (interactive "r") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2620 (ses-export-tab t)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2621 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2622 (defun ses-export-tab (want-formulas) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2623 "Export the current range with tabs between columns and newlines between |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2624 rows. Result is placed in kill ring. The export is values unless |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2625 WANT-FORMULAS is non-nil. Newlines and tabs in the export text are escaped." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2626 (ses-check-curcell 'needrange) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2627 (let ((print-escape-newlines t) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2628 result item) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2629 (ses-dorange ses--curcell |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2630 (setq item (if want-formulas |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2631 (ses-cell-formula row col) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2632 (ses-cell-value row col))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2633 (if (eq (car-safe item) 'ses-safe-formula) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2634 ;;Hide our deferred safety-check marker |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2635 (setq item (cadr item))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2636 (if (or (not item) (eq item '*skip*)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2637 (setq item "")) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2638 (when (eq (car-safe item) 'quote) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2639 (push "'" result) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2640 (setq item (cadr item))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2641 (setq item (prin1-to-string item t)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2642 (setq item (replace-regexp-in-string "\t" "\\\\t" item)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2643 (push item result) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2644 (cond |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2645 ((< col maxcol) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2646 (push "\t" result)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2647 ((< row maxrow) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2648 (push "\n" result)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2649 (setq result (apply 'concat (nreverse result))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2650 (kill-new result))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2651 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2652 |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
2653 ;;---------------------------------------------------------------------------- |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
2654 ;; Other user commands |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
2655 ;;---------------------------------------------------------------------------- |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2656 |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2657 (defun ses-unset-header-row () |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2658 "Select the default header row." |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2659 (interactive) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2660 (ses-set-header-row 0)) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2661 |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2662 (defun ses-set-header-row (row) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2663 "Set the ROW to display in the header-line. |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2664 With a numerical prefix arg, use that row. |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2665 With no prefix arg, use the current row. |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2666 With a \\[universal-argument] prefix arg, prompt the user. |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2667 The top row is row 1. Selecting row 0 displays the default header row." |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2668 (interactive |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2669 (list (if (numberp current-prefix-arg) current-prefix-arg |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2670 (let ((currow (1+ (car (ses-sym-rowcol ses--curcell))))) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2671 (if current-prefix-arg |
54571
54265a0f59a7
(ses-read-number): Move to subr.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53944
diff
changeset
|
2672 (read-number "Header row: " currow) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2673 currow))))) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2674 (if (or (< row 0) (> row ses--numrows)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2675 (error "Invalid header-row")) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2676 (ses-begin-change) |
70964
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
2677 (let ((oldval ses--header-row)) |
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
2678 (let (buffer-undo-list) |
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
2679 (ses-set-parameter 'ses--header-row row)) |
e5adfcfcffa0
* ses.el (defadvice undo-more): Delete this defadvice. The undo
Jonathan Yavner <jyavner@member.fsf.org>
parents:
68359
diff
changeset
|
2680 (push `(apply ses-set-header-row ,oldval) buffer-undo-list)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2681 (ses-reset-header-string)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2682 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2683 (defun ses-mark-row () |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2684 "Marks the entirety of current row as a range." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2685 (interactive) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2686 (ses-check-curcell 'range) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2687 (let ((row (car (ses-sym-rowcol (or (car-safe ses--curcell) ses--curcell))))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2688 (push-mark (point)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2689 (ses-goto-print (1+ row) 0) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2690 (push-mark (point) nil t) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2691 (ses-goto-print row 0))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2692 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2693 (defun ses-mark-column () |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2694 "Marks the entirety of current column as a range." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2695 (interactive) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2696 (ses-check-curcell 'range) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2697 (let ((col (cdr (ses-sym-rowcol (or (car-safe ses--curcell) ses--curcell)))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2698 (row 0)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2699 (push-mark (point)) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2700 (ses-goto-print (1- ses--numrows) col) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2701 (forward-char 1) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2702 (push-mark (point) nil t) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2703 (while (eq '*skip* (ses-cell-value row col)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2704 ;;Skip over initial cells in column that can't be selected |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2705 (setq row (1+ row))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2706 (ses-goto-print row col))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2707 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2708 (defun ses-end-of-line () |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2709 "Move point to last cell on line." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2710 (interactive) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2711 (ses-check-curcell 'end 'range) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2712 (when ses--curcell ;Otherwise we're at the bottom row, which is empty anyway |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2713 (let ((col (1- ses--numcols)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2714 row rowcol) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2715 (if (symbolp ses--curcell) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2716 ;;Single cell |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2717 (setq row (car (ses-sym-rowcol ses--curcell))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2718 ;;Range - use whichever end of the range the point is at |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2719 (setq rowcol (ses-sym-rowcol (if (< (point) (mark)) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2720 (car ses--curcell) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2721 (cdr ses--curcell)))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2722 ;;If range already includes the last cell in a row, point is actually |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2723 ;;in the following row |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2724 (if (<= (cdr rowcol) (1- col)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2725 (setq row (car rowcol)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2726 (setq row (1+ (car rowcol))) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2727 (if (= row ses--numrows) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2728 ;;Already at end - can't go anywhere |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2729 (setq col 0)))) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2730 (when (< row ses--numrows) ;Otherwise it's a range that includes last cell |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2731 (while (eq (ses-cell-value row col) '*skip*) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2732 ;;Back to beginning of multi-column cell |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2733 (setq col (1- col))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2734 (ses-goto-print row col))))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2735 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2736 (defun ses-renarrow-buffer () |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2737 "Narrow the buffer so only the print area is visible. Use after \\[widen]." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2738 (interactive) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2739 (setq ses--deferred-narrow t)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2740 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2741 (defun ses-sort-column (sorter &optional reverse) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2742 "Sorts the range by a specified column. With prefix, sorts in |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2743 REVERSE order." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2744 (interactive "*sSort column: \nP") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2745 (ses-check-curcell 'needrange) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2746 (let ((min (ses-sym-rowcol (car ses--curcell))) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2747 (max (ses-sym-rowcol (cdr ses--curcell)))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2748 (let ((minrow (car min)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2749 (mincol (cdr min)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2750 (maxrow (car max)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2751 (maxcol (cdr max)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2752 keys extracts end) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2753 (setq sorter (cdr (ses-sym-rowcol (intern (concat sorter "1"))))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2754 (or (and sorter (>= sorter mincol) (<= sorter maxcol)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2755 (error "Invalid sort column")) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2756 ;;Get key columns and sort them |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2757 (dotimes (x (- maxrow minrow -1)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2758 (ses-goto-print (+ minrow x) sorter) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2759 (setq end (next-single-property-change (point) 'intangible)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2760 (push (cons (buffer-substring-no-properties (point) end) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2761 (+ minrow x)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2762 keys)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2763 (setq keys (sort keys #'(lambda (x y) (string< (car x) (car y))))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2764 ;;Extract the lines in reverse sorted order |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2765 (or reverse |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2766 (setq keys (nreverse keys))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2767 (dolist (x keys) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2768 (ses-goto-print (cdr x) (1+ maxcol)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2769 (setq end (point)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2770 (ses-goto-print (cdr x) mincol) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2771 (push (ses-copy-region (point) end) extracts)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2772 (deactivate-mark) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2773 ;;Paste the lines sequentially |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2774 (dotimes (x (- maxrow minrow -1)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2775 (ses-goto-print (+ minrow x) mincol) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2776 (ses-set-curcell) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2777 (ses-yank-cells (pop extracts) nil))))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2778 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2779 (defun ses-sort-column-click (event reverse) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2780 "Mouse version of `ses-sort-column'." |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2781 (interactive "*e\nP") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2782 (setq event (event-end event)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2783 (select-window (posn-window event)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2784 (setq event (car (posn-col-row event))) ;Click column |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2785 (let ((col 0)) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2786 (while (and (< col ses--numcols) (> event (ses-col-width col))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2787 (setq event (- event (ses-col-width col) 1) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2788 col (1+ col))) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2789 (if (>= col ses--numcols) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2790 (ding) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2791 (ses-sort-column (ses-column-letter col) reverse)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2792 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2793 (defun ses-insert-range () |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2794 "Inserts into minibuffer the list of cells currently highlighted in the |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2795 spreadsheet." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2796 (interactive "*") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2797 (let (x) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2798 (with-current-buffer (window-buffer minibuffer-scroll-window) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2799 (ses-command-hook) ;For ses-coverage |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2800 (ses-check-curcell 'needrange) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2801 (setq x (cdr (macroexpand `(ses-range ,(car ses--curcell) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2802 ,(cdr ses--curcell)))))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2803 (insert (substring (prin1-to-string (nreverse x)) 1 -1)))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2804 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2805 (defun ses-insert-ses-range () |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2806 "Inserts \"(ses-range x y)\" in the minibuffer to represent the currently |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2807 highlighted range in the spreadsheet." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2808 (interactive "*") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2809 (let (x) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2810 (with-current-buffer (window-buffer minibuffer-scroll-window) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2811 (ses-command-hook) ;For ses-coverage |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2812 (ses-check-curcell 'needrange) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2813 (setq x (format "(ses-range %S %S)" |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2814 (car ses--curcell) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2815 (cdr ses--curcell)))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2816 (insert x))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2817 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2818 (defun ses-insert-range-click (event) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2819 "Mouse version of `ses-insert-range'." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2820 (interactive "*e") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2821 (mouse-set-point event) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2822 (ses-insert-range)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2823 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2824 (defun ses-insert-ses-range-click (event) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2825 "Mouse version of `ses-insert-ses-range'." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2826 (interactive "*e") |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2827 (mouse-set-point event) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2828 (ses-insert-ses-range)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2829 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2830 |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
2831 ;;---------------------------------------------------------------------------- |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
2832 ;; Checking formulas for safety |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
2833 ;;---------------------------------------------------------------------------- |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2834 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2835 (defun ses-safe-printer (printer) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2836 "Returns PRINTER if safe, or the substitute printer `ses-unsafe' otherwise." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2837 (if (or (stringp printer) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2838 (stringp (car-safe printer)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2839 (not printer) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2840 (ses-warn-unsafe printer 'unsafep-function)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2841 printer |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2842 'ses-unsafe)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2843 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2844 (defun ses-safe-formula (formula) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2845 "Returns FORMULA if safe, or the substitute formula *unsafe* otherwise." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2846 (if (ses-warn-unsafe formula 'unsafep) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2847 formula |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2848 `(ses-unsafe ',formula))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2849 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2850 (defun ses-warn-unsafe (formula checker) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2851 "Applies CHECKER to FORMULA. If result is non-nil, asks user for |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2852 confirmation about FORMULA, which might be unsafe. Returns t if formula |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2853 is safe or user allows execution anyway. Always returns t if |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2854 `safe-functions' is t." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2855 (if (eq safe-functions t) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2856 t |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2857 (setq checker (funcall checker formula)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2858 (if (not checker) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2859 t |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2860 (y-or-n-p (format "Formula %S\nmight be unsafe %S. Process it? " |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2861 formula checker))))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2862 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2863 |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
2864 ;;---------------------------------------------------------------------------- |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
2865 ;; Standard formulas |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
2866 ;;---------------------------------------------------------------------------- |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2867 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2868 (defmacro ses-range (from to) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2869 "Expands to a list of cell-symbols for the range. The range automatically |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2870 expands to include any new row or column inserted into its middle. The SES |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2871 library code specifically looks for the symbol `ses-range', so don't create an |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2872 alias for this macro!" |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2873 (let (result) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2874 (ses-dorange (cons from to) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2875 (push (ses-cell-symbol row col) result)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2876 (cons 'list result))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2877 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2878 (defun ses-delete-blanks (&rest args) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2879 "Return ARGS reversed, with the blank elements (nil and *skip*) removed." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2880 (let (result) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2881 (dolist (cur args) |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
2882 (unless (memq cur '(nil *skip*)) |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
2883 (push cur result))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2884 result)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2885 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2886 (defun ses+ (&rest args) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2887 "Compute the sum of the arguments, ignoring blanks." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2888 (apply '+ (apply 'ses-delete-blanks args))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2889 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2890 (defun ses-average (list) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2891 "Computes the sum of the numbers in LIST, divided by their length. Blanks |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2892 are ignored. Result is always floating-point, even if all args are integers." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2893 (setq list (apply 'ses-delete-blanks list)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2894 (/ (float (apply '+ list)) (length list))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2895 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2896 (defmacro ses-select (fromrange test torange) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2897 "Select cells in FROMRANGE that are `equal' to TEST. For each match, return |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2898 the corresponding cell from TORANGE. The ranges are macroexpanded but not |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2899 evaluated so they should be either (ses-range BEG END) or (list ...). The |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2900 TEST is evaluated." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2901 (setq fromrange (cdr (macroexpand fromrange)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2902 torange (cdr (macroexpand torange)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2903 test (eval test)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2904 (or (= (length fromrange) (length torange)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2905 (error "ses-select: Ranges not same length")) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2906 (let (result) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2907 (dolist (x fromrange) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2908 (if (equal test (symbol-value x)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2909 (push (car torange) result)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2910 (setq torange (cdr torange))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2911 (cons 'list result))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2912 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2913 ;;All standard formulas are safe |
73160
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
2914 (dolist (x '(ses-cell-value ses-range ses-delete-blanks ses+ ses-average |
78e299b7e214
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
70964
diff
changeset
|
2915 ses-select)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2916 (put x 'side-effect-free t)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2917 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2918 |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
2919 ;;---------------------------------------------------------------------------- |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
2920 ;; Standard print functions |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
2921 ;;---------------------------------------------------------------------------- |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2922 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2923 ;;These functions use the variables 'row' and 'col' that are |
79258
7ddb2a8509d7
(ses-unload-function): New function.
Juanma Barranquero <lekktu@gmail.com>
parents:
78884
diff
changeset
|
2924 ;;dynamically bound by ses-print-cell. We define these variables at |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2925 ;;compile-time to make the compiler happy. |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2926 (eval-when-compile |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2927 (dolist (x '(row col)) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2928 (make-local-variable x) |
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2929 (set x nil))) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2930 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2931 (defun ses-center (value &optional span fill) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2932 "Print VALUE, centered within column. FILL is the fill character for |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2933 centering (default = space). SPAN indicates how many additional rightward |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2934 columns to include in width (default = 0)." |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2935 (let ((printer (or (ses-col-printer col) ses--default-printer)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2936 (width (ses-col-width col)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2937 half) |
64020
463e088b8531
(ses): Finish `defgroup' description with period.
Juanma Barranquero <lekktu@gmail.com>
parents:
63622
diff
changeset
|
2938 (or fill (setq fill ?\s)) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2939 (or span (setq span 0)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2940 (setq value (ses-call-printer printer value)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2941 (dotimes (x span) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2942 (setq width (+ width 1 (ses-col-width (+ col span (- x)))))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2943 (setq width (- width (length value))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2944 (if (<= width 0) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2945 value ;Too large for field, anyway |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2946 (setq half (make-string (/ width 2) fill)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2947 (concat half value half |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2948 (if (> (% width 2) 0) (char-to-string fill)))))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2949 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2950 (defun ses-center-span (value &optional fill) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2951 "Print VALUE, centered within the span that starts in the current column |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2952 and continues until the next nonblank column. FILL specifies the fill |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2953 character (default = space)." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2954 (let ((end (1+ col))) |
53944
e647f66db84b
Delete function ses-build-load-map and distribute its functions to
Jonathan Yavner <jyavner@member.fsf.org>
parents:
53758
diff
changeset
|
2955 (while (and (< end ses--numcols) |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2956 (memq (ses-cell-value row end) '(nil *skip*))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2957 (setq end (1+ end))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2958 (ses-center value (- end col 1) fill))) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2959 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2960 (defun ses-dashfill (value &optional span) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2961 "Print VALUE centered using dashes. SPAN indicates how many rightward |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2962 columns to include in width (default = 0)." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2963 (ses-center value span ?-)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2964 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2965 (defun ses-dashfill-span (value) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2966 "Print VALUE, centered using dashes within the span that starts in the |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2967 current column and continues until the next nonblank column." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2968 (ses-center-span value ?-)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2969 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2970 (defun ses-tildefill-span (value) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2971 "Print VALUE, centered using tildes within the span that starts in the |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2972 current column and continues until the next nonblank column." |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2973 (ses-center-span value ?~)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2974 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2975 (defun ses-unsafe (value) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2976 "Substitute for an unsafe formula or printer" |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2977 (error "Unsafe formula or printer")) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2978 |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2979 ;;All standard printers are safe, including ses-unsafe! |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2980 (dolist (x (cons 'ses-unsafe ses-standard-printer-functions)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2981 (put x 'side-effect-free t)) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2982 |
79258
7ddb2a8509d7
(ses-unload-function): New function.
Juanma Barranquero <lekktu@gmail.com>
parents:
78884
diff
changeset
|
2983 (defun ses-unload-function () |
7ddb2a8509d7
(ses-unload-function): New function.
Juanma Barranquero <lekktu@gmail.com>
parents:
78884
diff
changeset
|
2984 "Unload the Simple Emacs Spreadsheet." |
7ddb2a8509d7
(ses-unload-function): New function.
Juanma Barranquero <lekktu@gmail.com>
parents:
78884
diff
changeset
|
2985 (dolist (fun '(copy-region-as-kill yank)) |
7ddb2a8509d7
(ses-unload-function): New function.
Juanma Barranquero <lekktu@gmail.com>
parents:
78884
diff
changeset
|
2986 (ad-remove-advice fun 'around (intern (concat "ses-" (symbol-name fun)))) |
7ddb2a8509d7
(ses-unload-function): New function.
Juanma Barranquero <lekktu@gmail.com>
parents:
78884
diff
changeset
|
2987 (ad-update fun)) |
7ddb2a8509d7
(ses-unload-function): New function.
Juanma Barranquero <lekktu@gmail.com>
parents:
78884
diff
changeset
|
2988 (save-current-buffer |
7ddb2a8509d7
(ses-unload-function): New function.
Juanma Barranquero <lekktu@gmail.com>
parents:
78884
diff
changeset
|
2989 (dolist (buf (buffer-list)) |
7ddb2a8509d7
(ses-unload-function): New function.
Juanma Barranquero <lekktu@gmail.com>
parents:
78884
diff
changeset
|
2990 (set-buffer buf) |
7ddb2a8509d7
(ses-unload-function): New function.
Juanma Barranquero <lekktu@gmail.com>
parents:
78884
diff
changeset
|
2991 (when (eq major-mode 'ses-mode) |
7ddb2a8509d7
(ses-unload-function): New function.
Juanma Barranquero <lekktu@gmail.com>
parents:
78884
diff
changeset
|
2992 (funcall (or default-major-mode 'fundamental-mode))))) |
7ddb2a8509d7
(ses-unload-function): New function.
Juanma Barranquero <lekktu@gmail.com>
parents:
78884
diff
changeset
|
2993 ;; continue standard unloading |
7ddb2a8509d7
(ses-unload-function): New function.
Juanma Barranquero <lekktu@gmail.com>
parents:
78884
diff
changeset
|
2994 nil) |
7ddb2a8509d7
(ses-unload-function): New function.
Juanma Barranquero <lekktu@gmail.com>
parents:
78884
diff
changeset
|
2995 |
47667
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2996 (provide 'ses) |
96b260e0ff3d
New major mode "SES" for spreadsheets.
Jonathan Yavner <jyavner@member.fsf.org>
parents:
diff
changeset
|
2997 |
58409
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
2998 ;; arch-tag: 88c1ccf0-4293-4824-8c5d-0757b52217f3 |
924fa48ab4bf
Add coding cookie. Fix up docstrings, follow new commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55366
diff
changeset
|
2999 ;;; ses.el ends here |