From J.k.cunningham at comcast.net Sun Mar 28 20:10:53 2010 From: J.k.cunningham at comcast.net (J. K. Cunningham) Date: Sun, 28 Mar 2010 13:10:53 -0700 Subject: [cl-who-devel] Macros for outlining Message-ID: <1269807053.19322.116.camel@golum.olympus.net> I've been playing around with a way to partially automate writing outline-based pages and run into something I don't know how to do. I'm hoping someone can perhaps offer a solution or point me in the right direction. I've reduced the scope to a fairly simple situation which might seem unmotivated in this form. But if I can find a way to do this, the rest of what I'm doing will fall into place. I'd like to be able to write code that looks like this (example): (let ((hform "A Title")) (with-html-output (*standard-output* nil :indent 0) (section (hform) (:p "A paragraph can go here. ") (section ("A Subtitle") "Subsection text goes here.")) (section ("Second Title") "Any cl-who syntax input here:" (:ol (:li "Item 1") (:li "Item 2"))))) where SECTION would be a macro so that it can take CL-WHO syntax arguments. The idea is that the SECTION macro would expand so that I ended up effectively with this: (let ((form "A Title")) (with-html-output (*standard-output* nil :indent 0) (:h1 (str form)) (:p "A paragraph can go here. ") (:h2 "A Subtitle") "Subsection text goes here." (:h1 "Second Title") "Any cl-who syntax input here:" (:ol (:li "Item 1") (:li "Item 2")))) I came up with a helper macro like this to handle the levels as a variable: (defmacro hn (level &body body) ``(,(intern (format nil "H~d" ,level) :keyword) ,, at body)) (let ((lvl 2) (title "A Title")) (with-html-output (*standard-output*) (str (hn lvl (:b (str title)))))) ;; =>

A Title

This enables me to write code that looks like this: (defmacro section ((n &rest heading) &body body) `(str (with-html-output-to-string (s nil :indent 0) (str (hn ,n , at heading)) (str (with-html , at body))))) (let ((lvl 1) (form "A Title")) (with-html-output (*standard-output* nil :indent 0) (section (lvl form) (:p "A paragraph can go here. ") (section ((1+ lvl) "A Subtitle") "Subsection text goes here.")) (section (lvl "Second Title") "Any cl-who syntax input here:" (:ol (:li "Item 1") (:li "Item 2"))))) But this leaves me with having to manage the levels manually. What I can't figure out how to do is write the SECTION macro so it doesn't require the LVL arguments, incrementing them recursively. If it could be written as a function, I could use a closure that started at LVL = 1 and incremented at each level, but I'm not good enough with macros to see how to do this. I'm probably looking at this the wrong way. Does anyone have any ideas how to go about this? Regards, Jeff Cunningham -------------- next part -------------- An HTML attachment was scrubbed... URL: From vseloved at gmail.com Sun Mar 28 21:21:50 2010 From: vseloved at gmail.com (Vsevolod Dyomkin) Date: Mon, 29 Mar 2010 00:21:50 +0300 Subject: [cl-who-devel] Macros for outlining In-Reply-To: <1269807053.19322.116.camel@golum.olympus.net> References: <1269807053.19322.116.camel@golum.olympus.net> Message-ID: <89dc7c5b1003281421o1129f2bcl94c2172bffb5a807@mail.gmail.com> See this: http://common-lisp.net/pipermail/cl-who-devel/2010-February/000421.html Best regards, Vsevolod On Sun, Mar 28, 2010 at 11:10 PM, J. K. Cunningham < J.k.cunningham at comcast.net> wrote: > I've been playing around with a way to partially automate writing > outline-based pages and run into something I don't know how to do. I'm > hoping someone can perhaps offer a solution or point me in the right > direction. I've reduced the scope to a fairly simple situation which might > seem unmotivated in this form. But if I can find a way to do this, the rest > of what I'm doing will fall into place. > > I'd like to be able to write code that looks like this (example): > > (let ((hform "A Title")) (with-html-output (*standard-output* nil :indent 0) (section (hform) (:p "A paragraph can go here. ") (section ("A Subtitle") "Subsection text goes here.")) (section ("Second Title") "Any cl-who syntax input here:" (:ol (:li "Item 1") (:li "Item 2"))))) > > where SECTION would be a macro so that it can take CL-WHO syntax arguments. > The idea is that the SECTION macro would expand so that I ended up > effectively with this: > > (let ((form "A Title")) (with-html-output (*standard-output* nil :indent 0) (:h1 (str form)) (:p "A paragraph can go here. ") (:h2 "A Subtitle") "Subsection text goes here." (:h1 "Second Title") "Any cl-who syntax input here:" (:ol (:li "Item 1") (:li "Item 2")))) > > I came up with a helper macro like this to handle the levels as a variable: > > (defmacro hn (level &body body) ``(,(intern (format nil "H~d" ,level) :keyword) ,, at body)) > (let ((lvl 2) (title "A Title")) (with-html-output (*standard-output*) (str (hn lvl (:b (str title)))))) > > ;; =>

A Title

> > > This enables me to write code that looks like this: > > (defmacro section ((n &rest heading) &body body) `(str (with-html-output-to-string (s nil :indent 0) (str (hn ,n , at heading)) (str (with-html , at body))))) > (let ((lvl 1) (form "A Title")) (with-html-output (*standard-output* nil :indent 0) (section (lvl form) (:p "A paragraph can go here. ") (section ((1+ lvl) "A Subtitle") "Subsection text goes here.")) (section (lvl "Second Title") "Any cl-who syntax input here:" (:ol (:li "Item 1") (:li "Item 2"))))) > > > But this leaves me with having to manage the levels manually. What I can't > figure out how to do is write the SECTION macro so it doesn't require the > LVL arguments, incrementing them recursively. > > If it could be written as a function, I could use a closure that started at > LVL = 1 and incremented at each level, but I'm not good enough with macros > to see how to do this. > > I'm probably looking at this the wrong way. Does anyone have any ideas how to go about this? > > Regards, > Jeff Cunningham > > > > > > > _______________________________________________ > cl-who-devel site list > cl-who-devel at common-lisp.net > http://common-lisp.net/mailman/listinfo/cl-who-devel > -- vsevolod -------------- next part -------------- An HTML attachment was scrubbed... URL: From J.k.cunningham at comcast.net Sun Mar 28 21:52:55 2010 From: J.k.cunningham at comcast.net (J. K. Cunningham) Date: Sun, 28 Mar 2010 14:52:55 -0700 Subject: [cl-who-devel] Macros for outlining In-Reply-To: <89dc7c5b1003281421o1129f2bcl94c2172bffb5a807@mail.gmail.com> References: <1269807053.19322.116.camel@golum.olympus.net> <89dc7c5b1003281421o1129f2bcl94c2172bffb5a807@mail.gmail.com> Message-ID: <1269813175.19322.126.camel@golum.olympus.net> On Mon, 2010-03-29 at 00:21 +0300, Vsevolod Dyomkin wrote: > See > this: http://common-lisp.net/pipermail/cl-who-devel/2010-February/000421.html I have taken a look at your macro enhancements, Vsevolod, but haven't yet found a way to use them here. Can you be more specific? Regards, Jeff -------------- next part -------------- An HTML attachment was scrubbed... URL: