ob: Replace angle brackets with parenthesis in Babel hashes

* lisp/ob-core.el (org-babel-hash-show-time): Remove
unnecessary :version keyword.
(org-babel-result-regexp):
(org-babel--insert-results-keyword): Remove angle brackets from time
stamp in hash.
* testing/lisp/test-ob.el (test-ob/where-is-src-block-result): Update
test.

Reported-by: stardiviner <numbchild@gmail.com>
<http://lists.gnu.org/r/emacs-orgmode/2020-05/msg00198.html>
This commit is contained in:
Nicolas Goaziou 2020-05-13 15:13:14 +02:00
parent 4349402f3f
commit 89c759f3ad
2 changed files with 23 additions and 15 deletions

View File

@ -165,7 +165,6 @@ This string must include a \"%s\" which will be replaced by the results."
"Non-nil means show the time the code block was evaluated in the result hash."
:group 'org-babel
:type 'boolean
:version "26.1"
:package-version '(Org . "9.0")
:safe #'booleanp)
@ -488,11 +487,21 @@ 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]*"
org-babel-results-keyword
;; <%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\\}\\)>")
(rx (seq bol
(zero-or-more (any "\t "))
"#+results"
(opt "["
;; Time stamp part.
(opt "("
(= 4 digit) (= 2 "-" (= 2 digit))
" "
(= 2 digit) (= 2 ":" (= 2 digit))
") ")
;; SHA1 hash.
(group (one-or-more hex-digit))
"]")
":"
(zero-or-more (any "\t "))))
"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.")
@ -1940,7 +1949,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 "<%F %T>")
(format-time-string "(%F %T)")
hash))
(t (format "[%s]" hash)))
":"

View File

@ -2090,34 +2090,33 @@ default-directory
;; Handle hashes with times.
(should
(equal
"#+RESULTS[<2014-03-04 00:41:10> bbbb]:"
"#+RESULTS[(2014-03-04 00:41:10) bbbb]:"
(org-test-with-temp-text
"
<point>#+BEGIN_SRC emacs-lisp
"#+BEGIN_SRC emacs-lisp
\(+ 1 1)
#+END_SRC
#+RESULTS[<2012-03-29 16:40:12> aaaa]:"
#+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>")))
(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]:"
"#+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]:"
#+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>")))
(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.