“Parental control” for emacs

2018/09/21

It easily becomes automatic to check for notifications/new messages/new emails etc. To give my rational self some time to intercept compulsive behaviour I have made this elisp snippet.

(defun sarg/otp-for-confirm ()
  "Generates random hex string"
  (format "%06x%06x%06x"
          (random (expt 16 6))
          (random (expt 16 6))
          (random (expt 16 6))))

(defun confirm-advice (proc &rest args)
  "Asks to enter random string as confirmation before executing PROC."
  (interactive)
  (let* ((pass (sarg/otp-for-confirm))
         (input (read-string (format "Enter %s if you wish to proceed: " pass))))

    (if (string= input pass)
        (apply proc args))))

;; Apply the advice.
(advice-add 'ivy-telega-chat-with :around #'confirm-advice)