commit de53c1eade0b53579dda80a91a7c59a849bf6b4b
parent b072daf63f65d59580b7bc96ff128677bec79ee5
Author: KΓ©vin Le Gouguec <kevin.legouguec@gmail.com>
Date: Sun, 24 Mar 2024 12:24:10 +0100
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.
Diffstat:
| M | .emacs | | | 23 | ++++++++++++++++++++++- |
1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/.emacs b/.emacs
@@ -186,6 +186,26 @@
;; * executable: (info "(manual) Node"), "man 7 manual"
;; * <https://somewhe.re/manual.html#node>
+(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)))