From 3d0262d67fdfd6454a2fa570a4d90af8ff73f694 Mon Sep 17 00:00:00 2001 From: capitaomorte Date: Tue, 17 Nov 2009 17:34:55 +0000 Subject: [PATCH] * textmate_import imports macros just like commands (no body) * imported the Rails macros, no adjustments * logic in rails-mode/.yas-setup.el supports the "intelligent" migration snippet --- extras/imported/rails-mode/.yas-setup.el | 46 +++++++++++++++++++ .../rails-mode/Drop 3A Create Table.yasnippet | 7 +++ .../Indexes/Add 3A Remove Index.yasnippet | 7 +++ .../Add 3A Remove Named Index.yasnippet | 7 +++ .../Add 3A Remove Unique Index.yasnippet | 7 +++ .../rails-mode/Remove 3A Add Column.yasnippet | 7 +++ extras/textmate_import.rb | 2 +- 7 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 extras/imported/rails-mode/Drop 3A Create Table.yasnippet create mode 100644 extras/imported/rails-mode/Indexes/Add 3A Remove Index.yasnippet create mode 100644 extras/imported/rails-mode/Indexes/Add 3A Remove Named Index.yasnippet create mode 100644 extras/imported/rails-mode/Indexes/Add 3A Remove Unique Index.yasnippet create mode 100644 extras/imported/rails-mode/Remove 3A Add Column.yasnippet diff --git a/extras/imported/rails-mode/.yas-setup.el b/extras/imported/rails-mode/.yas-setup.el index 70869c5..a2f6dd8 100644 --- a/extras/imported/rails-mode/.yas-setup.el +++ b/extras/imported/rails-mode/.yas-setup.el @@ -48,4 +48,50 @@ (and (yas/rails-root) (string-match "db/migrate/" default-directory))) +(defvar yas/rails-intelligent-migration-snippet-bits + '((:rename_column . ((:up . "rename_column :${1:table_name}, :${2:column_name}, :${3:new_column_name}$0") + (:down . "rename_column :$1, :$3, :$2" ))) + (:rename_column_continue . ((:up . "rename_column :${1:table_name}, :${2:column_name}, :${3:new_column_name}\nmncc$0") + (:down . "rename_column :$1, :$3, :$2" ))) + + (:rename_table . ((:up . "rename_table :${1:old_table_name}, :${2:new_table_name}$0") + (:down . "rename_table :$2, :$1" ))) + + (:rename_table_continue . ((:up . "rename_table :${1:old_table_name}, :${2:new_table_name}\nmntc$0") + (:down . "rename_table :$2, :$1" ))) + + (:add_remove_column . ((:up . "add_column :${1:table_name}, :${2:column_name}, :${3:string}$0") + (:down . "remove_column :$1, :$2" ))) + + (:add_remove_column_continue . ((:up . "add_column :${1:table_name}, :${2:column_name}, :${3:string}\nmarcc$0") + (:down . "remove_column :$1, :$2" ))) + + (:create_drop_table . ((:up . "create_table :${1:table_name}, :force . true do |t|\nt.$0\nt.timestamps\nend") + (:down . "drop_table :$1" ))) + + (:change_change_table . ((:up . "change_table :${1:table_name} do |t|\nt.$0\nend") + (:down . "change_table :$1 do |t|\nend" ))) + + (:add_remove_index . ((:up . "add_index :${1:table_name}, :${2:column_name}$0") + (:down . "remove_index :$1, :$2" ))) + + (:add_remove_unique_index . ((:up . "add_index :${1:table_name}, ${2:[:${3:column_name}${4:, :${5:column_name}}]}, :unique . true$0") + (:down . "remove_index :$1, :column . $2" ))) + + (:add_remove_named_index . ((:up . "add_index :${1:table_name}, [:${2:column_name}${3:, :${4:column_name}}], :name . \"${5:index_name}\"${6:, :unique . true}$0") + (:down . "remove_index :$1, :name . :$5" ))))) + + +(defun yas/rails-intelligent-migration-snippet (type) + (let* ((start (point)) + (end (save-excursion + (search-forward-regexp "^\s*def\sself\.down" nil 'noerror))) + (up (aget (aget yas/rails-intelligent-migration-snippet-bits type) :up)) + (down (aget (aget yas/rails-intelligent-migration-snippet-bits type) :down)) + (snippet + (and up down start end (concat up + (buffer-substring-no-properties start end) + "\n" down)))) + (delete-region start end) + (yas/expand-snippet snippet))) diff --git a/extras/imported/rails-mode/Drop 3A Create Table.yasnippet b/extras/imported/rails-mode/Drop 3A Create Table.yasnippet new file mode 100644 index 0000000..fc83a5f --- /dev/null +++ b/extras/imported/rails-mode/Drop 3A Create Table.yasnippet @@ -0,0 +1,7 @@ +# -*- mode: snippet -*- +# type: command +# key: [press tab twice to generate create_table] +# contributor: Translated from TextMate Snippet +# name: Drop / Create Table (Second Half) +## condition: "meta.rails.migration - meta.rails.migration.create_table - meta.rails.migration.change_table" +# -- diff --git a/extras/imported/rails-mode/Indexes/Add 3A Remove Index.yasnippet b/extras/imported/rails-mode/Indexes/Add 3A Remove Index.yasnippet new file mode 100644 index 0000000..b1fd014 --- /dev/null +++ b/extras/imported/rails-mode/Indexes/Add 3A Remove Index.yasnippet @@ -0,0 +1,7 @@ +# -*- mode: snippet -*- +# type: command +# key: mind +# contributor: Translated from TextMate Snippet +# name: Add / Remove Index +## condition: "meta.rails.migration - meta.rails.migration.create_table - meta.rails.migration.change_table" +# -- diff --git a/extras/imported/rails-mode/Indexes/Add 3A Remove Named Index.yasnippet b/extras/imported/rails-mode/Indexes/Add 3A Remove Named Index.yasnippet new file mode 100644 index 0000000..ea6ae53 --- /dev/null +++ b/extras/imported/rails-mode/Indexes/Add 3A Remove Named Index.yasnippet @@ -0,0 +1,7 @@ +# -*- mode: snippet -*- +# type: command +# key: mind +# contributor: Translated from TextMate Snippet +# name: Add / Remove Named Index +## condition: "meta.rails.migration - meta.rails.migration.create_table - meta.rails.migration.change_table" +# -- diff --git a/extras/imported/rails-mode/Indexes/Add 3A Remove Unique Index.yasnippet b/extras/imported/rails-mode/Indexes/Add 3A Remove Unique Index.yasnippet new file mode 100644 index 0000000..a7b067b --- /dev/null +++ b/extras/imported/rails-mode/Indexes/Add 3A Remove Unique Index.yasnippet @@ -0,0 +1,7 @@ +# -*- mode: snippet -*- +# type: command +# key: mind +# contributor: Translated from TextMate Snippet +# name: Add / Remove Unique Index +## condition: "meta.rails.migration - meta.rails.migration.create_table - meta.rails.migration.change_table" +# -- diff --git a/extras/imported/rails-mode/Remove 3A Add Column.yasnippet b/extras/imported/rails-mode/Remove 3A Add Column.yasnippet new file mode 100644 index 0000000..a2701ab --- /dev/null +++ b/extras/imported/rails-mode/Remove 3A Add Column.yasnippet @@ -0,0 +1,7 @@ +# -*- mode: snippet -*- +# type: command +# key: [press tab twice to generate add_column] +# contributor: Translated from TextMate Snippet +# name: Remove / Add Column (Second Half) +## condition: "meta.rails.migration - meta.rails.migration.create_table - meta.rails.migration.change_table" +# -- diff --git a/extras/textmate_import.rb b/extras/textmate_import.rb index b2a0515..d5438e0 100755 --- a/extras/textmate_import.rb +++ b/extras/textmate_import.rb @@ -49,7 +49,7 @@ Choice.options do short '-f' long '--file=SNIPPET FILE NAME' desc 'A specific snippet that you want to copy or a glob for various files' - default '*.{tmSnippet,plist}' + default '*.{tmSnippet,plist,tmMacro}' end option :print_pretty do