0

When I use the org-schedule function the time stamp is inserted below the line it was called from. However, when I call org-time-stamp it is inserted where the cursor is, often being inserted between the last letter and the rest of the word. Is there a way I can make org-time-stamp insert itself on the next line, like org-schedule does?

Thanks.

3

org-time-stamp inserts at point (see definition of point in the Emacs manual) so you are in complete control of where the string is inserted. If it is not inserted where you expect, then you need to move point (i.e. your cursor) to the appropriate place. Note that point is between two characters: the character that your cursor is on and the character before it.

org-time-stamp is also used by other functions (e.g. org-schedule) to insert the time stamp, so it does not insert anything extra: if anything extra needs to be added, it is added by the caller either manually or using PRE and POST arguments of org-insert-time-stamp, depending where you want to insert the strings.

You can define your own function to make it do what you want, e.g.:

(defun my/org-time-stamp-on-new-line ()
   (interactive)
   (end-of-line)
   (insert "\n")
   (org-time-stamp nil))

or

(defun my/org-time-stamp-on-new-line ()
   (interactive)
   (end-of-line)
   (org-insert-time-stamp nil nil nil "\n"))

If you don't want to change point, you can do this:

(defun my/org-time-stamp-on-new-line ()
   (interactive)
   (save-excursion
      (end-of-line)
      (org-insert-time-stamp nil nil nil "\n")))

You call it with M-x my/org-time-stamp-on-new-line or you can bind it to a key e.g.

(define-key org-mode-map (kbd "C-c z") #'my/org-time-stamp-on-new-line)
8
  • org-time-stamp is somehow a smart wrap of lower-level org-insert-time-stamp which - to me- seems more suited to this particular case. – Muihlinn Jan 6 at 22:03
  • @Muihlinn - maybe so, but it takes a TIME param which has to be specified (or converted from a current time). But I didn't bother with that, because I thought that the OP's basic problem was with the definition of point: the fact that he complains that "often" the string ends up where he does not expect it was the basic clue. The rest is more for the sake of completeness: if I had to do something like that, how would I do it? And again, the emphasis is more on where the string ends up rather than on what the string is. – NickD Jan 6 at 22:12
  • I wasn't particularly happy about your edit, exactly because it obscures that point: the complications of org-time-stamp are irrelevant in my view. – NickD Jan 6 at 22:14
  • It's perfectly fine to me, as long as org-time-stamp can take the same arguments which remains after your correction of my edit,, something I cannot check right now – Muihlinn Jan 6 at 22:52
  • 1
    @RaoulComninos Depending the context the approach could be different, but as jack of all trades, C-h f RET org-insert-time-stamp and fake it in your own function. – Muihlinn Jan 7 at 7:45

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.