From 713820ab03f3c021c4c142d95508f52c08815ff1 Mon Sep 17 00:00:00 2001 From: noa Date: Sun, 16 Feb 2025 21:49:32 +0800 Subject: Improve defun to insert date/time --- emacs/init.el | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'emacs') diff --git a/emacs/init.el b/emacs/init.el index 37abb6f..94d9e34 100644 --- a/emacs/init.el +++ b/emacs/init.el @@ -543,9 +543,16 @@ The misspelled word is taken from OVERLAY. WORD is the corrected word." ;; Insert date and time at point ;; Sometimes it's useful to be able to add a timestamp. I use this for notes. Use the same binding as notepad.exe. -(defun noa/insert-date-time () +(defun noa/insert-date (&optional time) + "Insert the current date into the buffer. +With prefix argument TIME, also add the current time." + (interactive "P") + (if time + (insert (format-time-string "[%Y-%m-%d %H:%M]")) + (insert (format-time-string "[%Y-%m-%d]")))) +(defun noa/insert-datetime () (interactive) - (insert (format-time-string "<%Y-%m-%d>"))) + (noa/insert-date t)) (global-set-key (kbd "") 'noa/insert-date-time) -- cgit 1.4.1-2-gfad0