branch: master commit 21007c2395105a14301c2f999549b533e2137e22 Author: Oleh Krehel <ohwoeo...@gmail.com> Commit: Oleh Krehel <ohwoeo...@gmail.com>
Add counsel-rhythmbox * counsel.el (counsel-completion-beg): (counsel-completion-end): Move declarations before first use. (dired-jump): Declare. (counsel-rhythmbox-enqueue-song): New defun. (counsel-rhythmbox): New command. Requires `helm-rhythmbox' package, and Rhythmbox, obviously. * ivy.el (ivy-call): Make interactive. Add special handling for the case when the collection is an alist. In that case, call the action not with the collection item, but with the cdr of said item. A bit weird, but that's the way Helm does it, and doing it in the same way means the action functions are cross-compatible. * ivy-hydra.el (hydra-ivy): Bind "g" to call the current action on current candidate without exiting. Now it's possible to make a query to Rhythmbox, "C-o" and navigate to a song with "j" and "k". Try the song with "g". Or use "s" once and then enqueue different songs with e.g. "jjgjjjgjgkkg". --- counsel.el | 43 +++++++++++++++++++++++++++++++++++++------ ivy-hydra.el | 3 ++- ivy.el | 13 +++++++++---- 3 files changed, 48 insertions(+), 11 deletions(-) diff --git a/counsel.el b/counsel.el index 5f48f30..0c589e1 100644 --- a/counsel.el +++ b/counsel.el @@ -34,6 +34,12 @@ (require 'swiper) +(defvar counsel-completion-beg nil + "Completion bounds start.") + +(defvar counsel-completion-end nil + "Completion bounds end.") + ;;;###autoload (defun counsel-el () "Elisp completion at point." @@ -75,12 +81,6 @@ :initial-input str :action #'counsel--el-action))) -(defvar counsel-completion-beg nil - "Completion bounds start.") - -(defvar counsel-completion-end nil - "Completion bounds end.") - (defun counsel--el-action (symbol) "Insert SYMBOL, erasing the previous one." (when (stringp symbol) @@ -439,6 +439,7 @@ Skip some dotfiles unless `ivy-text' requires them." shell-command-switch (format "xdg-open %s" (shell-quote-argument x)))) +(declare-function dired-jump "dired-x") (defun counsel-locate-action-dired (x) "Use `dired-jump' on X." (dired-jump nil x)) @@ -684,6 +685,36 @@ Usable with `ivy-resume', `ivy-next-line-and-call' and (custom-available-themes)) :action #'counsel--load-theme-action)) +(defvar rhythmbox-library) +(declare-function rhythmbox-load-library "ext:helm-rhythmbox") +(declare-function dbus-call-method "dbus") +(declare-function rhythmbox-song-uri "ext:helm-rhythmbox") +(declare-function helm-rhythmbox-candidates "ext:helm-rhythmbox") + +(defun counsel-rhythmbox-enqueue-song (song) + "Let Rhythmbox enqueue SONG." + (let ((service "org.gnome.Rhythmbox3") + (path "/org/gnome/Rhythmbox3/PlayQueue") + (interface "org.gnome.Rhythmbox3.PlayQueue")) + (dbus-call-method :session service path interface + "AddToQueue" (rhythmbox-song-uri song)))) + +;;;###autoload +(defun counsel-rhythmbox () + "Choose a song from the Rhythmbox library to play or enqueue." + (interactive) + (unless (require 'helm-rhythmbox nil t) + (error "Please install `helm-rhythmbox'")) + (unless rhythmbox-library + (rhythmbox-load-library) + (while (null rhythmbox-library) + (sit-for 0.1))) + (ivy-read "Rhythmbox: " + (helm-rhythmbox-candidates) + :action + '(1 + ("Play song" helm-rhythmbox-play-song) + ("Enqueue song" counsel-rhythmbox-enqueue-song)))) (provide 'counsel) diff --git a/ivy-hydra.el b/ivy-hydra.el index 030978f..cdaff1f 100644 --- a/ivy-hydra.el +++ b/ivy-hydra.el @@ -51,7 +51,7 @@ ^^^^^^^^^^^^^^--------------------------------------------------- ^ ^ _k_ ^ ^ _f_ollow _i_nsert _c_: calling %s(if ivy-calling \"on\" \"off\") _w_/_s_: %s(ivy-action-name) _h_ ^+^ _l_ _d_one _o_ops _m_: matcher %s(if (eq ivy--regex-function 'ivy--regex-fuzzy) \"fuzzy\" \"ivy\") -^ ^ _j_ ^ ^ ^ ^ ^ ^ _<_/_>_: shrink/grow window +^ ^ _j_ ^ ^ _g_o ^ ^ _<_/_>_: shrink/grow window " ;; arrows ("h" ivy-beginning-of-buffer) @@ -66,6 +66,7 @@ _h_ ^+^ _l_ _d_one _o_ops _m_: matcher %s(if (eq ivy--regex-function 'i ("f" ivy-alt-done :exit nil) ("C-j" ivy-alt-done :exit nil) ("d" ivy-done :exit t) + ("g" ivy-call) ("C-m" ivy-done :exit t) ("c" ivy-toggle-calling) ("m" ivy-toggle-fuzzy) diff --git a/ivy.el b/ivy.el index a768c18..876204f 100644 --- a/ivy.el +++ b/ivy.el @@ -539,10 +539,16 @@ If the input is empty, select the previous history element instead." (defun ivy-call () "Call the current action without exiting completion." + (interactive) (let ((action (ivy--get-action ivy-last))) (when action - (with-selected-window (ivy-state-window ivy-last) - (funcall action ivy--current))))) + (let* ((collection (ivy-state-collection ivy-last)) + (x (if (and (consp collection) + (consp (car collection))) + (cdr (assoc ivy--current collection)) + ivy--current))) + (with-selected-window (ivy-state-window ivy-last) + (funcall action x)))))) (defun ivy-next-line-and-call (&optional arg) "Move cursor vertically down ARG candidates. @@ -841,8 +847,7 @@ candidates with each input." (remove-hook 'post-command-hook #'ivy--exhibit) (when (setq unwind (ivy-state-unwind ivy-last)) (funcall unwind))) - (when (setq action (ivy--get-action ivy-last)) - (funcall action ivy--current)))) + (ivy-call))) (defun ivy--reset-state (state) "Reset the ivy to STATE.