Re: [STUMP] Patch to STUMPWM::FORMAT-EXPANDER in primitives.lisp

2009-10-25 Thread Adlai Chandrasekhar

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Sun, 25 Oct 2009, Ben Spencer wrote:

On Sat, Oct 24, 2009 at 09:33:48AM +0200, Adlai Chandrasekhar wrote:

I've written a little patch for a friend, that enables the use of ^
after a number in a format expansion string (such as
*SCREEN-MODE-LINE-FORMAT* or *WINDOW-FORMAT*) to trim from the left,
instead of the right.


While reviewing this patch, I noticed what appears to be a
pre-existing bug.  Unless I'm missing something, the (format t %~a
len) in format-expand should actually be appending onto the output
(since the idea is to add the literal string if there's no format
char).


That looks like a bug to me too... I guess one solution would be to wrap
it with (setf output (concatenate 'string output (format nil ...))).


The patch itself has a minor bug in that from-left-p is referred to as
from-end-p at one point (only just spotted that thanks to a compile
warning).  Other than that it looks fine (although I think the
function as a whole could do with a cleanup, especially if we add more
stuff like this), and I'll push it shortly if nobody else has comments
to make.


Thank you for catching that bug. I'll try cleaning up that function as a 
whole (once you've pushed my fix, to avoid merge conflicts...), does 
anybody have any suggestions? I think a good approach would be to use 
WITH-OUTPUT-TO-STRING rather than the current approach.


Happy Tiling,

Adlai
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Topal (http://freshmeat.net/projects/topal)

iQEcBAEBAgAGBQJK5JnXAAoJEEQDvZxQqpedKFoIAK9BIEwMvteuHIptTeTDm6NA
UACzhavnbEs5essTk3nIAGajNt2Xr03F27VCkfBy4y89sS1R+D51zBXRMbOeWFtV
0L4ojig5nQKy1vQGqfokjH50uStoaBNa+doOIULvjI78ogd0JkqLVFd16ybJkkpW
AVOP28+EfF+Zw0JSKf+NtraYYxIwC8K8muiqW2XjNwWTqoR3hzRjBM+bPwXRuC0a
Va2vDMJ5HvfpogdePwiLyL+fbXaaPbIAzeVSyU9jnHx1+nGjCV+p/nDhoBgIFO5M
4T9G6DlnAejbcnO+pPFc7nfoIjkp5VuRXc5nfJDBqj28ni9o9wmFxlYNiI1WiZI=
=QVE3
-END PGP SIGNATURE-


___
Stumpwm-devel mailing list
Stumpwm-devel@nongnu.org
http://lists.nongnu.org/mailman/listinfo/stumpwm-devel


[STUMP] Patch to STUMPWM::FORMAT-EXPANDER in primitives.lisp

2009-10-24 Thread Adlai Chandrasekhar

Greetings, fellow tilers of windows!

I've written a little patch for a friend, that enables the use of ^ after 
a number in a format expansion string (such as *SCREEN-MODE-LINE-FORMAT* 
or *WINDOW-FORMAT*) to trim from the left, instead of the right.


I picked the #\^ character because it's fairly standard for an 
end-of-string anchor, because of its use in perl-compatible regex. I 
considered using one of the FORMAT modify characters, but since format 
expansion strings aren't format strings, I ended up settling with this.


Thoughts? Comments? Cookies? Flames? Patch attached.

The patch was made against commit 95c420e6214908d96e08eeed27bb7a1ee0d103bf 
from the official git repo. I've made a commit in my local repo, so I 
could push this myself if that's more convenient.


Happy Hacking,
AdlaiFrom 7e833c6aa927d9cb4222c215aa0369b2cbfbf4e8 Mon Sep 17 00:00:00 2001
From: Adlai Chandrasekhar munchk...@gmail.com
Date: Sat, 24 Oct 2009 09:07:13 +0200
Subject: [PATCH] Added left trim option for format-expand strings

---
 primitives.lisp |   15 ++-
 1 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/primitives.lisp b/primitives.lisp
index 4fd7e41..b0f9224 100644
--- a/primitives.lisp
+++ b/primitives.lisp
@@ -706,9 +706,11 @@ do:
 (setf cur (cdr cur))
 (let* ((tmp (loop while (and cur (char= #\0 (car cur) #\9))
   collect (pop cur)))
-   (len (and tmp (parse-integer (coerce tmp 'string)
+   (len (and tmp (parse-integer (coerce tmp 'string
+   ;; So that eg %25^t will trim from the left
+   (from-left-p (when (char= #\^ (car cur)) (pop cur
   (if (null cur)
-  (format t %~a len)
+  (format t %...@[~a~] len from-end-p)
   (let* ((fmt (cadr (assoc (car cur) fmt-alist :test 'char=)))
  (str (cond (fmt
  ;; it can return any type, not jut as 
string.
@@ -718,9 +720,12 @@ do:
 (t
  (concatenate 'string (string #\%) (string 
(car cur)))
 ;; crop string if needed
-(setf output (concatenate 'string output (if len
- (subseq str 0 
(min len (length str)))
- str)))
+(setf output (concatenate 'string output
+  (cond ((null len) str)
+((not from-left-p) ; 
Default behavior
+ (subseq str 0 (min len 
(length str
+;; New behavior -- trim 
from the left
+(t (subseq str (max 0 (- 
(length str) len)))
 (setf cur (cdr cur))
(t
 (setf output (concatenate 'string output (string (car cur)))
-- 
1.6.5.1

___
Stumpwm-devel mailing list
Stumpwm-devel@nongnu.org
http://lists.nongnu.org/mailman/listinfo/stumpwm-devel