]> code.delx.au - gnu-emacs-elpa/commitdiff
Add counsel-rhythmbox
authorOleh Krehel <ohwoeowho@gmail.com>
Thu, 9 Jul 2015 13:54:51 +0000 (15:54 +0200)
committerOleh Krehel <ohwoeowho@gmail.com>
Thu, 9 Jul 2015 13:54:51 +0000 (15:54 +0200)
* 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
ivy-hydra.el
ivy.el

index 5f48f3037b107a6a9d414e526be82c47ddecd330..0c589e13dfd152cba5e4c03be43dc8e59e96984e 100644 (file)
 
 (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."
               :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)
 
index 030978fc43fe7fb2fb454e9ec29dcb4e8709d606..cdaff1fbc34e506c00ff44bdceb956f416b24bee 100644 (file)
@@ -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 a768c18ed076dcdd203977700f4fb01683fdbab6..876204fd8889ed9ac3864eaeb02eb0b0871a37dd 100644 (file)
--- 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.