Discussion:
Change Filters
Paul Kramer
2011-08-15 13:21:11 UTC
Permalink
Hello,

Is there currently any way in cmus to edit a filter? I have a few
filters that look like

artist="artist1"|artist="artist2"|...

If I want to add or remove an artist, I cannot get the current filter
string (except when I edit the right file, I suppose).

What would be possible is, that when you create a filter and press Tab,
that if the filter name exists, the string is appended. For example, if
I have a filter named filter1 which is set to
artist="artist1"|artist="artist2", that I input the following:

fset filter1=<Tab>

And it completes the filter string for the user to edit:

fset filter1=artist="artist1"|artist="artist2"

Is that (or something similar) possible?

Greetings,
Paul
Johannes Weißl
2011-08-27 18:38:35 UTC
Permalink
Hello Paul,
Post by Paul Kramer
Is there currently any way in cmus to edit a filter? I have a few
filters that look like
artist="artist1"|artist="artist2"|...
If I want to add or remove an artist, I cannot get the current filter
string (except when I edit the right file, I suppose).
I'm sure this used to work by pressing "Enter", I will check soon if I
have more time! Maybe this functionality got lost with a recent
update...


Johannes
Gregory Petrosyan
2011-08-29 12:10:05 UTC
Permalink
Post by Johannes Weißl
Hello Paul,
Post by Paul Kramer
Is there currently any way in cmus to edit a filter? I have a few
filters that look like
artist="artist1"|artist="artist2"|...
If I want to add or remove an artist, I cannot get the current filter
string (except when I edit the right file, I suppose).
I'm sure this used to work by pressing "Enter", I will check soon if I
have more time! Maybe this functionality got lost with a recent
update...
FYI: just checked — "Enter" in the filters view does nothing now.

                Gregory
Paul Kramer
2011-08-29 12:24:24 UTC
Permalink
Post by Johannes Weißl
Hello Paul,
Post by Paul Kramer
Is there currently any way in cmus to edit a filter? I have a few
filters that look like
artist="artist1"|artist="artist2"|...
If I want to add or remove an artist, I cannot get the current filter
string (except when I edit the right file, I suppose).
I'm sure this used to work by pressing "Enter", I will check soon if I
have more time! Maybe this functionality got lost with a recent
update...
FYI: just checked — "Enter" in the filters view does nothing now.
Thanks for checking. I didn't get around to it. Can this be fixed?
Johannes Weißl
2011-08-29 12:46:36 UTC
Permalink
Hi Gregory,
Post by Gregory Petrosyan
Post by Johannes Weißl
I'm sure this used to work by pressing "Enter", I will check soon if I
have more time! Maybe this functionality got lost with a recent
update...
FYI: just checked — "Enter" in the filters view does nothing now.
Yes, but has there been any functionality to edit the filters? I'm was
sure there was, but I've checked a few older versions and it doesn't
work there, too. Maybe I just used copy&paste (mouse) all the time, or
confused it with the settings view :-(.

So if everybody agrees that enter should bring up
:fset filter_name=filer_value
I can do that!

Auto-completing might be a bit harder, but also possible!


Johannes
Johannes Weißl
2011-08-29 12:51:53 UTC
Permalink
Post by Johannes Weißl
So if everybody agrees that enter should bring up
:fset filter_name=filer_value
I can do that!
argh, <enter> already activates the current filter selection, how about
"e" for "edit"?


Johannes
Paul Kramer
2011-08-29 14:11:09 UTC
Permalink
Sounds good. :) Thanks for the effort.

Paul
Post by Johannes Weißl
Post by Johannes Weißl
So if everybody agrees that enter should bring up
:fset filter_name=filer_value
I can do that!
argh, <enter> already activates the current filter selection, how about
"e" for "edit"?
Johannes
------------------------------------------------------------------------------
EMC VNX: the world's simplest storage, starting under $10K
The only unified storage solution that offers unified management
Up to 160% more powerful than alternatives and 25% more efficient.
Guaranteed. http://p.sf.net/sfu/emc-vnx-dev2dev
Johannes Weißl
2011-08-29 14:12:00 UTC
Permalink
Post by Johannes Weißl
Post by Johannes Weißl
So if everybody agrees that enter should bring up
:fset filter_name=filer_value
I can do that!
argh, <enter> already activates the current filter selection, how about
"e" for "edit"?
Me again... I implemented both (actually it was *really* easy), and I
attached the patch for the auto-complete stuff. Please test and give
feedback if this is the right way to do it...

