From de53c1eade0b53579dda80a91a7c59a849bf6b4b Mon Sep 17 00:00:00 2001 From: Kévin Le Gouguec Date: Sun, 24 Mar 2024 12:24:10 +0100 Subject: Add command to kill the current date Comes up often enough, e.g. to add a stamp to a filename; probably was the original motivation for my/kill-shell. Gave a honest attempt at using a transient for this, but got bogged down second-guessing whether I should define my arguments as shorthands inside my transient-define-prefix form, or as dedicated transient-define-argument forms; gave up while trying to figure out whether the shorthand form could use transient-read-date. --- .emacs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/.emacs b/.emacs index e6d10bd..b3866da 100644 --- a/.emacs +++ b/.emacs @@ -186,6 +186,26 @@ ;; * executable: (info "(manual) Node"), "man 7 manual" ;; * +(defun my/read (prompt default) + (read-string (format-prompt prompt default) nil nil default)) + +(defun my/run (program &rest args) + (let ((handler (lambda (status) + (unless (eq status 0) + (user-error + "%s returned %d:\n%s" + program status (buffer-string)))))) + (apply 'process-lines-handling-status program handler args))) + +(defun my/kill-date (date format) + (interactive + (if current-prefix-arg + (list (my/read "Date spec?" "today") + (my/read "Format?" "%F")) + (list "today" "%F"))) + (my/kill + (car (my/run "date" (concat "-d" date) (concat "+" format))))) + (defun my/kill-filename () (interactive) (my/kill (or (buffer-file-name) default-directory))) @@ -276,7 +296,8 @@ (my/define-prefix-command my/kill-map "Keymap for adding things to the kill ring." - '(("f" my/kill-filename) + '(("d" my/kill-date) + ("f" my/kill-filename) ("|" my/kill-pipe-region) ("!" my/kill-shell))) -- cgit v1.2.3