5

I'd like to insert a timestamp in a custom format in emacs orgmode. I want to insert just the current time (without date!) in this form: [HH:MM], by pressing C-c -. I am completely new to lisp and couldn't figure out how to do this. My starting point for my ~/.emacs-file is like this:

(defun org-my-custom-timestamp ()
  (interactive)
  ( :SOME_CODE: )
)


(define-key global-map "\C-c-" 'org-my-custom-timestamp)

Now this is just the definition of my custom function called org-my-custom-timestamp, the "interactivation" and a Shortcut-assignment. However i have tried various things for :SOME_CODE: without any success.

What can be fitted in the function to make it work in the described way?

Does any experienced emacs-user even consider this way to tackle it practical or is there a smarter way to do it? Perhaps org-mode-internally?

1 Answer 1

6

Org mode's local keymap has an entry that binds C-c -, so we have to change it instead of a global one:

(defun org-my-custom-timestamp ()
  (interactive)
  (insert (format-time-string "[%H:%M]")))
(add-hook 'org-mode-hook
          (lambda ()
            (local-set-key "\C-c-" 'org-my-custom-timestamp)))

Note again that it replaces the org-ctrl-c-minus command, which is bound to C-c - by default in Org mode, with your own.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot! The Code-Snippet above works just fine and does exactly what i was looking for!Since this binding would overwrite an org-mode feature I decided to find another shortcut for this command.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.