Re: [PATCH] awful.util: add linewrap()

2009-05-30 Thread Julien Danjou
At 1243640834 time_t, koniu wrote:
 On Thu, May 28, 2009 at 13:14, Julien Danjou jul...@danjou.info wrote:
  Pushed.
 
 Ay, sorry, forgot to add string to the environment, see amended patch.

Pushed.

-- 
Julien Danjou
// ᐰ jul...@danjou.info   http://julien.danjou.info
// 9A0D 5FD9 EB42 22F6 8974  C95C A462 B51E C2FE E5CD
// Anna Molly! Anna Molly! Anna Molly!


signature.asc
Description: Digital signature


Re: [PATCH] awful.util: add linewrap()

2009-05-29 Thread koniu
On Thu, May 28, 2009 at 13:14, Julien Danjou jul...@danjou.info wrote:
 Pushed.

Ay, sorry, forgot to add string to the environment, see amended patch.

kk
From fa95409bee45053474ab50f0422ca147913dd5ed Mon Sep 17 00:00:00 2001
From: koniu gkusni...@gmail.com
Date: Wed, 27 May 2009 16:49:20 +0100
Subject: [PATCH] awful.util: add linewrap()

Signed-off-by: koniu gkusni...@gmail.com
Signed-off-by: Julien Danjou jul...@danjou.info
---
 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 5965bda..95d6717 100644
--- a/lib/awful/util.lua.in
+++ b/lib/awful/util.lua.in
@@ -15,6 +15,7 @@ local print = print
 local type = type
 local rtable = table
 local pairs = pairs
+local string = string
 local capi =
 {
 awesome = awesome,
@@ -261,4 +262,24 @@ function table.hasitem(t, item)
 end
 end
 
+--- Split a string into multiple lines
+-- @param text String to wrap.
+-- @param width Maximum length of each line. Default: 72.
+-- @param indent Number of spaces added before each wrapped line. Default: 0.
+-- @return The string with lines wrapped to width.
+function linewrap(text, width, indent)
+local text = text or 
+local width = width or 72
+local indent = indent or 0
+
+local pos = 1
+return text:gsub((%s+)()(%S+)(),
+function(sp, st, word, fi)
+if fi - pos  width then
+pos = st
+return \n .. string.rep( , indent) .. word
+end
+end)
+end
+
 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
-- 
1.6.3.1



[PATCH] awful.util: add linewrap()

2009-05-27 Thread koniu
Heya,

The patch adds a function for wrapping lines on long strings. I'm
using it in awful.help and it could also be used in naughty and
otherwise.

I'm wondering, by the way, perhaps this should be called string.wrap()
and therefore string.escape(), string.unescape() - to follow
table.hasitem/join example.
To take the idea further, at least as far as awful.util goes, we could:

checkfile - file.validate
file_readable - file.readable
subsets - table.subsets

And maybe more. The problem is that these functions are bound to be
explicitly used by some users and this would be breaking API (again).
We could of course deprecate them to make the process smoother but
still. In fact, there's a lot more in the namespace that could be
unified - think awful.tag.getproperty vs awful.client.property.get -
at what stage would we be cleaning all of this up?

cheers,
koniu
From f827aacf9d44cad13d5d582e89b64b35c74b1e25 Mon Sep 17 00:00:00 2001
From: koniu gkusni...@gmail.com
Date: Wed, 27 May 2009 16:49:20 +0100
Subject: [PATCH] awful.util: add linewrap()

Signed-off-by: koniu gkusni...@gmail.com
---
 lib/awful/util.lua.in |   20 
 1 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/lib/awful/util.lua.in b/lib/awful/util.lua.in
index 5965bda..9878ffa 100644
--- a/lib/awful/util.lua.in
+++ b/lib/awful/util.lua.in
@@ -261,4 +261,24 @@ function table.hasitem(t, item)
 end
 end
 
+--- Split a string into multiple lines
+-- @param text String to wrap.
+-- @param width Maximum length of each line. Default: 72.
+-- @param indent Number of spaces added before each wrapped line. Default: 0.
+-- @return The string with lines wrapped to width.
+function linewrap(text, width, indent)
+local text = text or 
+local width = width or 72
+local indent = indent or 0
+
+local pos = 1
+return text:gsub((%s+)()(%S+)(),
+function(sp, st, word, fi)
+if fi - pos  width then
+pos = st
+return \n .. string.rep( , indent) .. word
+end
+end)
+end
+
 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
-- 
1.6.3.1



Re: [PATCH] awful.util: add linewrap()

2009-05-27 Thread Julien Danjou
At 1243445257 time_t, Andrei Thorp wrote:
 Sounds great, I love more hooks.

Too bad, I'm going to deprecate them.

Then deprecating the deprecation hook will be fun so much fun. :)

Cheers,
-- 
Julien Danjou
// ᐰ jul...@danjou.info   http://julien.danjou.info
// 9A0D 5FD9 EB42 22F6 8974  C95C A462 B51E C2FE E5CD
// Don't give up.


signature.asc
Description: Digital signature


Re: [PATCH] awful.util: add linewrap()

2009-05-27 Thread Andrei Thorp
Nooo! Don't deprecate my deprecating deprecation deprecator!

-AT

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


Re: [PATCH] awful.util: add linewrap()

2009-05-27 Thread koniu
On Wed, May 27, 2009 at 17:21, Julien Danjou jul...@danjou.info wrote:
 So, for unification we should do it ASAP, but first, we should make a
 clear decision, written in marble and in STYLES, about how we name
 things.

 (So for your patch, tell me if you want me to merge it right now or if
 you want to rename the function now.)

I don't really want to rename it since we don't have the styles
written in marble so I don't know what to rename it to. If the big
cleanup happens before next is merged into master we could just rename
it then (without deprecation stage). If, otoh, next is merged with
master before the cleanup (which would then happen in master or maybe
a new branch), it's better that we don't have just one function that
is called awful.util.string.something() in master for the time being.
For this reason I'd say merge it as it is.

cheers,
koniu

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