Re: format indentation
- From: Alberto Riva <alb@xxxxxxxxxxxxxx>
- Date: Thu, 07 Jun 2012 12:52:47 -0400
On 06/07/2012 12:32 PM, Bigos wrote:
Hi,
I need to print several indented lines.
This is my present solution:
(setq r (concatenate 'string
r
(format nil "~2&~A~A~%~A#~%~Aelse~%~A#~%~Aend" (spaces 4) (fourth e)
(spaces 6) (spaces 4) (spaces 6) (spaces 4) )))
It looks appalling and I wonder if there's better way to do it. I think
having 5 (spaces n) looks horrible. I couldn't find anything on
Hyperspec of Google.
In a case like this you can use the ~T directive:
(format nil "~2&~4T~A~%~6T#~%~4Telse~%~6T#~%~4Tend" (fourth e))
If the amount of indentation is determined at runtime, you can use ~VT:
(format nil "~VT~a" 5 "test")
=> " test"
Note that ~xT means "move to position x from the start of the line", not "insert x spaces", that's why I said that this works in the example you provided, ie to indent strings from the left margin.
Also, instead of (concatenate 'string r (format nil "...")) I would add a ~a at the beginning of the format string, and simply use
(format nil "~a..." r other-arguments...)
Alberto
.
- Follow-Ups:
- Re: format indentation
- From: Bigos
- Re: format indentation
- References:
- format indentation
- From: Bigos
- format indentation
- Prev by Date: format indentation
- Next by Date: code duplication: (setq r (concatenate 'string r (format nil ...
- Previous by thread: format indentation
- Next by thread: Re: format indentation
- Index(es):
Relevant Pages
|