0

The function #'org-time-stamp prompts a minibuffer that reads control strings from the user, and call #'org-insert-time-stamp to insert the resulting time stamp as a string into the buffer. For example, the control string "2021-01-01 9am" results to the time stamp "<2021-01-01 Fri 09:00>".

How to factor these functions to create a new function that still prompts a minibuffer, but only returns a string without insertion? Some thing like

(org-time-stamp-read "2021-01-01 9am") 
;; => "<2021-01-01 Fri 09:00>"

2 Answers 2

2

org-read-date does what you want:

org-read-date is a compiled Lisp function in `org.el'.

(org-read-date &optional WITH-TIME TO-TIME FROM-STRING PROMPT
DEFAULT-TIME DEFAULT-INPUT INACTIVE)

Read a date, possibly a time, and make things smooth for the user.
0

A direct way that offers the same result is

(with-temp-buffer
  (org-time-stamp nil)
  (buffer-string))

However, this is not efficient enough. I still hope to see a proper factoring.

3
  • Why do you think that is not efficient enough?
    – NickD
    Jun 10, 2021 at 23:50
  • Because #'org-time-stamp must have included the functionality I want. My method effectively gets the desired string, write it to a temporary buffer, and then copy the buffer string to the result.
    – Student
    Jun 11, 2021 at 3:52
  • You are right that it is (slightly) inefficient in that respect, but in practice, this is a pretty good way to go: the inefficiency is probably not going to manifest itself unless you do this millions of times. You can try profiling the code and see how much of a difference it makes. I grant you that the other answer is probably a better way to go in this case.
    – NickD
    Jun 11, 2021 at 14:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.