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,
Adlai
From 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

Reply via email to