On Fri, Feb 17, 2012 at 8:04 PM, Uli Schlachter <psyc...@znc.in> wrote:
> I just noticed that this would bring us awful.util.cycle and
> awful.util.table.cycle which do completely different things. How about
> awful.util.table.iterate? Anyone has any good ideas? (I definitely don't)

I want to keep the name cycle because it actually cycles through the
table -- if you start from index 4, it stops at 3, returning clients
that match the given filter.  I think it is ok to have the same key in
two different tables because you can infer which is which from the
context.  Instead, how about splitting awful.util.table into a module
of its own? awful.table perhaps?

> Second patch:
>
>> +-- c.minimized = false <br/>
>> +-- end <br/>
>> +--
>> +-- </code></p>
>
> I actually have not much clue about luadoc, so: Why the empty line?

No purpose actually.  Must have introduced it by accident.

> Also: Urgh, really have to add <br /> inside of code examples? :-(

Yeah.  Otherwise all code comes up on the same line in the final HTML
out.  This is the most important reason for which I want to see
markdown in commit messages.

> Finally: What about indentation?

Luadoc ignores it.  IIRC, only one code example in the entire doc uses
indentation: awful.menu.new.  It is painfully difficult to add
indentation; see 514fd796f3272583ee409b784fcd9ee2a6f95875 (one of my
first patches :-|).


> [...]
>> +function cycle(filter, start)
>> +    local clients = capi.client.get()
>> +    local focused = capi.client.focus
>             ^^^^^^^
>> +    local start   = start or util.table.hasitem(clients, focussed)
>                                                            ^^^^^^^^
> Typo? (The second one has "ss", the first one is correct with "s")

Phooey! :-/

>> +    return util.table.cycle(clients, filter, start)
>> +end
>
> Could this get a screen argument (called 's', I guess)?
> It would only have to be "cycle(filter, start, s)" and could be directly 
> passed
> to capi.client.get().

Umm, ok.  But I am not doing:

local screen = s or mouse.screen

> Cheers,
> Pedantic-Uli

Your signature eerily changes with the feedback you give :-).

PFA, revised 2nd patch.

-- 
Anurag Priyam
From 2a2c65a5c5ba932cbe0f1238bf93973f46659db4 Mon Sep 17 00:00:00 2001
From: Anurag Priyam <anurag08pri...@gmail.com>
Date: Fri, 17 Feb 2012 02:32:28 +0530
Subject: [PATCH 2/2] add awful.client.cycle to iterate through clients that
 match a given condition

A common use case is to cycle through clients that match a given rule and take
certain action on them: raise, set or get property, etc.; see usage example in
the docs.

Signed-off-by: Anurag Priyam <anurag08pri...@gmail.com>
---
 lib/awful/client.lua.in |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/lib/awful/client.lua.in b/lib/awful/client.lua.in
index 2d5ec45..04236aa 100644
--- a/lib/awful/client.lua.in
+++ b/lib/awful/client.lua.in
@@ -862,6 +862,29 @@ function property.set(c, prop, value)
     c:emit_signal("property::" .. prop)
 end
 
+---
+-- Returns an iterator to cycle through, starting from the client in focus or
+-- the given index, all clients that match a given criteria.
+-- @param filter a function that returns true to indicate a positive match
+-- @param start  what index to start iterating from.  Defaults to using the
+-- index of the currently focused client.
+-- @usage e.g.: un-minimize all urxvt instances
+-- <p><code>
+-- local urxvt = function (c) <br/>
+-- return awful.rules.match(c, {class = "URxvt"}) <br/>
+-- end <br/>
+-- </br>
+-- for c in awful.client.cycle(urxvt) do <br/>
+-- c.minimized = false <br/>
+-- end <br/>
+-- </code></p>
+function cycle(filter, start, s)
+    local clients = capi.client.get(s)
+    local focused = capi.client.focus
+    local start   = start or util.table.hasitem(clients, focused)
+    return util.table.cycle(clients, filter, start)
+end
+
 -- Register standards signals
 capi.client.add_signal("property::floating_geometry")
 capi.client.add_signal("property::floating")
-- 
1.7.9

Reply via email to