" " VimPdb.vim " " Intergrates a Python debugger into Vim in an IDE-like fashion. " " Author: " Yaron Budowski " " " Initialization code " " if !has('python') map :echoerr 'No python -> no debugger ...' finish endif let current_dir = expand(":h") python import sys exe 'python sys.path.insert(0, r"' . current_dir . '")' python import VimPdb function! PdbInitialize() " Initializes the VimPdb pluging. au BufLeave *.py :call PdbBuffLeave() au BufEnter *.py :call PdbBuffEnter() au BufEnter *.py :call PdbMapKeyboard() au VimLeave *.py :call PdbStopDebug() call PdbMapKeyboard() let current_dir = expand(":h") python import sys exe 'python sys.path.insert(0, r"' . current_dir . '")' python import VimPdb python << EOF import vim import threading import time import re reload(VimPdb) # The VimPdb instance used for debugging. vim_pdb = VimPdb.VimPdb() vim_pdb.stack_entry_format = vim.eval('g:stack_entry_format') vim_pdb.stack_entry_prefix = vim.eval('g:stack_entry_prefix') vim_pdb.current_stack_entry_prefix = vim.eval('g:current_stack_entry_prefix') vim_pdb.stack_entries_joiner = vim.eval('g:stack_entries_joiner') def vim_pdb_start_debug(stop_immediately, args): global vim_pdb vim_pdb.start_debugging(vim.current.buffer.name, stop_immediately, args) def parse_command_line(line): """Parses command line.""" args = [] while (len(line) > 0): if (line[0] == '"'): next_quotation_mark = line.find('"', 1) if (next_quotation_mark == -1): # No ending quotation mark found. line = line[1:] continue # Treat anything between the two quotation marks as one argument. args.append(line[1:next_quotation_mark]) line = line[next_quotation_mark + 1:] continue match = re.search('\s+', line) if (not match): # No whitespace found - save the argument until the end of the line. args.append(line) line = "" continue if (match.start() == 0): # Whitespace in the beginning of the line - skip it. line = line[match.end():] continue args.append(line[:match.start()]) line = line[match.end():] return args EOF endfunction " " Vim event related functions " function! PdbBuffLeave() " Used when leaving the current buffer - clear all highlighting. python < 0)): vim_pdb.add_queued_method('do_toggle_breakpoint', vim.current.buffer.name, line_number, condition.strip()) else: condition = None vim_pdb.add_queued_method('do_toggle_breakpoint', vim.current.buffer.name, line_number, condition) else: print VimPdb.VimPdb.MESSAGE_NOT_IN_DEBUG_MODE EOF endfunction function! PdbToggleTemporaryBreakpointOnCurrentLine() " Toggles a temporary breakpoint on the current line. python << EOF if (vim_pdb.is_debugged()): line_number = int(vim.eval('line(".")')) vim_pdb.add_queued_method('do_toggle_breakpoint', vim.current.buffer.name, line_number, None, True) else: print VimPdb.VimPdb.MESSAGE_NOT_IN_DEBUG_MODE EOF endfunction function PdbClearAllBreakpointsInCurrentFile() " Clears all breakpoints in the current file. python << EOF if (vim_pdb.is_debugged()): vim_pdb.add_queued_method('do_clear_all_breakpoints', vim.current.buffer.name) else: print VimPdb.VimPdb.MESSAGE_NOT_IN_DEBUG_MODE EOF endfunction function PdbClearAllBreakpoints() " Clears all breakpoints in all files. python << EOF if (vim_pdb.is_debugged()): vim_pdb.add_queued_method('do_clear_all_breakpoints') else: print VimPdb.VimPdb.MESSAGE_NOT_IN_DEBUG_MODE EOF endfunction function! PdbPrintBreakpointConditionOnCurrentLine() " Prints the condition of the conditional breakpoint in the current line. python << EOF if (vim_pdb.is_debugged()): line_number = int(vim.eval('line(".")')) print vim_pdb.run_method('do_print_breakpoint_condition', vim.current.buffer.name, line_number) else: print VimPdb.VimPdb.MESSAGE_NOT_IN_DEBUG_MODE EOF endfunction function! PdbEvalCurrentWord() " Evals the word currently under the cursor. python <")') if ((current_word is not None) and (len(current_word.strip()) > 0)): vim_pdb.run_method('do_eval', current_word) else: print VimPdb.VimPdb.MESSAGE_NOT_IN_DEBUG_MODE EOF endfunction function! PdbEvalCurrentWORD() " Evals the WORD currently under the cursor. python <")') if ((current_word is not None) and (len(current_word.strip()) > 0)): vim_pdb.run_method('do_eval', current_word) else: print VimPdb.VimPdb.MESSAGE_NOT_IN_DEBUG_MODE EOF endfunction function! PdbEvalExpression() " Evals an expression given by the user. python < :call PdbStartDebug(1, []) " Start debug and don't pause immediately. map :call PdbStartDebug(0, []) map :call PdbStartDebugWithArguments() map :call PdbStopDebug() map :call PdbRestartDebug() map l :call PdbLoadSavedBreakpoints() map s :call PdbSaveSavedBreakpoints() map :call PdbStepInto() map :call PdbStepOver() map :call PdbContinueUntilReturn() map :call PdbMoveUpInStackFrame() map :call PdbMoveDownInStackFrame() map :call PdbSetFocusToCurrentDebugLine() map :call PdbJumpToCurrentLine() map :call PdbToggleBreakpointOnCurrentLine() map :call PdbToggleConditionalBreakpointOnCurrentLine() map :call PdbToggleTemporaryBreakpointOnCurrentLine() map :call PdbClearAllBreakpointsInCurrentFile() map :call PdbClearAllBreakpoints() map :call PdbPrintBreakpointConditionOnCurrentLine() map :call PdbEvalCurrentWord() map :call PdbEvalCurrentWORD() map :call PdbEvalExpression() map :call PdbExecStatement() map :call PdbPrintStackTrace() endfunction " The format string for displaying a stack entry. let g:stack_entry_format = "%(dir)s\\%(filename)s (%(line)d): %(function)s(%(args)s) %(return_value)s %(source_line)s" " The string used to join stack entries together. let g:stack_entries_joiner = " ==>\n" " The prefix to each stack entry - 'regular' and current stack entry. let g:stack_entry_prefix = " " let g:current_stack_entry_prefix = "* " " Should VimPdb look for saved breakpoints file when starting a debug session? let g:auto_load_breakpoints_file = 0 " Should VimPdb save the breakpoints file when stopping the debug session? let g:auto_save_breakpoints_file = 0 " The name of the default saved breakpoints file (in the currently debugged directory). " Used when auto_load_breakpoints_file/auto_save_breakpoints_file are turned on. let g:default_breakpoints_filename = "bplist.vpb" " " Main code " call PdbInitialize()