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.
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 KeyboardInterrupt: 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 import src.open_dialog as open_dialog import src.message_loop as 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.
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.
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.
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 KeyboardInterrupt: 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.
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.