diff options
| author | Yuchen Pei <id@ypei.org> | 2026-11-08 07:58:30 +1100 |
|---|---|---|
| committer | Yuchen Pei <id@ypei.org> | 2026-11-08 07:58:30 +1100 |
| commit | 37c64109dc07a16417a42931c4eb4c682efc08ad (patch) | |
| tree | ac479bae5bf119caf337080267d02bd10e73bef9 | |
| parent | d1ab29768fb1d21e7733f7f3f5ab1960bf99de42 (diff) | |
[emacs][mpv] Add emms focus mode
| -rw-r--r-- | emacs/.emacs.d/init/ycp-emms.el | 3 | ||||
| -rw-r--r-- | emacs/.emacs.d/init/ycp-gnus.el | 2 | ||||
| -rw-r--r-- | emacs/.emacs.d/init/ycp-org.el | 1 | ||||
| -rw-r--r-- | emacs/.emacs.d/init/ycp-web.el | 1 | ||||
| -rw-r--r-- | misc/.config/mpv/input.conf | 1 | ||||
| -rwxr-xr-x | misc/bin/emms-audio-focus.sh | 45 | ||||
| -rwxr-xr-x | misc/bin/emms.sh | 3 |
7 files changed, 55 insertions, 1 deletions
diff --git a/emacs/.emacs.d/init/ycp-emms.el b/emacs/.emacs.d/init/ycp-emms.el index e49209f..65a121d 100644 --- a/emacs/.emacs.d/init/ycp-emms.el +++ b/emacs/.emacs.d/init/ycp-emms.el @@ -43,6 +43,7 @@ (my-keybind emms-playlist-mode-map "C-x C-f" #'emms-play-playlist) (setq emms-player-list '(emms-player-mpv emms-player-vlc)) (setq emms-player-vlc-parameters '("--intf=qt" "--extraintf=rc")) + (add-to-list 'emms-player-mpv-parameters "--audio-client-name=emms" t) (setq emms-playlist-buffer-name "*EMMS Playlist*") (setq emms-source-file-directory-tree-function 'emms-source-file-directory-tree-find) @@ -50,6 +51,8 @@ (setq emms-info-auto-update nil) (add-hook 'emms-playlist-mode-hook #'hl-line-mode) (add-hook 'emms-metaplaylist-mode-hook #'hl-line-mode) + (setq server-name "emms") + (server-start) ) (my-package my-emms diff --git a/emacs/.emacs.d/init/ycp-gnus.el b/emacs/.emacs.d/init/ycp-gnus.el index 7275363..2a3b64f 100644 --- a/emacs/.emacs.d/init/ycp-gnus.el +++ b/emacs/.emacs.d/init/ycp-gnus.el @@ -230,7 +230,7 @@ (setq bbdb-mail-user-agent 'gnus-user-agent) (setq bbdb-update-records-p 'create) (setq bbdb-message-clean-mail-function 'my-bbdb-clean-mail) - (my-setq-from-local bbdb-message-ignore-mail-re) + (setq bbdb-message-ignore-mail-re "not?[-_]?reply") (setq bbdb-add-name nil) (require 'my-bbdb) (my-keybind bbdb-mode-map "C-c C-c" #'my-bbdb-done) diff --git a/emacs/.emacs.d/init/ycp-org.el b/emacs/.emacs.d/init/ycp-org.el index 3e73088..3774b35 100644 --- a/emacs/.emacs.d/init/ycp-org.el +++ b/emacs/.emacs.d/init/ycp-org.el @@ -30,6 +30,7 @@ ;;; the glorious org mode (my-package org + (calendar-set-date-style 'iso) (my-keybind global-map "M-u" #'org-store-link "C-c a" #'org-agenda diff --git a/emacs/.emacs.d/init/ycp-web.el b/emacs/.emacs.d/init/ycp-web.el index 89099d9..407b2f6 100644 --- a/emacs/.emacs.d/init/ycp-web.el +++ b/emacs/.emacs.d/init/ycp-web.el @@ -53,6 +53,7 @@ (my-package osm (:install t) (:delay 30) + (setq osm-server 'de) (require 'my-osm) (my-keybind osm-mode-map "C-<left>" nil diff --git a/misc/.config/mpv/input.conf b/misc/.config/mpv/input.conf index 0238138..8d0f7a3 100644 --- a/misc/.config/mpv/input.conf +++ b/misc/.config/mpv/input.conf @@ -1,3 +1,4 @@ PREV seek -15 NEXT stop a vf toggle hflip +j script-message-to console type "seek absolute" 6 diff --git a/misc/bin/emms-audio-focus.sh b/misc/bin/emms-audio-focus.sh new file mode 100755 index 0000000..44a2080 --- /dev/null +++ b/misc/bin/emms-audio-focus.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +# Pause EMMS while any other app plays audio; resume when quiet again. +RESUME_DELAY=2 # seconds of silence before resuming + +others_playing() { + pactl --format=json list sink-inputs 2>/dev/null | jq ' + [ .[] | select(.corked == false) + | select(.properties."application.name" != "emms") + | select(.properties."media.role" != "event") ] | length' +} + +emms_pause_if_playing() { # prints t only if *we* paused it + emacsclient -s emms --eval '(when (and emms-player-playing-p + (not emms-player-paused-p)) + (emms-pause) t)' 2>/dev/null +} + +emms_resume() { + emacsclient -s emms --eval '(when emms-player-paused-p (emms-pause))' >/dev/null 2>&1 +} + +exec 3< <(pactl subscribe) +paused_by_us=0 +quiet_since=0 + +while :; do + # Wake up on a sound-server event or once a second; drain event bursts. + read -r -t 1 -u 3 _ + while read -r -t 0.05 -u 3 _; do :; done + + n=$(others_playing) + if (( ${n:-0} > 0 )); then + quiet_since=0 + if (( ! paused_by_us )) && [[ $(emms_pause_if_playing) == t ]]; then + paused_by_us=1 + fi + elif (( paused_by_us )); then + (( quiet_since )) || quiet_since=$SECONDS + if (( SECONDS - quiet_since >= RESUME_DELAY )); then + emms_resume + paused_by_us=0 + quiet_since=0 + fi + fi +done diff --git a/misc/bin/emms.sh b/misc/bin/emms.sh new file mode 100755 index 0000000..0367671 --- /dev/null +++ b/misc/bin/emms.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +EMACS_PROFILE=emms emacs |
