def CMDedit(parser):
  """Searches for <query> then opens it in $EDITOR"""
  parser.add_option('--current-filename', dest='current_filename', action='store', default=None, help="Hints quickopen about the current buffer to improve search relevance.")
  parser.add_option('--open-filenames', dest='open_filenames', action='store', default=[], help="Hints quickopen about the filenames currently open to improve search relevance.")
  (options, args) = parser.parse_args()

  if len(args) > 1:
    parser.error('Expected: <query> or nothing')

  if not os.getenv('EDITOR'):
    parser.error('$EDITOR must be set in environment')

  db = open_db(options)
  if not db.has_index:
    print "Database is not fully indexed. Wait a bit or try quickopen status"
    return 255

  def edit(filenames, canceled):
    if canceled:
      return 255
    args = shlex.split(os.getenv('EDITOR'))
    args.extend(filenames)
    proc = subprocess.Popen(args, shell=False)
    try:
      return proc.wait()
    except __HOLE__:
      proc.kill()
      return 255

  search_args = {}
  if options.current_filename:
    search_args["current_filename"] = options.current_filename
  if options.open_filenames:
    search_args["open_filenames"] = split_open_filenames(options.open_filenames)

  if len(args):
    initial_filter = args[0]
  else:
    initial_filter = None

  from src import open_dialog
  from src import message_loop
  def edit_at_quit(filenames, canceled):
    def do_edit():
      edit(filenames, canceled)
    message_loop.add_quit_handler(do_edit)
  open_dialog.run(options, db, initial_filter, edit_at_quit) # will not return on osx.
dataset/ETHPy150Open natduca/quickopen/src/quickopen.py/CMDedit