For the "click <enter> to edit" feature, we have two possibilities:
* abuse another win-xxx command to do it (e.g. win-next), which is not
very intuitive
* give win-activate two meanings:
* if a selection is not yet activated (e.g. "[*]" before a filter), it
activates it
* otherwise it would be a dead command anyway (I think), so it can
as well edit the current filter

I've also attached a patch, please give feedback :-)!


Johannes
Johannes Weißl
2011-08-29 14:14:01 UTC
Permalink
---
command_mode.c | 22 +++++++++++++++++++++-
1 files changed, 21 insertions(+), 1 deletions(-)

diff --git a/command_mode.c b/command_mode.c
index ed7a5c8..763f211 100644
--- a/command_mode.c
+++ b/command_mode.c
@@ -2289,6 +2289,26 @@ static void expand_factivate(const char *str)
tabexp.count = array.count;
}

+static void expand_fset(const char *str)
+{
+ struct filter_entry *e;
+ PTR_ARRAY(array);
+
+ list_for_each_entry(e, &filters_head, node) {
+ char *line = xnew(char, strlen(e->name) + strlen(e->filter) + 2);
+ sprintf(line, "%s=%s", e->name, e->filter);
+ if (!strncmp(str, line, strlen(str)))
+ ptr_array_add(&array, xstrdup(line + strlen(str)));
+ free(line);
+ }
+ if (!array.count)
+ return;
+
+ tabexp.head = xstrdup(str);
+ tabexp.tails = array.ptrs;
+ tabexp.count = array.count;
+}
+
static void expand_options(const char *str)
{
struct cmus_opt *opt;
@@ -2434,7 +2454,7 @@ struct command commands[] = {
{ "echo", cmd_echo, 1,-1, NULL, 0, 0 },
{ "factivate", cmd_factivate, 0, 1, expand_factivate, 0, 0 },
{ "filter", cmd_filter, 0, 1, NULL, 0, 0 },
- { "fset", cmd_fset, 1, 1, NULL, 0, 0 },
+ { "fset", cmd_fset, 1, 1, expand_fset, 0, 0 },
{ "help", cmd_help, 0, 0, NULL, 0, 0 },
{ "invert", cmd_invert, 0, 0, NULL, 0, 0 },
{ "live-filter", cmd_live_filter,0, 1, NULL, 0, CMD_LIVE },
--
1.7.6
Johannes Weißl
2011-08-29 14:14:02 UTC
Permalink
---
filters.c | 27 +++++++++++++++++++++++++++
1 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/filters.c b/filters.c
index da508d3..901d894 100644
--- a/filters.c
+++ b/filters.c
@@ -17,6 +17,7 @@
*/

#include "filters.h"
+#include "cmdline.h"
#include "expr.h"
#include "window.h"
#include "search.h"
@@ -27,6 +28,7 @@
#include "ui_curses.h"
#include "xmalloc.h"

+#include <stdio.h>
#include <ctype.h>

struct window *filters_win;
@@ -114,10 +116,34 @@ static const char *get_filter(const char *name)
return NULL;
}

+static void edit_sel_filter(void)
+{
+ struct iter sel;
+ struct filter_entry *e;
+ char buf[512];
+
+ if (!window_get_sel(filters_win, &sel))
+ return;
+
+ e = iter_to_filter_entry(&sel);
+ snprintf(buf, sizeof(buf), "fset %s=%s", e->name, e->filter);
+ cmdline_set_text(buf);
+ enter_command_mode();
+}
+
void filters_activate(void)
{
struct filter_entry *f;
struct expr *e, *expr = NULL;
+ int unchanged = 1;
+
+ /* if no pending selection is to apply, edit currently select filter */
+ list_for_each_entry(f, &filters_head, node) {
+ if (f->act_stat != f->sel_stat)
+ unchanged = 0;
+ }
+ if (unchanged)
+ edit_sel_filter();

/* mark visited and AND together all selected filters
* mark any other filters unvisited */
@@ -344,6 +370,7 @@ static void do_filters_set_filter(const char *keyval)
/* replace */
struct iter iter;

+ new->sel_stat = e->sel_stat;
if (ui_initialized) {
filter_entry_to_iter(e, &iter);
window_row_vanishes(filters_win, &iter);
--
1.7.6
Gregory Petrosyan
2011-08-29 18:29:23 UTC
Permalink
Post by Johannes Weißl
---
command_mode.c | 22 +++++++++++++++++++++-
1 files changed, 21 insertions(+), 1 deletions(-)
Tested and merged both patches to master, thanks a lot!

Gregory

Loading...