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.
This commit is contained in:
Eric Schulte 2013-01-30 10:05:51 -07:00
parent ff2d373dc3
commit c1226e80d4
1 changed files with 31 additions and 14 deletions

View File

@ -36,6 +36,7 @@
(defvar org-babel-call-process-region-original) (defvar org-babel-call-process-region-original)
(defvar org-src-lang-modes) (defvar org-src-lang-modes)
(defvar org-babel-library-of-babel) (defvar org-babel-library-of-babel)
(defvar org-ts-regexp)
(declare-function show-all "outline" ()) (declare-function show-all "outline" ())
(declare-function org-reduce "org" (CL-FUNC CL-SEQ &rest CL-KEYS)) (declare-function org-reduce "org" (CL-FUNC CL-SEQ &rest CL-KEYS))
(declare-function org-mark-ring-push "org" (&optional pos buffer)) (declare-function org-mark-ring-push "org" (&optional pos buffer))
@ -453,7 +454,9 @@ specific header arguments as well.")
(defvar org-babel-result-regexp (defvar org-babel-result-regexp
(concat "^[ \t]*#\\+" (concat "^[ \t]*#\\+"
(regexp-opt org-babel-data-names t) (regexp-opt org-babel-data-names t)
"\\(\\[\\([[:alnum:]]+\\)\\]\\)?\\:[ \t]*") "\\(\\[\\([[:alnum:]]+\\)\\]\\|\\[\\[\\([[:alnum:]]+\\)\\]\\["
org-ts-regexp
"\\]\\]\\)?\\:[ \t]*")
"Regular expression used to match result lines. "Regular expression used to match result lines.
If the results are associated with a hash key then the hash will If the results are associated with a hash key then the hash will
be saved in the second match data.") be saved in the second match data.")
@ -479,6 +482,9 @@ can not be resolved.")
(defvar org-babel-hash-show 4 (defvar org-babel-hash-show 4
"Number of initial characters to show of a hidden results hash.") "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 (defvar org-babel-after-execute-hook nil
"Hook for functions to be called after `org-babel-execute-src-block'") "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 () (defun org-babel-current-result-hash ()
"Return the current in-buffer hash." "Return the current in-buffer hash."
(org-babel-where-is-src-block-result) (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) (defun org-babel-set-current-result-hash (hash)
"Set the current in-buffer hash to 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 will remain visible. This function should be called as part of
the `org-mode-hook'." the `org-mode-hook'."
(save-excursion (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)) (goto-char (match-beginning 0))
(org-babel-hide-hash) (org-babel-hide-hash)
(goto-char (match-end 0))))) (goto-char (match-end 0)))))
@ -1745,7 +1752,8 @@ following the source block."
;; - if it does need to be rebuilt then do set end ;; - if it does need to be rebuilt then do set end
name (setq beg (org-babel-find-named-result name)) name (setq beg (org-babel-find-named-result name))
(prog1 beg (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 (goto-char beg) (setq end beg) ;; beginning of result
(forward-line 1) (forward-line 1)
(delete-region end (org-babel-result-end)) nil))) (delete-region end (org-babel-result-end)) nil)))
@ -1763,14 +1771,17 @@ following the source block."
(beginning-of-line 1) (beginning-of-line 1)
(looking-at (looking-at
(concat org-babel-result-regexp "\n"))) (concat org-babel-result-regexp "\n")))
(prog1 (point) (let ((this-hash (or ;; from org-babel-result-regexp
;; must remove and rebuild if hash!=old-hash (match-string 3)
(if (and hash (not (string= hash (match-string 3)))) (match-string 4))))
(prog1 nil (prog1 (point)
(forward-line 1) ;; must remove and rebuild if hash!=old-hash
(delete-region (if (and hash (not (string= hash this-hash)))
end (org-babel-result-end))) (prog1 nil
(setq end nil)))))))))) (forward-line 1)
(delete-region
end (org-babel-result-end)))
(setq end nil)))))))))))
(if (not (and insert end)) found (if (not (and insert end)) found
(goto-char end) (goto-char end)
(unless beg (unless beg
@ -1778,12 +1789,18 @@ following the source block."
(insert (concat (insert (concat
(when (wholenump indent) (make-string indent ? )) (when (wholenump indent) (make-string indent ? ))
"#+" org-babel-results-keyword "#+" 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")) (when name (concat " " name)) "\n"))
(unless beg (insert "\n") (backward-char)) (unless beg (insert "\n") (backward-char))
(beginning-of-line 0) (beginning-of-line 0)
(if hash (org-babel-hide-hash)) (when (and hash (not org-babel-hash-show-time)) (org-babel-hide-hash))
(point))))) (point)))))
(defvar org-block-regexp) (defvar org-block-regexp)