summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Schulte <schulte.eric@gmail.com>2013-01-30 17:05:51 (GMT)
committer Eric Schulte <schulte.eric@gmail.com>2013-01-30 17:08:38 (GMT)
commitc1226e80d4babe6b046c66d2e7ed92349bbb4768 (patch)
tree3debcc711e13b5a9c95eb90145ca81e1717d64f5
parentff2d373dc3701d896225876938120dae318e1268 (diff)
downloadorg-mode-c1226e80d4babe6b046c66d2e7ed92349bbb4768.zip
org-mode-c1226e80d4babe6b046c66d2e7ed92349bbb4768.tar.gz
option to show time stamps over result hashes
suggested by Thomas Alexander Gerds * lisp/ob-core.el (org-babel-result-regexp): Now matching time stamp as well. (org-babel-hash-show-time): Variable controlling the display of time stamps. (org-babel-current-result-hash): With hash time stamps. (org-babel-hide-all-hashes): With hash time stamps. (org-babel-where-is-src-block-result): With hash time stamps.
-rw-r--r--lisp/ob-core.el45
1 files changed, 31 insertions, 14 deletions
diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 9e4c8b1..fef56ed 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -36,6 +36,7 @@
(defvar org-babel-call-process-region-original)
(defvar org-src-lang-modes)
(defvar org-babel-library-of-babel)
+(defvar org-ts-regexp)
(declare-function show-all "outline" ())
(declare-function org-reduce "org" (CL-FUNC CL-SEQ &rest CL-KEYS))
(declare-function org-mark-ring-push "org" (&optional pos buffer))
@@ -453,7 +454,9 @@ specific header arguments as well.")
(defvar org-babel-result-regexp
(concat "^[ \t]*#\\+"
(regexp-opt org-babel-data-names t)
- "\\(\\[\\([[:alnum:]]+\\)\\]\\)?\\:[ \t]*")
+ "\\(\\[\\([[:alnum:]]+\\)\\]\\|\\[\\[\\([[:alnum:]]+\\)\\]\\["
+ org-ts-regexp
+ "\\]\\]\\)?\\:[ \t]*")
"Regular expression used to match result lines.
If the results are associated with a hash key then the hash will
be saved in the second match data.")
@@ -479,6 +482,9 @@ can not be resolved.")
(defvar org-babel-hash-show 4
"Number of initial characters to show of a hidden results hash.")
+(defvar org-babel-hash-show-time nil
+ "When not nil show the time the code block was evaluated in the result hash.")
+
(defvar org-babel-after-execute-hook nil
"Hook for functions to be called after `org-babel-execute-src-block'")
@@ -1073,7 +1079,7 @@ the current subtree."
(defun org-babel-current-result-hash ()
"Return the current in-buffer hash."
(org-babel-where-is-src-block-result)
- (org-no-properties (match-string 3)))
+ (org-no-properties (or (match-string 3) (match-string 4))))
(defun org-babel-set-current-result-hash (hash)
"Set the current in-buffer hash to HASH."
@@ -1107,7 +1113,8 @@ Only the initial `org-babel-hash-show' characters of each hash
will remain visible. This function should be called as part of
the `org-mode-hook'."
(save-excursion
- (while (re-search-forward org-babel-result-regexp nil t)
+ (while (and (not org-babel-hash-show-time)
+ (re-search-forward org-babel-result-regexp nil t))
(goto-char (match-beginning 0))
(org-babel-hide-hash)
(goto-char (match-end 0)))))
@@ -1745,7 +1752,8 @@ following the source block."
;; - if it does need to be rebuilt then do set end
name (setq beg (org-babel-find-named-result name))
(prog1 beg
- (when (and hash (not (string= hash (match-string 3))))
+ (when (and hash (not (string= hash (or (match-string 3)
+ (match-string 4)))))
(goto-char beg) (setq end beg) ;; beginning of result
(forward-line 1)
(delete-region end (org-babel-result-end)) nil)))
@@ -1763,14 +1771,17 @@ following the source block."
(beginning-of-line 1)
(looking-at
(concat org-babel-result-regexp "\n")))
- (prog1 (point)
- ;; must remove and rebuild if hash!=old-hash
- (if (and hash (not (string= hash (match-string 3))))
- (prog1 nil
- (forward-line 1)
- (delete-region
- end (org-babel-result-end)))
- (setq end nil))))))))))
+ (let ((this-hash (or ;; from org-babel-result-regexp
+ (match-string 3)
+ (match-string 4))))
+ (prog1 (point)
+ ;; must remove and rebuild if hash!=old-hash
+ (if (and hash (not (string= hash this-hash)))
+ (prog1 nil
+ (forward-line 1)
+ (delete-region
+ end (org-babel-result-end)))
+ (setq end nil)))))))))))
(if (not (and insert end)) found
(goto-char end)
(unless beg
@@ -1778,12 +1789,18 @@ following the source block."
(insert (concat
(when (wholenump indent) (make-string indent ? ))
"#+" org-babel-results-keyword
- (when hash (concat "["hash"]"))
+ (when hash
+ (if org-babel-hash-show-time
+ (concat "[[" hash
+ "]["
+ (format-time-string "<%Y-%m-%d %H:%M:%S>")
+ "]]")
+ (concat "["hash"]")))
":"
(when name (concat " " name)) "\n"))
(unless beg (insert "\n") (backward-char))
(beginning-of-line 0)
- (if hash (org-babel-hide-hash))
+ (when (and hash (not org-babel-hash-show-time)) (org-babel-hide-hash))
(point)))))
(defvar org-block-regexp)