0

I'm looking for the cleanest way to have a language agnostic keybinding that will insert my initials + formatted timestamp e.g.:

--<my initials> (28 Oct 2013 11:38:20 AM)

into an Emacs buffer, so that I can initial my comments. I know I could create a function and create a keybinding to call it, but I feel like Emacs probably has a de facto way to do stuff like this, presumedly through the use of macros.

NFicano
  • 1,065
  • 1
  • 11
  • 26
  • I'm not using any of these: http://orgmode.org/worg/org-tutorials/org-outside-org.html but I'd imagine it would be the way to go (this let's you use some of the Org-mode functionality inside other modes, inserting a date from a calendar would be something like `C-c C-d` then, I presume. –  Oct 28 '13 at 15:56

2 Answers2

1

F3 (start recording macro)

--AA C-u M-! date C-e (insert text, insert output from date command)

F4 (stop recording macro)

C-x C-k n my-initial-timestamp (name the macro)

C-x C-k b ... (bind the macro to an appropriate key combination)

And finally, open ~/.emacs and type C-u M-x insert-kbd-macro RET my-initial-timestamp, which will insert the Lisp code to recreate the macro and bind it to the same key at startup.

legoscia
  • 39,593
  • 22
  • 116
  • 167
0

Emacs does not have such a function, AFAIK. There is function time-stamp, which updates time-stamp templates in a buffer, but that is not what you want here.

This command gives you what you requested. Other time/date formats are available - see format-time-string. You can also use functions such as user-full-name and user-login-name, if you want your name instead of your initials. Here, I've just hard-coded your initials, NF. This should work for any buffer where a comment syntax is defined (comment-start).

(defun my-timestamp-comment ()
  (interactive)
  (insert (format "%s NF (%s)" comment-start
                  (format-time-string "%b %e %Y %r" (current-time)))))
Drew
  • 29,895
  • 7
  • 74
  • 104