Snippet help.

16 views
Skip to first unread message

NCS_One

unread,
Apr 4, 2011, 5:37:49 AM4/4/11
to xptemplate
Hi,

I'm loving XPTemplate.

e.g.
What is the best way to obtain this result?

#<xptemplate_key>
<# | #> cursor at |

Now the hard part, if I press <CR> I would like it to become:

<#
|
#>

With the cusor at | and removing the spaces after the first # and
before the second one.

Thank you very much.

dr-dr xp

unread,
Apr 4, 2011, 8:35:14 AM4/4/11
to xptem...@googlegroups.com
Reference to snippet "_tag" in ftplugins/html/html.xpt.vim . All html tag snippets now behave like what you expect.

This can be done with utilizing 'ontype' event. The snippet should be like this:
XPT #                                                                              
XSET content|ontype=html_cont_ontype()                                             
<#`content^^`content^html_cont_helper()^#>

The above example has to be in html/html.xpt.vim to work because it uses two functions in that file.
If you'd like to create your own snippet file, copy these two functions into your .xpt.vim file and rename them.


--
You received this message because you are subscribed to the Google Groups "xptemplate" group.
To post to this group, send email to xptem...@googlegroups.com.
To unsubscribe from this group, send email to xptemplate+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/xptemplate?hl=en.




--
要了几天饱饭就不记得西北风啥味了

NCS_One

unread,
Apr 4, 2011, 10:03:07 AM4/4/11
to xptemplate
Hi,

Yes I tryed that. But I can't place the spaces between the cursor and
the #, like <# | #> it should have a space after the first # and one
space before the second #.
And the spaces should disapear if <CR> is pressed.

dr-dr xp

unread,
Apr 4, 2011, 10:40:52 AM4/4/11
to xptem...@googlegroups.com
Snippet for html tags can not accomplish such task. Use these 2 modified function:

let s:nIndent = 0                                                                
fun! s:f.html_cont_ontype()                                                      
    let v = self.V()                                                             
    if v =~ '\V\n'                                                               
        let v = self.V0()                                                        
        let v = matchstr( v, '\V\.\*\S\ze\s\*\n' )                               
        let s:nIndent = &indentexpr != ''                                        
              \ ? eval( substitute( &indentexpr, '\Vv:lnum', 'line(".")', '' ) ) - indent( line( "." ) - 1 ) 
              \ : self.NIndent()                                                 
                                                                                 
        return self.Finish( v . "\n" . repeat( ' ', s:nIndent ) )                
    else                                                                         
        return v                                                                 
    endif                                                                        
endfunction                                                                      
                                                                                 
fun! s:f.html_cont_helper()                                                      
    let v = self.V()                                                             
    if v =~ '\V\n'                                                               
        return self.ResetIndent( -s:nIndent, "\n" )                              
    else                                                                         
        return matchstr( v, '\V\^\s\*' )                                         
    endif                                                                       
endfunction



And add a space as "edge" of place holder "content":

XPT #                                                                           
XSET content|ontype=html_cont_ontype()                                          
<#` `content^^`content^html_cont_helper()^#>


With these setup, when you remove the space before cursor, the space after cursor will be removed automatically.

 


--
You received this message because you are subscribed to the Google Groups "xptemplate" group.
To post to this group, send email to xptem...@googlegroups.com.
To unsubscribe from this group, send email to xptemplate+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/xptemplate?hl=en.




--
要了几天饱饭就不记得西北风啥味了

NCS_One

unread,
Apr 4, 2011, 4:05:23 PM4/4/11
to xptemplate
Hi,

It works great.
Only problem is that if you press <CR> without typing something the
space after the first # is not removed.

dr-dr xp

unread,
Apr 5, 2011, 12:29:08 AM4/5/11
to xptem...@googlegroups.com
Well, it's my fault. Replace html_cont_ontype with this:

fun! s:f.html_cont_ontype()                                                     
    let v = self.V()                                                            
    if v =~ '\V\n'                                                              
        let v = matchstr( v, '\V\.\*\S\ze\s\*\n' )                              
        let s:nIndent = &indentexpr != ''                                       
              \ ? eval( substitute( &indentexpr, '\Vv:lnum', 'line(".")', '' ) ) - indent( l<
              \ : self.NIndent()                                                
                                                                                
        return self.FinishOuter( v . "\n" . repeat( ' ', s:nIndent ) )          
    else                                                                        
        return v                                                                
    endif                                                                       
endfunction


--
You received this message because you are subscribed to the Google Groups "xptemplate" group.
To post to this group, send email to xptem...@googlegroups.com.
To unsubscribe from this group, send email to xptemplate+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/xptemplate?hl=en.




--
要了几天饱饭就不记得西北风啥味了

NCS_One

unread,
Apr 5, 2011, 3:49:28 AM4/5/11
to xptemplate
Hi,

Sorry for bothering you again but it seams to be incomplete:

) ) - indent( l<

Tryed to solve it my self but without success. :(

dr-dr xp

unread,
Apr 5, 2011, 3:56:27 AM4/5/11
to xptem...@googlegroups.com
what does this mean?


--
You received this message because you are subscribed to the Google Groups "xptemplate" group.
To post to this group, send email to xptem...@googlegroups.com.
To unsubscribe from this group, send email to xptemplate+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/xptemplate?hl=en.




--
要了几天饱饭就不记得西北风啥味了

NCS_One

unread,
Apr 5, 2011, 4:36:27 AM4/5/11
to xptemplate
Hi,

Is this part:

let s:nIndent = &indentexpr != ''

\ ? eval( substitute( &indentexpr, '\Vv:lnum',
'line(".")', ''
) ) - indent( l<
\ : self.NIndent()

isn't the line:

) ) - indent( l<

incomplete?

dr-dr xp

unread,
Apr 5, 2011, 5:46:54 AM4/5/11
to xptem...@googlegroups.com
This line didn't change.
It must be a problem with my terminal when I copied codes. Sorry. It should be like this:

fun! s:f.html_cont_ontype()                                                        
    let v = self.V()                                                               
    if v =~ '\V\n'                                                                 
        let v = matchstr( v, '\V\.\*\S\ze\s\*\n' )                                 
        let s:nIndent = &indentexpr != ''                                          
              \ ? eval( substitute( &indentexpr, '\Vv:lnum', 'line(".")', '' ) ) - indent( line( "." ) - 1 ) 
              \ : self.NIndent()                                                   
                                                                                   
        return self.FinishOuter( v . "\n" . repeat( ' ', s:nIndent ) )             
    else                                                                           
        return v                                                                   
    endif                                                                          
endfunction

--
You received this message because you are subscribed to the Google Groups "xptemplate" group.
To post to this group, send email to xptem...@googlegroups.com.
To unsubscribe from this group, send email to xptemplate+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/xptemplate?hl=en.




--
要了几天饱饭就不记得西北风啥味了

NCS_One

unread,
Apr 5, 2011, 3:47:41 PM4/5/11
to xptemplate
Works great.

Thanks you very much.t
Reply all
Reply to author
Forward
0 new messages