summaryrefslogtreecommitdiffhomepage
path: root/lib/media
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2026-08-28 10:05:55 +0100
committerjao <jao@gnu.org>2026-08-28 10:05:55 +0100
commit637347ed22733392b0fccddc8a91770091aa523f (patch)
treee177fde3c74461896970209baa72a1f0dc946b34 /lib/media
parent40111e4b0beb96b6832740a2a4674226297acef4 (diff)
downloadelibs-637347ed22733392b0fccddc8a91770091aa523f.tar.gz
elibs-637347ed22733392b0fccddc8a91770091aa523f.tar.bz2
random album with multisession
Diffstat (limited to 'lib/media')
-rw-r--r--lib/media/jao-random-album.el44
1 files changed, 20 insertions, 24 deletions
diff --git a/lib/media/jao-random-album.el b/lib/media/jao-random-album.el
index f3f758e..cfe9080 100644
--- a/lib/media/jao-random-album.el
+++ b/lib/media/jao-random-album.el
@@ -18,35 +18,32 @@
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+(require 'multisession)
+
(defvar jao-random-album-active t)
-(defvar jao-random-lines nil)
-(defvar jao-random-lines-file (expand-file-name "~/.emacs.d/random-lines"))
(defvar jao-random-album-notify nil)
(defvar jao-random-album-skip-lines 2)
+(define-multisession-variable jao-random-lines nil)
+
+(defun jao-random-album--buffer-lines ()
+ (let ((lines nil))
+ (dotimes (n (1- (line-number-at-pos (point-max))) lines)
+ (when (> n jao-random-album-skip-lines)
+ (push (1+ n) lines)))))
+
(defun jao-random-lines ()
- (or jao-random-lines
- (and (file-exists-p jao-random-lines-file)
- (with-current-buffer
- (find-file-noselect jao-random-lines-file)
- (goto-char (point-min))
- (setq jao-random-lines (read (current-buffer)))))
- (dotimes (n (1- (line-number-at-pos (point-max)))
- jao-random-lines)
- (when (> n jao-random-album-skip-lines)
- (push (1+ n) jao-random-lines)))))
-
-(defun jao-random-lines-save ()
- (with-current-buffer (find-file-noselect jao-random-lines-file)
- (delete-region (point-min) (point-max))
- (insert (format "%s\n" jao-random-lines))
- (save-buffer)))
+ (or (multisession-value jao-random-lines)
+ (jao-random-lines-save (jao-random-album--buffer-lines))))
+
+(defun jao-random-lines-save (v)
+ (setf (multisession-value jao-random-lines) v))
(defun jao-goto-random-album ()
- (let* ((pos (random (length (jao-random-lines))))
- (line (nth pos jao-random-lines)))
- (setq jao-random-lines (remove line jao-random-lines))
- (jao-random-lines-save)
+ (let* ((lines (jao-random-lines))
+ (pos (random (length lines)))
+ (line (nth pos lines)))
+ (jao-random-lines-save (remove line lines))
(goto-line line)))
@@ -82,8 +79,7 @@
(defun jao-random-album-reset ()
(interactive)
- (setq jao-random-lines nil)
- (jao-random-lines-save))
+ (jao-random-lines-save nil))
(defun jao-random-album-setup (album-buffer add-and-play stop)
(setq jao-random-album-buffer album-buffer