-
Notifications
You must be signed in to change notification settings - Fork 810
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #827 from moble/master
Added new extension snippets_menu
- Loading branch information
Showing
27 changed files
with
10,758 additions
and
0 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
src/jupyter_contrib_nbextensions/nbextensions/snippets_menu/config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
Type: Jupyter Notebook Extension | ||
Name: Snippets Menu | ||
Link: readme.md | ||
Description: | | ||
Add a customizable menu item to insert code and markdown snippets. | ||
Comes with extensive defaults for popular python modules, including fairly | ||
complete listings of many important functions and constants, to save | ||
searching through documentation. | ||
Main: main.js | ||
Icon: thumbnail.png | ||
Compatibility: 4.x | ||
Parameters: | ||
- name: snippets.insert_as_new_cell | ||
description: "Insert snippets as new cells, rather than at cursor inside current cell" | ||
input_type: checkbox | ||
default: false | ||
- name: snippets.include_custom_menu | ||
description: "Include custom menu" | ||
input_type: checkbox | ||
default: false | ||
- name: snippets.custom_menu_content | ||
description: "Custom menu code (only used if the option above is checked)" | ||
input_type: textarea | ||
default: | | ||
{ | ||
"name" : "My favorites", | ||
"sub-menu" : [ | ||
{ | ||
"name" : "Menu item text", | ||
"snippet" : ["import something", | ||
"", | ||
"new_command(3.14)", | ||
"other_new_code_on_new_line('with a string!')", | ||
"stringy(\"if you need them, escape double quotes with a single backslash\")", | ||
"backslashy('This \\ appears as just one backslash in the output')", | ||
"backslashy2('Here \\\\ are two backslashes')"] | ||
}, | ||
{ | ||
"name" : "TeX can be written in menu labels $\\alpha_W e\\int_0 \\mu \\epsilon$", | ||
"snippet" : ["another_new_command(2.78)"] | ||
} | ||
] | ||
} | ||
- name: snippets.include_submenu_numpy | ||
description: "Include numpy sub-menu" | ||
input_type: checkbox | ||
default: true | ||
- name: snippets.include_submenu_scipy | ||
description: "Include scipy sub-menu" | ||
input_type: checkbox | ||
default: true | ||
- name: snippets.include_submenu_matplotlib | ||
description: "Include matplotlib sub-menu" | ||
input_type: checkbox | ||
default: true | ||
- name: snippets.include_submenu_sympy | ||
description: "Include sympy sub-menu" | ||
input_type: checkbox | ||
default: true | ||
- name: snippets.include_submenu_pandas | ||
description: "Include pandas sub-menu" | ||
input_type: checkbox | ||
default: true | ||
- name: snippets.include_submenu_astropy | ||
description: "Include astropy sub-menu" | ||
input_type: checkbox | ||
default: true | ||
- name: snippets.include_submenu_h5py | ||
description: "Include h5py sub-menu" | ||
input_type: checkbox | ||
default: true | ||
- name: snippets.include_submenu_numba | ||
description: "Include numba sub-menu" | ||
input_type: checkbox | ||
default: true | ||
- name: snippets.include_submenu_python | ||
description: "Include python sub-menu" | ||
input_type: checkbox | ||
default: true | ||
- name: snippets.include_submenu_markdown | ||
description: "Include markdown sub-menu" | ||
input_type: checkbox | ||
default: true |
187 changes: 187 additions & 0 deletions
187
src/jupyter_contrib_nbextensions/nbextensions/snippets_menu/examples_for_custom.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
// The following are various examples taken from README.md. Each section | ||
// contains code that you could place into your own custom.js file. Note that | ||
// only one of these should be used, though you might want to combine ideas | ||
// from the various examples. | ||
|
||
|
||
//// 1. Simple "My favorites" menu inserted at the *bottom* of "Snippets", with horizontal-line separator | ||
require(["nbextensions/snippets_menu/main"], function (snippets_menu) { | ||
console.log('Loading `snippets_menu` customizations from `custom.js`'); | ||
var horizontal_line = '---'; | ||
var my_favorites = { | ||
'name' : 'My favorites', | ||
'sub-menu' : [ | ||
{ | ||
'name' : 'Menu item text', | ||
'snippet' : ['new_command(3.14)',], | ||
}, | ||
{ | ||
'name' : 'Another menu item', | ||
'snippet' : ['another_new_command(2.78)',], | ||
}, | ||
], | ||
}; | ||
snippets_menu.options['menus'] = snippets_menu.default_menus; | ||
snippets_menu.options['menus'][0]['sub-menu'].push(horizontal_line); | ||
snippets_menu.options['menus'][0]['sub-menu'].push(my_favorites); | ||
console.log('Loaded `snippets_menu` customizations from `custom.js`'); | ||
}); | ||
|
||
|
||
//// 2. "My favorites" menu with lots of stringy goodness | ||
require(["nbextensions/snippets_menu/main"], function (snippets_menu) { | ||
console.log('Loading `snippets_menu` customizations from `custom.js`'); | ||
var horizontal_line = '---'; | ||
var my_favorites = { | ||
'name' : 'My $\\nu$ favorites', | ||
'sub-menu' : [ | ||
{ | ||
'name' : 'Multi-line snippet', | ||
'snippet' : ['new_command(3.14)', | ||
'other_new_code_on_new_line("with a string!")', | ||
'stringy(\'escape single quotes once\')', | ||
"stringy2('or use single quotes inside of double quotes')", | ||
'backslashy("This \\ appears as just one backslash in the output")', | ||
'backslashy2("Here are \\\\ two backslashes")',], | ||
}, | ||
{ | ||
'name' : 'TeX appears correctly $\\alpha_W e\\int_0 \\mu \\epsilon$', | ||
'snippet' : ['another_new_command(2.78)',], | ||
}, | ||
], | ||
}; | ||
snippets_menu.options['menus'].push(snippets_menu.default_menus[0]); | ||
snippets_menu.options['menus'][0]['sub-menu'].push(horizontal_line); | ||
snippets_menu.options['menus'][0]['sub-menu'].push(my_favorites); | ||
console.log('Loaded `snippets_menu` customizations from `custom.js`'); | ||
}); | ||
|
||
|
||
|
||
//// 3. Delete "Matplotlib"'s "Setup for scripts" item | ||
require(["nbextensions/snippets_menu/main"], function (snippets_menu) { | ||
console.log('Loading `snippets_menu` customizations from `custom.js`'); | ||
snippets_menu.python.matplotlib['sub-menu'].splice(1, 1); // Delete 1 element starting at position 1 of the sub-menu | ||
console.log('Loaded `snippets_menu` customizations from `custom.js`'); | ||
}); | ||
|
||
|
||
|
||
//// 4. Swap setup items in "Matplotlib" sub-menu | ||
require(["nbextensions/snippets_menu/main"], function (snippets_menu) { | ||
console.log('Loading `snippets_menu` customizations from `custom.js`'); | ||
var tmp = snippets_menu.python.matplotlib['sub-menu'][0]; | ||
snippets_menu.python.matplotlib['sub-menu'][0] = snippets_menu.python.matplotlib['sub-menu'][1]; | ||
snippets_menu.python.matplotlib['sub-menu'][1] = tmp; | ||
console.log('Loaded `snippets_menu` customizations from `custom.js`'); | ||
}); | ||
|
||
|
||
|
||
//// 5. Insert "My favorites" as a new top-level menu before "Snippets", instead of inside "Snippets" | ||
require(["nbextensions/snippets_menu/main"], function (snippets_menu) { | ||
console.log('Loading `snippets_menu` customizations from `custom.js`'); | ||
var my_favorites = { | ||
'name' : 'My favorites', | ||
'sub-menu' : [ | ||
{ | ||
'name' : 'Menu item text', | ||
'snippet' : ['new_command(3.14)',], | ||
}, | ||
{ | ||
'name' : 'Another menu item', | ||
'snippet' : ['another_new_command(2.78)',], | ||
}, | ||
], | ||
}; | ||
snippets_menu.options['menus'].push(my_favorites); | ||
snippets_menu.options['menus'].push(snippets_menu.default_menus[0]); | ||
console.log('Loaded `snippets_menu` customizations from `custom.js`'); | ||
}); | ||
|
||
|
||
|
||
//// 6. Insert "My favorites" as a new top-level menu after "Snippets", instead of inside "Snippets" | ||
require(["nbextensions/snippets_menu/main"], function (snippets_menu) { | ||
console.log('Loading `snippets_menu` customizations from `custom.js`'); | ||
var my_favorites = { | ||
'name' : 'My favorites', | ||
'sub-menu' : [ | ||
{ | ||
'name' : 'Menu item text', | ||
'snippet' : ['new_command(3.14)',], | ||
}, | ||
{ | ||
'name' : 'Another menu item', | ||
'snippet' : ['another_new_command(2.78)',], | ||
}, | ||
], | ||
}; | ||
snippets_menu.options['menus'].push(snippets_menu.default_menus[0]); | ||
snippets_menu.options['menus'].push(my_favorites); | ||
console.log('Loaded `snippets_menu` customizations from `custom.js`'); | ||
}); | ||
|
||
|
||
|
||
//// 7. Place "Snippets" before "Help" menu | ||
require(["nbextensions/snippets_menu/main"], function (snippets_menu) { | ||
console.log('Loading `snippets_menu` customizations from `custom.js`'); | ||
snippets_menu.options['insert_before_or_after'] = 'before'; | ||
console.log('Loaded `snippets_menu` customizations from `custom.js`'); | ||
}); | ||
|
||
|
||
|
||
//// 8. Move SymPy and Numpy to navbar and delete pandas | ||
require(["nbextensions/snippets_menu/main"], function (snippets_menu) { | ||
console.log('Loading `snippets_menu` customizations from `custom.js`'); | ||
snippets_menu.default_menus[0]['sub-menu'].splice(3, 2); // Remove SymPy and pandas | ||
snippets_menu.python.sympy['sub-menu-direction'] = 'left'; // Point new SymPy menus to left | ||
snippets_menu.python.numpy['sub-menu-direction'] = 'left'; // Point new Numpy menus to left | ||
snippets_menu.options['menus'].push(snippets_menu.default_menus[0]); // Start with the remaining "Snippets" menu | ||
snippets_menu.options['menus'].push(snippets_menu.python.sympy); // Follow that with a new SymPy menu | ||
snippets_menu.options['menus'].push(snippets_menu.python.numpy); // Follow that with a new Numpy menu | ||
console.log('Loaded `snippets_menu` customizations from `custom.js`'); | ||
}); | ||
|
||
|
||
|
||
//// 9. Change direction of sub-menus under "Snippets" | ||
require(["nbextensions/snippets_menu/main"], function (snippets_menu) { | ||
console.log('Loading `snippets_menu` customizations from `custom.js`'); | ||
snippets_menu.options['direction_of_top_level_submenu'] = 'right'; | ||
console.log('Loaded `snippets_menu` customizations from `custom.js`'); | ||
}); | ||
|
||
|
||
|
||
//// 10. Place "Snippets" inside "Insert" menu | ||
require(["nbextensions/snippets_menu/main"], function (snippets_menu) { | ||
console.log('Loading `snippets_menu` customizations from `custom.js`'); | ||
snippets_menu.default_menus[0]['menu-direction'] = 'left'; // Open top-level menu to the left... | ||
snippets_menu.default_menus[0]['sub-menu-direction'] = 'right'; // ...and sub-menus to the right. | ||
snippets_menu.options['menus'].push('---', snippets_menu.default_menus[0]); // Add horizontal line and default menus | ||
snippets_menu.options['sibling'] = $("#insert_cell_below"); // Find the place at which to insert the new menus | ||
console.log('Loaded `snippets_menu` customizations from `custom.js`'); | ||
}); | ||
|
||
|
||
|
||
//// 11. Multiple menus in different places | ||
require(["nbextensions/snippets_menu/main"], function (snippets_menu) { | ||
console.log('Loading `snippets_menu` customizations from `custom.js`'); | ||
var sympy_menu = [snippets_menu.python.sympy,]; | ||
sympy_menu[0]['sub-menu-direction'] = 'left'; | ||
snippets_menu.options['menus'] = sympy_menu; | ||
snippets_menu.default_menus[0]['sub-menu'].splice(3, 1); // Remove SymPy from defaults | ||
snippets_menu.default_menus[0]['menu-direction'] = 'left'; | ||
snippets_menu.default_menus[0]['sub-menu-direction'] = 'right'; | ||
var sibling = $("#insert_cell_below"); | ||
var inserted_menu = [ | ||
'---', | ||
snippets_menu.default_menus[0], | ||
]; | ||
snippets_menu.menu_setup(inserted_menu, sibling, 'after'); | ||
console.log('Loaded `snippets_menu` customizations from `custom.js`'); | ||
}); |
Oops, something went wrong.