2

C-u C-c ! generates a time stamp like [2015-05-04 Mon 17:13]

I would like to assign a shortcut (e.g F1) to this action.

So far I have:

(defun my/timenow (&optional arg) 
 (interactive) 
 (let ((current-prefix-arg 4)) ;; emulate C-u
 (org-time-stamp arg 'inactive)
 )
)

But this prompts me for the time and I have to press RET to insert it.

How can I insert the inactive timestamp without any prompts at all?

6

From the documentation of org-time-stamp:

With two universal prefix arguments, insert an active timestamp with the current time without prompting the user.

So eval the below:

(org-time-stamp '(16) t)
  • '(4) - one prefix arg (4)
  • '(16) - two prefix args (4 * 4)
  • '(64) - three prefix args (4 * 4 * 4)

To read more about the universal arguments and arguments in general:

  • Bonus points for explaining the 4/16/64 notion of prefix args ^_^. Thank you. – Leo Ufimtsev May 5 '15 at 14:01
  • This command (insert (org-time-stamp '(16) t)) inserts two timestamps next to each other. Do you know why? – miguelmorin Oct 15 '18 at 15:42
  • 1
    @mmorin if you look at org-time-stamp code (use M-x find-function), it's inserting by itself, so you don't need extra insert. Alternatively, you can use insert with a combination of format-time-string and org-time-stamp-format. – karlicoss Feb 15 at 23:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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