Loading ...
Sorry, an error occurred while loading the content.

[Cheetahtemplate-discuss] #indent

Expand Messages
  • Mike Orr
    Any objections to removing #indent until it can be implemented properly? -- -Mike (Iron) Orr, iron@mso.oz.net (if mail problems: mso@oz.net) http://iron.cx/
    Message 1 of 8 , Nov 16, 2002
    • 0 Attachment
      Any objections to removing #indent until it can be implemented
      properly?

      --
      -Mike (Iron) Orr, iron@... (if mail problems: mso@...)
      http://iron.cx/ English * Esperanto * Russkiy * Deutsch * Espan~ol


      -------------------------------------------------------
      This sf.net email is sponsored by: To learn the basics of securing
      your web site with SSL, click here to get a FREE TRIAL of a Thawte
      Server Certificate: http://www.gothawte.com/rd524.html
      _______________________________________________
      Cheetahtemplate-discuss mailing list
      Cheetahtemplate-discuss@...
      https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
    • robert_kuzelj@yahoo.com
      hi mike, ... sorry gut it completly wrong. the version is 0.9.15a1 ... no ... no ... yes ... yes ... no ... no ... yes ... yes ... yes ... yes ... spaces) no
      Message 2 of 8 , Nov 21, 2002
      • 0 Attachment
        hi mike,

        > You mean 0.9.14b1?
        sorry gut it completly wrong. the version is
        0.9.15a1

        > Which #indent features are you using? I'm currently leaning toward
        > supporting:
        > #indent strip ; strip leading whitespace on input lines
        no

        > #indent add ; add indentation to output lines as appropriate
        no

        > #indent on ; do both
        yes
        > #indent off ; do neither
        yes

        > #indent +EXPR ; add N levels to indentation
        no

        > #indent -EXPR ; subtract N levels from indentation
        no

        > #indent ++ ; add 1 level to indentation
        yes

        > #indent -- ; subtract 1 level from indentation
        yes

        > #indent =EXPR ; set indentation level to N
        yes

        > #indent pop [EXPR=1] ; revert to Nth previous level (default 1)
        yes

        > #indent chars EXPR ; output this string for each indent level (default 4
        spaces)
        no

        > #indent debug ; output current indent level, stack and chars
        no

        > All the +/-/= combinations would implicitly push the previous level, so
        > we wouldn't need "#indent push".
        sounds ok for me
        +1

        >Attempts to pop past the end of the stack would result in
        >level 0 (no added indentation).
        +1

        >There would be one indentation object per template, shared with methods
        >and include files.
        isn't that the case allready?

        > I'm thinking we should not document or support it until we can make it a
        > bona fide directive, meaning it converts each command to Python code.
        <hmm> it think we should document it but it needs not necessary be the
        way it is at the moment. there could be an appendix "additional directives".

        > Currently it uses a preprocessor kludge to convert commands to
        > "$_indent.level(3)" or something like that, putting "$_indent.indent()"
        > at the beginning of each output line.
        well that was the only way i knew to get it run.

        >This screws up the diagnostic
        > messages in the .py template module which carefully try to give the
        > row/column position of each construct from the .tmpl, but these added
        > placeholders change the position. But I don't understand the
        > parser/compiler enough to do all that right now.
        neither do i.

        > I'm also thinking that to do indentation right, we should automatically
        > indent all the lines in a multiline placeholder.
        true, here my code definitly breaks down.

        >That means adding
        >another method call around each placeholder, in addition to the filter
        >call. Again, I don't have the expertise to do this right no,w and I
        >won't have time to do it in the next few weeks, and we'd like to get 1.0
        >done now rather than wait forever.
        i'd say move the doc outside the "core" into the appendix. maybe document
        the shortcommings and thats it. of course you could also remove it
        completely
        from the docs and the code. since it seems i am the only one using it right
        now. on the other hand if somebody comes along who needs such a
        functionality
        he might find it handy (especially if documented).

        ciao robertj

        ------------------------------------------------------------
        Robert Kuzelj
        Gaissacherstrasse 7 email: robert_kuzelj@...
        81371 Muenchen tel: 0177/5302230

        the trinity of desirables of (software) architecture:
        Firmitas, Utilitas, Venustas (marcus vitruvius 20 BC)
        strength, utility, beauty




        -------------------------------------------------------
        This sf.net email is sponsored by:ThinkGeek
        Welcome to geek heaven.
        http://thinkgeek.com/sf
        _______________________________________________
        Cheetahtemplate-discuss mailing list
        Cheetahtemplate-discuss@...
        https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
      • robert_kuzelj@yahoo.com
        hi mike, ... i must admit i don t know why i came up with that then. it is so long ago ;-) then i also admit that i didn t need cheetah from then on. only
        Message 3 of 8 , Nov 21, 2002
        • 0 Attachment
          hi mike,

          >>> #indent -EXPR ; subtract N levels from indentation
          >> no
          > So maybe we can drop these. I guess people wouldn't be likely to add or
          > subtract multiple levels at once.
          i must admit i don't know why i came up with that then.
          it is so long ago ;-)
          then i also admit that i didn't need cheetah from then on. only
          recently i was again faced with the problem of generating lots of code
          (something i realy like to do since i am too lazy to write code ;-) )
          and suddenly cheetah was again on my workbench. and it came really handy
          especially the indention stuff.

          > #indent reset ; set level to 0 and clear stack.
          +1

          > Probably de facto. We used to insist that methods be balanced, that is,
          > undo any indentation changes they make before returning, but you said
          > that would hurt some common uses of methods.
          sure i said this? i could only finding a mail where i was bubbling
          about #indents to be accumulative. i guess this was more a misunderstanding
          on my side if you meant to have the python-scope-rules in place and
          pushing the indent stuff implicitly to the next method-call.

          but anyway any pushing to the stack within a method would need
          to be accompanied by implicit #indent pop x at the end of a method. this
          certainly is harder to implement then what is done at the moment.
          the processor would have to know about the syntactical structure
          of the template (at least partially).

          but since i was beginning to think very much along those lines it
          might be a road we (or i) should travel. especially since the actual
          #indent-design gets verbose very fast.
          the structure is now very visible (as indented, sorry intended that was )
          but is hidden somehow in very many #indent directives. this is especially
          true for rather small methods

          example:
          01: #def doCheckIfNeeded($modelobject)
          02: #indent push
          03: #indent = 2
          04: #if $modelobject.isReference
          05: if (value == null)
          06: {
          07: #indent ++
          08: value = new Reference();
          09: #indent --
          10: }
          11: #end if
          12: #indent pop
          13: #end def

          of the above 13 lines 6 deal exclusivly with indention. so the
          code to be generated soon drowns in #indents. no good :-(

          so the folowing would be very much better

          01: #def doCheckIfNeeded($modelobject)
          02: #indent = 2
          03: #if $modelobject.isReference
          04: if (value == null)
          05: {
          06: value = new Reference();
          07: }
          08: #end if
          09: #end def

          if the indent processor would know about the structure of the
          cheetah code it would cut of white spaces on outputlines that are
          caused by cheetah structure statements (#if, #def, #for) and only
          then add the appropriate indention.

          >>If we had "#indent reset", would you need "#indent =EXPR"? When do you
          >>use it?
          i am not as you are suggestiong using #indent =expr for reseting indention
          but instead for setting the start indention

          a very recent example:

          01: public class ${holder_class}Extender extends ${holder_class}
          02: {
          03: //private static final Category LOGGER =
          Tools.getLogger(${holder_class}Extender.class, "log4j.xml");
          04: private static Set KEYS =
          IntrospectionPropertyHolder.parseKeys(${holder_class}.class);
          05:
          06: public ${holder_class}Extender()
          07: {
          08: this.initProperties(KEYS);
          09: }
          10:
          11: protected void initProperties()
          12: {
          13: $createNewProperty()
          14: }
          15: }
          16:
          17: #def createNewProperty()
          18:
          19: #indent on
          20: #indent push
          21: #indent=2
          22: #for $prop in $holder.getPropertyKeys().iterator()
          23: this.addProperty(new ${prop}Property(this));
          24: #end for
          25: #indent pop
          26: #indent off
          27: #end def

          ok, i guess thats enuff for this evening.

          ciao robertj
          ------------------------------------------------------------
          Robert Kuzelj
          Gaissacherstrasse 7 email: robert_kuzelj@...
          81371 Muenchen tel: 0177/5302230

          the trinity of desirables of (software) architecture:
          Firmitas, Utilitas, Venustas (marcus vitruvius 20 BC)
          strength, utility, beauty




          -------------------------------------------------------
          This sf.net email is sponsored by:ThinkGeek
          Welcome to geek heaven.
          http://thinkgeek.com/sf
          _______________________________________________
          Cheetahtemplate-discuss mailing list
          Cheetahtemplate-discuss@...
          https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
        • Mike Orr
          ... I was saying that indentation should be balanced in a method, so that you leave the method at the same indentation level and stack as you started at. You
          Message 4 of 8 , Nov 21, 2002
          • 0 Attachment
            On Fri, Nov 22, 2002 at 05:45:31AM +0100, robert_kuzelj@... wrote:
            > > Probably de facto. We used to insist that methods be balanced, that is,
            > > undo any indentation changes they make before returning, but you said
            > > that would hurt some common uses of methods.
            > sure i said this? i could only finding a mail where i was bubbling
            > about #indents to be accumulative. i guess this was more a misunderstanding
            > on my side if you meant to have the python-scope-rules in place and
            > pushing the indent stuff implicitly to the next method-call.

            I was saying that indentation should be balanced in a method, so that
            you leave the method at the same indentation level and stack as you
            started at. You said you may want to call one method that increases
            the indentation, then returns and you do some other stuff, then you
            call another method to decrease it. E.g.,

            #def $javaMethodBegin($methodName, $argsString)
            void ${methodName}(${argsString}) {
            #indent ++
            #end def


            #def $javaMethodEnd
            #indent --
            }

            #end def

            To me, that looks like a sufficient reason not to require
            indentation balancing in methods. The tradeoff is, maybe the
            user wants the reassurance of an error if they aren't balanced.
            We could make it switchable:
            #indent balance True
            but we don't want to go overboard with features.

            > but anyway any pushing to the stack within a method would need
            > to be accompanied by implicit #indent pop x at the end of a method. this
            > certainly is harder to implement then what is done at the moment.
            > the processor would have to know about the syntactical structure
            > of the template (at least partially).

            The compiler knows how many +/-/= commands were called in the method,
            so it can do an implicit pop that many levels.
            #indent implicitPop True

            How often do you think users would want to write:
            * a balanced method?
            * an unbalanced method?
            * an "unbalanced" method that gets balanced by an implicit pop


            > example:
            > 01: #def doCheckIfNeeded($modelobject)
            > 02: #indent push
            > 03: #indent = 2
            > 04: #if $modelobject.isReference
            > 05: if (value == null)
            > 06: {
            > 07: #indent ++
            > 08: value = new Reference();
            > 09: #indent --
            > 10: }
            > 11: #end if
            > 12: #indent pop
            > 13: #end def
            >
            > of the above 13 lines 6 deal exclusivly with indention. so the
            > code to be generated soon drowns in #indents. no good :-(
            >
            > so the folowing would be very much better
            >
            > 01: #def doCheckIfNeeded($modelobject)
            > 02: #indent = 2
            > 03: #if $modelobject.isReference
            > 04: if (value == null)
            > 05: {
            > 06: value = new Reference();
            > 07: }
            > 08: #end if
            > 09: #end def

            "#indent push" is already gone in the spec. Bye bye.

            "#indent = 2", yeah, if you need it. I think most programs prefer
            to deal with relative levels as much as possible, to make them
            portable. doCheckIfNeeded can be used only in for a top-level
            method; if you used it for an inner method, or a method in an
            inner class, the indentation would be wrong.

            Whether to use a pair of "#indent ++" and "indent --" within the method
            rather than literal whitespace is totally up to you. Literal whitespace
            looks cleaner, but it doesn't allow you to globally change the indent
            chars (4 spaces -> tab) globally at the top of the file.

            > if the indent processor would know about the structure of the
            > cheetah code it would cut of white spaces on outputlines that are
            > caused by cheetah structure statements (#if, #def, #for) and only
            > then add the appropriate indention.

            Cheetah already discards lines that consist only of directives and
            whitespace.

            > >>If we had "#indent reset", would you need "#indent =EXPR"? When do you
            > >>use it?
            > i am not as you are suggestiong using #indent =expr for reseting indention
            > but instead for setting the start indention

            Would it really be that inconvenient if you had to use relative
            indentation commands always rather than absolute ones? Why?

            --
            -Mike (Iron) Orr, iron@... (if mail problems: mso@...)
            http://iron.cx/ English * Esperanto * Russkiy * Deutsch * Espan~ol


            -------------------------------------------------------
            This sf.net email is sponsored by:ThinkGeek
            Welcome to geek heaven.
            http://thinkgeek.com/sf
            _______________________________________________
            Cheetahtemplate-discuss mailing list
            Cheetahtemplate-discuss@...
            https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
          • robert_kuzelj@yahoo.com
            hi mike, ... now that you mention it. yes i could imagine scenarios where this might be helpfull. even thou i have to admit i do not use such a scheme at the
            Message 5 of 8 , Nov 26, 2002
            • 0 Attachment
              hi mike,

              > I was saying that indentation should be balanced in a method, so that
              > you leave the method at the same indentation level and stack as you
              > started at. You said you may want to call one method that increases
              > the indentation, then returns and you do some other stuff, then you
              > call another method to decrease it. E.g.,
              >
              > #def $javaMethodBegin($methodName, $argsString)
              > void ${methodName}(${argsString}) {
              > #indent ++
              > #end def
              >
              >
              > #def $javaMethodEnd
              > #indent --
              > }
              >
              > #end def
              now that you mention it. yes i could imagine scenarios
              where this might be helpfull. even thou i have to admit
              i do not use such a scheme at the moment.

              > To me, that looks like a sufficient reason not to require
              > indentation balancing in methods. The tradeoff is, maybe the
              > user wants the reassurance of an error if they aren't balanced.
              > We could make it switchable:
              > #indent balance True
              > but we don't want to go overboard with features.
              i think we should let it settle first. i am planning to write
              an article about cheetah and code-generation. basically it is
              an article about different code-gen-tools (java, xls, python, cheetah).

              > The compiler knows how many +/-/= commands were called in the method,
              > so it can do an implicit pop that many levels.
              > #indent implicitPop True
              last time i looked into it this was not the case.

              > How often do you think users would want to write:
              > * a balanced method?
              > * an unbalanced method?
              > * an "unbalanced" method that gets balanced by an implicit pop
              <oops> this is really hard. i really cant answer that in any
              reasonably way.

              > "#indent push" is already gone in the spec. Bye bye.
              yep

              > "#indent = 2", yeah, if you need it. I think most programs prefer
              > to deal with relative levels as much as possible, to make them
              > portable. doCheckIfNeeded can be used only in for a top-level
              > method; if you used it for an inner method, or a method in an
              > inner class, the indentation would be wrong.
              i simply must say that there is not enough hard data to really support
              that claim. for the moment i have written relativly small generators.
              at this time the code base of my generators is about 700 loc where
              probably 400 loc are template code and thhe rest is pure python.

              > Whether to use a pair of "#indent ++" and "indent --" within the method
              > rather than literal whitespace is totally up to you. Literal whitespace
              > looks cleaner, but it doesn't allow you to globally change the indent
              > chars (4 spaces -> tab) globally at the top of the file.
              that is right but might be ok - besides that one should allways be
              able to revert to the explicit form.

              > > if the indent processor would know about the structure of the
              > > cheetah code it would cut of white spaces on outputlines that are
              > > caused by cheetah structure statements (#if, #def, #for) and only
              > > then add the appropriate indention.
              > Cheetah already discards lines that consist only of directives and
              > whitespace.
              what i meant was, that the indenter would know about the code structure
              and would only cut off that whitepspaces that are caused by structural
              statements

              eg
              01: #if foo=1
              02: public int foo()
              03: {
              04: return FOO;
              05: }
              06: #end if

              the only ws (2) here would be on line 4.

              > Would it really be that inconvenient if you had to use relative
              > indentation commands always rather than absolute ones? Why?
              at the moment yes. but this might change when i have more
              experience.

              ciao robertj
              ------------------------------------------------------------
              Robert Kuzelj
              Gaissacherstrasse 7 email: robert_kuzelj@...
              81371 Muenchen tel: 0177/5302230

              the trinity of desirables of (software) architecture:
              Firmitas, Utilitas, Venustas (marcus vitruvius 20 BC)
              strength, utility, beauty




              -------------------------------------------------------
              This SF.net email is sponsored by: Get the new Palm Tungsten T
              handheld. Power & Color in a compact size!
              http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0002en
              _______________________________________________
              Cheetahtemplate-discuss mailing list
              Cheetahtemplate-discuss@...
              https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
            • Mike Orr
              #indent is now undocumented. The code remains so Robert can use his existing templates for now. BEGIN INCUDE=== This directive is not implemented yet.
              Message 6 of 8 , Nov 26, 2002
              • 0 Attachment
                #indent is now undocumented. The code remains so Robert can use his existing
                templates for now.

                BEGIN INCUDE=== This directive is not implemented yet. When/if it's completed,
                it will allow you to \begin{enumerate} \item indent your template definition in
                a natural way (e.g., the bodies of \code{\#if} blocks) without affecting the
                output \item add indentation to output lines without encoding it literally in
                the template definition. This will make it easier to use Cheetah to produce
                indented source code programmatically (e.g., Java source code).
                \end{enumerate}

                There is some experimental code that recognizes the \code{\#indent} directive
                with options, but the options are purposely undocumented at this time. So
                pretend it doesn't exist. If you have a use for this feature and would like to
                see it implemented sooner rather than later, let us know on the mailing list.

                The latest specification for the future \code{\#indent} directive is in the
                TODO file in the Cheetah source distribution. END INCLUDE===


                "#indent =EXPR" is listed as a future extension but will likely make it into
                phase 1 if I can figure out how to make Cheetah's parser/compiler parse the
                expression.

                "#indent balance BOOL" and "#indent implicitPop BOOL" are listed as future
                extensions but may never become reality, because the implementation will be
                harder than I initially thought. I thought you could just count #indent +/-/=
                in the method at compile time, but what if it's in one branch in an #if, or in
                a loop? A bigger issue is, in order to do implicit pops, we'd have to have a
                second stack that marks the checkpoints (=which level of the original stack we
                were at when the function started). That would double the code for a minor
                feature.


                On Tue, Nov 26, 2002 at 06:38:10PM +0100, robert_kuzelj@... wrote:
                > > > if the indent processor would know about the structure of the cheetah
                > > > code it would cut of white spaces on outputlines that are caused by
                > > > cheetah structure statements (#if, #def, #for) and only then add the
                > > > appropriate indention.
                > > Cheetah already discards lines that consist only of directives and
                > > whitespace.
                > what i meant was, that the indenter would know about the code structure and
                > would only cut off that whitepspaces that are caused by structural statements
                >
                > eg 01: #if foo=1 02: public int foo() 03: { 04: return FOO; 05:
                > } 06: #end if
                >
                > the only ws (2) here would be on line 4.

                This makes sense. Let's revisit it when phase 1 gets off the ground. Maybe
                stripping off all leading whitespace is too simplistic. On the other hand, I'm
                not sure we can come up with rules that will do what everybody wants without
                undesired side effects.

                --
                -Mike (Iron) Orr, iron@... (if mail problems: mso@...)
                http://iron.cx/ English * Esperanto * Russkiy * Deutsch * Espan~ol


                -------------------------------------------------------
                This SF.net email is sponsored by: Get the new Palm Tungsten T
                handheld. Power & Color in a compact size!
                http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0002en
                _______________________________________________
                Cheetahtemplate-discuss mailing list
                Cheetahtemplate-discuss@...
                https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
              • Leonard J. Reder
                Hello all, I am using Cheetah to generate C code and looking for easy ways to align arguments. Does anyone know if the #indent can be used for this. Is it
                Message 7 of 8 , Jun 20, 2007
                • 0 Attachment
                  Hello all,

                  I am using Cheetah to generate C code and looking for easy ways to
                  align arguments. Does anyone know if the #indent can be used for this.
                  Is it even implemented at all? Are there examples? For example one
                  thing I would like to do is produce something that looks like this:

                  tyepdef union {
                  ArmAcMsgCalibrate cal;
                  ArmAcMsgChangeTool change_tool;
                  ArmAcMsgSetSomthing set_somthing;
                  } ArmUnion

                  See how all the arguments to the types are nicely aligned. Any pointers
                  on easy ways to do this would be welcome. Currently I am doing it in
                  Python and inserting spaces into my template.

                  Thanks,
                  Len
                  --
                  ____________________________________________________
                  Leonard J. Reder
                  Jet Propulsion Laboratory
                  Interferometry Systems and Technology Section 383
                  Email: reder@...
                  Phone (Voice): 818-354-3639
                  Phone (FAX): 818-354-4357
                  Mail Address:
                  Mail Stop: 171-113
                  4800 Oak Grove Dr.
                  Pasadena, CA. 91109
                  ---------------------------------------------------


                  -------------------------------------------------------------------------
                  This SF.net email is sponsored by DB2 Express
                  Download DB2 Express C - the FREE version of DB2 express and take
                  control of your XML. No limits. Just data. Click to get it now.
                  http://sourceforge.net/powerbar/db2/
                  _______________________________________________
                  Cheetahtemplate-discuss mailing list
                  Cheetahtemplate-discuss@...
                  https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
                • Mike Orr
                  ... #indent was never finished and is unsupported. It was intended to indent the whole line, not to line up columns within a line. I don t know if the parser
                  Message 8 of 8 , Jun 20, 2007
                  • 0 Attachment
                    On 6/20/07, Leonard J. Reder <reder@...> wrote:
                    > I am using Cheetah to generate C code and looking for easy ways to
                    > align arguments. Does anyone know if the #indent can be used for this.
                    > Is it even implemented at all? Are there examples? For example one
                    > thing I would like to do is produce something that looks like this:
                    >
                    > tyepdef union {
                    > ArmAcMsgCalibrate cal;
                    > ArmAcMsgChangeTool change_tool;
                    > ArmAcMsgSetSomthing set_somthing;
                    > } ArmUnion
                    >
                    > See how all the arguments to the types are nicely aligned. Any pointers
                    > on easy ways to do this would be welcome. Currently I am doing it in
                    > Python and inserting spaces into my template.

                    #indent was never finished and is unsupported. It was intended to
                    indent the whole line, not to line up columns within a line. I don't
                    know if the parser even recognizes the #indent directive anymore.

                    --
                    Mike Orr <sluggoster@...>

                    -------------------------------------------------------------------------
                    This SF.net email is sponsored by DB2 Express
                    Download DB2 Express C - the FREE version of DB2 express and take
                    control of your XML. No limits. Just data. Click to get it now.
                    http://sourceforge.net/powerbar/db2/
                    _______________________________________________
                    Cheetahtemplate-discuss mailing list
                    Cheetahtemplate-discuss@...
                    https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
                  Your message has been successfully submitted and would be delivered to recipients shortly.