From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?UTF-8?B?Q8OpZHJpYyBDaMOpcGllZA==?= Newsgroups: gmane.emacs.devel Subject: Re: ampc back on elpa? Date: Wed, 15 Jun 2016 11:53:07 +0200 Message-ID: References: <573736bd.442cc20a.8d117.ffff9cd7@mx.google.com> <5745411e.aaf0c20a.8e140.4623@mx.google.com> <575abfdd.697ac20a.d9403.5ca0@mx.google.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1465984407 1695 80.91.229.3 (15 Jun 2016 09:53:27 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 15 Jun 2016 09:53:27 +0000 (UTC) To: emacs-devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Jun 15 11:53:27 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1bD7Vl-0004kO-Qi for ged-emacs-devel@m.gmane.org; Wed, 15 Jun 2016 11:53:26 +0200 Original-Received: from localhost ([::1]:41091 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bD7Vk-0000wI-Av for ged-emacs-devel@m.gmane.org; Wed, 15 Jun 2016 05:53:24 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33610) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bD7VX-0000t1-52 for emacs-devel@gnu.org; Wed, 15 Jun 2016 05:53:12 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bD7VU-00039J-L4 for emacs-devel@gnu.org; Wed, 15 Jun 2016 05:53:10 -0400 Original-Received: from mail-io0-x232.google.com ([2607:f8b0:4001:c06::232]:36164) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bD7VU-000396-E6 for emacs-devel@gnu.org; Wed, 15 Jun 2016 05:53:08 -0400 Original-Received: by mail-io0-x232.google.com with SMTP id n127so18021598iof.3 for ; Wed, 15 Jun 2016 02:53:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-transfer-encoding; bh=247ArswxVjaR0eS9MrOGAP/pQ4FAfKseY3Owc0pO1GI=; b=MiUG2xzppXtei4v/kTm0C+kOtWaLEKQVmxu4dks4GIEFGePwLFtAdKP1PstIFhujWx 1/wSSL7B5+pB15RrpoZeMXhanBUZ8JzKQwGoRixqniOd1uvpgJDq1/bNyd4tlKaNimHx yNQryAeHeJYPQf0cEzcoB1naaeSJJ+8qf9SbV1xNwhQ+M9JAiqylDHIxhaA23cXJuim4 vo4UYedrtc8vpQFb+dD4hXzRGqtDeejxdAWPkA/Dieayr0RfwvCOOzXh6oHVI7aJjdhz 0nq5lrdgECnPFy0I8GItDSfQvSN0+onO1Ste4OTT33PHQ2IhAite79GjXLcMULOFhOYA 3iRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-transfer-encoding; bh=247ArswxVjaR0eS9MrOGAP/pQ4FAfKseY3Owc0pO1GI=; b=djGEVZP6uZVPKlPtK/6dAOqtM5O7UDegiYYII/0ddMZCahYsitHnj7NPx90PqTXR8I 1g7qvbRN5NqXE8nTsTtGpkkSUu2GutVgS5omHl5vD7Qyu2bM9LxYJ3meMPX55tN2D9qJ 9tBEAUo55iVS9LJXmCsF79Ot44UuWol4tyMy4pKzkTvzxtkQjTmMEMv3EXRvlWzSfb// DCnAger/zeTUyT0OjpdzaI/21WM2yKjjBk/gaMsGiDSmcD6xbz5MtcWpomUmYczT961s I6wR3fo9g9lqwB/zvMOjXbQVql/6wnQ/AV5GWLcIWhk9fS6MtAaQoytX0kU7fc/hNDXi pMvw== X-Gm-Message-State: ALyK8tI10LDsKCttcfCwU0JuSAP0tvYSne0n2S1y2PIts90o010ZL9hDjGJh0i4fgH4gdXMQPEHM2URoKulWtw== X-Received: by 10.107.132.37 with SMTP id g37mr37564721iod.147.1465984387467; Wed, 15 Jun 2016 02:53:07 -0700 (PDT) Original-Received: by 10.36.199.194 with HTTP; Wed, 15 Jun 2016 02:53:07 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4001:c06::232 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:204379 Archived-At: Hi, I must use gmail webclient :-/ I hope this email and the patch pasted at the end will be readable. On Mon, 13 Jun 2016 14:45:16 +0200, Stefan Monnier wrote: > > @@ -569,6 +573,13 @@ modified." > > (0.4 playlist ,@pl-prop) > > (1.0 playlists))) > > ,rs_b) > > + ("Search view" > > + ,(kbd "F") > > + horizontal > > + (0.4 vertical > > + (6 status) > > + (1.0 current-playlist ,@pl-prop)) > > + ,search-view) > > ("Outputs view" > > ,(kbd "L") > > outputs :properties (("outputname" :title "Name" :min 10 :max 3= 0) > > Indentation looks odd here. Maybe a mix of spaces and tabs? Only spaces here. One extra space before ,(kbd "F") Fixed in new patch below. Is that the problem you are talking about? > > (defmacro ampc-iterate-source-output (delimiter bindings pad-data &res= t body) > > + "delimiter =3D what delimit command results in mpd response" > > Thank you for helping document the code. Could you add a first line > describing of the general functionality? Also put `delimiter` in > all-caps since that's the convention used in Emacs for function/macro > arguments in docstrings. I'm not documenting the code :-D I was just trying to understand it. I can'= t document this macro because I don't really know what it does. I put `delimi= ter` in all caps but I can't do more. Should I remove it? > Can you rewrite it to something like > > (search > (unless (active-minibuffer-window) > ;; Can't find a better way to check minibuffer > (let ((search (read-from-minibuffer "Keywords: "))) > (setq ampc-search-keywords > (unless (string=3D "" search) search)))) > (when ampc-search-keywords > (ampc-send-command 'search nil "any" > (ampc-quote ampc-search-keywords)))) > > But in any case, this looks fishy. `ampc-update` doesn't seem like > a good place to have user interaction. Why do you need to > `read-from-minibuffer` *here* (BTW, I recommend you use `read-string` > instead)? I mean, why can't you set ampc-search-keywords elsewhere? Done. I removed code in ampc-update and added a new function ampc-start-sea= rch binded to the 's' key in search view. No need to check minibuffer, using read-string and your nice `(setq ampc-search-keywords (unless (string=3D "" search) search)))` line. Regards, --=20 C=C3=A9dric Ch=C3=A9pied >From 64dfb675509d29653f0945abfd0619148deb6a25 Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?C=3DC3=3DA9dric=3D20Ch=3DC3=3DA9pied?=3D Date: Wed, 15 Jun 2016 11:36:52 +0200 Subject: [PATCH] ampc: add search function --- packages/ampc/ampc.el | 73 +++++++++++++++++++++++++++++++++++++++++++++++= ---- 1 file changed, 68 insertions(+), 5 deletions(-) diff --git a/packages/ampc/ampc.el b/packages/ampc/ampc.el index 7a28bc7..8134c5c 100644 --- a/packages/ampc/ampc.el +++ b/packages/ampc/ampc.el @@ -76,11 +76,11 @@ ;; selected window for its window setup, customise `ampc-use-full-frame' t= o a ;; non-nil value. ;; -;; ampc offers three independent views which expose different parts of the= user +;; ampc offers independent views which expose different parts of the user ;; interface. The current playlist view, the default view at startup, may= be ;; accessed using the `J' key (that is `S-j'). The playlist view may be ;; accessed using the `K' key. The outputs view may be accessed by pressi= ng -;; `L'. +;; `L'. The search view may be accessed using the `F' key (find). ;;; *** current playlist view ;; The playlist view looks like this: @@ -161,6 +161,11 @@ ;; MPD. To toggle the enabled property of the selected outputs, press `a' ;; (ampc-toggle-output-enabled) or `'. +;;; *** search view +;; The search view contains the result of the last performed search. You c= an +;; start a new search with the `s' key while in the search view or use M-x +;; ampc-start-search. Use the `a' key to add a song displayed in result li= st. + ;;; ** tagger ;; To start the tagging subsystem, press `I' (ampc-tagger). This key bind= ing ;; works in every buffer associated with ampc. First, the command tries t= o @@ -521,7 +526,11 @@ modified." (pl-prop '(:properties (("Title" :min 15 :max 40) ("Artist" :min 15 :max 40) ("Album" :min 15 :max 40) - ("Time" :width 6))))) + ("Time" :width 6)))) + (search-view '(1.0 search :properties (("Track" :title "#" :width= 4) + ("Title" :min 15 :max 40) + ("Artist" :min 15 :max 40) + ("Album" :min 15 :max 40))= ))) `((tagger horizontal (0.65 files-list @@ -569,6 +578,13 @@ modified." (0.4 playlist ,@pl-prop) (1.0 playlists))) ,rs_b) + ("Search view" + ,(kbd "F") + horizontal + (0.4 vertical + (6 status) + (1.0 current-playlist ,@pl-prop)) + ,search-view) ("Outputs view" ,(kbd "L") outputs :properties (("outputname" :title "Name" :min 10 :max 30) @@ -602,6 +618,7 @@ modified." (defconst ampc-tagger-version "0.1") (defconst ampc-tagger-tags '(Title Artist Album Comment Genre Year Track)) +(defconst ampc-buffer-name " *ampc*") ;;; *** mode maps (defvar ampc-mode-map @@ -696,6 +713,16 @@ modified." (define-key map (kbd "") 'ampc-mouse-align-point) map)) +(defvar ampc-search-mode-map + (let ((map (make-sparse-keymap))) + (suppress-keymap map) + (define-key map (kbd "a") 'ampc-add) + (define-key map (kbd "s") 'ampc-start-search) + (define-key map (kbd "") 'ampc-mouse-add) + (define-key map (kbd "") 'ampc-mouse-align-point) + map) + "Key map for search view") + (defvar ampc-outputs-mode-map (let ((map (make-sparse-keymap))) (suppress-keymap map) @@ -732,6 +759,10 @@ modified." (define-key map (kbd "C-c C-t") 'ampc-tagger-dired) map)) +(defvar ampc-search-keywords + nil + "Ampc last performed search") + ;;; **** menu (easy-menu-define nil ampc-mode-map nil `("ampc" @@ -952,6 +983,7 @@ modified." do (goto-char next))))) (defmacro ampc-iterate-source-output (delimiter bindings pad-data &rest bo= dy) + "DELIMITER is the field that delimit command results in mpd response" (declare (indent 2) (debug t)) `(let ((output-buffer (current-buffer)) (tags (cl-loop for (tag . props) in @@ -985,6 +1017,8 @@ modified." (define-derived-mode ampc-tag-song-mode ampc-item-mode "ampc-ts") +(define-derived-mode ampc-search-mode ampc-item-mode "ampc-search") + (define-derived-mode ampc-current-playlist-mode ampc-playlist-mode "ampc-c= pl" (setq font-lock-defaults `(((ampc-find-current-song (1 'ampc-current-song-mark-face) @@ -1311,6 +1345,8 @@ modified." ((current-playlist playlist outputs)) (playlists (ampc-update-playlist)) + (search + (message "Don't know what to do here")) ((song tag) (cl-loop for w in @@ -1507,6 +1543,10 @@ modified." (ampc-send-command 'currentsong)) (playlists (ampc-send-command 'listplaylists)) + (search + (when ampc-search-keywords + (ampc-send-command 'search nil "any" + (ampc-quote ampc-search-keywords)))) (current-playlist (ampc-send-command 'playlistinfo)))))) (ampc-send-command 'status) @@ -1983,6 +2023,27 @@ modified." (defun ampc-handle-update () (message "Database update started")) +(defun ampc-handle-search () + "Uses mpd search result to fill search view" + (ampc-fill-skeleton 'search + (ampc-iterate-source-output + "file" + (file) + (cl-loop for (tag . tag-regexp) in tags + collect (ampc-clean-tag tag (ampc-extract tag-regexp))) + `(,file) + ))) + +(defun ampc-start-search () + "Ask mpd to search for songs matching keywords" + (interactive) + (cl-assert (ampc-in-ampc-p)) + (let ((search (read-string "Keywords: "))) + (setq ampc-search-keywords (unless (string=3D "" search) search)) + (when ampc-search-keywords + (ampc-send-command 'search nil "any" + (ampc-quote ampc-search-keywords))))) + (defun ampc-handle-command (status) (cond ((eq status 'error) @@ -2018,7 +2079,9 @@ modified." (listallinfo (ampc-handle-listallinfo)) (outputs - (ampc-fill-outputs)))) + (ampc-fill-outputs)) + (search + (ampc-handle-search)))) (unless ampc-outstanding-commands (ampc-update))))) @@ -3082,7 +3145,7 @@ default to the ones specified in `ampc-default-server= '." (unless ampc-connection (let ((connection (open-network-stream "ampc" (with-current-buffer - (get-buffer-create " *ampc*= ") + (get-buffer-create ampc-buffer-name) (erase-buffer) (current-buffer)) host --=20 2.8.3