HTML, auto-complete and snippets (was Re: [TextMate] (no subject))

marc mnothrop at elaunceston.com
Wed Oct 6 16:54:14 UTC 2004


On 07/10/2004, at 2:09 AM, Justin French wrote:

> On 07/10/2004, at 12:01 AM, mnothrop wrote:
>
>> I'm afraid I find the auto-complete somewhat underwhelming; it seems 
>> pretty basic, and (I think) belies it's simple pattern-matching basis 
>> -- it doesn't display any knowledge of syntax (e.g. will suggest 
>> 'body' in the context of a div tag, instead of 'border'), and is 
>> strict in it's matching (will match 'cellS...' for cellSpacing, but 
>> not 'cells...' -- oh, and hitting Escape each time isn't the most 
>> ergonomic aspect of editing.
>
> It's actually not auto-complete in the sense that it's not trying to 
> guess what you want based on context (yet)... it's simply guessing 
> what you want to type based on what you've already typed elsewhere in 
> the document.  It suggested "body" because it appeared further up the 
> page.  It possibly would have suggested border as a second option if 
> you'd typed border elsewhere.

OK, that's interesting; I read that in the help, but not while I was 
editing, it makes sense in that context, and I can see it's value for 
variables/classes, and to a lesser extent, HTML tags. The main 
drawback, IMHO, being the awkward Esc key -- while Tab seems suitable 
for snippet triggers (has the appropriate 'issuing a command' feel!) I 
tend to find the selecting completions from a code-hint menu, via Space 
to be a far more comfortable, and efficient, after all Space functions 
to 'finish this word and move on'.

> Personally, I don't mind hitting escape a few times to find what I 
> want.

I'll try it, maybe it'll work! I can see your points about customising 
it to fit... I guess I'm training my editor.  : )

> Instead of auto-complete, I've become fond of the "Make HTML Tag 2" 
> Macro, which takes the current word (eg div) and makes it into a tag.

Yeah, but I'm favouring snippets with tab stops, I like to be able to 
jump to specific points in the tags, for attribute values etc. like 
I've been pleading for... hmmm, maybe I'm starting to grok this whole 
'fits like a glove' thing...

>> ...but of course, at the moment, you've got to do the heavy lifting! 
>> It would take some time to enter a useful set of snippets, but I've 
>> started... If anyone else has, we must share!
>
> I shared everything I could come up in the few hours left before 1.0 
> was released (most of the snippet menu)... I expect that most people 
> will delete my defaults and start creating their own, which work the 
> way they want to work... after all, that's what TM does :)

Well, thanks for that, to start with!

Ah, I'm just whining about it all not just 'being there'! I am getting 
a feel for the app, in adding the snippets that I want... and yes it is 
cool to be able to specify exactly how your syntax should work.

>> I own skEdit, and really like it's auto-complete feature, which you 
>> might consider more traditional, in that it's implemented similarly 
>> to other apps (e.g. Dreamweaver, HomeSite); it suggests the likely 
>> tag *as* you type, with a drop down menu that is likewise filtered in 
>> real-time.
>
> I hate those things, but I think something like this is planned for 
> later on.

I know, they seem to be love-or-hate features... but thinking broadly 
about these features, keyboard-triggered snippets are *extremely* close 
in concept, so I'm interested in how you use these features for HTML.

>> In comparing the features you quickly see that skEdit's approach 
>> augment's the user's knowledge and memory of syntax (either 
>> reminding/reinforcing, or teaching), whereas TM requires a mental 
>> mapping of not only specifics of syntax, but an additional aspect, in 
>> the triggers. It may just be my perspective on this feature (i.e. 
>> largely reliably, and strict syntax of HTML, vs. highly variable, 
>> creative arrangements of syntax in programming languages,) but I 
>> don't find this approach as convenient for X/HTML editing.
>
> I think the point is that you re-shape TM to suit what you want... 
> it's the perfect (and better) mental model to "become one" with your 
> editor.  Write a snippet you need, attach it to a trigger that seems 
> natural to YOU, and smile :)

Hmmm, OK, now I've made a few macros... yes, I'm getting it 
more-and-more! : )

skEdit also has Snippets, but they function differently; they are 
triggered by menu or key command, but crucially, they *optionally* 
operate on selected text; they are intended to augment the default 
always-on auto-complete, when working with existing text, or non-tag 
text formatting.

The selection, and the cursor are 'variables' in the Snippet, al a Tab 
Stops in TM -- If there is no selection, they simply insert the 
contents of the Snippet, but without TM's tab stops. One possible issue 
with TM Macros are ones not prepared for a null selection (e.g. 
Selection to Link), while it's great that distinguishes between web and 
mail links, if there is no selection it appear to operate on the full 
document.

I quickly recorded a Macro to apply <strong>, by using Select Word, 
which is great, in that it can be applied to any *word* the insertion 
point is touching, and happily a selection is not over-ridden, so you 
get both options. OK, that's good! : )

But it would be wicked to combine some of the benefits of Macros and 
Snippets, so that I can apply a Macro to a selection (or not!) and also 
get tab stops. Of course there are come complex things that can be done 
with Macros, but this basic formatting function could be very 
effective.

>> Having said that, once I had a full compliment of HTML snippets, 
>> defining my coding standards (e.g. always include certain attributes, 
>> like class, id etc.), I could see it feeling more efficient... I 
>> guess the problem becomes finding the balances between these two 
>> different approaches, but the way I envisage it, my snippent menu 
>> will go on for ever!
>
> Exactly -- and it will be YOURS, to suit the way YOU work :)

Yes, except it will be annoying! ; )

Perhaps if I were able to group items in the Snippet and Macro menus 
that might help, but they're already one level down in the menu...

I tend to find the Macro and Snippet menus a little bit awkward being 
buried one level down (more so because the Macro menu jumps to the 
left, because it is long.) It seems that these are the two areas that 
will focus a lot of extension effort, and while it's logical to have 
them under automate, maybe there could be some thoughts on how they 
might be made a little more accessible...?

Anyway, TM is an interesting beast, and I'm only scratching the surface.


marc




More information about the textmate mailing list