+function mtag.movetonext(s)
+ local t = mtag.getnext(s)
+ awful.client.movetotag(t)
+ awful.tag.viewonly(t)
+end
+function mtag.getprev(s)
+ if s == nil then s = getscreen() end
+
+ local p = mtag.occupied(s)
+ local curtag = awful.tag.selected()
+
+ local t = 0
+
+ -- Get tag #
+ if mtag.isoccupied(s, curtag) then
+ for x in pairs(p) do
+ if curtag == p[x] then t = x end
+ end
+ end
+
+ local lasto = 1
+ local o = 0
+
+ for x in pairs(tags[s]) do
+ if curtag == tags[s][x] then o = x end
+ if mtag.isoccupied(s, tags[s][x]) then lasto = x end
+ end
+
+ -- Now: t is # in non-empty, o is # in all
+ if o == 1 then
+ -- We're the very first tag, wrap around
+ return p[ table.maxn(p) ]
+ else
+ -- We're not first, just go prev
+ return tags[s][o-1]
+ end
+end
+function mtag.prev(s)
+ awful.tag.viewonly(mtag.getprev(s))
+end
+function mtag.movetoprev(s)
+ local t = mtag.getprev(s)
+ awful.client.movetotag(t)
+ awful.tag.viewonly(t)
+end
+