summaryrefslogtreecommitdiff
path: root/lisp/ses.el
diff options
context:
space:
mode:
authorVincent Belaïche <vincentb1@users.sourceforge.net>2022-04-04 19:42:07 +0200
committerVincent Belaïche <vincentb1@users.sourceforge.net>2022-04-04 19:42:07 +0200
commitf4b649ad0b1bcd347432928d967d49fab24a4c91 (patch)
tree29cafb5bed6ac526a0991eeef0539a069c21f07f /lisp/ses.el
parent7a8798de95a57c8ff85f070075e0a0176b458578 (diff)
downloademacs-f4b649ad0b1bcd347432928d967d49fab24a4c91.tar.gz
SES with case insensitive cell names for jumping.
* doc/misc/ses.texi (The Basics): Document that ses-jump may be customized. (Customizing @acronym{SES}): Document new customisations for ses-jump. * lisp/ses.el (ses-jump-cell-name-function) (ses-jump-prefix-function): New defcustoms. (ses-jump-prefix): New defun. (ses-jump): Make ses-jump use the new defcustoms. * test/lisp/ses-tests.el (ses-jump-B2-prefix-arg) (ses-jump-B2-lowcase, ses-jump-B2-lowcase-keys) (ses-jump-B2-symbol, ses-jump-B2-renamed): New tests.
Diffstat (limited to 'lisp/ses.el')
-rw-r--r--lisp/ses.el63
1 files changed, 49 insertions, 14 deletions
diff --git a/lisp/ses.el b/lisp/ses.el
index 45e323e8051..e3b3a45776b 100644
--- a/lisp/ses.el
+++ b/lisp/ses.el
@@ -112,6 +112,24 @@ Each function is called with ARG=1."
:group 'ses
:type 'hook)
+(defcustom ses-jump-cell-name-function 'upcase
+ "Function to process the string passed to function ‘ses-jump’. Set it to 'identity to make no change.
+Set it to 'upcase to make cell name change case isensitive.
+
+ May return
+
+* a string, in this case this must be a cell name.
+* a (row . col) cons cell, in this case that must be valid cell coordinate."
+ :group 'ses
+ :type 'function)
+
+(defcustom ses-jump-prefix-function 'ses-jump-prefix
+ "Function that takes the prefix argument passed to function ‘ses-jump’. It may return the same
+sort of thing as ‘ses-jump-cell-name-function’."
+ :group 'ses
+ :type 'function)
+
+
;;----------------------------------------------------------------------------
;; Global variables and constants
@@ -2233,24 +2251,41 @@ Based on the current set of columns and `window-hscroll' position."
;;----------------------------------------------------------------------------
;; Redisplay and recalculation
;;----------------------------------------------------------------------------
+(defun ses-jump-prefix (prefix-int)
+ "Convert an integer into a (ROW . COL), by numbering cells starting from 0 from top left to bottom right, going row by row."
+ (and (>= prefix-int 0)
+ (< prefix-int (* ses--numcols ses--numrows))
+ (cons (/ prefix-int ses--numcols) (% prefix-int ses--numcols))))
-(defun ses-jump (sym)
+
+(defun ses-jump (&optional sym)
"Move point to cell SYM."
- (interactive (let* (names
- (s (completing-read
- "Jump to cell: "
- (and ses--named-cell-hashmap
- (progn (maphash (lambda (key _val)
- (push (symbol-name key) names))
- ses--named-cell-hashmap)
- names)))))
- (if (string= s "")
- (user-error "Invalid cell name")
- (list (intern s)))))
- (let ((rowcol (ses-sym-rowcol sym)))
+ (interactive "P")
+ (setq sym
+ (if current-prefix-arg
+ (funcall ses-jump-prefix-function (prefix-numeric-value sym))
+ (or sym
+ (completing-read
+ "Jump to cell: "
+ (and ses--named-cell-hashmap
+ (let (names)
+ (maphash (lambda (key _val)
+ (push (symbol-name key) names))
+ ses--named-cell-hashmap)
+ names))))))
+ (and (stringp sym)
+ (not (and ses--named-cell-hashmap (gethash (intern sym) ses--named-cell-hashmap)))
+ (setq sym (funcall ses-jump-cell-name-function sym)))
+ (if (stringp sym)
+ (if (string= sym "")
+ (user-error "Empty cell name")
+ (setq sym (intern sym))))
+ (let ((rowcol (if (consp sym)
+ (prog1 sym (setq sym (ses-cell-symbol (car sym) (cdr sym))))
+ (ses-sym-rowcol sym))))
(or rowcol (error "Invalid cell name"))
(if (eq (symbol-value sym) '*skip*)
- (error "Cell is covered by preceding cell"))
+ (error "Cell is covered by preceding cell"))
(ses-goto-print (car rowcol) (cdr rowcol))))
(defun ses-jump-safe (cell)