diff options
| author | Kévin Le Gouguec <kevin.legouguec@gmail.com> | 2024-03-24 12:24:10 +0100 |
|---|---|---|
| committer | Kévin Le Gouguec <kevin.legouguec@gmail.com> | 2024-03-24 12:24:10 +0100 |
| commit | de53c1eade0b53579dda80a91a7c59a849bf6b4b (patch) | |
| tree | 4b7364dba5f3d2c9e552ac116b7aea338f50620a | |
| parent | b072daf63f65d59580b7bc96ff128677bec79ee5 (diff) | |
| download | dotfiles-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.
| -rw-r--r-- | .emacs | 23 |
1 files changed, 22 insertions, 1 deletions
@@ -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))) |
