davidmiller / pony-mode

Django mode for emacs
Other
149 stars 32 forks source link

Django tags should be indentable #9

Closed zerko closed 12 years ago

zerko commented 13 years ago

Will be nice to have indentation of django tags in PonyTpl mode.

davidmiller commented 13 years ago

Agreed - Assuming the desired behaviour is that when we have the block:

{% block indentaware %}
indent me please
{% endblock %}

and the contents indented ?

zerko commented 13 years ago

Yes, basically indent content of every {% name %} {% endname %} blocks. Thank you for great mode, keep it up.

oleiade commented 12 years ago

Hey, i'm digging this issue a little bit : really need this feature, any progress on this?

as @zerko said, really thank you for this mode :-)

davidmiller commented 12 years ago

What's required as a new indent-line function that takes into account Django Tags.

Something like (#Unclosed-Django-template-tags-before-point * indent-width)+ sgml-mode-indent-line

And then you set indent-line-function in the minor-mode-init function.

I tried a "Let's throw regex at the problem" solution which made things sluggish with large files, at which point you either tune the regexps or just write a parser & be done with it. I basically didn't make a decision yet...

Will take another look though

On 24 October 2011 11:54, Tho Crevon < reply@reply.github.com>wrote:

Hey, i'm digging this issue a little bit : really need this feature, any progress on this?

as @zerko said, really thank you for this mode :-)

Reply to this email directly or view it on GitHub: https://github.com/davidmiller/pony-mode/issues/9#issuecomment-2502055

Love regards etc

David Miller http://www.deadpansincerity.com 07854 880 883

gkmngrgn commented 12 years ago

does it work? i could not run it. can you share a simple settings for django tag indentation?

davidmiller commented 12 years ago

Only for particularly obtuse interpretations of "work" :)

Not looked at this for a few months, but thanks for the reminder - I use the Django templating language so rarely that it just never comes up as an itch to scratch...

I'll try and make some time to work on this again though

code4ghana commented 12 years ago

Great job david!

Could you please get the indentations to work, it would be greatly appreciated ? Also in django tags I think font-locking should be present even if more than one space is present between the "%" and the first word.

Currently: in the tag {% endblock content %} endblock will be appropriately highlighted. However in {% endblock content %} endblock will not be hgihlighted due to multiple spaces between % and endblock It appears that this is only present in block tags

Thanks.

davidmiller commented 12 years ago

The indentation branch has a working (for me with relatively limited testcases) version of indentation for {% block %} and {% for %}

Pending extra bugs, what remains is to add support for the remaining indentable tags and optimize the regexps.

Planned support for:

block for if/elif/else/endif ifchanged ifequal ifnotequal

Using current heuristics performance is O(N) but should be reasonable as long as the regex can be kept sane.

If people genuinely complain about time to indent in their 12MB template files we can deal with that later.

davidmiller commented 12 years ago

Having merged a new indentation implementation borrowed from the seemingly excellent https://github.com/paradoxxxzero/jinja2-mode

Pony mode's template mode now comes complete with working indentation for template tags.

Apologies that this has taken so long :s

If anyone finds bugs with this implementation, please add to the file https://github.com/davidmiller/pony-mode/blob/master/tests/resources/indentation.html

which contains the cases I am currently using to test the implementation and I will be happy to merge and make sure that they work.

davidmiller commented 12 years ago

P.S. pulling the latest master is the best way to get this right now...