diff options
| author | Jonathan Yavner | 2006-09-29 02:42:39 +0000 |
|---|---|---|
| committer | Jonathan Yavner | 2006-09-29 02:42:39 +0000 |
| commit | ddd1c21447db672398ad78fcff301aa2602eda08 (patch) | |
| tree | fb8ab81127517af1ed06a5afb89442b91a931ccc | |
| parent | 354f1cb332c14fa4db3da7e0459692da644612a3 (diff) | |
| download | emacs-ddd1c21447db672398ad78fcff301aa2602eda08.tar.gz emacs-ddd1c21447db672398ad78fcff301aa2602eda08.zip | |
Make undo of "insert row" work by keeping markers for data-area and parameters-area.
| -rw-r--r-- | lisp/ChangeLog | 7 | ||||
| -rw-r--r-- | lisp/ses.el | 101 |
2 files changed, 63 insertions, 45 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index e637915d3b0..aaa9e69e340 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2006-09-28 Jonathan Yavner <jyavner@member.fsf.org> | ||
| 2 | |||
| 3 | * ses.el (ses-in-print-area, ses-goto-data, ses-load) | ||
| 4 | (ses-reconstruct-all): Make undo of "insert row" work by keeping | ||
| 5 | markers for data-area and parameters-area. | ||
| 6 | |||
| 1 | 2006-09-28 Stefan Monnier <monnier@iro.umontreal.ca> | 7 | 2006-09-28 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 8 | ||
| 3 | * progmodes/make-mode.el (makefile-mode): Don't disable jit-lock. | 9 | * progmodes/make-mode.el (makefile-mode): Don't disable jit-lock. |
| @@ -76,7 +82,6 @@ | |||
| 76 | continued lines. | 82 | continued lines. |
| 77 | (line-move-1): Remove flawed test for that case. | 83 | (line-move-1): Remove flawed test for that case. |
| 78 | 84 | ||
| 79 | >>>>>>> 1.10122 | ||
| 80 | 2006-09-24 Ken Manheimer <ken.manheimer@gmail.com> | 85 | 2006-09-24 Ken Manheimer <ken.manheimer@gmail.com> |
| 81 | 86 | ||
| 82 | * icomplete.el (icomplete-simple-completing-p): Use the correct | 87 | * icomplete.el (icomplete-simple-completing-p): Use the correct |
diff --git a/lisp/ses.el b/lisp/ses.el index fc594167187..85f6f8db378 100644 --- a/lisp/ses.el +++ b/lisp/ses.el | |||
| @@ -237,13 +237,6 @@ Each function is called with ARG=1." | |||
| 237 | ses-initial-file-trailer) | 237 | ses-initial-file-trailer) |
| 238 | "The initial contents of an empty spreadsheet.") | 238 | "The initial contents of an empty spreadsheet.") |
| 239 | 239 | ||
| 240 | (defconst ses-paramlines-plist | ||
| 241 | '(ses--col-widths 2 ses--col-printers 3 ses--default-printer 4 | ||
| 242 | ses--header-row 5 ses--file-format 8 ses--numrows 9 | ||
| 243 | ses--numcols 10) | ||
| 244 | "Offsets from last cell line to various parameter lines in the data area | ||
| 245 | of a spreadsheet.") | ||
| 246 | |||
| 247 | (defconst ses-box-prop '(:box (:line-width 2 :style released-button)) | 240 | (defconst ses-box-prop '(:box (:line-width 2 :style released-button)) |
| 248 | "Display properties to create a raised box for cells in the header line.") | 241 | "Display properties to create a raised box for cells in the header line.") |
| 249 | 242 | ||
| @@ -255,13 +248,19 @@ functions. None of these standard-printer functions is suitable for use as a | |||
| 255 | column printer or a global-default printer because they invoke the column or | 248 | column printer or a global-default printer because they invoke the column or |
| 256 | default printer and then modify its output.") | 249 | default printer and then modify its output.") |
| 257 | 250 | ||
| 251 | |||
| 252 | ;;---------------------------------------------------------------------------- | ||
| 253 | ;; Local variables and constants | ||
| 254 | ;;---------------------------------------------------------------------------- | ||
| 255 | |||
| 258 | (eval-and-compile | 256 | (eval-and-compile |
| 259 | (defconst ses-localvars | 257 | (defconst ses-localvars |
| 260 | '(ses--blank-line ses--cells ses--col-printers ses--col-widths ses--curcell | 258 | '(ses--blank-line ses--cells ses--col-printers ses--col-widths ses--curcell |
| 261 | ses--curcell-overlay ses--default-printer ses--deferred-narrow | 259 | ses--curcell-overlay ses--default-printer ses--deferred-narrow |
| 262 | ses--deferred-recalc ses--deferred-write ses--file-format | 260 | ses--deferred-recalc ses--deferred-write ses--file-format |
| 263 | ses--header-hscroll ses--header-row ses--header-string ses--linewidth | 261 | ses--header-hscroll ses--header-row ses--header-string ses--linewidth |
| 264 | ses--numcols ses--numrows ses--symbolic-formulas | 262 | ses--numcols ses--numrows ses--symbolic-formulas ses--data-marker |
| 263 | ses--params-marker | ||
| 265 | ;;Global variables that we override | 264 | ;;Global variables that we override |
| 266 | mode-line-process next-line-add-newlines transient-mark-mode) | 265 | mode-line-process next-line-add-newlines transient-mark-mode) |
| 267 | "Buffer-local variables used by SES.")) | 266 | "Buffer-local variables used by SES.")) |
| @@ -272,6 +271,13 @@ default printer and then modify its output.") | |||
| 272 | (make-local-variable x) | 271 | (make-local-variable x) |
| 273 | (set x nil))) | 272 | (set x nil))) |
| 274 | 273 | ||
| 274 | (defconst ses-paramlines-plist | ||
| 275 | '(ses--col-widths -5 ses--col-printers -4 ses--default-printer -3 | ||
| 276 | ses--header-row -2 ses--file-format 1 ses--numrows 2 | ||
| 277 | ses--numcols 3) | ||
| 278 | "Offsets from 'Global parameters' line to various parameter lines in the | ||
| 279 | data area of a spreadsheet.") | ||
| 280 | |||
| 275 | 281 | ||
| 276 | ;; | 282 | ;; |
| 277 | ;; "Side-effect variables". They are set in one function, altered in | 283 | ;; "Side-effect variables". They are set in one function, altered in |
| @@ -408,6 +414,7 @@ for safety. This is a macro to prevent propagate-on-load viruses." | |||
| 408 | "Execute BODY repeatedly, with the variables `row' and `col' set to each | 414 | "Execute BODY repeatedly, with the variables `row' and `col' set to each |
| 409 | cell in the range specified by CURCELL. The range is available in the | 415 | cell in the range specified by CURCELL. The range is available in the |
| 410 | variables `minrow', `maxrow', `mincol', and `maxcol'." | 416 | variables `minrow', `maxrow', `mincol', and `maxcol'." |
| 417 | (declare (indent defun) (debug (form body))) | ||
| 411 | (let ((cur (make-symbol "cur")) | 418 | (let ((cur (make-symbol "cur")) |
| 412 | (min (make-symbol "min")) | 419 | (min (make-symbol "min")) |
| 413 | (max (make-symbol "max")) | 420 | (max (make-symbol "max")) |
| @@ -429,9 +436,6 @@ variables `minrow', `maxrow', `mincol', and `maxcol'." | |||
| 429 | (setq col (+ ,c mincol)) | 436 | (setq col (+ ,c mincol)) |
| 430 | ,@body)))))) | 437 | ,@body)))))) |
| 431 | 438 | ||
| 432 | (put 'ses-dorange 'lisp-indent-function 'defun) | ||
| 433 | (def-edebug-spec ses-dorange (form body)) | ||
| 434 | |||
| 435 | ;;Support for coverage testing. | 439 | ;;Support for coverage testing. |
| 436 | (defmacro 1value (form) | 440 | (defmacro 1value (form) |
| 437 | "For code-coverage testing, indicate that FORM is expected to always have | 441 | "For code-coverage testing, indicate that FORM is expected to always have |
| @@ -650,7 +654,7 @@ the old and FORCE is nil." | |||
| 650 | (defun ses-update-cells (list &optional force) | 654 | (defun ses-update-cells (list &optional force) |
| 651 | "Recalculate cells in LIST, checking for dependency loops. Prints | 655 | "Recalculate cells in LIST, checking for dependency loops. Prints |
| 652 | progress messages every second. Dependent cells are not recalculated | 656 | progress messages every second. Dependent cells are not recalculated |
| 653 | if the cell's value is unchanged if FORCE is nil." | 657 | if the cell's value is unchanged and FORCE is nil." |
| 654 | (let ((ses--deferred-recalc list) | 658 | (let ((ses--deferred-recalc list) |
| 655 | (nextlist list) | 659 | (nextlist list) |
| 656 | (pos (point)) | 660 | (pos (point)) |
| @@ -709,7 +713,7 @@ if the cell's value is unchanged if FORCE is nil." | |||
| 709 | 713 | ||
| 710 | (defun ses-in-print-area () | 714 | (defun ses-in-print-area () |
| 711 | "Returns t if point is in print area of spreadsheet." | 715 | "Returns t if point is in print area of spreadsheet." |
| 712 | (eq (get-text-property (point) 'keymap) 'ses-mode-print-map)) | 716 | (<= (point) ses--data-marker)) |
| 713 | 717 | ||
| 714 | ;;We turn off point-motion-hooks and explicitly position the cursor, in case | 718 | ;;We turn off point-motion-hooks and explicitly position the cursor, in case |
| 715 | ;;the intangible properties have gotten screwed up (e.g., when | 719 | ;;the intangible properties have gotten screwed up (e.g., when |
| @@ -953,14 +957,16 @@ is one of the symbols ses--col-widths, ses--col-printers, | |||
| 953 | ses--default-printer, ses--numrows, or ses--numcols." | 957 | ses--default-printer, ses--numrows, or ses--numcols." |
| 954 | (ses-widen) | 958 | (ses-widen) |
| 955 | (let ((inhibit-point-motion-hooks t)) ;In case intangible attrs are wrong | 959 | (let ((inhibit-point-motion-hooks t)) ;In case intangible attrs are wrong |
| 956 | (goto-char (point-min)) | ||
| 957 | (if col | 960 | (if col |
| 958 | ;;It's a cell | 961 | ;;It's a cell |
| 959 | (forward-line (+ ses--numrows 2 (* def (1+ ses--numcols)) col)) | 962 | (progn |
| 960 | ;;Convert def-symbol to offset | 963 | (goto-char ses--data-marker) |
| 961 | (setq def (plist-get ses-paramlines-plist def)) | 964 | (forward-line (+ 1 (* def (1+ ses--numcols)) col))) |
| 962 | (or def (signal 'args-out-of-range nil)) | 965 | ;;Convert def-symbol to offset |
| 963 | (forward-line (+ (* ses--numrows (+ ses--numcols 2)) def))))) | 966 | (setq def (plist-get ses-paramlines-plist def)) |
| 967 | (or def (signal 'args-out-of-range nil)) | ||
| 968 | (goto-char ses--params-marker) | ||
| 969 | (forward-line def)))) | ||
| 964 | 970 | ||
| 965 | (defun ses-set-parameter (def value &optional elem) | 971 | (defun ses-set-parameter (def value &optional elem) |
| 966 | "Set parameter DEF to VALUE (with undo) and write the value to the data area. | 972 | "Set parameter DEF to VALUE (with undo) and write the value to the data area. |
| @@ -1070,6 +1076,23 @@ or t to get a wrong-type-argument error when the first reference is found." | |||
| 1070 | )))) | 1076 | )))) |
| 1071 | result-so-far) | 1077 | result-so-far) |
| 1072 | 1078 | ||
| 1079 | (defsubst ses-relocate-symbol (sym rowcol startrow startcol rowincr colincr) | ||
| 1080 | "Relocate one symbol SYM, whichs corresponds to ROWCOL (a cons of ROW and | ||
| 1081 | COL). Cells starting at (STARTROW,STARTCOL) are being shifted | ||
| 1082 | by (ROWINCR,COLINCR)." | ||
| 1083 | (let ((row (car rowcol)) | ||
| 1084 | (col (cdr rowcol))) | ||
| 1085 | (if (or (< row startrow) (< col startcol)) | ||
| 1086 | sym | ||
| 1087 | (setq row (+ row rowincr) | ||
| 1088 | col (+ col colincr)) | ||
| 1089 | (if (and (>= row startrow) (>= col startcol) | ||
| 1090 | (< row ses--numrows) (< col ses--numcols)) | ||
| 1091 | ;;Relocate this variable | ||
| 1092 | (ses-create-cell-symbol row col) | ||
| 1093 | ;;Delete reference to a deleted cell | ||
| 1094 | nil)))) | ||
| 1095 | |||
| 1073 | (defun ses-relocate-formula (formula startrow startcol rowincr colincr) | 1096 | (defun ses-relocate-formula (formula startrow startcol rowincr colincr) |
| 1074 | "Produce a copy of FORMULA where all symbols that refer to cells in row | 1097 | "Produce a copy of FORMULA where all symbols that refer to cells in row |
| 1075 | STARTROW or above and col STARTCOL or above are altered by adding ROWINCR | 1098 | STARTROW or above and col STARTCOL or above are altered by adding ROWINCR |
| @@ -1114,23 +1137,6 @@ Sets `ses-relocate-return' to 'delete if cell-references were removed." | |||
| 1114 | result)))) | 1137 | result)))) |
| 1115 | (nreverse result)))) | 1138 | (nreverse result)))) |
| 1116 | 1139 | ||
| 1117 | (defun ses-relocate-symbol (sym rowcol startrow startcol rowincr colincr) | ||
| 1118 | "Relocate one symbol SYM, whichs corresponds to ROWCOL (a cons of ROW and | ||
| 1119 | COL). Cells starting at (STARTROW,STARTCOL) are being shifted | ||
| 1120 | by (ROWINCR,COLINCR)." | ||
| 1121 | (let ((row (car rowcol)) | ||
| 1122 | (col (cdr rowcol))) | ||
| 1123 | (if (or (< row startrow) (< col startcol)) | ||
| 1124 | sym | ||
| 1125 | (setq row (+ row rowincr) | ||
| 1126 | col (+ col colincr)) | ||
| 1127 | (if (and (>= row startrow) (>= col startcol) | ||
| 1128 | (< row ses--numrows) (< col ses--numcols)) | ||
| 1129 | ;;Relocate this variable | ||
| 1130 | (ses-create-cell-symbol row col) | ||
| 1131 | ;;Delete reference to a deleted cell | ||
| 1132 | nil)))) | ||
| 1133 | |||
| 1134 | (defun ses-relocate-range (range startrow startcol rowincr colincr) | 1140 | (defun ses-relocate-range (range startrow startcol rowincr colincr) |
| 1135 | "Relocate one RANGE, of the form '(ses-range min max). Cells starting | 1141 | "Relocate one RANGE, of the form '(ses-range min max). Cells starting |
| 1136 | at (STARTROW,STARTCOL) are being shifted by (ROWINCR,COLINCR). Result is the | 1142 | at (STARTROW,STARTCOL) are being shifted by (ROWINCR,COLINCR). Result is the |
| @@ -1337,6 +1343,7 @@ execute cell formulas or print functions." | |||
| 1337 | (goto-char (point-max)) | 1343 | (goto-char (point-max)) |
| 1338 | (search-backward ";; Local Variables:\n" nil t) | 1344 | (search-backward ";; Local Variables:\n" nil t) |
| 1339 | (backward-list 1) | 1345 | (backward-list 1) |
| 1346 | (setq ses--params-marker (point-marker)) | ||
| 1340 | (let ((params (condition-case nil (read (current-buffer)) (error nil)))) | 1347 | (let ((params (condition-case nil (read (current-buffer)) (error nil)))) |
| 1341 | (or (and (= (safe-length params) 3) | 1348 | (or (and (= (safe-length params) 3) |
| 1342 | (numberp (car params)) | 1349 | (numberp (car params)) |
| @@ -1366,7 +1373,9 @@ execute cell formulas or print functions." | |||
| 1366 | (forward-line ses--numrows) | 1373 | (forward-line ses--numrows) |
| 1367 | (or (looking-at ses-print-data-boundary) | 1374 | (or (looking-at ses-print-data-boundary) |
| 1368 | (error "Missing marker between print and data areas")) | 1375 | (error "Missing marker between print and data areas")) |
| 1369 | (forward-char (length ses-print-data-boundary)) | 1376 | (forward-char 1) |
| 1377 | (setq ses--data-marker (point-marker)) | ||
| 1378 | (forward-char (1- (length ses-print-data-boundary))) | ||
| 1370 | ;;Initialize printer and symbol lists | 1379 | ;;Initialize printer and symbol lists |
| 1371 | (mapc 'ses-printer-record ses-standard-printer-functions) | 1380 | (mapc 'ses-printer-record ses-standard-printer-functions) |
| 1372 | (setq ses--symbolic-formulas nil) | 1381 | (setq ses--symbolic-formulas nil) |
| @@ -1573,10 +1582,7 @@ narrows the buffer now." | |||
| 1573 | ;;We're not allowed to narrow the buffer until after-find-file has | 1582 | ;;We're not allowed to narrow the buffer until after-find-file has |
| 1574 | ;;read the local variables at the end of the file. Now it's safe to | 1583 | ;;read the local variables at the end of the file. Now it's safe to |
| 1575 | ;;do the narrowing. | 1584 | ;;do the narrowing. |
| 1576 | (save-excursion | 1585 | (narrow-to-region (point-min) ses--data-marker) |
| 1577 | (goto-char (point-min)) | ||
| 1578 | (forward-line ses--numrows) | ||
| 1579 | (narrow-to-region (point-min) (point))) | ||
| 1580 | (setq ses--deferred-narrow nil)) | 1586 | (setq ses--deferred-narrow nil)) |
| 1581 | ;;Update the modeline | 1587 | ;;Update the modeline |
| 1582 | (let ((oldcell ses--curcell)) | 1588 | (let ((oldcell ses--curcell)) |
| @@ -1803,11 +1809,17 @@ cells." | |||
| 1803 | (dotimes (row ses--numrows) | 1809 | (dotimes (row ses--numrows) |
| 1804 | (insert ses--blank-line)) | 1810 | (insert ses--blank-line)) |
| 1805 | (insert ses-print-data-boundary) | 1811 | (insert ses-print-data-boundary) |
| 1812 | (backward-char (1- (length ses-print-data-boundary))) | ||
| 1813 | (setq ses--data-marker (point-marker)) | ||
| 1814 | (forward-char (1- (length ses-print-data-boundary))) | ||
| 1806 | ;;Placeholders for cell data | 1815 | ;;Placeholders for cell data |
| 1807 | (insert (make-string (* ses--numrows (1+ ses--numcols)) ?\n)) | 1816 | (insert (make-string (* ses--numrows (1+ ses--numcols)) ?\n)) |
| 1808 | ;;Placeholders for col-widths, col-printers, default-printer, header-row | 1817 | ;;Placeholders for col-widths, col-printers, default-printer, header-row |
| 1809 | (insert "\n\n\n\n") | 1818 | (insert "\n\n\n\n") |
| 1810 | (insert ses-initial-global-parameters)) | 1819 | (insert ses-initial-global-parameters) |
| 1820 | (backward-char (1- (length ses-initial-global-parameters))) | ||
| 1821 | (setq ses--params-marker (point-marker)) | ||
| 1822 | (forward-char (1- (length ses-initial-global-parameters)))) | ||
| 1811 | (ses-set-parameter 'ses--col-widths ses--col-widths) | 1823 | (ses-set-parameter 'ses--col-widths ses--col-widths) |
| 1812 | (ses-set-parameter 'ses--col-printers ses--col-printers) | 1824 | (ses-set-parameter 'ses--col-printers ses--col-printers) |
| 1813 | (ses-set-parameter 'ses--default-printer ses--default-printer) | 1825 | (ses-set-parameter 'ses--default-printer ses--default-printer) |
| @@ -2880,7 +2892,8 @@ TEST is evaluated." | |||
| 2880 | (cons 'list result))) | 2892 | (cons 'list result))) |
| 2881 | 2893 | ||
| 2882 | ;;All standard formulas are safe | 2894 | ;;All standard formulas are safe |
| 2883 | (dolist (x '(ses-range ses-delete-blanks ses+ ses-average ses-select)) | 2895 | (dolist (x '(ses-cell-value ses-range ses-delete-blanks ses+ ses-average |
| 2896 | ses-select)) | ||
| 2884 | (put x 'side-effect-free t)) | 2897 | (put x 'side-effect-free t)) |
| 2885 | 2898 | ||
| 2886 | 2899 | ||