unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH 1/2] test: add general Emacs hook counter
@ 2011-12-21 18:18 Dmitry Kurochkin
  2011-12-21 18:18 ` [PATCH 2/2] test: add test for `notmuch-hello-refresh-hook' Dmitry Kurochkin
  2011-12-22 11:29 ` [PATCH 1/2] test: add general Emacs hook counter David Bremner
  0 siblings, 2 replies; 7+ messages in thread
From: Dmitry Kurochkin @ 2011-12-21 18:18 UTC (permalink / raw)
  To: notmuch

Replace `notmuch-hello-mode-hook-counter' with general `hook-counter'
and `add-hook-counter' functions to allow counting calls for any hook.
---
 test/test-lib.el |   21 +++++++++++++--------
 1 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/test/test-lib.el b/test/test-lib.el
index 3bca138..83b8a65 100644
--- a/test/test-lib.el
+++ b/test/test-lib.el
@@ -62,11 +62,16 @@ running, quit if it terminated."
       (kill-emacs)
     (run-at-time "1 min" nil 'orphan-watchdog pid)))
 
-(defun notmuch-hello-mode-hook-counter ()
-  "Count how many times `notmuch-hello-mode-hook' is called.
-Increments `notmuch-hello-mode-hook-counter' variable value if it
-is bound, otherwise does nothing."
-  (if (boundp 'notmuch-hello-mode-hook-counter)
-      (setq notmuch-hello-mode-hook-counter
-	    (1+ notmuch-hello-mode-hook-counter))))
-(add-hook 'notmuch-hello-mode-hook 'notmuch-hello-mode-hook-counter)
+(defun hook-counter (hook)
+  "Count how many times a hook is called.  Increments
+`hook'-counter variable value if it is bound, otherwise does
+nothing."
+  (let ((counter (intern (concat (symbol-name hook) "-counter"))))
+    (if (boundp counter)
+	(set counter (1+ (symbol-value counter))))))
+
+(defun add-hook-counter (hook)
+  "Add hook to count how many times `hook' is called."
+  (add-hook hook (apply-partially 'hook-counter hook)))
+
+(add-hook-counter 'notmuch-hello-mode-hook)
-- 
1.7.7.3

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-12-22 11:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-21 18:18 [PATCH 1/2] test: add general Emacs hook counter Dmitry Kurochkin
2011-12-21 18:18 ` [PATCH 2/2] test: add test for `notmuch-hello-refresh-hook' Dmitry Kurochkin
2011-12-21 21:49   ` Thomas Jost
2011-12-21 21:54     ` Dmitry Kurochkin
2011-12-21 22:09       ` Thomas Jost
2011-12-22  8:55   ` Tomi Ollila
2011-12-22 11:29 ` [PATCH 1/2] test: add general Emacs hook counter David Bremner

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).