diff options
| author | Jonathan Yavner | 2006-05-26 17:39:06 +0000 |
|---|---|---|
| committer | Jonathan Yavner | 2006-05-26 17:39:06 +0000 |
| commit | bd93e3e1aa80960b2c6f49faab96751f456aa6f9 (patch) | |
| tree | effab9b8c5bcd13ff7b8a37f3719ec2f5387a28a | |
| parent | a8dc674f5f0842870c3f5121f2af7ad82d7237e2 (diff) | |
| download | emacs-bd93e3e1aa80960b2c6f49faab96751f456aa6f9.tar.gz emacs-bd93e3e1aa80960b2c6f49faab96751f456aa6f9.zip | |
* ses.el (defadvice undo-more): Delete this defadvice. The undo
overrides will now be done a different way.
(ses-set-parameter): Reapply this function for undo.
(ses-set-header-row): Reconstruct header row during undo.
(ses-widen): New function.
(ses-goto-data, ses-reconstruct-all): Use new function.
(ses-command-hook): Widen buffer during undo, before unupdating
the cells.
(ses-insert-row, ses-delete-row): Widen buffer during undo.
(ses-load, ses-header-row): Permit empty (zero-row) spreadsheets.
(ses-read-cell): Avoid stupid warning for RET RET on a cell whose
formula hasn't been executed yet.
| -rw-r--r-- | lisp/ChangeLog | 15 | ||||
| -rw-r--r-- | lisp/ses.el | 81 |
2 files changed, 57 insertions, 39 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index b5d0653be1b..4c8177f51f7 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,18 @@ | |||
| 1 | 2006-05-26 Jonathan Yavner <jyavner@member.fsf.org> | ||
| 2 | |||
| 3 | * ses.el (defadvice undo-more): Delete this defadvice. The undo | ||
| 4 | overrides will now be done a different way. | ||
| 5 | (ses-set-parameter): Reapply this function for undo. | ||
| 6 | (ses-set-header-row): Reconstruct header row during undo. | ||
| 7 | (ses-widen): New function. | ||
| 8 | (ses-goto-data, ses-reconstruct-all): Use new function. | ||
| 9 | (ses-command-hook): Widen buffer during undo, before unupdating | ||
| 10 | the cells. | ||
| 11 | (ses-insert-row, ses-delete-row): Widen buffer during undo. | ||
| 12 | (ses-load, ses-header-row): Permit empty (zero-row) spreadsheets. | ||
| 13 | (ses-read-cell): Avoid stupid warning for RET RET on a cell whose | ||
| 14 | formula hasn't been executed yet. | ||
| 15 | |||
| 1 | 2006-05-26 Reiner Steib <Reiner.Steib@gmx.de> | 16 | 2006-05-26 Reiner Steib <Reiner.Steib@gmx.de> |
| 2 | 17 | ||
| 3 | * comint.el (comint-kill-whole-line): Rename arg to count. Fix | 18 | * comint.el (comint-kill-whole-line): Rename arg to count. Fix |
diff --git a/lisp/ses.el b/lisp/ses.el index debb22d84db..fc594167187 100644 --- a/lisp/ses.el +++ b/lisp/ses.el | |||
| @@ -399,7 +399,7 @@ for safety. This is a macro to prevent propagate-on-load viruses." | |||
| 399 | (defmacro ses-header-row (row) | 399 | (defmacro ses-header-row (row) |
| 400 | "Load the header row from the spreadsheet file and checks it | 400 | "Load the header row from the spreadsheet file and checks it |
| 401 | for safety. This is a macro to prevent propagate-on-load viruses." | 401 | for safety. This is a macro to prevent propagate-on-load viruses." |
| 402 | (or (and (wholenump row) (< row ses--numrows)) | 402 | (or (and (wholenump row) (or (zerop ses--numrows) (< row ses--numrows))) |
| 403 | (error "Bad header-row")) | 403 | (error "Bad header-row")) |
| 404 | (setq ses--header-row row) | 404 | (setq ses--header-row row) |
| 405 | t) | 405 | t) |
| @@ -940,14 +940,18 @@ cell (ROW,COL) has changed." | |||
| 940 | 940 | ||
| 941 | (defun ses-narrowed-p () (/= (- (point-max) (point-min)) (buffer-size))) | 941 | (defun ses-narrowed-p () (/= (- (point-max) (point-min)) (buffer-size))) |
| 942 | 942 | ||
| 943 | (defun ses-widen () | ||
| 944 | "Turn off narrowing, to be reenabled at end of command loop." | ||
| 945 | (if (ses-narrowed-p) | ||
| 946 | (setq ses--deferred-narrow t)) | ||
| 947 | (widen)) | ||
| 948 | |||
| 943 | (defun ses-goto-data (def &optional col) | 949 | (defun ses-goto-data (def &optional col) |
| 944 | "Move point to data area for (DEF,COL). If DEF is a row | 950 | "Move point to data area for (DEF,COL). If DEF is a row |
| 945 | number, COL is the column number for a data cell -- otherwise DEF | 951 | number, COL is the column number for a data cell -- otherwise DEF |
| 946 | is one of the symbols ses--col-widths, ses--col-printers, | 952 | is one of the symbols ses--col-widths, ses--col-printers, |
| 947 | ses--default-printer, ses--numrows, or ses--numcols." | 953 | ses--default-printer, ses--numrows, or ses--numcols." |
| 948 | (if (ses-narrowed-p) | 954 | (ses-widen) |
| 949 | (setq ses--deferred-narrow t)) | ||
| 950 | (widen) | ||
| 951 | (let ((inhibit-point-motion-hooks t)) ;In case intangible attrs are wrong | 955 | (let ((inhibit-point-motion-hooks t)) ;In case intangible attrs are wrong |
| 952 | (goto-char (point-min)) | 956 | (goto-char (point-min)) |
| 953 | (if col | 957 | (if col |
| @@ -966,9 +970,6 @@ If ELEM is specified, it is the array subscript within DEF to be set to VALUE." | |||
| 966 | ;;We call ses-goto-data early, using the old values of numrows and | 970 | ;;We call ses-goto-data early, using the old values of numrows and |
| 967 | ;;numcols in case one of them is being changed. | 971 | ;;numcols in case one of them is being changed. |
| 968 | (ses-goto-data def) | 972 | (ses-goto-data def) |
| 969 | (if elem | ||
| 970 | (ses-aset-with-undo (symbol-value def) elem value) | ||
| 971 | (ses-set-with-undo def value)) | ||
| 972 | (let ((inhibit-read-only t) | 973 | (let ((inhibit-read-only t) |
| 973 | (fmt (plist-get '(ses--col-widths "(ses-column-widths %S)" | 974 | (fmt (plist-get '(ses--col-widths "(ses-column-widths %S)" |
| 974 | ses--col-printers "(ses-column-printers %S)" | 975 | ses--col-printers "(ses-column-printers %S)" |
| @@ -977,9 +978,20 @@ If ELEM is specified, it is the array subscript within DEF to be set to VALUE." | |||
| 977 | ses--file-format " %S ;SES file-format" | 978 | ses--file-format " %S ;SES file-format" |
| 978 | ses--numrows " %S ;numrows" | 979 | ses--numrows " %S ;numrows" |
| 979 | ses--numcols " %S ;numcols") | 980 | ses--numcols " %S ;numcols") |
| 980 | def))) | 981 | def)) |
| 981 | (delete-region (point) (line-end-position)) | 982 | oldval) |
| 982 | (insert (format fmt (symbol-value def)))))) | 983 | (if elem |
| 984 | (progn | ||
| 985 | (setq oldval (aref (symbol-value def) elem)) | ||
| 986 | (aset (symbol-value def) elem value)) | ||
| 987 | (setq oldval (symbol-value def)) | ||
| 988 | (set def value)) | ||
| 989 | ;;Special undo since it's outside the narrowed buffer | ||
| 990 | (let (buffer-undo-list) | ||
| 991 | (delete-region (point) (line-end-position)) | ||
| 992 | (insert (format fmt (symbol-value def)))) | ||
| 993 | (push `(apply ses-set-parameter ,def ,oldval ,elem) buffer-undo-list)))) | ||
| 994 | |||
| 983 | 995 | ||
| 984 | (defun ses-write-cells () | 996 | (defun ses-write-cells () |
| 985 | "Write cells in `ses--deferred-write' from local variables to data area. | 997 | "Write cells in `ses--deferred-write' from local variables to data area. |
| @@ -1278,23 +1290,6 @@ to each symbol." | |||
| 1278 | ;; Undo control | 1290 | ;; Undo control |
| 1279 | ;;---------------------------------------------------------------------------- | 1291 | ;;---------------------------------------------------------------------------- |
| 1280 | 1292 | ||
| 1281 | ;; This should be unnecessary, because the feature is now built in. | ||
| 1282 | |||
| 1283 | (defadvice undo-more (around ses-undo-more activate preactivate) | ||
| 1284 | "For SES mode, allow undo outside of narrowed buffer range." | ||
| 1285 | (if (not (eq major-mode 'ses-mode)) | ||
| 1286 | ad-do-it | ||
| 1287 | ;;Here is some extra code for SES mode. | ||
| 1288 | (setq ses--deferred-narrow | ||
| 1289 | (or ses--deferred-narrow (ses-narrowed-p))) | ||
| 1290 | (widen) | ||
| 1291 | (condition-case x | ||
| 1292 | ad-do-it | ||
| 1293 | (error | ||
| 1294 | ;;Restore narrow if appropriate | ||
| 1295 | (ses-command-hook) | ||
| 1296 | (signal (car x) (cdr x)))))) | ||
| 1297 | |||
| 1298 | (defun ses-begin-change () | 1293 | (defun ses-begin-change () |
| 1299 | "For undo, remember point before we start changing hidden stuff." | 1294 | "For undo, remember point before we start changing hidden stuff." |
| 1300 | (let ((inhibit-read-only t)) | 1295 | (let ((inhibit-read-only t)) |
| @@ -1303,7 +1298,7 @@ to each symbol." | |||
| 1303 | 1298 | ||
| 1304 | (defun ses-set-with-undo (sym newval) | 1299 | (defun ses-set-with-undo (sym newval) |
| 1305 | "Like set, but undoable. Result is t if value has changed." | 1300 | "Like set, but undoable. Result is t if value has changed." |
| 1306 | ;;We avoid adding redundant entries to the undo list, but this is | 1301 | ;;We try to avoid adding redundant entries to the undo list, but this is |
| 1307 | ;;unavoidable for strings because equal ignores text properties and there's | 1302 | ;;unavoidable for strings because equal ignores text properties and there's |
| 1308 | ;;no easy way to get the whole property list to see if it's different! | 1303 | ;;no easy way to get the whole property list to see if it's different! |
| 1309 | (unless (and (boundp sym) | 1304 | (unless (and (boundp sym) |
| @@ -1346,7 +1341,7 @@ execute cell formulas or print functions." | |||
| 1346 | (or (and (= (safe-length params) 3) | 1341 | (or (and (= (safe-length params) 3) |
| 1347 | (numberp (car params)) | 1342 | (numberp (car params)) |
| 1348 | (numberp (cadr params)) | 1343 | (numberp (cadr params)) |
| 1349 | (> (cadr params) 0) | 1344 | (>= (cadr params) 0) |
| 1350 | (numberp (nth 2 params)) | 1345 | (numberp (nth 2 params)) |
| 1351 | (> (nth 2 params) 0)) | 1346 | (> (nth 2 params) 0)) |
| 1352 | (error "Invalid SES file")) | 1347 | (error "Invalid SES file")) |
| @@ -1568,11 +1563,12 @@ narrows the buffer now." | |||
| 1568 | (let ((old ses--deferred-recalc)) | 1563 | (let ((old ses--deferred-recalc)) |
| 1569 | (setq ses--deferred-recalc nil) | 1564 | (setq ses--deferred-recalc nil) |
| 1570 | (ses-update-cells old))) | 1565 | (ses-update-cells old))) |
| 1571 | (if ses--deferred-write | 1566 | (when ses--deferred-write |
| 1572 | ;;We don't reset the deferred list before starting -- the most | 1567 | ;;We don't reset the deferred list before starting -- the most |
| 1573 | ;;likely error is keyboard-quit, and we do want to keep trying | 1568 | ;;likely error is keyboard-quit, and we do want to keep trying |
| 1574 | ;;these writes after a quit. | 1569 | ;;these writes after a quit. |
| 1575 | (ses-write-cells)) | 1570 | (ses-write-cells) |
| 1571 | (push '(apply ses-widen) buffer-undo-list)) | ||
| 1576 | (when ses--deferred-narrow | 1572 | (when ses--deferred-narrow |
| 1577 | ;;We're not allowed to narrow the buffer until after-find-file has | 1573 | ;;We're not allowed to narrow the buffer until after-find-file has |
| 1578 | ;;read the local variables at the end of the file. Now it's safe to | 1574 | ;;read the local variables at the end of the file. Now it's safe to |
| @@ -1794,9 +1790,7 @@ cells." | |||
| 1794 | (cons (ses-cell-symbol row col) | 1790 | (cons (ses-cell-symbol row col) |
| 1795 | (ses-cell-references yrow ycol))))))) | 1791 | (ses-cell-references yrow ycol))))))) |
| 1796 | ;;Delete everything and reconstruct basic data area | 1792 | ;;Delete everything and reconstruct basic data area |
| 1797 | (if (ses-narrowed-p) | 1793 | (ses-widen) |
| 1798 | (setq ses--deferred-narrow t)) | ||
| 1799 | (widen) | ||
| 1800 | (let ((inhibit-read-only t)) | 1794 | (let ((inhibit-read-only t)) |
| 1801 | (goto-char (point-max)) | 1795 | (goto-char (point-max)) |
| 1802 | (if (search-backward ";; Local Variables:\n" nil t) | 1796 | (if (search-backward ";; Local Variables:\n" nil t) |
| @@ -1877,7 +1871,9 @@ cell formula was unsafe and user declined confirmation." | |||
| 1877 | ses-mode-edit-map | 1871 | ses-mode-edit-map |
| 1878 | t ;Convert to Lisp object | 1872 | t ;Convert to Lisp object |
| 1879 | 'ses-read-cell-history | 1873 | 'ses-read-cell-history |
| 1880 | (prin1-to-string curval))))) | 1874 | (prin1-to-string (if (eq (car-safe curval) 'ses-safe-formula) |
| 1875 | (cadr curval) | ||
| 1876 | curval)))))) | ||
| 1881 | (when (ses-edit-cell row col newval) | 1877 | (when (ses-edit-cell row col newval) |
| 1882 | (ses-command-hook) ;Update cell widths before movement | 1878 | (ses-command-hook) ;Update cell widths before movement |
| 1883 | (dolist (x ses-after-entry-functions) | 1879 | (dolist (x ses-after-entry-functions) |
| @@ -2073,6 +2069,8 @@ before current one." | |||
| 2073 | (ses-reset-header-string))) | 2069 | (ses-reset-header-string))) |
| 2074 | ;;Reconstruct text attributes | 2070 | ;;Reconstruct text attributes |
| 2075 | (ses-setup) | 2071 | (ses-setup) |
| 2072 | ;;Prepare for undo | ||
| 2073 | (push '(apply ses-widen) buffer-undo-list) | ||
| 2076 | ;;Return to current cell | 2074 | ;;Return to current cell |
| 2077 | (if ses--curcell | 2075 | (if ses--curcell |
| 2078 | (ses-jump-safe ses--curcell) | 2076 | (ses-jump-safe ses--curcell) |
| @@ -2109,6 +2107,8 @@ current one." | |||
| 2109 | (ses-reset-header-string))) | 2107 | (ses-reset-header-string))) |
| 2110 | ;;Reconstruct attributes | 2108 | ;;Reconstruct attributes |
| 2111 | (ses-setup) | 2109 | (ses-setup) |
| 2110 | ;;Prepare for undo | ||
| 2111 | (push '(apply ses-widen) buffer-undo-list) | ||
| 2112 | (ses-jump-safe ses--curcell)) | 2112 | (ses-jump-safe ses--curcell)) |
| 2113 | 2113 | ||
| 2114 | (defun ses-insert-column (count &optional col width printer) | 2114 | (defun ses-insert-column (count &optional col width printer) |
| @@ -2643,7 +2643,10 @@ The top row is row 1. Selecting row 0 displays the default header row." | |||
| 2643 | (if (or (< row 0) (> row ses--numrows)) | 2643 | (if (or (< row 0) (> row ses--numrows)) |
| 2644 | (error "Invalid header-row")) | 2644 | (error "Invalid header-row")) |
| 2645 | (ses-begin-change) | 2645 | (ses-begin-change) |
| 2646 | (ses-set-parameter 'ses--header-row row) | 2646 | (let ((oldval ses--header-row)) |
| 2647 | (let (buffer-undo-list) | ||
| 2648 | (ses-set-parameter 'ses--header-row row)) | ||
| 2649 | (push `(apply ses-set-header-row ,oldval) buffer-undo-list)) | ||
| 2647 | (ses-reset-header-string)) | 2650 | (ses-reset-header-string)) |
| 2648 | 2651 | ||
| 2649 | (defun ses-mark-row () | 2652 | (defun ses-mark-row () |