On Fri, Jun 10, 2011 at 9:07 PM, Michael Hauser <awarewa...@gmail.com> wrote:
> I've the following construct in my 'lua.rc'

I guess you mean your rc.lua.

>  { rule = { class = "Audacity" },
>   properties = { tag = tags[1][2], switchtotag = true, floating = false } },
>  { rule = { class = "sunvox" },
>   properties = { tag = tags[1][2], switchtotag = true, floating = false } },
>  { rule = { class = "Hydrogen" },
>   properties = { tag = tags[1][2], switchtotag = true, floating = false } },
>  { rule = { class = "Evince" },
>   properties = { tag = tags[1][2], switchtotag = true, floating = false } },
>
> 8 lines with much redundancy, ie. the same options for many programs.
>
> Can I put the class names in a table and have a for loop iterate over
> these to set this options in 3 lines?
> How would the code look like?

Yes, you can.
First, you must notice that these are tables, and that you are putting
them inside another table. So you can create these tables outside of
this table definition and add tem to you awful.rules.rules table
later.
Also, you probably want to create one table with {"Audacity",
"sunvox", "Hydrogen", "Evince"} and send it to a code to generate
another table with the ones you wrote, and then you add them to
awful.rules.rules.

So, something like the following untested code should do it

myapps =  {"Audacity", "sunvox", "Hydrogen", "Evince"}
for index, value in ipairs(myapps) do
    myrules[index] = { rule = { class = value },  properties = { tag =
tags[1][2], switchtotag = true, floating = false } }
end
awfule.rules.rules = awful.util.table.join(awful.rules.rules, myrules)

HTH

--
To unsubscribe, send mail to awesome-unsubscr...@naquadah.org.

Reply via email to