Function: ses-mode

ses-mode is an autoloaded, interactive and byte-compiled function defined in ses.el.gz.

Signature

(ses-mode)

Documentation

Major mode for Simple Emacs Spreadsheet.

When you invoke SES in a new buffer, it is divided into cells that you can enter data into. You can navigate the cells with the arrow keys and add more cells with the tab key. The contents of these cells can be numbers, text, or Lisp expressions. (To enter text, enclose it in double quotes.)

In an expression, you can use cell coordinates to refer to the contents of another cell. For example, you can sum a range of cells with (+ A1 A2 A3). There are specialized functions like ses+ (addition for ranges with empty cells), ses-average (for performing calculations on cells), and ses-range and ses-select
(for extracting ranges of cells).

Each cell also has a print function that controls how it is displayed.

Each SES buffer is divided into a print area and a data area. Normally, you can simply use SES to look at and manipulate the print area, and let SES manage the data area outside the visible region.

See "ses-example.ses" (in data-directory) for an example spreadsheet, and the Info node (ses)Top.

In the following, note the separate keymaps for cell editing mode and print mode specifications. Key definitions:

<header-line> <mouse-2> ses-sort-column-click
C-M-l ses-reprint-all
C-S-l ses-reprint-all
C-c C-M-h ses-set-header-row
C-c C-M-l ses-reconstruct-all
C-c C-M-s ses-sort-column
C-c C-c ses-recalculate-cell
C-c C-j ses-jump
C-c C-l ses-recalculate-all
C-c C-n ses-renarrow-buffer
C-c C-p ses-read-default-printer
C-c C-t ses-truncate-cell
These key definitions are active only in the print area (the visible part):
           ses-end-of-line
           ses-kill-override
