Repository: spyder-ide/spyder

Issue:
Shortcuts: reset console / empty namespace
## Description of your problem

**What steps will reproduce the problem?**
1. Use Editor or console
2. assign some variable
3. `%reset` in cosole

**What is the expected output? What do you see instead?**
All OK.

**Please provide any additional information below**
I would like to assign a key combination to automatically reset / empty namespace.
Optionally, this could also be added to the run configuration.
## Versions and main components
- Spyder Version: 3.0.0
- Python Version: 3.5
- Operating system: Windows 7
## Dependencies

Please go to the menu entry `Help > Optional Dependencies` (or
`Help > Dependencies`), press the button `Copy to clipboard`
and paste the contents below:



Discussion:

Resolving patch:
diff --git a/spyderlib/widgets/ipython.py b/spyderlib/widgets/ipython.py
--- a/spyderlib/widgets/ipython.py
+++ b/spyderlib/widgets/ipython.py
@@ -237,6 +237,20 @@ def short_banner(self):
 
     def clear_console(self):
         self.execute("%clear")
+        
+    def reset_namespace(self):
+        """Resets the namespace by removing all names defined by the user"""
+        
+        reply = QMessageBox.question(
+            self,
+            _("Reset IPython namespace"),
+            _("All user-defined variables will be removed."
+            "<br>Are you sure you want to reset the namespace?"),
+            QMessageBox.Yes | QMessageBox.No,
+            )
+
+        if reply == QMessageBox.Yes:
+            self.execute("%reset -f")
 
     def write_to_stdin(self, line):
         """Send raw characters to the IPython kernel through stdin"""
@@ -253,9 +267,10 @@ def create_shortcuts(self):
                                   parent=self)
         clear_console = create_shortcut(self.clear_console, context='Console',
                                         name='Clear shell', parent=self)
-
+                                        
         # Fixed shortcuts
         new_shortcut("Ctrl+T", self, lambda: self.new_client.emit())
+        new_shortcut("Ctrl+R", self, lambda: self.reset_namespace())
         new_shortcut(SHORTCUT_INLINE, self,
                      lambda: self._control.enter_array_inline())
         new_shortcut(SHORTCUT_TABLE, self,
@@ -584,6 +599,9 @@ def add_actions_to_context_menu(self, menu):
                                           QKeySequence("Shift+Escape"),
                                           icon=ima.icon('editdelete'),
                                           triggered=self.clear_line)
+        reset_namespace_action = create_action(self, _("Reset namespace"),
+                                          QKeySequence("Ctrl+R"),
+                                          triggered=self.reset_namespace)
         clear_console_action = create_action(self, _("Clear console"),
                                              QKeySequence(get_shortcut('console',
                                                                'clear shell')),
@@ -592,7 +610,8 @@ def add_actions_to_context_menu(self, menu):
         quit_action = create_action(self, _("&Quit"), icon=ima.icon('exit'),
                                     triggered=self.exit_callback)
         add_actions(menu, (None, inspect_action, clear_line_action,
-                           clear_console_action, None, quit_action))
+                           clear_console_action, reset_namespace_action,
+                           None, quit_action))
         return menu
     
     def set_font(self, font):
@@ -627,7 +646,12 @@ def clear_line(self):
     @Slot()
     def clear_console(self):
         """Clear the whole console"""
-        self.shellwidget.execute("%clear")
+        self.shellwidget.clear_console()
+        
+    @Slot()
+    def reset_namespace(self):
+        """Resets the namespace by removing all names defined by the user"""
+        self.shellwidget.reset_namespace()
     
     def if_kernel_dies(self, t):
         """


Test patch: