From enaeher at gmail.com Sat Feb 2 21:18:09 2008 From: enaeher at gmail.com (Eli Naeher) Date: Sat, 2 Feb 2008 15:18:09 -0600 Subject: [cl-who-devel] Macroexpansion of with-html-output body? Message-ID: Hello, It seems like it would be nice to expand any macros detected while walking the tree of the w-h-o body. This would allow users to define their own pseudo-tags a little more flexibly than is possible with convert-tag-to-string-list. In particular, it would allow the user to create a tag which modifies its body (as a tree) even when that body contains the expansion of another user-defined tag. I don't believe this is currently possible, as this hypothetical outer tag would have access only to the HTML strings returned by the convert-tag-to-string-list specialized on the inner tag and not to the relevant s-expressions. Is there any interest in a patch implementing this behavior? Thanks, --Eli From jeffrey at cunningham.net Sat Feb 2 22:15:14 2008 From: jeffrey at cunningham.net (Jeff Cunningham) Date: Sat, 02 Feb 2008 14:15:14 -0800 Subject: [cl-who-devel] Macroexpansion of with-html-output body? In-Reply-To: References: Message-ID: <47A4EB72.6030008@cunningham.net> Eli Naeher wrote: > Hello, > > It seems like it would be nice to expand any macros detected while > walking the tree of the w-h-o body. This would allow users to define > their own pseudo-tags a little more flexibly than is possible with > convert-tag-to-string-list. In particular, it would allow the user to > create a tag which modifies its body (as a tree) even when that body > contains the expansion of another user-defined tag. I don't believe > this is currently possible, as this hypothetical outer tag would have > access only to the HTML strings returned by the > convert-tag-to-string-list specialized on the inner tag and not to the > relevant s-expressions. > > Is there any interest in a patch implementing this behavior? > > Thanks, > > --Eli > ____________ I'm not sure I follow what you are suggesting. Could you give a simple example? Thanks --Jeff From enaeher at gmail.com Sun Feb 3 04:38:18 2008 From: enaeher at gmail.com (Eli Naeher) Date: Sat, 2 Feb 2008 22:38:18 -0600 Subject: [cl-who-devel] Macroexpansion of with-html-output body? In-Reply-To: <47A4EB72.6030008@cunningham.net> References: <47A4EB72.6030008@cunningham.net> Message-ID: On Feb 2, 2008 4:15 PM, Jeff Cunningham wrote: > I'm not sure I follow what you are suggesting. Could you give a simple > example? Sure -- my explanation was not a model of clarity. Here's what I've been playing with: (cl-who:with-html-output (var test-file :prologue t :indent t) (with-numbered-figures ("Fig. ~@R") (:h2 "Here are some images.") (:p "It is interesting to examine foo and bar over the past" (:em "n") "years:") (png-inline ("Foo vs. Bar Over Time" stream) (adw-charting:with-line-chart (400 100) (adw-charting:add-series "Foo" '((1 1) (2 1) (3 5) (4 8))) (adw-charting:add-series "Bar" '((1 -3) (4 -2) (6 -1) (8 7))) (adw-charting:save-stream stream))) (:p "Here is a picture of my cat:") (:img :src "picture-of-my-cat.jpg" :alt "My Cat."))) png-inline is a macro that lets its body write binary PNG data to stream and expands to: (:img :src "" :alt "Foo vs. Bar Over Time") with-numbered-figures finds all the lists like (:img ...) in its body and inserts: (:div :class "caption" "Figure n") after each one, where "Figure n" is an iterator formatted with the specified format string. The functionality of either of these on their own could be achieved simply by writing macros which themselves use with-html-output and expand to strings. However, in order for with-numbered-figures to correctly find the (:img ...) created by the expansion of png-inline, it is necessary that the latter expand to w-h-o forms, and, if we want to be able to also use png-inline in w-h-o directly without using with-numbered-figures, it is necessary that w-h-o perform macroexpansion during its tree-walking, or else png-inline will be expanded subsequent to the w-h-o expansion and Lisp will see it as an attempt to call an :img function. I hope this is a little clearer (and that GMail does not break the formatting too badly). Thanks, --Eli From yazicivo at ttmail.com Sun Feb 3 11:00:09 2008 From: yazicivo at ttmail.com (Volkan YAZICI) Date: Sun, 03 Feb 2008 13:00:09 +0200 Subject: [cl-who-devel] Re: Macroexpansion of with-html-output body? In-Reply-To: (Eli Naeher's message of "Sat\, 2 Feb 2008 15\:18\:09 -0600") References: Message-ID: <87hcgqjoee.fsf@ttmail.com> "Eli Naeher" writes: > It seems like it would be nice to expand any macros detected while > walking the tree of the w-h-o body. This would allow users to define > their own pseudo-tags a little more flexibly than is possible with > convert-tag-to-string-list. IIRC, there had been some similar discussions on the list about this matter. Expanding found macros during walking the tree can be quite useful. (OTOH, this method may have some problems, that I cannot find one now.) > In particular, it would allow the user to create a tag which > modifies its body (as a tree) even when that body contains the > expansion of another user-defined tag. I don't believe this is > currently possible, as this hypothetical outer tag would have access > only to the HTML strings returned by the convert-tag-to-string-list > specialized on the inner tag and not to the relevant s-expressions. > > Is there any interest in a patch implementing this behavior? I hope so. At least, I do. If you have one ready (or you're volunteered to implement one) let's see it in action. Regards. From edi at agharta.de Sun Feb 3 14:50:06 2008 From: edi at agharta.de (Edi Weitz) Date: Sun, 03 Feb 2008 15:50:06 +0100 Subject: [cl-who-devel] Macroexpansion of with-html-output body? In-Reply-To: (Eli Naeher's message of "Sat, 2 Feb 2008 15:18:09 -0600") References: Message-ID: On Sat, 2 Feb 2008 15:18:09 -0600, "Eli Naeher" wrote: > It seems like it would be nice to expand any macros detected while > walking the tree of the w-h-o body. This would allow users to define > their own pseudo-tags a little more flexibly than is possible with > convert-tag-to-string-list. In particular, it would allow the user > to create a tag which modifies its body (as a tree) even when that > body contains the expansion of another user-defined tag. I don't > believe this is currently possible, as this hypothetical outer tag > would have access only to the HTML strings returned by the > convert-tag-to-string-list specialized on the inner tag and not to > the relevant s-expressions. > > Is there any interest in a patch implementing this behavior? Modifying CL-WHO's internals to allow this is on my todo list, but there are a lot more things on this list, so the chances of me doing this myself in the near future are not very big. So, if someone wants to do this, I'm all for it. Please read this first, though: http://weitz.de/patches.html In the case of CL-WHO I'd think that backwards compatibility would be pretty important. Edi. From jeffrey at cunningham.net Sun Feb 3 16:15:57 2008 From: jeffrey at cunningham.net (Jeff Cunningham) Date: Sun, 03 Feb 2008 08:15:57 -0800 Subject: [cl-who-devel] Macroexpansion of with-html-output body? In-Reply-To: References: Message-ID: <47A5E8BD.9080709@cunningham.net> Edi Weitz wrote: > On Sat, 2 Feb 2008 15:18:09 -0600, "Eli Naeher" wrote: > > >> It seems like it would be nice to expand any macros detected while >> walking the tree of the w-h-o body. This would allow users to define >> their own pseudo-tags a little more flexibly than is possible with >> convert-tag-to-string-list. In particular, it would allow the user >> to create a tag which modifies its body (as a tree) even when that >> body contains the expansion of another user-defined tag. I don't >> believe this is currently possible, as this hypothetical outer tag >> would have access only to the HTML strings returned by the >> convert-tag-to-string-list specialized on the inner tag and not to >> the relevant s-expressions. >> >> Is there any interest in a patch implementing this behavior? >> > > Modifying CL-WHO's internals to allow this is on my todo list, but > there are a lot more things on this list, so the chances of me doing > this myself in the near future are not very big. So, if someone wants > to do this, I'm all for it. Please read this first, though: > > http://weitz.de/patches.html > > In the case of CL-WHO I'd think that backwards compatibility would be > pretty important. > > Edi. > I also like the idea. And as I have tens of thousands of lines of cl-who code in operation, I emphatically vote for backwards compatibility. --Jeff From jeffrey at cunningham.net Sun Feb 3 16:40:07 2008 From: jeffrey at cunningham.net (Jeff Cunningham) Date: Sun, 03 Feb 2008 08:40:07 -0800 Subject: [cl-who-devel] Macroexpansion of with-html-output body? In-Reply-To: References: <47A4EB72.6030008@cunningham.net> Message-ID: <47A5EE67.3040809@cunningham.net> Eli Naeher wrote: > png-inline is a macro that lets its body write binary PNG data to > stream and expands to: > > (:img :src "" > :alt "Foo vs. Bar Over Time") > > with-numbered-figures finds all the lists like (:img ...) in its body > I am curious as to how you have implemented png-inline. Would you mind sharing it? Regards. --Jeff From edi at agharta.de Wed Feb 6 23:35:40 2008 From: edi at agharta.de (Edi Weitz) Date: Thu, 07 Feb 2008 00:35:40 +0100 Subject: [cl-who-devel] with-html-output-to-string (str) In-Reply-To: (Victor Kryukov's message of "Thu, 31 Jan 2008 01:36:11 -0600") References: Message-ID: On Thu, 31 Jan 2008 01:36:11 -0600, "Victor Kryukov" wrote: > The following code produces errors on two of my systems (Linux and > Mac) for both CLISP and SBCL: > > (require 'asdf) > (asdf:oos 'asdf:load-op :cl-who) > > (defpackage :test > (:use :cl :cl-who)) > > (in-package :test) > > (with-html-output-to-string (str) > (:html (:title "test"))) > > It looks like a bug, macro variable capture, to me, but it may well > be my misunderstanding/misuse of CL-WHO. > > I'd appreciate your comments, as usual. Sorry for the delay. Just a confirmation that this seems to be a bug. Will be fixed in the next days when I find some time. Thanks for the report, Edi. From victor.kryukov at gmail.com Sun Feb 10 06:44:33 2008 From: victor.kryukov at gmail.com (Victor Kryukov) Date: Sun, 10 Feb 2008 00:44:33 -0600 Subject: [cl-who-devel] Re: Macroexpansion of with-html-output body? References: <47A5E8BD.9080709@cunningham.net> Message-ID: <87zlu948fi.fsf@esculap.gateway.2wire.net> Jeff Cunningham writes: > Edi Weitz wrote: >> On Sat, 2 Feb 2008 15:18:09 -0600, "Eli Naeher" wrote: >> >> >>> It seems like it would be nice to expand any macros detected while >>> walking the tree of the w-h-o body. This would allow users to define >>> their own pseudo-tags a little more flexibly than is possible with >>> convert-tag-to-string-list. In particular, it would allow the user >>> to create a tag which modifies its body (as a tree) even when that >>> body contains the expansion of another user-defined tag. I don't >>> believe this is currently possible, as this hypothetical outer tag >>> would have access only to the HTML strings returned by the >>> convert-tag-to-string-list specialized on the inner tag and not to >>> the relevant s-expressions. >>> >> >> Modifying CL-WHO's internals to allow this is on my todo list, but >> there are a lot more things on this list, so the chances of me doing >> this myself in the near future are not very big. So, if someone wants >> to do this, I'm all for it. Please read this first, though: >> >> http://weitz.de/patches.html >> >> In the case of CL-WHO I'd think that backwards compatibility would be >> pretty important. >> >> Edi. >> > I also like the idea. > And as I have tens of thousands of lines of cl-who code in operation, > I emphatically vote for backwards compatibility. Below is my attempt to implement macroexpansion capability in with-html-output body. Before sending it formally as a patch I want to get your feedback on the implementation and also ask for some testing. The idea is simple: we define new special variable *MACRO-TO-EXPAND* which stores names of all the macros that should be expanded before with-html-output comes into play. Notice that specail forms 'htm', 'esc', 'str' and 'fmt' are no exception here, and may be defined as similar macros. That simplifies code of TREE-TO-TEMPLATE, TREE-TO-COMMANDS-AUX and TREE-TO-COMMANDS significantly. Below[1] is an example of how we're using this functionality. def-syntax-macro is a syntactic sugar that defines a normal macro and also adds its name to *MACRO-TO-EXPAND* (defpackage :cl-who-example (:use :cl :cl-who)) (in-package :cl-who-example) (cl-who::def-syntax-macro html-list (&body body) `(:ul ,@(loop for elem in body collect `(:li ,elem)))) (with-html-output-to-string (s) (:html (:title "Title")) (:body (:h1 "H1 header") (:p "A small list" (html-list "First" "Second" (:a :href "/link" "Third"))))) => "Title

H1 header

A small list

" To test new functionality, simply load the code in who1.lisp[2] after you load CL-WHO - that will allow you to keep the original CL-WHO intact. I'm also attaching very simple test to check that we haven't braken things at least for the three examples advertised on CL-WHO web page. Please let me know your feedback, Victor. -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: who1.lisp URL: -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: cl-who-example.lisp URL: -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: cl-who-test.lisp URL: -------------- next part -------------- ;;; -*- mode: lisp; -*- (with-html-output-to-string (http-stream) (loop for (link . title) in '(("http://zappa.com/" . "Frank Zappa") ("http://marcusmiller.com/" . "Marcus Miller") ("http://www.milesdavis.com/" . "Miles Davis")) do (htm (:a :href link (:b (str title))) :br))) "Frank Zappa
Marcus Miller
Miles Davis
" (with-html-output-to-string (http-stream) (:table :border 0 :cellpadding 4 (loop for i below 25 by 5 do (htm (:tr :align "right" (loop for j from i below (+ i 5) do (htm (:td :bgcolor (if (oddp j) "pink" "green") (fmt "~@R" (1+ j)))))))))) "
IIIIIIIVV
VIVIIVIIIIXX
XIXIIXIIIXIVXV
XVIXVIIXVIIIXIXXX
XXIXXIIXXIIIXXIVXXV
" (with-html-output-to-string (http-stream) (:h4 "Look at the character entities generated by this example") (loop for i from 0 for string in '("F?te" "S?rensen" "na?ve" "H?hner" "Stra?e") do (htm (:p :style (conc "background-color:" (case (mod i 3) ((0) "red") ((1) "orange") ((2) "blue"))) (htm (esc string)))))) "

Look at the character entities generated by this example

Fête

Sørensen

naïve

Hühner

Straße

" (with-html-output-to-string (str) (:html (:title "test"))) "test" -------------- next part -------------- -- [1] http://paste.lisp.org/display/55662 [2] http://paste.lisp.org/display/55663 From victor.kryukov at gmail.com Sun Feb 10 06:54:09 2008 From: victor.kryukov at gmail.com (Victor Kryukov) Date: Sun, 10 Feb 2008 00:54:09 -0600 Subject: [cl-who-devel] Re: Macroexpansion of with-html-output body? References: <47A5E8BD.9080709@cunningham.net> <87zlu948fi.fsf@esculap.gateway.2wire.net> Message-ID: <87r6fl47zi.fsf@esculap.gateway.2wire.net> Victor Kryukov writes: > Jeff Cunningham writes: > >> Edi Weitz wrote: >>> On Sat, 2 Feb 2008 15:18:09 -0600, "Eli Naeher" wrote: >>> >>> >>>> It seems like it would be nice to expand any macros detected while >>>> walking the tree of the w-h-o body. This would allow users to define >>>> their own pseudo-tags a little more flexibly than is possible with >>>> convert-tag-to-string-list. In particular, it would allow the user >>>> to create a tag which modifies its body (as a tree) even when that >>>> body contains the expansion of another user-defined tag. I don't >>>> believe this is currently possible, as this hypothetical outer tag >>>> would have access only to the HTML strings returned by the >>>> convert-tag-to-string-list specialized on the inner tag and not to >>>> the relevant s-expressions. >>>> >>> >>> Modifying CL-WHO's internals to allow this is on my todo list, but >>> there are a lot more things on this list, so the chances of me doing >>> this myself in the near future are not very big. So, if someone wants >>> to do this, I'm all for it. Please read this first, though: >>> >>> http://weitz.de/patches.html >>> >>> In the case of CL-WHO I'd think that backwards compatibility would be >>> pretty important. >>> >>> Edi. >>> >> I also like the idea. >> And as I have tens of thousands of lines of cl-who code in operation, >> I emphatically vote for backwards compatibility. > > Below is my attempt to implement macroexpansion capability in > with-html-output body. Before sending it formally as a patch I want to > get your feedback on the implementation and also ask for some testing. It also seems to resolve (with-html-output-to-str (str) ...) bug. Regards, Victor. From jeffrey at cunningham.net Sun Feb 10 07:07:57 2008 From: jeffrey at cunningham.net (Jeff Cunningham) Date: Sat, 09 Feb 2008 23:07:57 -0800 Subject: [cl-who-devel] Re: Macroexpansion of with-html-output body? In-Reply-To: <87zlu948fi.fsf@esculap.gateway.2wire.net> References: <47A5E8BD.9080709@cunningham.net> <87zlu948fi.fsf@esculap.gateway.2wire.net> Message-ID: <47AEA2CD.8060206@cunningham.net> Victor Kryukov wrote: > To test new functionality, simply load the code in who1.lisp[2] after you > load CL-WHO - that will allow you to keep the original CL-WHO intact. > > I'm also attaching very simple test to check that we haven't braken > things at least for the three examples advertised on CL-WHO web page. > > Please let me know your feedback, > > Victor. > Victor, So far so good. Your mod is running now on one live test site and there's no sign of breakage. I'll do more extensive testing tomorrow. Jeff From victor.kryukov at gmail.com Sun Feb 10 07:10:09 2008 From: victor.kryukov at gmail.com (Victor Kryukov) Date: Sun, 10 Feb 2008 01:10:09 -0600 Subject: [cl-who-devel] Re: Macroexpansion of with-html-output body? References: <47A5E8BD.9080709@cunningham.net> <87zlu948fi.fsf@esculap.gateway.2wire.net> <47AEA2CD.8060206@cunningham.net> Message-ID: <87ir0xs2we.fsf@esculap.gateway.2wire.net> Jeff Cunningham writes: > Victor, > > So far so good. Your mod is running now on one live test site and > there's no sign of breakage. I'll do more extensive testing tomorrow. Jeff, That was fast! I'm holding my breath... Victor. From jeffrey at cunningham.net Wed Feb 13 04:39:20 2008 From: jeffrey at cunningham.net (Jeff Cunningham) Date: Tue, 12 Feb 2008 20:39:20 -0800 Subject: [cl-who-devel] Re: Macroexpansion of with-html-output body? In-Reply-To: <87ir0xs2we.fsf@esculap.gateway.2wire.net> References: <47A5E8BD.9080709@cunningham.net> <87zlu948fi.fsf@esculap.gateway.2wire.net> <47AEA2CD.8060206@cunningham.net> <87ir0xs2we.fsf@esculap.gateway.2wire.net> Message-ID: <47B27478.8070309@cunningham.net> Victor Kryukov wrote: > Jeff, > > That was fast! I'm holding my breath... > > Victor. > > Victor, I'm not sure anything I'm doing really exercises your changes, but I now have it running on three servers without any sign of trouble (or difference in output, for that matter). I sat down this evening to try to understand it better, and for awhile I thought I might be able to use it to solve a macro expansion problem that's been bothering me. I don't think it can be applied, but I'm not sure. Here's a simplified version of a macro I use : (defmacro section (title &rest body) `(with-html-output (*standard-output* nil :indent t) (:table (:a :name ,title) (:tr (:td (:h2 (str ,title)) , at body))))) Here is a trivial example showing how I use it: (section "A Title" (:p "A cl-who formatted form") (:p "The body could be any collection of cl-who code")) What I'd like to be able to do is feed it unexpanded cl-who code like this: (let ((code1 '("A Title" (:p "A cl-who formatted form") (:p "The body could be any collection of cl-who code"))) (code2 '("Another title" (:h2 "Different code here")))) (section* code1) (section* code2)) And I've tried to make the first macro work by wrapping it in a second one like this: (defmacro section* (lst) (let ((ttl (gensym)) (bdy (gensym))) `(let ((,ttl (car ,lst)) (,bdy (cdr ,lst))) (section ,ttl ,bdy)))) Of course, the last form isn't right and evaluates without the body statements. I had expected to use , at bdy in the last form, but that give an error. Do you have any idea how to do something like this? --Jeff > _______________________________________________ > cl-who-devel site list > cl-who-devel at common-lisp.net > http://common-lisp.net/mailman/listinfo/cl-who-devel > > From victor.kryukov at gmail.com Wed Feb 13 05:11:27 2008 From: victor.kryukov at gmail.com (Victor Kryukov) Date: Tue, 12 Feb 2008 23:11:27 -0600 Subject: [cl-who-devel] Re: Macroexpansion of with-html-output body? References: <47A5E8BD.9080709@cunningham.net> <87zlu948fi.fsf@esculap.gateway.2wire.net> <47AEA2CD.8060206@cunningham.net> <87ir0xs2we.fsf@esculap.gateway.2wire.net> <47B27478.8070309@cunningham.net> Message-ID: <87skzxv3sw.fsf@esculap.gateway.2wire.net> Jeff Cunningham writes: > Victor, > > I'm not sure anything I'm doing really exercises your changes, but I > now have it running on three servers without any sign of trouble (or > difference in output, for that matter). Well, if you code ever uses special symbols str, esc, fmt or htm - that's a good sign - it means that macroexpansion is working. > I sat down this evening to try to understand it better, and for awhile > I thought I might be able to use it to solve a macro expansion problem > that's been bothering me. I don't think it can be applied, but I'm not > sure. Here's a simplified version of a macro I use : I highly recommend readign cl-who code. It's an easy read - the code is short, very well written and has just the right amount of comments. > (defmacro section (title &rest body) > `(with-html-output (*standard-output* nil :indent t) > (:table > (:a :name ,title) > (:tr > (:td > (:h2 (str ,title)) > , at body))))) With the new macro def-syntax-macro, you can achieve the same with the following code: (cl-who::def-syntax-macro section (title &rest body) `(:table (:a :name ,title) (:tr (:td (:h2 (str ,title)) , at body)))) BTW - your (:a :name ,title) inside a table looks really suspicious! Now whenever you use section macro inside your with-html-output, it will expanded _before_ with-html-output comes into play. Note cl-who:: qualifier before the def-syntax-macro name - I haven't touched original cl-who files for the purpose - it's much easier to try the changes this way - and therefore def-syntax-macro is not exported by default, hence the cl-who:: package specification. > Here is a trivial example showing how I use it: > > (section "A Title" > (:p "A cl-who formatted form") > (:p "The body could be any collection of cl-who code")) If you define section with the def-syntax-macro as above, you can legally use this inside your with-html-output macro. > What I'd like to be able to do is feed it unexpanded cl-who code like this: > > (let ((code1 '("A Title" > (:p "A cl-who formatted form") > (:p "The body could be any collection of cl-who code"))) > (code2 '("Another title" > (:h2 "Different code here")))) > (section* code1) > (section* code2)) Well - are you _sure_ you really need that? Currently, cl-who doesn't provide any interface for producing code out of sexps, and if you read who.lisp or cl-who documentation - esp. paying attention to "Syntax and Semantics" section - you'll understand why. In most cases, you just don't need that. If you _really_ insist, try this one: (defpackage :cl-who-sexp (:use :cl :cl-who)) (in-package :cl-who-sexp) (defun sexp-with-html-output (sexp) "Generates string out of SEXP according to CL-WHO rules" (with-output-to-string (s) (eval (cl-who::tree-to-commands sexp s)))) CL-WHO-SEXP> (sexp-with-html-output '(:html (:title "title"))) "title" This is either a very clever or very ugly hack. It would be better to re-write tree-to-commands-aux to provide such functionality instead. Regards, Victor -- http://macrodefinition.blogspot.com/ From jeffrey at cunningham.net Wed Feb 13 05:58:48 2008 From: jeffrey at cunningham.net (Jeff Cunningham) Date: Tue, 12 Feb 2008 21:58:48 -0800 Subject: [cl-who-devel] Re: Macroexpansion of with-html-output body? In-Reply-To: <87skzxv3sw.fsf@esculap.gateway.2wire.net> References: <47A5E8BD.9080709@cunningham.net> <87zlu948fi.fsf@esculap.gateway.2wire.net> <47AEA2CD.8060206@cunningham.net> <87ir0xs2we.fsf@esculap.gateway.2wire.net> <47B27478.8070309@cunningham.net> <87skzxv3sw.fsf@esculap.gateway.2wire.net> Message-ID: <47B28718.8070106@cunningham.net> Wow - talk about fast! Victor, I'm impressed. Victor Kryukov wrote: > Well, if you code ever uses special symbols str, esc, fmt or htm - > that's a good sign - it means that macroexpansion is working. > > I use all of them, so it's working. >> I sat down this evening to try to understand it better, and for awhile >> I thought I might be able to use it to solve a macro expansion problem >> that's been bothering me. I don't think it can be applied, but I'm not >> sure. Here's a simplified version of a macro I use : >> > > I highly recommend readign cl-who code. It's an easy read - the code > is short, very well written and has just the right amount of comments. > Okay, I'll do that. > With the new macro def-syntax-macro, you can achieve the same with the > following code: > > (cl-who::def-syntax-macro section (title &rest body) > `(:table > (:a :name ,title) > (:tr (:td (:h2 (str ,title)) , at body)))) > > BTW - your (:a :name ,title) inside a table looks really suspicious! > It should - it is a remnant of my simplification (belonged to a preceding row). I was trying to hack out everything not pertinent to the example. > Now whenever you use section macro inside your with-html-output, it > will expanded _before_ with-html-output comes into play. Note > cl-who:: qualifier before the def-syntax-macro name - I haven't > touched original cl-who files for the purpose - it's much easier to > try the changes this way - and therefore def-syntax-macro is not > exported by default, hence the cl-who:: package specification. > > > >> Here is a trivial example showing how I use it: >> >> (section "A Title" >> (:p "A cl-who formatted form") >> (:p "The body could be any collection of cl-who code")) >> > > If you define section with the def-syntax-macro as above, you can > legally use this inside your with-html-output macro. > > Excellent. >> What I'd like to be able to do is feed it unexpanded cl-who code like this: >> >> (let ((code1 '("A Title" >> (:p "A cl-who formatted form") >> (:p "The body could be any collection of cl-who code"))) >> (code2 '("Another title" >> (:h2 "Different code here")))) >> (section* code1) >> (section* code2)) >> > > Well - are you _sure_ you really need that? Currently, cl-who doesn't > provide any interface for producing code out of sexps, and if you read > who.lisp or cl-who documentation - esp. paying attention to "Syntax > and Semantics" section - you'll understand why. > > I'm not at all sure, and you're probably right that its a bad idea. Still, I'd like to understand it. Interesting... I just tried to write down what led me to it and in the process thought of a much simpler way. > In most cases, you just don't need that. If you _really_ insist, try > this one: > > (defpackage :cl-who-sexp > (:use :cl :cl-who)) > > (in-package :cl-who-sexp) > > (defun sexp-with-html-output (sexp) > "Generates string out of SEXP according to CL-WHO rules" > (with-output-to-string (s) > (eval (cl-who::tree-to-commands sexp s)))) > > CL-WHO-SEXP> (sexp-with-html-output '(:html (:title "title"))) > "title" > > This is either a very clever or very ugly hack. It would be better to > re-write tree-to-commands-aux to provide such functionality instead. > Its a fascinating piece of code. I'm going to play with it. Thanks! Regards, Jeff From lispercat at gmail.com Wed Feb 27 17:12:06 2008 From: lispercat at gmail.com (Andrei Stebakov) Date: Wed, 27 Feb 2008 12:12:06 -0500 Subject: [cl-who-devel] Parsing html again Message-ID: When we generate the JavaScript tag like so: (with-html-output-to-string (*standard-output* nil :prologue nil :indent nil) (:html (:head (:title "Temporary page") (:script :language "JavaScript" :src "/test/scripts.js" :type "text/javascript" "")))) It will generate: Temporary page Now if we parse the html with html-parse:parse-html command and convert it back to the string with tree-to-string (here is the threadabout this command) we'll get the broken It's because html-parse:parse-html will produce ((:HTML (:HEAD (:TITLE "Temporary page") ((:SCRIPT :LANGUAGE "JavaScript" :SRC "/test/scripts.js" :TYPE "text/javascript"))))) Note, that there is no "" at the end of (:script) anymore. My question is where this problem should be fixed at html-parse:parse-html level so that parse-html would insert the "" when it finds the tag like so: > (with-html-output-to-string (*standard-output* nil :prologue nil :indent nil) > (:html > (:head (:title "Temporary page") > (:script :language "JavaScript" :src "/test/scripts.js" > :type "text/javascript" "")))) > It will generate: > Temporary page That strange. On my system, both for SBCL and CLisp, WHO> (with-html-output-to-string (*standard-output* nil :prologue nil :indent nil) (:html (:head (:title "Temporary page") (:script :language "JavaScript" :src "/test/scripts.js" :type "text/javascript")))) "Temporary page" If you insist on using non-documented features, like tree-to-string, read the sources (although the following two variables are documented in the docs[1]). WHO> (documentation '*html-empty-tags* 'variable) "The list of HTML tags that should be output as empty tags. See *HTML-EMPTY-TAG-AWARE-P*." WHO> (documentation '*html-empty-tag-aware-p* 'variable) "Set this to NIL to if you want to use CL-WHO as a strict XML generator. Otherwise, CL-WHO will only write empty tags listed in *HTML-EMPTY-TAGS* as (XHTML mode) or (SGML mode). For all other tags, it will always generate ." WHO> (member :script *html-empty-tags*) NIL [1] http://www.weitz.de/cl-who/#*html-empty-tag-aware-p* Regards, Victor. -- My blog: http://macrodefinition.blogspot.com