summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2018-05-22 10:46:57 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2018-05-22 10:46:57 +0200
commit2918894f361c5803b9816f248dbd284eb0fd55b9 (patch)
treeaae4f64bcad1ce6a626c077ac787b0844d57e910
parent8def68b7238154fa52cab2d9f3b6708f8695a5c5 (diff)
downloadorg-mode-2918894f361c5803b9816f248dbd284eb0fd55b9.tar.gz
org-table: Tiny refactoring
* lisp/org-table.el (org-table-get-formula): Tiny refactoring. (org-table-get-stored-formulas): Fix string.
-rw-r--r--lisp/org-table.el41
1 files changed, 19 insertions, 22 deletions
diff --git a/lisp/org-table.el b/lisp/org-table.el
index 790c462..2273ae6 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -2275,34 +2275,31 @@ When NAMED is non-nil, look for a named equation."
(eq (cond
((and stored equation (string-match-p "^ *=? *$" equation))
stored)
- ((stringp equation)
- equation)
- (t (org-table-formula-from-user
- (read-string
- (org-table-formula-to-user
- (format "%s formula %s="
- (if named "Field" "Column")
- scol))
- (if stored (org-table-formula-to-user stored) "")
- 'org-table-formula-history
- )))))
+ ((stringp equation) equation)
+ (t
+ (org-table-formula-from-user
+ (read-string
+ (org-table-formula-to-user
+ (format "%s formula %s=" (if named "Field" "Column") scol))
+ (if stored (org-table-formula-to-user stored) "")
+ 'org-table-formula-history)))))
mustsave)
- (when (not (string-match "\\S-" eq))
- ;; remove formula
+ (unless (org-string-nw-p eq)
+ ;; Remove formula.
(setq stored-list (delq (assoc scol stored-list) stored-list))
(org-table-store-formulas stored-list)
(user-error "Formula removed"))
- (if (string-match "^ *=?" eq) (setq eq (replace-match "" t t eq)))
- (if (string-match " *$" eq) (setq eq (replace-match "" t t eq)))
- (if (and name (not named))
- ;; We set the column equation, delete the named one.
- (setq stored-list (delq (assoc name stored-list) stored-list)
- mustsave t))
+ (when (string-match "^ *=?" eq) (setq eq (replace-match "" t t eq)))
+ (when (string-match " *$" eq) (setq eq (replace-match "" t t eq)))
+ (when (and name (not named))
+ ;; We set the column equation, delete the named one.
+ (setq stored-list (delq (assoc name stored-list) stored-list)
+ mustsave t))
(if stored
(setcdr (assoc scol stored-list) eq)
(setq stored-list (cons (cons scol eq) stored-list)))
- (if (or mustsave (not (equal stored eq)))
- (org-table-store-formulas stored-list))
+ (when (or mustsave (not (equal stored eq)))
+ (org-table-store-formulas stored-list))
eq))
(defun org-table-store-formulas (alist &optional location)
@@ -2370,7 +2367,7 @@ LOCATION is a buffer position, consider the formulas there."
eq-alist seen)
(dolist (string strings (nreverse eq-alist))
(when (string-match "\\`\\(@[-+I<>0-9.$@]+\\|\\$\\([_a-zA-Z0-9]+\\|\
-[<>]+\\)\\) *= *\\(.*[^ \t]\\)"
+\[<>]+\\)\\) *= *\\(.*[^ \t]\\)"
string)
(let ((lhs
(let ((m (match-string 1 string)))