all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Marcin Borkowski <mbork@mbork.pl>
To: Help Gnu Emacs mailing list <help-gnu-emacs@gnu.org>
Subject: Making sure I'm not checking email (or doing other things) too often
Date: Sun, 14 Feb 2016 22:05:02 +0100	[thread overview]
Message-ID: <87d1rz2ebl.fsf@mbork.pl> (raw)

Hi all,

thanks to Michael Heerdegen, my code is now working, and even though it
is not finished, I'm quite happy/proud of it.  I will finish it within
a week or two and blog about it, but please let me show the current
state here, especially that I suspect a few people could find it handy.

The problem: I hit U (mu4e-update-mail-and-index) way too often.  I want
Emacs to help me fight this unproductive habit.

Also, I'm a mathematician, and I want to have a general solution to the
problem of launching certain commands too often.

So, here is my current solution.  It is not perfect, I will tinker with
it a bit more later.

--8<---------------cut here---------------start------------->8---
(defun not-too-often-add-guard (fun interval)
  "Add a not-too-often guard to FUN with INTERVAL.
This means that if FUN gets called less than INTERVAL minutes
after last call, the use is asked whether s?he really wants to
run the command."
  (let* ((fun-name (symbol-name fun))
	 (nto-int-sym
	  (intern (concat "not-too-often-interval-" fun-name)))
	 (nto-last-time-sym
	  (intern (concat "not-too-often-last-time-" fun-name)))
	 (nto-guard-sym
	  (intern (concat "not-too-often-guard-" fun-name))))
    (set nto-int-sym interval)
    (set nto-last-time-sym 0)
    (fset nto-guard-sym (lambda (orig-fun &rest args)
			  (let ((elapsed (time-to-seconds
					  (time-subtract
					   (current-time)
					   (symbol-value nto-last-time-sym)))))
			    (if (< elapsed
				   (* 60 (symbol-value nto-int-sym)))
				(cond ((y-or-n-p
					(format "You called %s %s minutes ago.  Are you sure you want to proceed? "
						fun-name (/ elapsed 60.0)))
				       (set nto-last-time-sym (current-time))
				       (apply orig-fun args))
				      (t
				       (keyboard-quit)))
			      (set nto-last-time-sym (current-time))))))
    (put nto-guard-sym 'function-documentation
	 (format
	  "Issue a warning if function `%s' is called less than %s minutes from last call."
	  fun-name interval))
    (advice-add fun :around nto-guard-sym)))
--8<---------------cut here---------------end--------------->8---

Now I can say e.g.

(not-too-often-add-guard 'mu4e-update-mail-and-index 15)

and have Emacs warn me if I want to check for new email sooner than 15
minutes after last time.

Opinions welcome.

Best,

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University



             reply	other threads:[~2016-02-14 21:05 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-14 21:05 Marcin Borkowski [this message]
2016-02-15  1:29 ` Making sure I'm not checking email (or doing other things) too often Emanuel Berg
2016-02-15 15:21   ` Marcin Borkowski
2016-02-15 16:32     ` tomas
2016-02-16  0:48       ` Emanuel Berg
2016-02-16  7:38         ` tomas
2016-02-17  2:38           ` Emanuel Berg
2016-02-16  0:37     ` Emanuel Berg
     [not found]   ` <mailman.4745.1455549737.843.help-gnu-emacs@gnu.org>
2016-02-15 21:10     ` Joost Kremers
2016-02-16  0:56       ` Emanuel Berg
2016-02-17 13:42       ` Rusi
2016-02-18  0:24         ` Emanuel Berg
2016-02-15 14:40 ` Michael Heerdegen
2016-02-15 14:58   ` Marcin Borkowski
2016-02-15 15:08     ` Michael Heerdegen
2016-02-15 15:18       ` Marcin Borkowski
2016-03-06 13:26   ` Marcin Borkowski
2016-03-06 13:36     ` Marcin Borkowski
2016-03-06 13:59       ` Michael Heerdegen
2016-03-06 13:39     ` Michael Heerdegen
2016-03-06 14:09       ` Marcin Borkowski
2016-03-06 14:22         ` Michael Heerdegen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87d1rz2ebl.fsf@mbork.pl \
    --to=mbork@mbork.pl \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.