From cb90a203a7967b99032cd806f685419d4d0e2cd9 Mon Sep 17 00:00:00 2001
From: Yuchen Pei <id@ypei.org>
Date: Tue, 14 Jan 2025 09:42:04 +1100
Subject: [emacs] Add timer to save score in emms

Also add isearch to common packages, so that search-whitespace-regexp
takes effect in the emms profile
---
 emacs/.emacs.d/init/ycp-emms.el      |  1 +
 emacs/.emacs.d/lisp/my/my-package.el | 13 ++++++++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)

(limited to 'emacs')

diff --git a/emacs/.emacs.d/init/ycp-emms.el b/emacs/.emacs.d/init/ycp-emms.el
index 458a6b0..08c9d92 100644
--- a/emacs/.emacs.d/init/ycp-emms.el
+++ b/emacs/.emacs.d/init/ycp-emms.el
@@ -97,6 +97,7 @@
   (my-keybind dired-mode-map "e" #'my-dired-add-to-emms)
   (my-override emms-track-simple-description)
   (my-emms-add-all)
+  (my-timer emms-save-scores-timer nil 900 'emms-score-save-hash)
   )
 
 (provide 'ycp-emms)
diff --git a/emacs/.emacs.d/lisp/my/my-package.el b/emacs/.emacs.d/lisp/my/my-package.el
index b591d0f..9eefa2e 100644
--- a/emacs/.emacs.d/lisp/my/my-package.el
+++ b/emacs/.emacs.d/lisp/my/my-package.el
@@ -216,6 +216,17 @@ same name, cancel that one first."
        (cancel-timer ,var-name))
      (setq ,var-name (run-with-timer ,secs ,repeat ,function))))
 
+(defmacro my-timer (var-name secs repeat function)
+  "Create a timer.
+
+The timer has name VAR-NAME. If there is an existing time with the
+same name, cancel that one first."
+
+  `(progn
+     (when (and (boundp ',var-name) (timerp ,var-name))
+       (cancel-timer ,var-name))
+     (setq ,var-name (run-with-timer ,secs ,repeat ,function))))
+
 (defun my-describe-package-from-url (url)
   (interactive "sUrl: ")
   (when (string-match
@@ -263,7 +274,7 @@ same name, cancel that one first."
     (add-hook hook function)))
 
 (defvar my-common-packages
-  '(package windmove consult icomplete
+  '(package windmove consult icomplete isearch
             my-utils my-buffer my-editing my-complete)
   "Common packages to include with any profile")
 
-- 
cgit v1.2.3