diff options
author | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2016-10-01 10:30:53 +0200 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2016-10-01 10:30:53 +0200 |
commit | 9d7d650cd74db96cb4c230bca8fadf5afb17501d (patch) | |
tree | 17344d085edc8fbf09066a11c81dbf2f1e653646 | |
parent | c0fb62dc68c27d3916e7502acbfccf172be7b786 (diff) | |
download | org-mode-9d7d650cd74db96cb4c230bca8fadf5afb17501d.tar.gz |
ob-core: Fix hash with time stamp
* lisp/ob-core.el (org-babel-result-regexp): Fix regexp.
(org-babel--insert-results-keyword): Simplify format-string.
(org-babel--clear-results-maybe): Fix return value.
* testing/lisp/test-ob.el (test-ob/where-is-src-block-result): Add
tests.
Reported-by: Thomas Alexander Gerds <tag@biostat.ku.dk>
<http://permalink.gmane.org/gmane.emacs.orgmode/109418>
-rw-r--r-- | lisp/ob-core.el | 12 | ||||
-rw-r--r-- | testing/lisp/test-ob.el | 33 |
2 files changed, 40 insertions, 5 deletions
diff --git a/lisp/ob-core.el b/lisp/ob-core.el index 3e919e7..cbbc6d6 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -481,9 +481,11 @@ For the format of SAFE-LIST, see `org-babel-safe-header-args'." "Regexp matching a NAME keyword.") (defconst org-babel-result-regexp - (format "^[ \t]*#\\+%s\\(?:\\[\\(?:%S\\)?\\([[:alnum:]]+\\)\\]\\)?:[ \t]*" + (format "^[ \t]*#\\+%s\\(?:\\[\\(?:%s \\)?\\([[:alnum:]]+\\)\\]\\)?:[ \t]*" org-babel-results-keyword - "<\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} ?[^\r\n>]*?\\)>") + ;; <%Y-%m-%d %H:%M:%S> + "<\\(?:[0-9]\\{4\\}-[0-1][0-9]-[0-3][0-9] \ +[0-2][0-9]\\(?::[0-5][0-9]\\)\\{2\\}\\)>") "Regular expression used to match result lines. If the results are associated with a hash key then the hash will be saved in match group 1.") @@ -1860,7 +1862,7 @@ the results hash, or nil. Leave point before the keyword." (cond ((not hash) nil) (org-babel-hash-show-time (format "[%s %s]" - (format-time-string "<%Y-%m-%d %H:%M:%S>") + (format-time-string "<%F %T>") hash)) (t (format "[%s]" hash))) ":" @@ -1895,8 +1897,8 @@ leave point where new results should be inserted." (delete-region (line-beginning-position) (line-beginning-position 2))) (goto-char post) - (set-marker post nil))) - t)) + (set-marker post nil) + t)))) (defun org-babel-where-is-src-block-result (&optional insert _info hash) "Find where the current source block results begin. diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el index 6e7b5e6..caeae04 100644 --- a/testing/lisp/test-ob.el +++ b/testing/lisp/test-ob.el @@ -1659,6 +1659,39 @@ echo \"$data\" (let ((org-babel-results-keyword "RESULTS")) (goto-char (org-babel-where-is-src-block-result nil nil "bbbb"))) (org-trim (buffer-substring-no-properties (point) (point-max)))))) + ;; Handle hashes with times. + (should + (equal + "#+RESULTS[<2014-03-04 00:41:10> bbbb]:" + (org-test-with-temp-text + " +<point>#+BEGIN_SRC emacs-lisp +\(+ 1 1) +#+END_SRC + +#+RESULTS[<2012-03-29 16:40:12> aaaa]:" + (let ((org-babel-results-keyword "RESULTS") + (org-babel-hash-show-time t)) + (cl-letf (((symbol-function 'format-time-string) + (lambda (&rest _) "<2014-03-04 00:41:10>"))) + (goto-char (org-babel-where-is-src-block-result nil nil "bbbb")) + (org-trim (buffer-substring-no-properties (point) (point-max)))))))) + (should + (equal + "#+RESULTS[<2012-03-29 16:40:12> aaaa]:" + (org-test-with-temp-text + " +<point>#+BEGIN_SRC emacs-lisp +\(+ 1 1) +#+END_SRC + +#+RESULTS[<2012-03-29 16:40:12> aaaa]:" + (let ((org-babel-results-keyword "RESULTS") + (org-babel-hash-show-time t)) + (cl-letf (((symbol-function 'format-time-string) + (lambda (&rest _) "<2014-03-04 00:41:10>"))) + (goto-char (org-babel-where-is-src-block-result nil nil "aaaa")) + (org-trim (buffer-substring-no-properties (point) (point-max)))))))) ;; RESULTS keyword may not be the last affiliated keyword. (should (equal |