Example #1
0
def CMDsearch(parser):
    """Search for a file"""
    if prelaunch.is_prelaunched_process() and message_loop.is_curses:
        print "Prelaunching not available for curses UI."
        return 255

    parser.add_option('--ok',
                      dest='ok',
                      action='store_true',
                      default=False,
                      help='Output "OK" before results')
    parser.add_option('--lisp-results',
                      dest='lisp_results',
                      action='store_true',
                      default=False,
                      help='Output results as a lisp-formatted list')
    parser.add_option(
        '--results-file',
        dest='results_file',
        action='store',
        help='Output results to the provided file instead of stdout')
    (options, args) = parser.parse_args()
    settings = load_settings(options)
    if not trace_is_enabled() and settings.trace:
        trace_enable("%s.trace" % sys.argv[0])
    db = open_db(options)

    import src.open_dialog as open_dialog
    if len(args):
        initial_filter = " ".join(args)
    else:
        initial_filter = None
    open_dialog.run(settings, options, db,
                    initial_filter)  # will not return on osx.
Example #2
0
def CMDsearch(parser):
  """Search for a file"""
  if prelaunch.is_prelaunched_process() and message_loop.is_curses:
    print "Prelaunching not available for curses UI."
    return 255

  parser.add_option('--ok', dest='ok', action='store_true', default=False, help='Output "OK" before results')
  parser.add_option('--lisp-results', dest='lisp_results', action='store_true', default=False, help='Output results as a lisp-formatted list')
  parser.add_option('--results-file', dest='results_file', action='store', help='Output results to the provided file instead of stdout')
  (options, args) = parser.parse_args()
  settings = load_settings(options)
  if not trace_is_enabled() and settings.trace:
    trace_enable("%s.trace" % sys.argv[0])
  db = open_db(options)

  import src.open_dialog as open_dialog
  if len(args):
    initial_filter = " ".join(args)
  else:
    initial_filter = None
  open_dialog.run(settings, options, db, initial_filter) # will not return on osx.
Example #3
0
def CMDsearch(parser):
  """Search for a file"""
  if prelaunch.is_prelaunched_process() and message_loop.is_curses:
    print "Prelaunching not available for curses UI."
    return 255

  parser.add_option('--ok', dest='ok', action='store_true', default=False, help='Output "OK" before results')
  parser.add_option('--lisp-results', dest='lisp_results', action='store_true', default=False, help='Output results as a lisp-formatted list')
  parser.add_option('--results-file', dest='results_file', action='store', help='Output results to the provided file instead of stdout')
  parser.add_option('--skip-ui-if-exact-match', dest='skip_if_exact', action='store_true', default=False, help="Don't show UI if there's an exact match")
  parser.add_option('--only-if-exact-match', dest='only_if_exact', action='store_true', default=False, help="Print only if there is an exact match, nothing otherwise")
  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()
  message_loop.ensure_has_message_loop()
  if not trace_is_enabled() and options.trace:
    trace_enable("%s.trace" % sys.argv[0])
  db = open_db(options)

  def print_results(res, canceled):
    if options.ok and not canceled:
      print "OK"

    if options.results_file:
      ofile = open(options.results_file, 'w')
    else:
      ofile = sys.stdout

    if options.lisp_results:
      ofile.write("(%s)\n" % (" ".join(['"%s"' % x for x in res])))
    else:
      ofile.write("\n".join(res))
    ofile.write("\n")

    if options.results_file:
      ofile.close()

  search_args = {}
  if options.current_filename:
    search_args["current_filename"] = options.current_filename
  if options.open_filenames:
    # Switch the options to the parsed form so the open dialog can use it directly.
    options.open_filenames = split_open_filenames(options.open_filenames)
    search_args["open_filenames"] = options.open_filenames
  # FIXME: Modify emacs to not use this option anymore and then remove it.
  if options.skip_if_exact:
    res = db.search(args[0], exact_match=True, **search_args)
    if len(res.filenames) == 1:
      print_results(res.filenames, False)
      return 0
  if options.only_if_exact:
    res = db.search(args[0], exact_match=True, **search_args)
    if len(res.filenames) == 1:
      print_results(res.filenames, False)
    return 0

  if len(args):
    initial_filter = " ".join(args)
  else:
    initial_filter = None

  import src.open_dialog as open_dialog
  open_dialog.run(options, db, initial_filter, print_results) # will not return on osx.
Example #4
0
def CMDsearch(parser):
    """Search for a file"""
    if prelaunch.is_prelaunched_process() and (
            not message_loop.supports_prelaunch()):
        print "Prelaunching not available for current UI."
        return 255

    parser.add_option('--ok',
                      dest='ok',
                      action='store_true',
                      default=False,
                      help='Output "OK" before results')
    parser.add_option('--lisp-results',
                      dest='lisp_results',
                      action='store_true',
                      default=False,
                      help='Output results as a lisp-formatted list')
    parser.add_option(
        '--results-file',
        dest='results_file',
        action='store',
        help='Output results to the provided file instead of stdout')
    parser.add_option('--skip-ui-if-exact-match',
                      dest='skip_if_exact',
                      action='store_true',
                      default=False,
                      help="Don't show UI if there's an exact match")
    parser.add_option(
        '--only-if-exact-match',
        dest='only_if_exact',
        action='store_true',
        default=False,
        help="Print only if there is an exact match, nothing otherwise")
    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()

    message_loop.ensure_has_message_loop()

    if not trace_is_enabled() and options.trace:
        trace_enable("%s.trace" % sys.argv[0])
    db = open_db(options)

    def print_results(res, canceled):
        if options.ok and not canceled:
            print "OK"

        if options.results_file:
            ofile = open(options.results_file, 'w')
        else:
            ofile = sys.stdout

        if options.lisp_results:
            ofile.write("(%s)\n" % (" ".join(['"%s"' % x for x in res])))
        else:
            ofile.write("\n".join(res))
        ofile.write("\n")

        if options.results_file:
            ofile.close()

    search_args = {}
    if options.current_filename:
        search_args["current_filename"] = options.current_filename
    if options.open_filenames:
        # Switch the options to the parsed form so the open dialog can use it directly.
        options.open_filenames = split_open_filenames(options.open_filenames)
        search_args["open_filenames"] = options.open_filenames
    # FIXME: Modify emacs to not use this option anymore and then remove it.
    if options.skip_if_exact:
        res = db.search(args[0], exact_match=True, **search_args)
        if len(res.filenames) == 1:
            print_results(res.filenames, False)
            return 0
    if options.only_if_exact:
        res = db.search(args[0], exact_match=True, **search_args)
        if len(res.filenames) == 1:
            print_results(res.filenames, False)
        return 0

    if len(args):
        initial_filter = " ".join(args)
    else:
        initial_filter = None

    from src import open_dialog
    open_dialog.run(options, db, initial_filter,
                    print_results)  # will not return on osx.