Permalink
Browse files

Print warning message if trying to debug with unsaved buffers, fix #57

An error message pops up telling the user to save their buffers. Until
they do, Vdebug will not enter into debug mode.
  • Loading branch information...
1 parent 46832f8 commit 9c2808c951abdd1b917a8ab6d2e17396c37a0d74 @joonty committed Mar 6, 2013
Showing with 83 additions and 62 deletions.
  1. +43 −36 plugin/python/vdebug/runner.py
  2. +40 −26 plugin/python/vdebug/ui/vimui.py
@@ -29,42 +29,49 @@ def open(self):
If either of these are already open, the current
connection or vdebug.ui is used.
"""
- vdebug.opts.Options.set(vim.eval('g:vdebug_options'))
-
- if vdebug.opts.Options.isset('debug_file'):
- vdebug.log.Log.set_logger(vdebug.log.FileLogger(\
- vdebug.opts.Options.get('debug_file_level'),\
- vdebug.opts.Options.get('debug_file')))
- self.listen(\
- vdebug.opts.Options.get('server'),\
- vdebug.opts.Options.get('port',int),\
- vdebug.opts.Options.get('timeout',int))
-
- self.ui.open()
- self.keymapper.map()
- self.ui.set_listener_details(\
- vdebug.opts.Options.get('server'),\
- vdebug.opts.Options.get('port'),\
- vdebug.opts.Options.get('ide_key'))
-
- addr = self.api.conn.address
- vdebug.log.Log("Found connection from " + str(addr),vdebug.log.Logger.INFO)
- self.ui.set_conn_details(addr[0],addr[1])
-
- self.set_features()
- self.breakpoints.update_lines(self.ui.get_breakpoint_sign_positions())
- self.breakpoints.link_api(self.api)
-
- cn_res = self.api.context_names()
- self.context_names = cn_res.names()
- vdebug.log.Log("Available context names: %s" %\
- str(self.context_names),vdebug.log.Logger.DEBUG)
-
- if vdebug.opts.Options.get('break_on_open',int) == 1:
- status = self.api.step_into()
- else:
- status = self.api.run()
- self.refresh(status)
+ try:
+ if self.ui.is_modified():
+ self.ui.error("Modified buffers must be saved before debugging")
+ return
+ vdebug.opts.Options.set(vim.eval('g:vdebug_options'))
+
+ if vdebug.opts.Options.isset('debug_file'):
+ vdebug.log.Log.set_logger(vdebug.log.FileLogger(\
+ vdebug.opts.Options.get('debug_file_level'),\
+ vdebug.opts.Options.get('debug_file')))
+ self.listen(\
+ vdebug.opts.Options.get('server'),\
+ vdebug.opts.Options.get('port',int),\
+ vdebug.opts.Options.get('timeout',int))
+
+ self.ui.open()
+ self.keymapper.map()
+ self.ui.set_listener_details(\
+ vdebug.opts.Options.get('server'),\
+ vdebug.opts.Options.get('port'),\
+ vdebug.opts.Options.get('ide_key'))
+
+ addr = self.api.conn.address
+ vdebug.log.Log("Found connection from " + str(addr),vdebug.log.Logger.INFO)
+ self.ui.set_conn_details(addr[0],addr[1])
+
+ self.set_features()
+ self.breakpoints.update_lines(self.ui.get_breakpoint_sign_positions())
+ self.breakpoints.link_api(self.api)
+
+ cn_res = self.api.context_names()
+ self.context_names = cn_res.names()
+ vdebug.log.Log("Available context names: %s" %\
+ str(self.context_names),vdebug.log.Logger.DEBUG)
+
+ if vdebug.opts.Options.get('break_on_open',int) == 1:
+ status = self.api.step_into()
+ else:
+ status = self.api.run()
+ self.refresh(status)
+ except Exception as e:
+ self.close()
+ raise e
def set_features(self):
"""Evaluate vim dictionary of features and pass to debugger.
@@ -16,45 +16,57 @@ def __init__(self,breakpoints):
self.emptybuffer = None
self.breakpointwin = BreakpointWindow(self,'rightbelow 7new')
self.current_tab = "1"
+ self.tabnr = None
+
+ def is_modified(self):
+ modified = int(vim.eval('&mod'))
+ if modified:
+ return True
+ else:
+ return False
def open(self):
if self.is_open:
return
self.is_open = True
- cur_buf_name = vim.eval("bufname('%')")
- if cur_buf_name is None:
- cur_buf_name = ''
+ try:
+ cur_buf_name = vim.eval("bufname('%')")
+ if cur_buf_name is None:
+ cur_buf_name = ''
- self.current_tab = vim.eval("tabpagenr()")
+ self.current_tab = vim.eval("tabpagenr()")
- vim.command('silent tabnew ' + cur_buf_name)
- self.tabnr = vim.eval("tabpagenr()")
+ vim.command('silent tabnew ' + cur_buf_name)
+ self.tabnr = vim.eval("tabpagenr()")
- srcwin_name = self.__get_srcwin_name()
+ srcwin_name = self.__get_srcwin_name()
- self.watchwin = WatchWindow(self,'vertical belowright new')
- self.watchwin.create()
+ self.watchwin = WatchWindow(self,'vertical belowright new')
+ self.watchwin.create()
- self.stackwin = StackWindow(self,'belowright new')
- self.stackwin.create()
+ self.stackwin = StackWindow(self,'belowright new')
+ self.stackwin.create()
- self.statuswin = StatusWindow(self,'belowright new')
- self.statuswin.create()
- self.statuswin.set_status("loading")
+ self.statuswin = StatusWindow(self,'belowright new')
+ self.statuswin.create()
+ self.statuswin.set_status("loading")
- self.watchwin.set_height(20)
- self.statuswin.set_height(5)
+ self.watchwin.set_height(20)
+ self.statuswin.set_height(5)
- logwin = LogWindow(self,'rightbelow 6new')
- vdebug.log.Log.set_logger(\
- vdebug.log.WindowLogger(\
- vdebug.opts.Options.get('debug_window_level'),\
- logwin))
+ logwin = LogWindow(self,'rightbelow 6new')
+ vdebug.log.Log.set_logger(\
+ vdebug.log.WindowLogger(\
+ vdebug.opts.Options.get('debug_window_level'),\
+ logwin))
- winnr = self.__get_srcwinno_by_name(srcwin_name)
- self.sourcewin = SourceWindow(self,winnr)
- self.sourcewin.focus()
+ winnr = self.__get_srcwinno_by_name(srcwin_name)
+ self.sourcewin = SourceWindow(self,winnr)
+ self.sourcewin.focus()
+ except Exception as e:
+ self.is_open = False
+ raise e
def set_source_position(self,file,lineno):
self.sourcewin.set_file(file)
@@ -153,8 +165,10 @@ def close(self):
self.statuswin.destroy()
vdebug.log.Log.remove_logger('WindowLogger')
- vim.command('silent! '+self.tabnr+'tabc!')
- vim.command('tabn '+self.current_tab)
+ if self.tabnr:
+ vim.command('silent! '+self.tabnr+'tabc!')
+ if self.current_tab:
+ vim.command('tabn '+self.current_tab)
self.watchwin = None
self.stackwin = None

0 comments on commit 9c2808c

Please sign in to comment.