浏览代码

Continue enhancing 7ac468

Thanks to Michael Brand for his feedback.
Bastien Guerry 11 年之前
父节点
当前提交
d8fdaf89ae
共有 2 个文件被更改,包括 36 次插入31 次删除
  1. 22 22
      lisp/org-table.el
  2. 14 9
      lisp/org.el

+ 22 - 22
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?

+ 14 - 9
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.