[Geany] The plugin - Re: Use snippets for HTML autocompletion?

Eugene Arshinov earshinov at xxxxx
Sun Nov 21 13:59:28 UTC 2010


On Wed, 17 Nov 2010 14:48:49 +0000%
Nick Treleaven <nick.treleaven at btinternet.com> wrote:

> On Tue, 16 Nov 2010 19:06:59 +0300
> Eugene Arshinov <earshinov at gmail.com> wrote:
> 
> > > > > In [HTML] section I have a snippet
> > > > > 
> > > > >   lia=<li><a href="%cursor%">%cursor%</a></li>
> > > > > 
> > > > > It begins with a tag, so the plugin will insert it after I
> > > > > type <lia> (it will result in <lia><li><a ...>...</a></li>
> > > > > which isn't useful).
> > > > 
> > > > Why would <lia> be kept? That should be removed, otherwise
> > > > <table> would result in <table><table>...</table>
> > > 
> > > Yes, removing the tag is a good idea, especially if we account
> > > that it's how "ordinary" snippets work now.  I had an idea that
> > > for snippets for the plugin snippet body should contain only the
> > > part that's inserted (i.e., shouldn't contain the first open tag)
> > > because it easily allows to save attributes user may have
> > > specified in the open tag that gets autocompleted.  If we remove
> > > this tag, we'll have to copy the attributes to the first tag
> > > within snippet body, but I think it's easy to implement.
> 
> I would implement it to not autocomplete tags with attributes, only
> match '<' + snippet_name + '>'. The user could add any attributes
> after snippet insertion. 
> 

Yes, but moving cursor back and forth for that, I think, would be too
annoying.  User can insert %cursor% when he might want to insert
attributes, but I think it isn't convenient too.  Moreover, this will
be a regression against the HTML table template which was built-in
previously (of course, a minor regression, but still).

For me as a user an acceptable solution would be copy "input
attributes" to the first tag of snippet body (we already search for the
first tag, by the way), if the latter does not already contain
attributes (which will be true most of the time).  And
implementing copying appeared not so hard for me, so I
implemented it.  The code got larger than I expected, but I still
thing it is normal for the benefit it gives.

I need to copy attributes before editor.c:snippets_make_replacements
runs to get correct cursor positions, so I have to escape the
attributes string.  But, in order the string got "unescaped" properly,
I had to fix the bug with {ob} and {cb} templates.  This is the first
patch.

The previous version of the patch incorrectly left the typed tag
intact.  To remove it I had to get open_xml_tag_pos instead of
open_xml_tag.  I added the corresponding function and exported it.
This is the second patch.

If you have some free time, please review and commit.  (I start to
think geany-devel would be the proper place for this discussion :-))

BTW, here is the current code of the plugin:
<http://nopaste.geany.org/p/m5d408564>.  It looks a bit scary because
of not-so-useful structs, but it's the way I chose to group pointers
by what they point to (input or snippet), otherwise I got confused
quickly.  My little C experience suggests me nothing less ugly.

Best regards,
Eugene.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: geany.28.snippets_make_replacements_fix.r5419.patch
Type: text/x-patch
Size: 7503 bytes
Desc: not available
URL: <http://lists.geany.org/pipermail/users/attachments/20101121/913a425d/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: geany.29.utils_find_open_xml_tag_pos.r5419.patch
Type: text/x-patch
Size: 5086 bytes
Desc: not available
URL: <http://lists.geany.org/pipermail/users/attachments/20101121/913a425d/attachment-0001.bin>


More information about the Users mailing list