From d8fdaf89aeecf40586f21ffae6ba8222bb0cf026 Mon Sep 17 00:00:00 2001 From: Bastien Guerry Date: Tue, 20 May 2014 21:44:37 +0200 Subject: [PATCH] Continue enhancing 7ac468 Thanks to Michael Brand for his feedback. --- lisp/org-table.el | 44 ++++++++++++++++++++++---------------------- lisp/org.el | 23 ++++++++++++++--------- 2 files changed, 36 insertions(+), 31 deletions(-) diff --git a/lisp/org-table.el b/lisp/org-table.el index 3ed574c0c..ce56e5751 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -41,6 +41,8 @@ (declare-function org-export-string-as "ox" (string backend &optional body-only ext-plist)) (declare-function aa2u "ext:ascii-art-to-unicode" ()) +(declare-function calc-eval "calc" (str &optional separator &rest args)) + (defvar orgtbl-mode) ; defined below (defvar orgtbl-mode-menu) ; defined when orgtbl mode get initialized (defvar constants-unit-system) @@ -1152,29 +1154,27 @@ to a number. In the case of a timestamp, increment by days." (org-table-blank-field)) (setq inc (cond ((numberp org-table-copy-increment) org-table-copy-increment) - (txt-up - (cond ((and (string-match org-ts-regexp3 txt-up) - (string-match org-ts-regexp3 txt)) - (- (org-time-string-to-absolute txt) - (org-time-string-to-absolute txt-up))) - (t (- (string-to-number txt) - (string-to-number txt-up))))) + (txt-up (cond ((and (string-match org-ts-regexp3 txt-up) + (string-match org-ts-regexp3 txt)) + (- (org-time-string-to-absolute txt) + (org-time-string-to-absolute txt-up))) + (t (- (string-to-number txt) + (string-to-number txt-up))))) (t 1))) - (if txt - (progn - (if (and org-table-copy-increment - (not (equal orig-n 0)) - (string-match "^[0-9]+$" txt) - (< (string-to-number txt) 100000000)) - (setq txt (format "%d" (+ (string-to-number txt) inc)))) - (insert txt) - (org-move-to-column col) - (if (and org-table-copy-increment (org-at-timestamp-p t)) - (org-timestamp-up-day inc) - (org-table-maybe-recalculate-line)) - (org-table-align) - (org-move-to-column col)) - (user-error "No non-empty field found")))) + (if (not txt) + (user-error "No non-empty field found") + (if (and org-table-copy-increment + (not (equal orig-n 0)) + (string-match "^[-+^/*0-9eE.]+$" txt) + (< (string-to-number txt) 100000000)) + (setq txt (calc-eval (concat txt "+" (number-to-string inc))))) + (insert txt) + (org-move-to-column col) + (if (and org-table-copy-increment (org-at-timestamp-p t)) + (org-timestamp-up-day inc) + (org-table-maybe-recalculate-line)) + (org-table-align) + (org-move-to-column col)))) (defun org-table-check-inside-data-field (&optional noerror) "Is point inside a table data field? diff --git a/lisp/org.el b/lisp/org.el index 027cfb608..6d963fe95 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -4376,6 +4376,7 @@ Normal means, no org-mode-specific context." (defvar texmathp-why) (declare-function speedbar-line-directory "speedbar" (&optional depth)) (declare-function table--at-cell-p "table" (position &optional object at-column)) +(declare-function calc-eval "calc" (str &optional separator &rest args)) ;;;###autoload (defun turn-on-orgtbl () @@ -20259,15 +20260,19 @@ Optional argument N tells to change by that many units." With an optional prefix numeric argument INC, increment using this numeric value." (interactive "p") - (unless inc (setq inc 1)) - (let ((nap (thing-at-point 'number))) - (when nap - (skip-chars-backward "-+0123456789") - (kill-word 1) - (insert (number-to-string (+ inc nap))))) - (when (org-at-table-p) - (org-table-align) - (org-table-end-of-field 1))) + (if (not (number-at-point)) + (user-error "Not on a number") + (unless inc (setq inc 1)) + (let ((pos (point)) + (beg (skip-chars-backward "-+^/*0-9eE.")) + (end (skip-chars-forward "-+^/*0-9eE^.")) nap) + (setq nap (buffer-substring-no-properties + (+ pos beg) (+ pos beg end))) + (delete-region (+ pos beg) (+ pos beg end)) + (insert (calc-eval (concat (number-to-string inc) "+" nap)))) + (when (org-at-table-p) + (org-table-align) + (org-table-end-of-field 1)))) (defun org-decrease-number-at-point (&optional inc) "Decrement the number at point. -- 2.11.4.GIT