Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

js2-refactor minor mode #54

Merged
merged 7 commits into from
Apr 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -38,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

Expand All @@ -56,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

Expand Down
7 changes: 7 additions & 0 deletions features/js2r-arguments-to-object.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions features/js2r-barf.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions features/js2r-debug-this.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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"
Expand All @@ -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:
Expand All @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions features/js2r-expand-collapse.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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' };"
Expand All @@ -48,13 +51,15 @@ 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' };"

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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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; }"
Expand All @@ -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]; }"
Expand All @@ -130,13 +139,15 @@ 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; }"

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:
Expand All @@ -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 ];"
10 changes: 10 additions & 0 deletions features/js2r-extract-function.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
Loading