From: Scott Sheffield
Subject: Format padding
Date: 
Message-ID: <3A59F59C.54CD5DF8@lmco.com>
I want to format so I can have something like this:

1........................4
2........................2
3 Added............4
4-1-1................3

So I want to have text, then padding then more text, with both the left
and right lined up. I am using Interleaf LISP and I cannot seem to get
the left and right lined up. Ideally I would like to insert a tab with
dots. I can insert the tab, I just can't figure out how to do the dots.
Any suggestions?

Scott

From: Mitchell R Whorlow
Subject: Re: Format padding
Date: 
Message-ID: <86n1d1n3ju.fsf@dhcp085172.res-hall.nwu.edu>
If I understand your problem correctly, I did something like this once
too.

(defun format-with-padding (list)
  (format t "~{~&~20,20,20,'.<~A~;~A~>~}" list))

[152]> (format-with-padding '(1 4 2 2 "3 Added" 4 "4-1-1" 3))
1......................................4
2......................................2
3 Added................................4
4-1-1..................................3
NIL
[153]> 

Hope this is somewhat useful,

Mitch

Scott Sheffield <·················@lmco.com> writes:

> I want to format so I can have something like this:
> 
> 1........................4
> 2........................2
> 3 Added............4
> 4-1-1................3
> 
> So I want to have text, then padding then more text, with both the left
> and right lined up. I am using Interleaf LISP and I cannot seem to get
> the left and right lined up. Ideally I would like to insert a tab with
> dots. I can insert the tab, I just can't figure out how to do the dots.
> Any suggestions?
> 
> Scott
From: Barry Margolin
Subject: Re: Format padding
Date: 
Message-ID: <4iq66.34$UJ5.512@burlma1-snr2>
In article <·················@lmco.com>,
Scott Sheffield  <·················@lmco.com> wrote:
>I want to format so I can have something like this:
>
>1........................4
>2........................2
>3 Added............4
>4-1-1................3
>
>So I want to have text, then padding then more text, with both the left
>and right lined up. 

Your example doesn't look lined up to me, so it's hard to tell what you
want.  Please set your news reader to a monospace font when posting
examples like this.

>		     I am using Interleaf LISP and I cannot seem to get
>the left and right lined up. Ideally I would like to insert a tab with
>dots. I can insert the tab, I just can't figure out how to do the dots.
>Any suggestions?

In Common Lisp's FORMAT, all the format directives that let you specify a
field width have an optional "padchar" argument.  Actually, there's one
notable exception: ~T, which skips to a specific column -- it always uses
spaces.  We probably should have included a padchar option for this as
well.

-- 
Barry Margolin, ······@genuity.net
Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Scott Sheffield
Subject: Re: Format padding
Date: 
Message-ID: <3A5A37F8.BF705CF0@lmco.com>
The example should be lined up on both sides. That's basically what I am shooting
for. I have used the padchar but it doesn't work well because when I pad with
periods the periods do not take up as much space as a capital M. Let's say I pad 10
characters the results come out like:
ABCDE....1
A........1

Both of the above examples are 10 chars long yet they are not the same length. That
is my problem.


Barry Margolin wrote:

> In article <·················@lmco.com>,
> Scott Sheffield  <·················@lmco.com> wrote:
> >I want to format so I can have something like this:
> >
> >1........................4
> >2........................2
> >3 Added............4
> >4-1-1................3
> >
> >So I want to have text, then padding then more text, with both the left
> >and right lined up.
>
> Your example doesn't look lined up to me, so it's hard to tell what you
> want.  Please set your news reader to a monospace font when posting
> examples like this.
>
> >                    I am using Interleaf LISP and I cannot seem to get
> >the left and right lined up. Ideally I would like to insert a tab with
> >dots. I can insert the tab, I just can't figure out how to do the dots.
> >Any suggestions?
>
> In Common Lisp's FORMAT, all the format directives that let you specify a
> field width have an optional "padchar" argument.  Actually, there's one
> notable exception: ~T, which skips to a specific column -- it always uses
> spaces.  We probably should have included a padchar option for this as
> well.
>
> --
> Barry Margolin, ······@genuity.net
> Genuity, Burlington, MA
> *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
> Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Rob Warnock
Subject: Re: Format padding
Date: 
Message-ID: <93e4om$mtc6f$1@fido.engr.sgi.com>
Scott Sheffield  <·················@lmco.com> wrote:
+---------------
| ...when I pad with periods the periods do not take up as much space
| as a capital M. Let's say I pad 10 characters the results come out like:
|     ABCDE....1
|     A........1
| Both of the above examples are 10 chars long yet they are not the
| same length. That is my problem.
+---------------

Yes, it's "your problem", but your problem is not the problem you *think*
it is. You see, to me (and everyone else on the net who uses a monospaced
font when reading netnews), your example above *IS* aligned correctly!!

And if you don't see it that way in this, my reply, then change the font
in your news reader to some monospaced font, not a proportional font.


-Rob

p.s. If what you're trying to do is pad correctly in a *proportional*
font and still keep the periods lined up, well, that's a much harder
problem. You will probably have to add variable whitespace kerning on
either side of each row of dots, depending on the texts on eother side.
But even if you solve *that* problem, your audience *won't* see it as
"solved" if they're reading in a monospaced font (as most of us are)...

p.p.s. I'm pretty sure TeX or LaTeX has some support macros for doing
this though, so if you write your documents in LaTeX, and output only
PostScript or PDF (*not* plain ASCII), you should be able to do it.

-----
Rob Warnock, 31-2-510		····@sgi.com
SGI Network Engineering		http://reality.sgi.com/rpw3/
1600 Amphitheatre Pkwy.		Phone: 650-933-1673
Mountain View, CA  94043	PP-ASEL-IA
From: ········@hex.net
Subject: Re: Format padding
Date: 
Message-ID: <SFy66.180282$IP1.6554025@news1.giganews.com>
Scott Sheffield <·················@lmco.com> writes:
> The example should be lined up on both sides. That's basically what
> I am shooting for. I have used the padchar but it doesn't work well
> because when I pad with periods the periods do not take up as much
> space as a capital M. Let's say I pad 10 characters the results come
> out like:
>
> ABCDE....1
> A........1
> 
> Both of the above examples are 10 chars long yet they are not the
> same length. That is my problem.

Apparently so.

The problem you think you're trying to solve cannot be solved simply
by counting characters; you need to determine the font metrics
relevant to your environment, and count the number of "dots" based on
filling the width to what's needed.

For instance, suppose the character widths were expressed via the
associative list:

(defparameter *char-widths*
      '((#\A 8) (#\B 8) (#\C 8) (#\D 8) (#\E 8) (#\F 8)
	(#\G 8) (#\H 8) (#\I 4) (#\space 8) (#\. 4)))

Then, suppose you decided that you wanted the total width to be, um,
(* 10 8) --> 80 units.

Then you would evaluate the arguments thus
(dolist (l '(("ABCDE" 1) ("A" 1)))
  (process-line 80 *char-widths* (car l) (cadr l)) #\.)

;; With...
(defun process-line (width metrics leftitem rightitem dot)
  (let* ((leftwidth (calcwidth leftitem metrics))
	 (rightwidth (calcwidth (princ-to-string rightitem) metrics))
	 (betweenwidth (- width (+ leftwidth rightwidth)))
	 (betweendots (/ betweenwidth (cdr (assoc dot metrics)))))
    (format "~A" leftitem)
    (loop for i from 1 to betweendots
	  do (format "~A" dot))
    (format "~A~%" leftitem)))

(defun calcwidth (string metrics)
  (let ((total 0))
    (loop for i from 0 to (length string)
	  for j = (+ i 1)
	do (incf total (cdr (assoc (subseq string i j) metrics))))))

Fixing the errors is left as an exercise for the reader :-).
-- 
(reverse (concatenate 'string ····················@" "454aa"))
<http://www.ntlug.org/~cbbrowne/>
"Normally, we don't do people's homework around here, but Venice is a
very beautiful city, so I'll make a small exception."
--- Robert Redelmeier compromises his principles