;;; -*- lexical-binding: t -*- ;; ;; this file: ;; https://dataswamp.org/~incal/emacs-init/dope.el (require 'cl-lib) (defun read-string-1 (ps &optional def hist) (setq ps (format-prompt ps def)) (read-string ps nil hist def)) ;; (read-string-1 "name" "Danger") (defun day (&optional ps) (let ((today-str (format-time-string "%F"))) (if ps (read-string-1 ps today-str) today-str) )) ;; (day) ;; (day "from") (defun date-to-time-1 (from) (date-to-time (format "%sT00:00+01:00" from)) ) (defun dope (from boxes pills dose) (interactive (list (day "from") (read-number "boxes: " 16) (read-number "pills/box: " 30) (read-number "pills/day: " 5) )) (let*((days (/ (* boxes pills) dose)) (done (time-add (date-to-time-1 from) (days-to-time (1- days)))) (str (format-time-string "%F" done)) (more (format-time-string "%F" (time-add done (days-to-time -8)))) ) (insert (format "%s [%s] %s" from more str) ))) (let ((def-days 30) (def-sets 2) ) (defun add-days (&optional from days sets) (interactive (list (day "from") (read-number "days: " def-days) (read-number "sets: " def-sets) )) (or from (setq from (day))) (or days (setq days def-days)) (or sets (setq sets def-sets)) (cl-loop for s from 1 to (1- sets) do (insert (format-time-string "%F\n" (time-add (date-to-time-1 from) (days-to-time (* s days))) )))) (declare-function add-days nil) ) (provide 'dope)