summaryrefslogtreecommitdiff
path: root/.emacs
diff options
context:
space:
mode:
authorKévin Le Gouguec <kevin.legouguec@gmail.com>2024-03-24 12:24:10 +0100
committerKévin Le Gouguec <kevin.legouguec@gmail.com>2024-03-24 12:24:10 +0100
commitde53c1eade0b53579dda80a91a7c59a849bf6b4b (patch)
tree4b7364dba5f3d2c9e552ac116b7aea338f50620a /.emacs
parentb072daf63f65d59580b7bc96ff128677bec79ee5 (diff)
downloaddotfiles-de53c1eade0b53579dda80a91a7c59a849bf6b4b.tar.xz
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 (limited to '.emacs')
-rw-r--r--.emacs23
1 files changed, 22 insertions, 1 deletions
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"
;; * <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)))