On Fri, Feb 17, 2012 at 8:52 PM, Uli Schlachter <psyc...@znc.in> wrote: > Thanks, both patches are merged. However, I had to mess with the commit > messages > (my git hooks refuse commits with a too long summary) and I added some luadoc > for the new "s" argument.
Yeah, first one was 80 or 81 chars. Thanks for the luadoc :). > Sadly, cherry pick into 3.4 failed, so this won't end up in 3.4.12 (no, I will > not manually fix up stuff). It conflicts because modeline changed in c2ea920ca016a8f19d464fd8a961ad45afcce8b3 !! PFA, the same patches based on 3.4 branch. -- Anurag Priyam
From 7107b73aaca96a829628df6aed6c234dff2d53df Mon Sep 17 00:00:00 2001 From: Anurag Priyam <anurag08pri...@gmail.com> Date: Fri, 17 Feb 2012 02:30:41 +0530 Subject: [PATCH 1/2] add awful.util.table.cycle awful.util.table.cycle iterates through elements of the table that match the given condition. This will help writing concise code when one wants to apply a function to (read, take some action) on a select list of elements in a table (of say, clients and tags). Conflicts: lib/awful/util.lua.in Signed-off-by: Anurag Priyam <anurag08pri...@gmail.com> --- lib/awful/util.lua.in | 21 +++++++++++++++++++++ 1 files changed, 21 insertions(+), 0 deletions(-) diff --git a/lib/awful/util.lua.in b/lib/awful/util.lua.in index ce14e32..77ba55c 100644 --- a/lib/awful/util.lua.in +++ b/lib/awful/util.lua.in @@ -363,4 +363,25 @@ function table.clone(t) return c end +--- +-- Returns an iterator to cycle through, starting from the first element or the +-- given index, all elments of a table that match a given criteria. +-- @param t the table to iterate +-- @param filter a function that returns true to indicate a positive match +-- @param start what index to start iterating from. Default is 1 (=> start of +-- the table) +function table.cycle(t, filter, start) + local count = 0 + local index = start or 1 + local length = #t + + return function () + while count < length do + local item = t[index] + index = cycle(#t, index + 1) + count = count + 1 + if filter(item) then return item end + end + end +end -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 -- 1.7.9
From 64a2d05e765b2f8af58dfbc0324d24b3ad69db2c 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 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 | 24 ++++++++++++++++++++++++ 1 files changed, 24 insertions(+), 0 deletions(-) diff --git a/lib/awful/client.lua.in b/lib/awful/client.lua.in index b63a646..fa60566 100644 --- a/lib/awful/client.lua.in +++ b/lib/awful/client.lua.in @@ -862,6 +862,30 @@ 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. +-- @param s which screen to use. nil means all screens. +-- @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("focus", focus.history.add) capi.client.add_signal("unmanage", focus.history.delete) -- 1.7.9