wiki:PadrePluginSnippet

Version 14 (modified by bowtie, 3 years ago) (diff)

--

Padre::Plugin::Snippet - Draft

This is used to document the finding about the Padre::Plugin::Snippets plugin and the TextMate/snipMate integration that I have been planning with bowtie (Kevin) and implementing at the moment in Padre::Plugin::Moose. We will eventually migrate this feature into this plugin once it is mature.

Notes

  • Snippet mode can be entered through <trigger><TAB>
  • <trigger> should be matched on a word boundary that ends with the current position
  • Shift-TAB traverses all variables (circular is a useful snipMate feature). Does not break snippet mode.
  • Movement keys and deletion: Up/down/right/left/page up/page down/home/end/delete automatically exit snippet mode
  • Cancel current selection when exiting snippet mode

Workflow

  • Snippet mode OFF:
    • $line = the current line text preceding the cursor
    • Find $trigger for $line and the current active snippet bundle or exit
    • Find the snippet associated with trigger or exit
    • Find all variables in snippet of the form:
      ${index:default_value},${index} or $index
      e.g. $1, ${1:...}, ${1}
    • $cursor = the first variable that has the index of 1
    • Insert snippet
    • Select $cursor in snippet and position the cursor at the end of it.

  • Snippet mode ON:

Sample snippet file

---
#
# Moose snippets bundle for Padre::Plugin::Moose
# Written by Ahmad M. Zawawi (azawawi)
#
# Adapted from 'TextMate Bundle for Moose' by Chris Prather (perigrin)
# https://github.com/perigrin/perl-moose.tmbundle/Snippets
# 

# after method modifier
after: |
  after '${1:method_name}' => sub {
      ${2:# body...}
  }; 

# before method modifier
before: |
  before '${1:method_name}' => sub {
      ${2:# body...}
  }; 

# Property
has: has '${1:property}' => ( is => '${2:rw}', isa  => '${3:Str}', );

TODO

  • Support extended syntax ${index:default_value:list_of_values}
  • Convert snipMate snippets
  • Add mojo snippets to the mix
  • Support a way to set the current subscope
  • Provide a default child document for Perl

Resources


__END__

Attachments (2)

Download all attachments as: .zip