code/elisp
2023-12-02 14:58:54 -05:00
..
README.org Add alu-time-now 2023-12-02 14:58:54 -05:00

alu-time-now

This function came from my desire to speed up a repetitive part of my blogging process. I have a last modified field in the metadata for my posts and when go to commit changes, I want to update that value. At first this function just shelled out and called date, but it also got tedious to delete the old timestamp. So this function is my one M-x solution.

Notable elisp features:

  • Using and cleaning up a temporary buffer
  • Writing the output of a shell command to some buffer
  • Inserting the content of a buffer into the current buffer
  (defun alu-time-now ()
    "With point on a date time string, replace with current time"
    (interactive)
    (let* ((tmp-buffer (generate-new-buffer "alu-scratch")))
      (shell-command "date -Iseconds"
                     tmp-buffer)
      (delete-char 25)
      (insert-buffer-substring (buffer-name tmp-buffer)
                               1 26)
      (kill-buffer tmp-buffer)))