diff --git a/extras/imported/rails-mode/.yas-setup.el b/extras/imported/rails-mode/.yas-setup.el index a2f6dd8..74eac2a 100644 --- a/extras/imported/rails-mode/.yas-setup.el +++ b/extras/imported/rails-mode/.yas-setup.el @@ -1,8 +1,8 @@ (defvar yas/rails-root-cache nil) (make-local-variable 'yas/rails-root-cache) -;; copied from rinari-mode's rinari-root -(defun yas/rails-root (&optional dir home) +;; stolen from rinari-mode's rinari-root +(defun yas/rails-root (&optional dir) (or yas/rails-root-cache (or dir (setq dir default-directory)) (if (file-exists-p (expand-file-name @@ -13,7 +13,7 @@ (unless (string-match "\\(^[[:alpha:]]:/$\\|^/[^\/]+:\\|^/$\\)" dir) (rinari-root new-dir)))))) -;; copied from rinari-mode's rinari-extract-partial +;; stolen from rinari-mode's rinari-extract-partial (defun yas/rails-extract-partial (begin end partial-name) (interactive "r\nsName your partial: ") (let* ((path (buffer-file-name)) ending) @@ -31,23 +31,9 @@ (yank) (pop-to-buffer nil) (insert (concat "<%= render :partial => '" partial-name "' %>\n"))) (message "not in a view")))) - -(defun yas/rails-model-p () - (and (yas/rails-root) - (string-match "app/models/$" default-directory))) - -(defun yas/rails-view-p () - (and (yas/rails-root) - (string-match "app/views/" default-directory))) - -(defun yas/rails-controller-p () - (and (yas/rails-root) - (string-match "app/controllers/$" default-directory))) - -(defun yas/rails-migration-p () - (and (yas/rails-root) - (string-match "db/migrate/" default-directory))) - +;;; +;;; The TextMate "intelligent" migration snippet +;; (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" ))) @@ -63,9 +49,12 @@ (: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" ))) + + (:remove_add_column . ((:up . "remove_column :${1:table_name}, :${2:column_name}$0") + (:down . "add_column :$1, :$2, :$3{string}" ))) (:create_drop_table . ((:up . "create_table :${1:table_name}, :force . true do |t|\nt.$0\nt.timestamps\nend") (:down . "drop_table :$1" ))) @@ -93,5 +82,63 @@ (and up down start end (concat up (buffer-substring-no-properties start end) "\n" down)))) - (delete-region start end) - (yas/expand-snippet snippet))) + (when snippet + (delete-region start end) + (yas/expand-snippet snippet)))) + +(yas/define-condition-cache + yas/rails-intelligent-migration-snippet-condition-p + "Non-nil if an \"intelligent\" migration snippet should be expanded" + (and (yas/rails-migration-p) + (not (yas/rails-in-create-table-p)) + (not (yas/rails-in-change-table-p)) + (yas/rails-in-ruby-block-like "self\.up"))) + +(defun yas/rails-in-ruby-block-like (regexp) + (save-excursion + (ruby-accurate-end-of-block) + (ruby-backward-sexp) + (search-forward-regexp regexp (line-end-position) t))) + +;;; conditions +(yas/define-condition-cache + yas/rails-in-create-table-p + "Non-nil if point is inside a 'create_table' method call." + (yas/rails-in-ruby-block-like "create_table")) + +(yas/define-condition-cache + yas/rails-in-change-table-p + "Non-nil if point is inside a 'change_table' method call." + (yas/rails-in-ruby-block-like "change_table")) + +(yas/define-condition-cache + yas/rails-model-p + "Non-nil if the current buffer is a rails model." + (and (yas/rails-root) + (string-match "app/models/$" default-directory))) + +(yas/define-condition-cache + yas/rails-view-p + "Non-nil if the current buffer is a rails view." + (and (yas/rails-root) + (string-match "app/views/" default-directory))) + +(yas/define-condition-cache + yas/rails-controller-p +"Non-nil if the current buffer is a rails controller." + (and (yas/rails-root) + (string-match "app/controllers/$" default-directory))) + +(yas/define-condition-cache + yas/rails-migration-p + "Non-nil if the current buffer is a rails migration." + (and (yas/rails-root) + (string-match "db/migrate/" default-directory))) + + +(defadvice cd (after yas/rails-on-cd-activate) + "Active/Deactive rinari-merb-minor-node when changing into and out +of raills project directories." + (setq yas/rails-root-cache nil) + (when (yas/rails-root) + (setq (make-local-variable 'yas/mode-symbol) 'rails-mode))) diff --git a/extras/imported/rails-mode/Change columns t. drop-down list/t_rename (tre).yasnippet b/extras/imported/rails-mode/Change columns t. drop-down list/t_rename (tre).yasnippet index de47ad1..09302e3 100644 --- a/extras/imported/rails-mode/Change columns t. drop-down list/t_rename (tre).yasnippet +++ b/extras/imported/rails-mode/Change columns t. drop-down list/t_rename (tre).yasnippet @@ -2,7 +2,7 @@ # key: t. # contributor: Translated from TextMate Snippet # name: t.rename (tre) -## condition: "meta.rails.migration.create_table, meta.rails.migration.change_table" +# condition: (and (yas/rails-migration-p) (yas/rails-in-create-table)) # -- t.rename(:${1:old_column_name}, :${2:new_column_name}) t.$0 \ No newline at end of file diff --git a/extras/imported/rails-mode/Columns/Migration Remove and Add Column (mrac).yasnippet b/extras/imported/rails-mode/Columns/Migration Remove and Add Column (mrac).yasnippet index 1247b66..9921f43 100644 --- a/extras/imported/rails-mode/Columns/Migration Remove and Add Column (mrac).yasnippet +++ b/extras/imported/rails-mode/Columns/Migration Remove and Add Column (mrac).yasnippet @@ -2,6 +2,6 @@ # key: mcol # contributor: Translated from TextMate Snippet # name: Remove / Add Column -## condition: "meta.rails.migration - meta.rails.migration.create_table - meta.rails.migration.change_table" +# condition: (yas/rails-intelligent-migration-snippet-condition-p) # -- -remove_column :${1:table}, :${2:column}${3: [press tab twice to generate add_column]} \ No newline at end of file +(yas/rails-intelligent-migration-snippet :remove_add_column) diff --git a/extras/imported/rails-mode/Create columns t. drop-down list/t_binary (tcbi).yasnippet b/extras/imported/rails-mode/Create columns t. drop-down list/t_binary (tcbi).yasnippet index dfe5f4f..e211035 100644 --- a/extras/imported/rails-mode/Create columns t. drop-down list/t_binary (tcbi).yasnippet +++ b/extras/imported/rails-mode/Create columns t. drop-down list/t_binary (tcbi).yasnippet @@ -2,7 +2,7 @@ # key: t. # contributor: Translated from TextMate Snippet # name: t.binary (tcbi) -## condition: "meta.rails.migration.create_table, meta.rails.migration.change_table" +# condition: (and (yas/rails-migration-p) (yas/rails-in-create-table-p)) # -- t.binary :${1:title}${2:, :limit => ${3:2}.megabytes} t.$0 \ No newline at end of file diff --git a/extras/imported/rails-mode/Create columns t. drop-down list/t_boolean (tcb).yasnippet b/extras/imported/rails-mode/Create columns t. drop-down list/t_boolean (tcb).yasnippet index 16c8489..4e8d9e4 100644 --- a/extras/imported/rails-mode/Create columns t. drop-down list/t_boolean (tcb).yasnippet +++ b/extras/imported/rails-mode/Create columns t. drop-down list/t_boolean (tcb).yasnippet @@ -2,7 +2,7 @@ # key: t. # contributor: Translated from TextMate Snippet # name: t.boolean (tcb) -## condition: "meta.rails.migration.create_table, meta.rails.migration.change_table" +# condition: (and (yas/rails-migration-p) (yas/rails-in-create-table-p)) # -- t.boolean :${1:title} t.$0 \ No newline at end of file diff --git a/extras/imported/rails-mode/Create columns t. drop-down list/t_date (tcda).yasnippet b/extras/imported/rails-mode/Create columns t. drop-down list/t_date (tcda).yasnippet index d9973ba..b6cf82b 100644 --- a/extras/imported/rails-mode/Create columns t. drop-down list/t_date (tcda).yasnippet +++ b/extras/imported/rails-mode/Create columns t. drop-down list/t_date (tcda).yasnippet @@ -2,7 +2,7 @@ # key: t. # contributor: Translated from TextMate Snippet # name: t.date (tcda) -## condition: "meta.rails.migration.create_table, meta.rails.migration.change_table" +# condition: (and (yas/rails-migration-p) (yas/rails-in-create-table-p)) # -- t.date :${1:title} t.$0 \ No newline at end of file diff --git a/extras/imported/rails-mode/Create columns t. drop-down list/t_datetime (tcdt).yasnippet b/extras/imported/rails-mode/Create columns t. drop-down list/t_datetime (tcdt).yasnippet index f7b5050..635b1ef 100644 --- a/extras/imported/rails-mode/Create columns t. drop-down list/t_datetime (tcdt).yasnippet +++ b/extras/imported/rails-mode/Create columns t. drop-down list/t_datetime (tcdt).yasnippet @@ -2,7 +2,7 @@ # key: t. # contributor: Translated from TextMate Snippet # name: t.datetime (tcdt) -## condition: "meta.rails.migration.create_table, meta.rails.migration.change_table" +# condition: (and (yas/rails-migration-p) (yas/rails-in-create-table-p)) # -- t.datetime :${1:title} t.$0 \ No newline at end of file diff --git a/extras/imported/rails-mode/Create columns t. drop-down list/t_decimal (tcd).yasnippet b/extras/imported/rails-mode/Create columns t. drop-down list/t_decimal (tcd).yasnippet index a60fa6e..99ef8e6 100644 --- a/extras/imported/rails-mode/Create columns t. drop-down list/t_decimal (tcd).yasnippet +++ b/extras/imported/rails-mode/Create columns t. drop-down list/t_decimal (tcd).yasnippet @@ -2,7 +2,7 @@ # key: t. # contributor: Translated from TextMate Snippet # name: t.decimal (tcd) -## condition: "meta.rails.migration.create_table, meta.rails.migration.change_table" +# condition: (and (yas/rails-migration-p) (yas/rails-in-create-table-p)) # -- t.decimal :${1:title}${2:${3:, :precision => ${4:10}}${5:, :scale => ${6:2}}} t.$0 \ No newline at end of file diff --git a/extras/imported/rails-mode/Create columns t. drop-down list/t_float (tcf).yasnippet b/extras/imported/rails-mode/Create columns t. drop-down list/t_float (tcf).yasnippet index 982ad40..010deae 100644 --- a/extras/imported/rails-mode/Create columns t. drop-down list/t_float (tcf).yasnippet +++ b/extras/imported/rails-mode/Create columns t. drop-down list/t_float (tcf).yasnippet @@ -2,7 +2,7 @@ # key: t. # contributor: Translated from TextMate Snippet # name: t.float (tcf) -## condition: "meta.rails.migration.create_table, meta.rails.migration.change_table" +# condition: (and (yas/rails-migration-p) (yas/rails-in-create-table-p)) # -- t.float :${1:title} t.$0 \ No newline at end of file diff --git a/extras/imported/rails-mode/Create columns t. drop-down list/t_integer (tci).yasnippet b/extras/imported/rails-mode/Create columns t. drop-down list/t_integer (tci).yasnippet index 2005a67..068520f 100644 --- a/extras/imported/rails-mode/Create columns t. drop-down list/t_integer (tci).yasnippet +++ b/extras/imported/rails-mode/Create columns t. drop-down list/t_integer (tci).yasnippet @@ -2,7 +2,7 @@ # key: t. # contributor: Translated from TextMate Snippet # name: t.integer (tci) -## condition: "meta.rails.migration.create_table, meta.rails.migration.change_table" +# condition: (and (yas/rails-migration-p) (yas/rails-in-create-table-p)) # -- t.integer :${1:title} t.$0 \ No newline at end of file diff --git a/extras/imported/rails-mode/Create columns t. drop-down list/t_lock_version (tcl).yasnippet b/extras/imported/rails-mode/Create columns t. drop-down list/t_lock_version (tcl).yasnippet index 4aab54f..a393bfd 100644 --- a/extras/imported/rails-mode/Create columns t. drop-down list/t_lock_version (tcl).yasnippet +++ b/extras/imported/rails-mode/Create columns t. drop-down list/t_lock_version (tcl).yasnippet @@ -2,7 +2,7 @@ # key: t. # contributor: Translated from TextMate Snippet # name: t.lock_version (tcl) -## condition: "meta.rails.migration.create_table, meta.rails.migration.change_table" +# condition: (and (yas/rails-migration-p) (yas/rails-in-create-table-p)) # -- t.integer :lock_version, :null => false, :default => 0 t.$0 \ No newline at end of file diff --git a/extras/imported/rails-mode/Create columns t. drop-down list/t_references (tcr).yasnippet b/extras/imported/rails-mode/Create columns t. drop-down list/t_references (tcr).yasnippet index 2cfbb86..167b291 100644 --- a/extras/imported/rails-mode/Create columns t. drop-down list/t_references (tcr).yasnippet +++ b/extras/imported/rails-mode/Create columns t. drop-down list/t_references (tcr).yasnippet @@ -2,7 +2,7 @@ # key: t. # contributor: Translated from TextMate Snippet # name: t.references (tcr) -## condition: "meta.rails.migration.create_table, meta.rails.migration.change_table" +# condition: (and (yas/rails-migration-p) (yas/rails-in-create-table-p)) # -- t.references :${1:taggable}${2:, :polymorphic => ${3:{ :default => '${4:Photo}' \}}} t.$0 \ No newline at end of file diff --git a/extras/imported/rails-mode/Create columns t. drop-down list/t_string (tcs).yasnippet b/extras/imported/rails-mode/Create columns t. drop-down list/t_string (tcs).yasnippet index ad7d197..196f5f9 100644 --- a/extras/imported/rails-mode/Create columns t. drop-down list/t_string (tcs).yasnippet +++ b/extras/imported/rails-mode/Create columns t. drop-down list/t_string (tcs).yasnippet @@ -2,7 +2,7 @@ # key: t. # contributor: Translated from TextMate Snippet # name: t.string (tcs) -## condition: "meta.rails.migration.create_table, meta.rails.migration.change_table" +# condition: (and (yas/rails-migration-p) (yas/rails-in-create-table-p)) # -- t.string :${1:title} t.$0 \ No newline at end of file diff --git a/extras/imported/rails-mode/Create columns t. drop-down list/t_text (tct).yasnippet b/extras/imported/rails-mode/Create columns t. drop-down list/t_text (tct).yasnippet index f8a5237..c9b75f4 100644 --- a/extras/imported/rails-mode/Create columns t. drop-down list/t_text (tct).yasnippet +++ b/extras/imported/rails-mode/Create columns t. drop-down list/t_text (tct).yasnippet @@ -2,7 +2,7 @@ # key: t. # contributor: Translated from TextMate Snippet # name: t.text (tct) -## condition: "meta.rails.migration.create_table, meta.rails.migration.change_table" +# condition: (and (yas/rails-migration-p) (yas/rails-in-create-table-p)) # -- t.text :${1:title} t.$0 \ No newline at end of file diff --git a/extras/imported/rails-mode/Create columns t. drop-down list/t_time (tcti).yasnippet b/extras/imported/rails-mode/Create columns t. drop-down list/t_time (tcti).yasnippet index 9c76322..acf4aaa 100644 --- a/extras/imported/rails-mode/Create columns t. drop-down list/t_time (tcti).yasnippet +++ b/extras/imported/rails-mode/Create columns t. drop-down list/t_time (tcti).yasnippet @@ -2,7 +2,7 @@ # key: t. # contributor: Translated from TextMate Snippet # name: t.time (tcti) -## condition: "meta.rails.migration.create_table, meta.rails.migration.change_table" +# condition: (and (yas/rails-migration-p) (yas/rails-in-create-table-p)) # -- t.time :${1:title} t.$0 \ No newline at end of file diff --git a/extras/imported/rails-mode/Create columns t. drop-down list/t_timestamp (tcts).yasnippet b/extras/imported/rails-mode/Create columns t. drop-down list/t_timestamp (tcts).yasnippet index 26bd76d..aea2268 100644 --- a/extras/imported/rails-mode/Create columns t. drop-down list/t_timestamp (tcts).yasnippet +++ b/extras/imported/rails-mode/Create columns t. drop-down list/t_timestamp (tcts).yasnippet @@ -2,7 +2,7 @@ # key: t. # contributor: Translated from TextMate Snippet # name: t.timestamp (tcts) -## condition: "meta.rails.migration.create_table, meta.rails.migration.change_table" +# condition: (and (yas/rails-migration-p) (yas/rails-in-create-table-p)) # -- t.timestamp :${1:title} t.$0 \ No newline at end of file diff --git a/extras/imported/rails-mode/Create columns t. drop-down list/t_timestamps (tctss).yasnippet b/extras/imported/rails-mode/Create columns t. drop-down list/t_timestamps (tctss).yasnippet index 883eac5..4ba7622 100644 --- a/extras/imported/rails-mode/Create columns t. drop-down list/t_timestamps (tctss).yasnippet +++ b/extras/imported/rails-mode/Create columns t. drop-down list/t_timestamps (tctss).yasnippet @@ -2,7 +2,7 @@ # key: t. # contributor: Translated from TextMate Snippet # name: t.timestamps (tctss) -## condition: "meta.rails.migration.create_table, meta.rails.migration.change_table" +# condition: (and (yas/rails-migration-p) (yas/rails-in-create-table-p)) # -- t.timestamps t.$0 \ No newline at end of file diff --git a/extras/imported/rails-mode/Indexes/Add 3A Remove Index.yasnippet b/extras/imported/rails-mode/Indexes/Add 3A Remove Index.yasnippet index b1fd014..567d7d6 100644 --- a/extras/imported/rails-mode/Indexes/Add 3A Remove Index.yasnippet +++ b/extras/imported/rails-mode/Indexes/Add 3A Remove Index.yasnippet @@ -3,5 +3,6 @@ # 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" +# condition: (yas/rails-intelligent-migration-snippet-condition-p) # -- +(yas/rails-intelligent-migration-snippet :add_remove_index) \ No newline at end of file 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 index ea6ae53..0be13df 100644 --- a/extras/imported/rails-mode/Indexes/Add 3A Remove Named Index.yasnippet +++ b/extras/imported/rails-mode/Indexes/Add 3A Remove Named Index.yasnippet @@ -3,5 +3,6 @@ # 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" +# condition: (yas/rails-intelligent-migration-snippet-condition-p) # -- +(yas/rails-intelligent-migration-snippet :add_remove_named_index) 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 index a7b067b..26e11a9 100644 --- a/extras/imported/rails-mode/Indexes/Add 3A Remove Unique Index.yasnippet +++ b/extras/imported/rails-mode/Indexes/Add 3A Remove Unique Index.yasnippet @@ -3,5 +3,6 @@ # 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" +# condition: (yas/rails-intelligent-migration-snippet-condition-p) # -- +(yas/rails-intelligent-migration-snippet :add_remove_unique_index) diff --git a/extras/imported/rails-mode/Tables/Migration Create Column (mcc).yasnippet b/extras/imported/rails-mode/Tables/Migration Create Column (mcc).yasnippet index 289bcc8..378e7a4 100644 --- a/extras/imported/rails-mode/Tables/Migration Create Column (mcc).yasnippet +++ b/extras/imported/rails-mode/Tables/Migration Create Column (mcc).yasnippet @@ -2,7 +2,7 @@ # key: mcol # contributor: Translated from TextMate Snippet # name: Create Column in Table -## condition: "meta.rails.migration.create_table" +# condition: (yas/rails-intelligent-migration-snippet-condition-p) # -- t.column ${1:title}, :${2:string} $0 \ No newline at end of file diff --git a/extras/imported/rails-mode/Tables/Migration Drop Create Table (mdct).yasnippet b/extras/imported/rails-mode/Tables/Migration Drop Create Table (mdct).yasnippet index abe99dc..7966f7f 100644 --- a/extras/imported/rails-mode/Tables/Migration Drop Create Table (mdct).yasnippet +++ b/extras/imported/rails-mode/Tables/Migration Drop Create Table (mdct).yasnippet @@ -2,6 +2,6 @@ # key: mtab # contributor: Translated from TextMate Snippet # name: Drop / Create Table -## condition: "meta.rails.migration - meta.rails.migration.create_table - meta.rails.migration.change_table" +# condition: (yas/rails-intelligent-migration-snippet-condition-p) # -- drop_table :${1:table}${2: [press tab twice to generate create_table]} \ No newline at end of file