From 20d15dd881c1b766f3af66794ac16bd16fc5a05c Mon Sep 17 00:00:00 2001 From: Nicolas Petton Date: Wed, 22 Apr 2015 18:51:14 +0200 Subject: [PATCH 1/6] Add a minor mode for js2-refactor * js2-refactor.el: js2-refactor now is a minor mode. --- js2-refactor.el | 77 ++++++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 33 deletions(-) diff --git a/js2-refactor.el b/js2-refactor.el index 575f72f..a46ba9d 100644 --- a/js2-refactor.el +++ b/js2-refactor.el @@ -38,6 +38,8 @@ ;; Then add this to your emacs settings: ;; (require 'js2-refactor) +;; (add-hook 'js2-mode-hook #'js2-refactor-mode) +;; (js2r-add-keybindings-with-prefix "C-c C-m") ;; Note: I am working on a smoother installation path through package.el, ;; but I haven't had the time to whip this project into that sort of @@ -122,6 +124,17 @@ (require 'js2r-conveniences) (require 'js2r-paredit) +(defvar js2-refactor-mode-map + (make-sparse-keymap) + "Keymap for js2-refactor.") + +(define-minor-mode js2-refactor-mode + "Minor mode providing JavaScript refactorings." + :lighter " js2r" + :keymap js2-refactor-mode-map + (when js2-refactor-mode + (yas-minor-mode-on))) + ;;; Settings ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defvar js2r-use-strict nil @@ -131,37 +144,37 @@ (defun js2r--add-keybindings (key-fn) "Add js2r refactoring keybindings to `js2-mode-map' using KEY-FN to create each keybinding." - (define-key js2-mode-map (funcall key-fn "eo") 'js2r-expand-object) - (define-key js2-mode-map (funcall key-fn "co") 'js2r-contract-object) - (define-key js2-mode-map (funcall key-fn "eu") 'js2r-expand-function) - (define-key js2-mode-map (funcall key-fn "cu") 'js2r-contract-function) - (define-key js2-mode-map (funcall key-fn "ea") 'js2r-expand-array) - (define-key js2-mode-map (funcall key-fn "ca") 'js2r-contract-array) - (define-key js2-mode-map (funcall key-fn "wi") 'js2r-wrap-buffer-in-iife) - (define-key js2-mode-map (funcall key-fn "ig") 'js2r-inject-global-in-iife) - (define-key js2-mode-map (funcall key-fn "ev") 'js2r-extract-var) - (define-key js2-mode-map (funcall key-fn "iv") 'js2r-inline-var) - (define-key js2-mode-map (funcall key-fn "rv") 'js2r-rename-var) - (define-key js2-mode-map (funcall key-fn "vt") 'js2r-var-to-this) - (define-key js2-mode-map (funcall key-fn "ag") 'js2r-add-to-globals-annotation) - (define-key js2-mode-map (funcall key-fn "sv") 'js2r-split-var-declaration) - (define-key js2-mode-map (funcall key-fn "ss") 'js2r-split-string) - (define-key js2-mode-map (funcall key-fn "ef") 'js2r-extract-function) - (define-key js2-mode-map (funcall key-fn "em") 'js2r-extract-method) - (define-key js2-mode-map (funcall key-fn "ip") 'js2r-introduce-parameter) - (define-key js2-mode-map (funcall key-fn "lp") 'js2r-localize-parameter) - (define-key js2-mode-map (funcall key-fn "tf") 'js2r-toggle-function-expression-and-declaration) - (define-key js2-mode-map (funcall key-fn "ao") 'js2r-arguments-to-object) - (define-key js2-mode-map (funcall key-fn "uw") 'js2r-unwrap) - (define-key js2-mode-map (funcall key-fn "wl") 'js2r-wrap-in-for-loop) - (define-key js2-mode-map (funcall key-fn "3i") 'js2r-ternary-to-if) - (define-key js2-mode-map (funcall key-fn "lt") 'js2r-log-this) - (define-key js2-mode-map (funcall key-fn "dt") 'js2r-debug-this) - (define-key js2-mode-map (funcall key-fn "sl") 'js2r-forward-slurp) - (define-key js2-mode-map (funcall key-fn "ba") 'js2r-forward-barf) - (define-key js2-mode-map (funcall key-fn "k") 'js2r-kill) - (define-key js2-mode-map (kbd "") 'js2r-move-line-down) - (define-key js2-mode-map (kbd "") 'js2r-move-line-up)) + (define-key js2-refactor-mode-map (funcall key-fn "eo") 'js2r-expand-object) + (define-key js2-refactor-mode-map (funcall key-fn "co") 'js2r-contract-object) + (define-key js2-refactor-mode-map (funcall key-fn "eu") 'js2r-expand-function) + (define-key js2-refactor-mode-map (funcall key-fn "cu") 'js2r-contract-function) + (define-key js2-refactor-mode-map (funcall key-fn "ea") 'js2r-expand-array) + (define-key js2-refactor-mode-map (funcall key-fn "ca") 'js2r-contract-array) + (define-key js2-refactor-mode-map (funcall key-fn "wi") 'js2r-wrap-buffer-in-iife) + (define-key js2-refactor-mode-map (funcall key-fn "ig") 'js2r-inject-global-in-iife) + (define-key js2-refactor-mode-map (funcall key-fn "ev") 'js2r-extract-var) + (define-key js2-refactor-mode-map (funcall key-fn "iv") 'js2r-inline-var) + (define-key js2-refactor-mode-map (funcall key-fn "rv") 'js2r-rename-var) + (define-key js2-refactor-mode-map (funcall key-fn "vt") 'js2r-var-to-this) + (define-key js2-refactor-mode-map (funcall key-fn "ag") 'js2r-add-to-globals-annotation) + (define-key js2-refactor-mode-map (funcall key-fn "sv") 'js2r-split-var-declaration) + (define-key js2-refactor-mode-map (funcall key-fn "ss") 'js2r-split-string) + (define-key js2-refactor-mode-map (funcall key-fn "ef") 'js2r-extract-function) + (define-key js2-refactor-mode-map (funcall key-fn "em") 'js2r-extract-method) + (define-key js2-refactor-mode-map (funcall key-fn "ip") 'js2r-introduce-parameter) + (define-key js2-refactor-mode-map (funcall key-fn "lp") 'js2r-localize-parameter) + (define-key js2-refactor-mode-map (funcall key-fn "tf") 'js2r-toggle-function-expression-and-declaration) + (define-key js2-refactor-mode-map (funcall key-fn "ao") 'js2r-arguments-to-object) + (define-key js2-refactor-mode-map (funcall key-fn "uw") 'js2r-unwrap) + (define-key js2-refactor-mode-map (funcall key-fn "wl") 'js2r-wrap-in-for-loop) + (define-key js2-refactor-mode-map (funcall key-fn "3i") 'js2r-ternary-to-if) + (define-key js2-refactor-mode-map (funcall key-fn "lt") 'js2r-log-this) + (define-key js2-refactor-mode-map (funcall key-fn "dt") 'js2r-debug-this) + (define-key js2-refactor-mode-map (funcall key-fn "sl") 'js2r-forward-slurp) + (define-key js2-refactor-mode-map (funcall key-fn "ba") 'js2r-forward-barf) + (define-key js2-refactor-mode-map (funcall key-fn "k") 'js2r-kill) + (define-key js2-refactor-mode-map (kbd "") 'js2r-move-line-down) + (define-key js2-refactor-mode-map (kbd "") 'js2r-move-line-up)) ;;;###autoload (defun js2r-add-keybindings-with-prefix (prefix) @@ -173,7 +186,5 @@ "Add js2r keybindings using the modifier MODIFIER." (js2r--add-keybindings (-partial 'js2r--key-pairs-with-modifier modifier))) -(add-hook 'js2-mode-hook #'yas-minor-mode-on) - (provide 'js2-refactor) ;;; js2-refactor.el ends here From 770feab3a8dab2accdde490c7d25be8e2cf9cee7 Mon Sep 17 00:00:00 2001 From: Nicolas Petton Date: Wed, 22 Apr 2015 18:51:49 +0200 Subject: [PATCH 2/6] Update all tests to enable the js2-refactor minor mode. --- features/js2r-arguments-to-object.feature | 7 +++++++ features/js2r-barf.feature | 8 ++++++++ features/js2r-debug-this.feature | 5 +++++ features/js2r-expand-collapse.feature | 12 ++++++++++++ features/js2r-extract-function.feature | 10 ++++++++++ features/js2r-extract-var.feature | 6 ++++++ features/js2r-inline-var.feature | 7 +++++++ features/js2r-introduce-parameter.feature | 1 + features/js2r-kill.feature | 18 ++++++++++++++++++ features/js2r-log-this.feature | 5 +++++ features/js2r-rename-var.feature | 5 +++++ features/js2r-slurp.feature | 9 +++++++++ features/js2r-split-string.feature | 4 ++++ features/js2r-split-var-declaration.feature | 3 +++ features/js2r-ternary-to-if.feature | 4 ++++ features/js2r-var-to-this.feature | 1 + features/js2r-wrapping.feature | 4 ++++ 17 files changed, 109 insertions(+) diff --git a/features/js2r-arguments-to-object.feature b/features/js2r-arguments-to-object.feature index 1bd20e9..262e84d 100644 --- a/features/js2r-arguments-to-object.feature +++ b/features/js2r-arguments-to-object.feature @@ -3,6 +3,7 @@ Feature: Arguments to object Scenario: Values Given I insert "abc(123, 4 + 5, 'hello');" And I turn on js2-mode + And I turn on js2-refactor-mode When I go to the end of the word "abc" And I press "C-c C-m ao" Then I should see: @@ -17,6 +18,7 @@ Feature: Arguments to object Scenario: Placeholders Given I insert "abc(123, 4 + 5, 'hello');" And I turn on js2-mode + And I turn on js2-refactor-mode When I go to the end of the word "abc" And I press "C-c C-m ao" And I type "def" @@ -37,6 +39,7 @@ Feature: Arguments to object Scenario: Known names Given I insert "abc(def, ghi, jkl);" And I turn on js2-mode + And I turn on js2-refactor-mode When I go to the end of the word "abc" And I press "C-c C-m ao" Then I should see: @@ -60,6 +63,7 @@ Feature: Arguments to object } """ And I turn on js2-mode + And I turn on js2-refactor-mode When I go to the end of the word "abc" And I press "C-c C-m ao" Then I should see: @@ -86,6 +90,7 @@ Feature: Arguments to object }); """ And I turn on js2-mode + And I turn on js2-refactor-mode When I go to the end of the word "add" And I press "C-c C-m ao" Then I should see: @@ -119,6 +124,7 @@ Feature: Arguments to object }); """ And I turn on js2-mode + And I turn on js2-refactor-mode When I go to the front of the word "abc" And I press "C-b C-b" And I press "C-c C-m ao" @@ -150,6 +156,7 @@ Feature: Arguments to object var a = new Add(1, 3); """ And I turn on js2-mode + And I turn on js2-refactor-mode When I go to the end of the word "new Add" And I press "C-c C-m ao" Then I should see: diff --git a/features/js2r-barf.feature b/features/js2r-barf.feature index 2c268a9..9c7f90d 100644 --- a/features/js2r-barf.feature +++ b/features/js2r-barf.feature @@ -11,6 +11,7 @@ Feature: JS Barf """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "def" And I press "C-c C-m ba" Then I should see: @@ -34,6 +35,7 @@ Feature: JS Barf jkl(); """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "abc" And I press "C-c C-m ba" Then I should see: @@ -57,6 +59,7 @@ Feature: JS Barf jkl(); """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the end of the word "function" And I press "C-c C-m ba" Then I should see: @@ -76,6 +79,7 @@ Feature: JS Barf jkl(); """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "ghi" And I press "C-c C-m ba" Then I should see: @@ -97,6 +101,7 @@ Feature: JS Barf jkl(); """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "ghi" And I press "C-c C-m ba" Then I should see: @@ -119,6 +124,7 @@ Feature: JS Barf jkl(); """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "abc" And I press "M-- 1 C-c C-m ba" Then I should see: @@ -142,6 +148,7 @@ Feature: JS Barf """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "abc" And I press "M-2 C-c C-m ba" Then I should see: @@ -168,6 +175,7 @@ Feature: JS Barf jkl(); """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "abc" And I press "M-2 C-c C-m ba" Then I should see: diff --git a/features/js2r-debug-this.feature b/features/js2r-debug-this.feature index 97db0a3..03ae597 100644 --- a/features/js2r-debug-this.feature +++ b/features/js2r-debug-this.feature @@ -3,6 +3,7 @@ Feature: Debug this Scenario: debug var Given I insert "var bah = { b: 1, c: 'def' };" And I turn on js2-mode + And I turn on js2-refactor-mode When I go to the front of the word "bah" And I press "C-c C-m dt" Then I should see: @@ -19,6 +20,7 @@ Feature: Debug this } """ And I turn on js2-mode + And I turn on js2-refactor-mode When I go to the front of the word "def" And I press "C-c C-m dt" Then I should see: @@ -35,6 +37,7 @@ Feature: Debug this var def = abc(123) + ghi(); """ And I turn on js2-mode + And I turn on js2-refactor-mode When I go to the front of the word "abc" And I set the mark And I press "C-8 C-f" @@ -51,6 +54,7 @@ Feature: Debug this def.ghi.jkl + 1; """ And I turn on js2-mode + And I turn on js2-refactor-mode When I go to the front of the word "ghi" And I press "C-c C-m dt" Then I should see: @@ -67,6 +71,7 @@ Feature: Debug this } """ And I turn on js2-mode + And I turn on js2-refactor-mode When I go to the front of the word "def" And I press "C-c C-m dt" Then I should see: diff --git a/features/js2r-expand-collapse.feature b/features/js2r-expand-collapse.feature index c882884..3baa828 100644 --- a/features/js2r-expand-collapse.feature +++ b/features/js2r-expand-collapse.feature @@ -3,6 +3,7 @@ Feature: Expand and collapse things Scenario: Expanding objects When I insert "var a = { b: 1, c: 'def' };" And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "b" And I press "C-c C-m eo" Then I should see: @@ -16,6 +17,7 @@ Feature: Expand and collapse things Scenario: Expanding objects with comma When I insert "var a = { b: 1, c: 'def, ghi' };" And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "b" And I press "C-c C-m eo" Then I should see: @@ -35,6 +37,7 @@ Feature: Expand and collapse things }; """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "b" And I press "C-c C-m co" Then I should see "var a = { b: 1, c: 'def' };" @@ -48,6 +51,7 @@ Feature: Expand and collapse things }; """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "b" And I press "C-c C-m co" Then I should see "var a = { b: 1, c: 'def, ghi' };" @@ -55,6 +59,7 @@ Feature: Expand and collapse things Scenario: Expanding functions When I insert "function f (a, b, c) { var t = a + b + c; return t; }" And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "var" And I press "C-c C-m eu" Then I should see: @@ -68,6 +73,7 @@ Feature: Expand and collapse things Scenario: Expanding functions containing arrays When I insert "function f (a, b, c) { var t = a + b + c; var arr = [1, 2, 3, a, b]; return [t, arr]; }" And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "var" And I press "C-c C-m eu" Then I should see: @@ -82,6 +88,7 @@ Feature: Expand and collapse things Scenario: Expanding functions containing object literals When I insert "function f (a, b, c) { var t = a + b + c; var o = {e1: a, e2: b + 1, e3: 'xyzzy'}; return o; }" And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "var" And I press "C-c C-m eu" Then I should see: @@ -102,6 +109,7 @@ Feature: Expand and collapse things } """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "var" And I press "C-c C-m cu" Then I should see "function f (a, b, c) { var t = a + b + c; return t; }" @@ -116,6 +124,7 @@ Feature: Expand and collapse things } """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "var" And I press "C-c C-m cu" Then I should see "function f (a, b, c) { var t = a + b + c; var arr = [1, 2, 3, a, b]; return [t, arr]; }" @@ -130,6 +139,7 @@ Feature: Expand and collapse things } """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "var" And I press "C-c C-m cu" Then I should see "function f (a, b, c) { var t = a + b + c; var o = {e1: a, e2: b + 1, e3: 'xyzzy'}; return o; }" @@ -137,6 +147,7 @@ Feature: Expand and collapse things Scenario: Expanding arrays When I insert "var a = [ b, 1, c, 3.1415927 ];" And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "b" And I press "C-c C-m ea" Then I should see: @@ -160,6 +171,7 @@ Feature: Expand and collapse things ]; """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "b" And I press "C-c C-m ca" Then I should see "var a = [ b, 1, c, 3.1415927 ];" diff --git a/features/js2r-extract-function.feature b/features/js2r-extract-function.feature index 48771d4..3a19c17 100644 --- a/features/js2r-extract-function.feature +++ b/features/js2r-extract-function.feature @@ -8,6 +8,7 @@ Feature: Extract function } """ And I turn on js2-mode + And I turn on js2-refactor-mode When I select "console.log" And I press "C-c C-m ef name RET" Then I should see: @@ -29,6 +30,7 @@ Feature: Extract function } """ And I turn on js2-mode + And I turn on js2-refactor-mode When I select "console.log" And I press "C-c C-m ef name RET" Then I should see: @@ -52,6 +54,7 @@ Feature: Extract function } """ And I turn on js2-mode + And I turn on js2-refactor-mode When I select "console.log" And I press "C-c C-m ef name RET" Then I should see: @@ -75,6 +78,7 @@ Feature: Extract function } """ And I turn on js2-mode + And I turn on js2-refactor-mode When I select "return" And I press "C-c C-m ef name RET" Then I should see: @@ -96,6 +100,7 @@ Feature: Extract function } """ And I turn on js2-mode + And I turn on js2-refactor-mode When I select "return" And I press "C-c C-m ef name RET" Then I should see: @@ -118,6 +123,7 @@ Feature: Extract function } """ And I turn on js2-mode + And I turn on js2-refactor-mode When I select "return" And I press "C-c C-m ef name RET" Then I should see: @@ -142,6 +148,7 @@ Feature: Extract function } """ And I turn on js2-mode + And I turn on js2-refactor-mode When I go to the front of the word "var" And I set the mark And I go to the end of the word "7" @@ -169,6 +176,7 @@ Feature: Extract function } """ And I turn on js2-mode + And I turn on js2-refactor-mode When I go to the front of the word "var" And I set the mark And I go to the end of the word "return" @@ -196,6 +204,7 @@ Feature: Extract function } """ And I turn on js2-mode + And I turn on js2-refactor-mode When I select "return" And I press "C-c C-m ef name RET" Then I should see: @@ -222,6 +231,7 @@ Feature: Extract function } """ And I turn on js2-mode + And I turn on js2-refactor-mode When I select "console.log" And I press "C-c C-m em name RET" Then I should see: diff --git a/features/js2r-extract-var.feature b/features/js2r-extract-var.feature index f804d94..1b96749 100644 --- a/features/js2r-extract-var.feature +++ b/features/js2r-extract-var.feature @@ -3,6 +3,7 @@ Feature: Extract var Scenario: Extracting region When I insert "abc(1 + 2 + 3, 4 + 5);" And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "1" And I set the mark And I go to the end of the word "2" @@ -18,6 +19,7 @@ Feature: Extract var Scenario: Extracting function parameter When I insert "abc(1 + 2 + 3, 4 + 5);" And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "2" And I press "C-c C-m ev" And I press "C-u DEL" @@ -36,6 +38,7 @@ Feature: Extract var } """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "abc" And I press "C-c C-m ev" And I press "C-u DEL" @@ -56,6 +59,7 @@ Feature: Extract var } """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "def" And I press "C-c C-m ev" And I press "C-u DEL" @@ -74,6 +78,7 @@ Feature: Extract var abc.def.ghi(); """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "def" And I press "C-c C-m ev" And I press "C-u DEL" @@ -92,6 +97,7 @@ Feature: Extract var }); """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "baz" And I press "C-c C-m ev" And I press "C-u DEL" diff --git a/features/js2r-inline-var.feature b/features/js2r-inline-var.feature index 1527eed..89a0f74 100644 --- a/features/js2r-inline-var.feature +++ b/features/js2r-inline-var.feature @@ -3,6 +3,7 @@ Feature: Extract var Scenario: Inlining variable When I insert "var foo = bar(1,2,3); foo();" And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "foo" And I press "C-c C-m iv" Then I should see: @@ -19,6 +20,7 @@ Feature: Extract var } """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "foo" And I press "C-c C-m iv" Then I should see: @@ -37,6 +39,7 @@ Feature: Extract var } """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "foo" And I press "C-c C-m iv" Then I should see: @@ -55,6 +58,7 @@ Feature: Extract var } """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "foo" And I press "C-c C-m iv" Then I should see: @@ -73,6 +77,7 @@ Feature: Extract var } """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "foo" And I press "C-c C-m iv" Then I should see: @@ -92,6 +97,7 @@ Feature: Extract var } """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "foo" And I press "C-c C-m iv" Then I should see: @@ -111,6 +117,7 @@ Feature: Extract var var asdfg = 'x'; """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "asdfg" And I press "C-c C-m iv" Then I should see: diff --git a/features/js2r-introduce-parameter.feature b/features/js2r-introduce-parameter.feature index d0cc016..b21d3a8 100644 --- a/features/js2r-introduce-parameter.feature +++ b/features/js2r-introduce-parameter.feature @@ -9,6 +9,7 @@ Feature: Introduce parameter abc(); """ And I turn on js2-mode + And I turn on js2-refactor-mode When I go to the front of the word "123" And I start an action chain And I press "C-c C-m ip" diff --git a/features/js2r-kill.feature b/features/js2r-kill.feature index a5d74d0..e2dbcdf 100644 --- a/features/js2r-kill.feature +++ b/features/js2r-kill.feature @@ -9,6 +9,7 @@ Feature: Killing lines //} """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "function" And I press "C-c C-m k" Then I should see: @@ -27,6 +28,7 @@ Feature: Killing lines } """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "function" And I press "C-c C-m k" Then I should see: @@ -46,6 +48,7 @@ Feature: Killing lines } """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "world" And I press "C-c C-m k" Then I should see: @@ -63,6 +66,7 @@ Feature: Killing lines } """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the end of the word "bar" And I press "C-c C-m k" Then I should see: @@ -84,6 +88,7 @@ Feature: Killing lines } """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "bar" And I press "C-c C-m k" Then I should see: @@ -105,6 +110,7 @@ Feature: Killing lines } """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "bar" And I press "C-c C-m k" Then I should see: @@ -123,6 +129,7 @@ Feature: Killing lines } """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "return" And I press "C-c C-m k" Then I should see: @@ -141,6 +148,7 @@ Feature: Killing lines } """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "return" And I press "C-c C-m k" Then I should see: @@ -159,6 +167,7 @@ Feature: Killing lines } """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "bar" And I press "C-c C-m k" Then I should see: @@ -175,6 +184,7 @@ Feature: Killing lines var foo = function() { return hello;}; bar; """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "hello" And I press "C-c C-m k" Then I should see: @@ -189,6 +199,7 @@ Feature: Killing lines function a(foo, bar) { return bar;} """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the end of the word "foo" And I press "C-c C-m k" Then I should see: @@ -203,6 +214,7 @@ Feature: Killing lines function a(foo, bar) { return bar;} """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "function" And I press "C-c C-m k" Then I should see: @@ -217,6 +229,7 @@ Feature: Killing lines var foo = 3; """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "foo" And I press "C-c C-m k" Then I should see: @@ -235,6 +248,7 @@ Feature: Killing lines ] """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to line "3" And I press "C-c C-m k" Then I should see: @@ -253,6 +267,7 @@ Feature: Killing lines foo(['foo', 'bar'], 2, 3); """ And I turn on js2-mode + And I turn on js2-refactor-mode And I place the cursor before "'foo" And I press "C-c C-m k" Then I should see: @@ -269,6 +284,7 @@ Feature: Killing lines }); """ And I turn on js2-mode + And I turn on js2-refactor-mode And I place the cursor before "function" And I press "C-c C-m k" Then I should see: @@ -286,6 +302,7 @@ Feature: Killing lines blah(); """ And I turn on js2-mode + And I turn on js2-refactor-mode And I place the cursor before "if" And I press "C-c C-m k" Then I should see: @@ -306,6 +323,7 @@ Feature: Killing lines ); """ And I turn on js2-mode + And I turn on js2-refactor-mode And I place the cursor before "hello" And I press "C-c C-m k" Then I should see: diff --git a/features/js2r-log-this.feature b/features/js2r-log-this.feature index 8c578ef..ca905ee 100644 --- a/features/js2r-log-this.feature +++ b/features/js2r-log-this.feature @@ -3,6 +3,7 @@ Feature: Log this Scenario: Console.log var Given I insert "var bah = { b: 1, c: 'def' };" And I turn on js2-mode + And I turn on js2-refactor-mode When I go to the front of the word "bah" And I press "C-c C-m lt" Then I should see: @@ -19,6 +20,7 @@ Feature: Log this } """ And I turn on js2-mode + And I turn on js2-refactor-mode When I go to the front of the word "def" And I press "C-c C-m lt" Then I should see: @@ -35,6 +37,7 @@ Feature: Log this var def = abc(123) + ghi(); """ And I turn on js2-mode + And I turn on js2-refactor-mode When I go to the front of the word "abc" And I set the mark And I press "C-8 C-f" @@ -51,6 +54,7 @@ Feature: Log this def.ghi.jkl + 1; """ And I turn on js2-mode + And I turn on js2-refactor-mode When I go to the front of the word "ghi" And I press "C-c C-m lt" Then I should see: @@ -67,6 +71,7 @@ Feature: Log this } """ And I turn on js2-mode + And I turn on js2-refactor-mode When I go to the front of the word "def" And I press "C-c C-m lt" Then I should see: diff --git a/features/js2r-rename-var.feature b/features/js2r-rename-var.feature index a2398fa..4977ac5 100644 --- a/features/js2r-rename-var.feature +++ b/features/js2r-rename-var.feature @@ -4,6 +4,7 @@ Feature: Rename variable Given delete-selection-mode is active When I insert "var abc = 123;" And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "abc" And I press "C-c C-m rv" And I type "def" @@ -13,6 +14,7 @@ Feature: Rename variable Given delete-selection-mode is active When I insert "var abc = 123, def = abc;" And I turn on js2-mode + And I turn on js2-refactor-mode And I go to character ";" And I press "C-b" And I press "C-c C-m rv" @@ -23,6 +25,7 @@ Feature: Rename variable Given delete-selection-mode is active When I insert "function test(abc) { alert(abc); }" And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the end of the word "alert" And I press "C-f" And I press "C-c C-m rv" @@ -33,6 +36,7 @@ Feature: Rename variable Given delete-selection-mode is active When I insert "var abc = { abc: 123 };" And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the end of the word "var" And I press "C-f" And I press "C-c C-m rv" @@ -43,6 +47,7 @@ Feature: Rename variable Given delete-selection-mode is active When I insert "var abc = this.abc;" And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the end of the word "var" And I press "C-f" And I press "C-c C-m rv" diff --git a/features/js2r-slurp.feature b/features/js2r-slurp.feature index b8cf318..d8d7a11 100644 --- a/features/js2r-slurp.feature +++ b/features/js2r-slurp.feature @@ -10,6 +10,7 @@ Feature: JS Slurp jkl(); """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "def" And I press "C-c C-m sl" Then I should see: @@ -34,6 +35,7 @@ Feature: JS Slurp jkl(); """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "abc" And I press "C-c C-m sl" Then I should see: @@ -56,6 +58,7 @@ Feature: JS Slurp jkl(); """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "abc" And I press "C-c C-m sl" Then I should see: @@ -75,6 +78,7 @@ Feature: JS Slurp jkl(); """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the end of the word "function" And I press "C-c C-m sl" Then I should see: @@ -94,6 +98,7 @@ Feature: JS Slurp jkl(); """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "abc" And I press "C-c C-m sl" Then I should see: @@ -115,6 +120,7 @@ Feature: JS Slurp jkl(); """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "else" And I press "C-c C-m sl" Then I should see: @@ -135,6 +141,7 @@ Feature: JS Slurp jkl(); """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "abc" And I press "M-- 1 C-c C-m sl" Then I should see: @@ -157,6 +164,7 @@ Feature: JS Slurp stu(); """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "abc" And I press "M-3 C-c C-m sl" Then I should see: @@ -184,6 +192,7 @@ Feature: JS Slurp pqr(); """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "else" And I press "M-2 C-c C-m sl" Then I should see: diff --git a/features/js2r-split-string.feature b/features/js2r-split-string.feature index 32536f2..90a69d1 100644 --- a/features/js2r-split-string.feature +++ b/features/js2r-split-string.feature @@ -6,6 +6,7 @@ Feature: Split string "foo bar" """ And I turn on js2-mode + And I turn on js2-refactor-mode And I place the cursor before "bar" And I press "C-c C-m ss" Then I should see: @@ -19,6 +20,7 @@ Feature: Split string 'foo bar' """ And I turn on js2-mode + And I turn on js2-refactor-mode And I place the cursor before "bar" And I press "C-c C-m ss" Then I should see: @@ -32,6 +34,7 @@ Feature: Split string "foo" + "bar" """ And I turn on js2-mode + And I turn on js2-refactor-mode And I place the cursor after "foo" And I press "C-c C-m ss" Then I should see: @@ -45,6 +48,7 @@ Feature: Split string 'foo' + 'bar' """ And I turn on js2-mode + And I turn on js2-refactor-mode And I place the cursor after "foo" And I press "C-c C-m ss" Then I should see: diff --git a/features/js2r-split-var-declaration.feature b/features/js2r-split-var-declaration.feature index 84adc8d..154a1f2 100644 --- a/features/js2r-split-var-declaration.feature +++ b/features/js2r-split-var-declaration.feature @@ -3,6 +3,7 @@ Feature: Split var declaration Scenario: Split simple var When I insert "var a, b, c;" And I turn on js2-mode + And I turn on js2-refactor-mode And I press "C-c C-m sv" Then I should see: """ @@ -15,6 +16,7 @@ Feature: Split var declaration Scenario: Split vars with values When I insert "var a = 1, b = '2', c = { d: 3 };" And I turn on js2-mode + And I turn on js2-refactor-mode And I press "C-c C-m sv" Then I should see: """ @@ -34,6 +36,7 @@ Feature: Split var declaration }; """ And I turn on js2-mode + And I turn on js2-refactor-mode And I press "C-c C-m sv" Then I should see: """ diff --git a/features/js2r-ternary-to-if.feature b/features/js2r-ternary-to-if.feature index f2fe701..90a7ecd 100644 --- a/features/js2r-ternary-to-if.feature +++ b/features/js2r-ternary-to-if.feature @@ -3,6 +3,7 @@ Feature: Rename variable Scenario: Replace simple ternary with if When I insert "console.log(a ? 1 : 2);" And I turn on js2-mode + And I turn on js2-refactor-mode And I go to character "?" And I press "C-c C-m 3i" Then I should see: @@ -17,6 +18,7 @@ Feature: Rename variable Scenario: Point can be anywhere in ternary When I insert "var x = abc ? 1 : 2;" And I turn on js2-mode + And I turn on js2-refactor-mode And I go to character "b" And I press "C-c C-m 3i" Then I should see: @@ -36,6 +38,7 @@ Feature: Rename variable }); """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to character "?" And I press "C-c C-m 3i" Then I should see: @@ -60,6 +63,7 @@ Feature: Rename variable ); """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to character "?" And I press "C-c C-m 3i" Then I should see: diff --git a/features/js2r-var-to-this.feature b/features/js2r-var-to-this.feature index 8ca84e8..8ec0cf9 100644 --- a/features/js2r-var-to-this.feature +++ b/features/js2r-var-to-this.feature @@ -9,6 +9,7 @@ Feature: Changing var to this } """ And I turn on js2-mode + And I turn on js2-refactor-mode Scenario: At declaration When I go to the front of the word "def" diff --git a/features/js2r-wrapping.feature b/features/js2r-wrapping.feature index 6de894a..a714f85 100644 --- a/features/js2r-wrapping.feature +++ b/features/js2r-wrapping.feature @@ -3,6 +3,7 @@ Feature: Wrapping stuff Scenario: Unwrapping statement When I insert "console.log('hi');" And I turn on js2-mode + And I turn on js2-refactor-mode And I select "'hi'" And I press "C-c C-m uw" Then I should see "'hi'" @@ -16,6 +17,7 @@ Feature: Wrapping stuff } """ And I turn on js2-mode + And I turn on js2-refactor-mode And I select "console.log('hi');" And I press "C-c C-m uw" Then I should not see "if (true) {" @@ -31,6 +33,7 @@ Feature: Wrapping stuff } """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "console" And I set the mark And I go to the end of the word "there" @@ -53,6 +56,7 @@ Feature: Wrapping stuff } """ And I turn on js2-mode + And I turn on js2-refactor-mode And I go to the front of the word "hello" And I press "C-c C-m uw" Then I should not see "if (true) {" From dd8e71d2e069697d24322a42bd9b05356fb14592 Mon Sep 17 00:00:00 2001 From: Nicolas Petton Date: Wed, 22 Apr 2015 18:52:15 +0200 Subject: [PATCH 3/6] Bump version 0.7.0 --- js2-refactor-pkg.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js2-refactor-pkg.el b/js2-refactor-pkg.el index a2d75a2..973ece8 100644 --- a/js2-refactor-pkg.el +++ b/js2-refactor-pkg.el @@ -1,3 +1,3 @@ -(define-package "js2-refactor" "0.6.1" +(define-package "js2-refactor" "0.7.0" "A JavaScript refactoring library for emacs." '((js2-mode "20101228") (s "1.9.0") (multiple-cursors "1.0.0") (dash "1.0.0") (s "1.0.0") (yasnippet "20130218"))) From 9921bfdad7f4d70eeedd22a610a2e92f981b8de3 Mon Sep 17 00:00:00 2001 From: Nicolas Petton Date: Wed, 22 Apr 2015 18:52:27 +0200 Subject: [PATCH 4/6] Update README.md * README.md: Update the readme to include breaking changes in v0.7.0. --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 59499a2..4b9584a 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,13 @@ A JavaScript refactoring library for emacs. This is a collection of small refactoring functions to further the idea of a JavaScript IDE in Emacs that started with js2-mode. +## Breaking change in 0.7.0 + +js2-refactor.el is now a minor mode that has to be enabled, with +something like the following: + + (add-hook 'js2-mode-hook #'js2-refactor-mode) + ## Breaking change in 0.6.0 You now choose your own keybinding scheme. If you just want what you had From 52d8f6e52cb35f2583b51398d1a9dec3520090bd Mon Sep 17 00:00:00 2001 From: Nicolas Petton Date: Wed, 22 Apr 2015 19:17:06 +0200 Subject: [PATCH 5/6] * features/js2r-kill.feature: Turn on js2-refactor-mode. --- features/js2r-kill.feature | 1 + 1 file changed, 1 insertion(+) diff --git a/features/js2r-kill.feature b/features/js2r-kill.feature index b2c0891..97f40db 100644 --- a/features/js2r-kill.feature +++ b/features/js2r-kill.feature @@ -345,6 +345,7 @@ Feature: Killing lines hello(); """ And I turn on js2-mode + And I turn on js2-refactor-mode And I place the cursor before "var" And I press "C-c C-m k" Then I should see: From 4a14c21597de98d79f0046098ef4b0e0a9bad0a1 Mon Sep 17 00:00:00 2001 From: Nicolas Petton Date: Wed, 22 Apr 2015 19:19:08 +0200 Subject: [PATCH 6/6] * README.md: copyedit --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4b9584a..092a311 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ vars, method calls and functions for refactorings. Then add this to your emacs settings: (require 'js2-refactor) + (add-hook 'js2-mode-hook #'js2-refactor-mode) ## Setup keybindings @@ -63,7 +64,7 @@ If you would rather have a modifier key, instead of a prefix, do: If neither of these appeal to your sense of keyboard layout aesthetics, feel free to pick and choose your own keybindings with a smattering of: - (define-key js2-mode-map (kbd "C-c C-e C-f") 'js2r-extract-function) + (define-key js2-refactor-mode-map (kbd "C-c C-e C-f") 'js2r-extract-function) ## Refactorings