summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Guerry <bzg@altern.org>2014-05-20 16:07:01 +0200
committerBastien Guerry <bzg@altern.org>2014-05-20 16:07:01 +0200
commit7ac468ff5547891503b6b8f5fa03793d79b3bff6 (patch)
tree93e33a938699645d7f895c2de511fde33f4c213b
parent32e77efa32a3c8d93c809bbed1f012d557ea3ca3 (diff)
downloadorg-mode-7ac468ff5547891503b6b8f5fa03793d79b3bff6.tar.gz
org-table.el (org-table-copy-increment): Change increment behavior
* org-table.el (org-table-copy-increment): Use a number as a way to force a fixed increment value. (org-table-copy-down): Increment by the difference between the current field and the field in the row above. This is the default behavior. To go back to the previous behavior (to always increment by 1 unit), set `org-table-copy-increment' to 1. Thanks to Michael Brand for suggesting this.
-rw-r--r--lisp/org-table.el58
1 files changed, 42 insertions, 16 deletions
diff --git a/lisp/org-table.el b/lisp/org-table.el
index c7bf789..87cf792 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -238,7 +238,12 @@ t accept as input and present for editing"
(defcustom org-table-copy-increment t
"Non-nil means increment when copying current field with \\[org-table-copy-down]."
:group 'org-table-calculation
- :type 'boolean)
+ :version "24.5"
+ :package-version '(Org . "8.3")
+ :type '(choice
+ (const :tag "Use the difference between the current and the above fields" t)
+ (integer :tag "Use a number" 1)
+ (const :tag "Don't increment the value when copying a field" t)))
(defcustom org-calc-default-modes
'(calc-internal-prec 12
@@ -1099,30 +1104,37 @@ Before doing so, re-align the table if necessary."
;;;###autoload
(defun org-table-copy-down (n)
- "Copy a field down in the current column.
-If the field at the cursor is empty, copy into it the content of
-the nearest non-empty field above. With argument N, use the Nth
-non-empty field. If the current field is not empty, it is copied
-down to the next row, and the cursor is moved with it.
-Therefore, repeating this command causes the column to be filled
-row-by-row.
+ "Copy the value of the current field one row below.
+
+If the field at the cursor is empty, copy the content of the
+nearest non-empty field above. With argument N, use the Nth
+non-empty field.
+
+If the current field is not empty, it is copied down to the next
+row, and the cursor is moved with it. Therefore, repeating this
+command causes the column to be filled row-by-row.
+
If the variable `org-table-copy-increment' is non-nil and the
field is an integer or a timestamp, it will be incremented while
-copying. In the case of a timestamp, increment by one day."
+copying. By default, increment by the difference between the
+value in the current field and the one in the field above. To
+increment using a fixed integer, set `org-table-copy-increment'
+to a number. In the case of a timestamp, increment by days."
(interactive "p")
(let* ((colpos (org-table-current-column))
(col (current-column))
(field (save-excursion (org-table-get-field)))
+ (field-up (or (save-excursion
+ (org-table-get (1- (org-table-current-line))
+ (org-table-current-column))) ""))
(non-empty (string-match "[^ \t]" field))
+ (non-empty-up (string-match "[^ \t]" field-up))
(beg (org-table-begin))
(orig-n n)
- txt)
+ txt txt-up inc)
(org-table-check-inside-data-field)
(if non-empty
- (progn
- (setq txt (org-trim field))
- (org-table-next-row)
- (org-table-blank-field))
+ (setq txt (org-trim field))
(save-excursion
(setq txt
(catch 'exit
@@ -1134,17 +1146,31 @@ copying. In the case of a timestamp, increment by one day."
"|[ \t]*\\([^| \t][^|]*?\\)[ \t]*|")
(<= (setq n (1- n)) 0))
(throw 'exit (match-string 1))))))))
+ (if non-empty-up (setq txt-up (org-trim field-up)))
+ (when txt
+ (org-table-next-row)
+ (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)))))
+ (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) 1))))
+ (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)
+ (org-timestamp-up-day inc)
(org-table-maybe-recalculate-line))
(org-table-align)
(org-move-to-column col))