;; working fine in most cases, however failed in some cases of several path
;; racing together.
;;
-;; The current algorithm is based on Dijksta algorithm. The ``cycle length'' is
+;; The current algorithm is based on Dijkstra's algorithm. The cycle length is
;; stored in some cell property. In order not to reset in all cells such
;; property at each update, the cycle length is stored in this property along
;; with some update attempt id that is incremented at each update. The current
;;; Code:
(require 'unsafep)
+(eval-when-compile (require 'cl))
;;----------------------------------------------------------------------------
(eval-and-compile
(defconst ses-localvars
'(ses--blank-line ses--cells ses--col-printers
- ses--col-widths (ses--curcell . nil) ses--curcell-overlay
+ ses--col-widths ses--curcell ses--curcell-overlay
ses--default-printer
- ses--deferred-narrow (ses--deferred-recalc
- . nil) (ses--deferred-write . nil) ses--file-format
+ ses--deferred-narrow ses--deferred-recalc
+ ses--deferred-write ses--file-format
(ses--header-hscroll . -1) ; Flag for "initial recalc needed"
ses--header-row ses--header-string ses--linewidth
ses--numcols ses--numrows ses--symbolic-formulas
- ses--data-marker ses--params-marker (ses--Dijkstra-attempt-nb
- . 0) ses--Dijkstra-weight-bound
+ ses--data-marker ses--params-marker (ses--Dijkstra-attempt-nb . 0)
+ ses--Dijkstra-weight-bound
;; Global variables that we override
mode-line-process next-line-add-newlines transient-mark-mode)
- "Buffer-local variables used by SES."))
+ "Buffer-local variables used by SES.")
(defun ses-set-localvars ()
"Set buffer-local and initialize some SES variables."
((symbolp x)
(set (make-local-variable x) nil))
((consp x)
- (set (make-local-variable (car x)) (cdr x)))
- (error "Unexpected elements `%S' in list `ses-localvars'"))))
+ (set (make-local-variable (car x)) (cdr x)))
+ (t (error "Unexpected elements `%S' in list `ses-localvars'" x))))))
+
+(eval-when-compile ; silence compiler
+ (ses-set-localvars))
;;; This variable is documented as being permitted in file-locals:
(put 'ses--symbolic-formulas 'safe-local-variable 'consp)
(put sym 'ses-cell (cons xrow xcol))
(make-local-variable sym)))))
-;;We do not delete the ses-cell properties for the cell-variables, in case a
-;;formula that refers to this cell is in the kill-ring and is later pasted
-;;back in.
+;; We do not delete the ses-cell properties for the cell-variables, in
+;; case a formula that refers to this cell is in the kill-ring and is
+;; later pasted back in.
(defun ses-destroy-cell-variable-range (minrow maxrow mincol maxcol)
"Destroy buffer-local variables for cells. This is undoable."
(let (sym)
(error "Circular references: %s" ses--deferred-recalc))
(message " "))
;; Can't use save-excursion here: if the cell under point is updated,
- ;; save-excusion's marker will move past the cell.
+ ;; save-excursion's marker will move past the cell.
(goto-char pos)))
(setq x (concat text (if (< maxcol ses--numcols) " " "\n")))
;; We use set-text-properties to prevent a wacky print function from
;; inserting rogue properties, and to ensure that the keymap property is
- ;; inherited (is it a bug that only unpropertied strings actually
+ ;; inherited (is it a bug that only unpropertized strings actually
;; inherit from surrounding text?)
(set-text-properties 0 (length x) nil x)
(insert-and-inherit x)
parenthesis to request left-justification, or the error-signal if the
printer signaled one (and \"%s\" is used as the default printer), else nil."
(setq ses-call-printer-return nil)
- (unless value
- (setq value ""))
(condition-case signal
(cond
((stringp printer)
- (format printer value))
+ (if value
+ (format printer value)
+ ""))
((stringp (car-safe printer))
(setq ses-call-printer-return t)
- (format (car printer) value))
+ (if value
+ (format (car printer) value)
+ ""))
(t
- (setq value (funcall printer value))
+ (setq value (funcall printer (or value "")))
(if (stringp value)
value
(or (stringp (car-safe value))
(setq formula (cadr formula)))
(if (eq (car-safe printer) 'ses-safe-printer)
(setq printer (cadr printer)))
- ;; This is noticably faster than (format "%S %S %S %S %S")
+ ;; This is noticeably faster than (format "%S %S %S %S %S")
(setq text (concat "(ses-cell "
(symbol-name sym)
" "
result-so-far)
(defsubst ses-relocate-symbol (sym rowcol startrow startcol rowincr colincr)
- "Relocate one symbol SYM, whichs corresponds to ROWCOL (a cons of ROW and
+ "Relocate one symbol SYM, which corresponds to ROWCOL (a cons of ROW and
COL). Cells starting at (STARTROW,STARTCOL) are being shifted
by (ROWINCR,COLINCR)."
(let ((row (car rowcol))
relative references to neighboring cells. This is best if the formulas
generally refer to other cells within the yanked text. You can use the C-u
prefix to specify insertion without relocation, which is best when the
-formulas refer to cells outsite the yanked text.
+formulas refer to cells outside the yanked text.
When inserting formulas, the text is treated as a string constant if it doesn't
make sense as a sexp or would otherwise be considered a symbol. Use 'sym to
is read and how it is formatted.
In the sequel we assume that cells A1, B1, A2 B2 have respective values
-1 2 3 and 4 for examplication.
+1 2 3 and 4.
Readout direction is specified by a `>v', '`>^', `<v', `<^',
`v>', `v<', `^>', `^<' flag. For historical reasons, in absence
flatten the result to a one row vector, and `*2' will make a
matrix whatever the number of rows.
-Warning: interaction with Calc is expermimental and may produce
+Warning: interaction with Calc is experimental and may produce
confusing results if you are not aware of Calc data format. Use
`math-format-value' as a printer for Calc objects."
(let (result-row
;; These functions use the variables 'row' and 'col' that are dynamically bound
;; by ses-print-cell. We define these variables at compile-time to make the
;; compiler happy.
-(eval-when-compile
- (dolist (x '(row col))
- (make-local-variable x)
- (set x nil)))
+(defvar row)
+(defvar col)
(defun ses-center (value &optional span fill)
"Print VALUE, centered within column. FILL is the fill character for