" ses-read-cell
' ses-read-symbol
( ses-read-cell
<backtab> backward-char
<tab> ses-forward-or-insert
= ses-edit-cell
C-d ses-clear-cell-forward
C-j ses-append-row-jump-first-column
C-k ses-delete-row
C-k ses-delete-row
C-o ses-insert-row
C-o ses-insert-row
C-w ses-kill-override
DEL ses-clear-cell-backward
M-H ses-mark-column
M-h ses-mark-row
M-k ses-delete-column
M-o ses-insert-column
M-p ses-read-column-printer
M-y ses-yank-pop
RET ses-edit-cell
SPC..~ undefined
TAB ses-forward-or-insert
c ses-recalculate-cell
j ses-jump
p ses-read-cell-printer
t ses-truncate-cell
w ses-set-column-width
x T ses-export-tsf
x t ses-export-tsv
€..\x3FFFFF ses-read-cell
€..\x3FFFFF ses-read-cell
These are active only in the minibuffer, when entering or editing a formula:
<XF86Back> previous-history-element
<XF86Forward> next-history-element
<down> next-line-or-history-element
<kp-4> tpu-search-forward-exit
<kp-5> tpu-search-backward-exit
<kp-enter> exit-minibuffer
<next> next-history-element
<prior> previous-history-element
<up> previous-line-or-history-element
C-<tab> file-cache-minibuffer-complete
C-M-i lisp-complete-symbol
C-S-<mouse-3> ses-insert-ses-range-click
C-c C-r ses-insert-range
C-c C-s ses-insert-ses-range
C-g minibuffer-keyboard-quit
C-h C-n ses-list-named-cells
C-h C-p ses-list-local-printers
C-j exit-minibuffer
C-x <down> minibuffer-complete-defaults
C-x <up> minibuffer-complete-history
M-< minibuffer-beginning-of-buffer
M-n next-history-element
M-p previous-history-element
M-r previous-matching-history-element
M-s next-matching-history-element
RET exit-minibuffer
S-<mouse-3> ses-insert-range-click
TAB self-insert-command

Probably introduced at or before Emacs version 22.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/ses.el.gz
;;;###autoload
(defun ses-mode ()
  "Major mode for Simple Emacs Spreadsheet.

When you invoke SES in a new buffer, it is divided into cells
that you can enter data into.  You can navigate the cells with
the arrow keys and add more cells with the tab key.  The contents
of these cells can be numbers, text, or Lisp expressions.  (To
enter text, enclose it in double quotes.)

In an expression, you can use cell coordinates to refer to the
contents of another cell.  For example, you can sum a range of
cells with `(+ A1 A2 A3)'.  There are specialized functions like
`ses+' (addition for ranges with empty cells), `ses-average' (for
performing calculations on cells), and `ses-range' and `ses-select'
\(for extracting ranges of cells).

Each cell also has a print function that controls how it is
displayed.

Each SES buffer is divided into a print area and a data area.
Normally, you can simply use SES to look at and manipulate the print
area, and let SES manage the data area outside the visible region.

See \"ses-example.ses\" (in `data-directory') for an example
spreadsheet, and the Info node `(ses)Top.'

In the following, note the separate keymaps for cell editing mode
and print mode specifications.  Key definitions:

\\{ses-mode-map}
These key definitions are active only in the print area (the visible
part):
\\{ses-mode-print-map}
These are active only in the minibuffer, when entering or editing a
formula:
\\{ses-mode-edit-map}"
  (interactive)
  (unless (and (boundp 'ses--deferred-narrow)
	       (eq ses--deferred-narrow 'ses-mode))
    (kill-all-local-variables)
    (ses-set-localvars)
    (setq major-mode             'ses-mode
	  mode-name              "SES"
	  next-line-add-newlines nil
	  truncate-lines         t
	  ;; SES deliberately puts lots of trailing whitespace in its buffer.
	  show-trailing-whitespace nil
	  ;; Cell ranges do not work reasonably without this.
	  transient-mark-mode    t
	  ;; Not to use tab characters for safe (tabs may do bad for column
	  ;; calculation).
	  indent-tabs-mode	 nil)
    (1value (add-hook 'change-major-mode-hook #'ses-cleanup nil t))
    (1value (add-hook 'kill-buffer-hook #'ses-killbuffer-hook nil t))
    (cl-pushnew (current-buffer) ses--ses-buffer-list :test 'eq)
    ;; This makes revert impossible if the buffer is read-only.
    ;; (1value (add-hook 'before-revert-hook 'ses-cleanup nil t))
    (setq header-line-format   '(:eval (progn
					 (when (/= (window-hscroll)
						   ses--header-hscroll)
					   ;; Reset ses--header-hscroll first,
					   ;; to avoid recursion problems when
					   ;; debugging ses-create-header-string
					   (setq ses--header-hscroll
						 (window-hscroll))
					   (ses-create-header-string))
					 ses--header-string)))
    (setq-local mode-line-process '(:eval (ses--mode-line-process)))
    (add-hook 'pre-redisplay-functions #'ses--cursor-sensor-highlight
              ;; Highlight the cell after moving cursor out of intangible.
              'append t)
    (cursor-intangible-mode 1)
    (let ((was-empty    (zerop (buffer-size)))
	  (was-modified (buffer-modified-p)))
      (save-excursion
	(if was-empty
	    ;; Initialize buffer to contain one cell, for now.
	    (insert ses-initial-file-contents))
	(ses-load)
	(ses-setup))
      (when was-empty
	(unless (equal ses-initial-default-printer
		       (1value ses--default-printer))
	  (1value (ses-read-default-printer ses-initial-default-printer)))
	(unless (= ses-initial-column-width (1value (ses-col-width 0)))
	  (1value (ses-set-column-width 0 ses-initial-column-width)))
	(ses-set-curcell)
	(if (> (car ses-initial-size) (1value ses--numrows))
	    (1value (ses-insert-row (1- (car ses-initial-size)))))
	(if (> (cdr ses-initial-size) (1value ses--numcols))
	    (1value (ses-insert-column (1- (cdr ses-initial-size)))))
	(ses-write-cells)
	(restore-buffer-modified-p was-modified)
	(buffer-disable-undo)
	(buffer-enable-undo)
	(goto-char (point-min))))
    (use-local-map ses-mode-map)
    ;; Set the deferred narrowing flag (we can't narrow until after
    ;; after-find-file completes).  If .ses is on the auto-load alist and the
    ;; file has "mode: ses", our ses-mode function will be called twice!  Use a
    ;; special flag to detect this (will be reset by ses-command-hook).  For
    ;; find-alternate-file, post-command-hook doesn't get run for some reason,
    ;; so use an idle timer to make sure.
    (setq ses--deferred-narrow 'ses-mode)
    (1value (add-hook 'post-command-hook #'ses-command-hook nil t))
    (run-with-idle-timer 0.01 nil #'ses-command-hook)
    (run-mode-hooks 'ses-mode-hook)))