Ejemplo n.º 1
0
def display(query, archive):  # {{{1
    """ Shows a list of notes.

    query: a string representing a regex search. Can be "".

    Builds a list of files for query and then processes it to show the list in the pad format.
    """
    if get_save_dir() == "":
        vim.command('let tmp = confirm("IMPORTANT:\n'\
                'Please set g:pad_dir to a valid path in your vimrc.", "OK", 1, "Error")')
        return
    pad_files = get_filelist(query, archive)
    if len(pad_files) > 0:
        if vim.eval("bufexists('__pad__')") == "1":
            vim.command("bw __pad__")
        if vim.eval('g:pad_position["list"]') == "right":
            vim.command("silent! rightbelow " +
                        str(vim.eval('g:pad_window_width')) + "vnew __pad__")
        else:
            vim.command("silent! botright " +
                        str(vim.eval("g:pad_window_height")) + "new __pad__")
        fill_list(pad_files, query != "")
        vim.command("set filetype=pad")
        vim.command("setlocal nomodifiable")
    else:
        print "no pads"
Ejemplo n.º 2
0
def incremental_search():  # {{{1
    """ Provides incremental search within the __pad__ buffer.
    """
    query = ""
    should_create_on_enter = False

    vim.command("echohl None")
    vim.command('echo ">> "')
    while True:
        raw_char = vim.eval("getchar()")
        if raw_char in ("13", "27"):
            if raw_char == "13" and should_create_on_enter:
                vim.command("bw")
                open_pad(first_line=query)
                vim.command("echohl None")
            vim.command("redraw!")
            break
        else:
            try:  # if we can convert to an int, we have a regular key
                int(raw_char)  # we bring up an error on nr2char
                last_char = vim.eval("nr2char(" + raw_char + ")")
                query = query + last_char
            except:  # if we don't, we have some special key
                keycode = unicode(raw_char, errors="ignore")
                if keycode == "kb":  # backspace
                    query = query[:-len(last_char)]
        vim.command("setlocal modifiable")
        pad_files = get_filelist(query)
        if pad_files != []:
            fill_list(pad_files, query != "")
            vim.command("setlocal nomodifiable")
            info = ""
            vim.command("echohl None")
            should_create_on_enter = False
        else:  # we will create a new pad
            del vim.current.buffer[:]
            info = "[NEW] "
            vim.command("echohl WarningMsg")
            should_create_on_enter = True
        vim.command("redraw")
        vim.command('echo ">> ' + info + query + '"')
Ejemplo n.º 3
0
def incremental_search(): #{{{1
	""" Provides incremental search within the __pad__ buffer.
	"""
	query = ""
	should_create_on_enter = False
	
	vim.command("echohl None")
	vim.command('echo ">> "')
	while True:
		raw_char = vim.eval("getchar()")
		if raw_char in ("13", "27"):
			if raw_char == "13" and should_create_on_enter:
				vim.command("bw")
				open_pad(first_line=query)
				vim.command("echohl None")
			vim.command("redraw!")
			break
		else:
			try: # if we can convert to an int, we have a regular key
				int(raw_char) # we check this way so we bring up an error on nr2char
				last_char = vim.eval("nr2char(" + raw_char + ")")
				query = query + last_char
			except: # if we don't, we have some special key
				keycode = unicode(raw_char, errors="ignore")
				if keycode == "kb": # backspace
					query = query[:-len(last_char)]
		vim.command("setlocal modifiable")
		pad_files = get_filelist(query)
		if pad_files != []:
			fill_list(pad_files, query != "")
			vim.command("setlocal nomodifiable")
			info = ""
			vim.command("echohl None")
			should_create_on_enter = False
		else: # we will create a new pad
			del vim.current.buffer[:]
			info = "[NEW] "
			vim.command("echohl WarningMsg")
			should_create_on_enter = True
		vim.command("redraw")
		vim.command('echo ">> ' + info + query + '"')
Ejemplo n.º 4
0
def global_incremental_search():  # {{{1
    """ Provides incremental search in normal mode without opening the list.
    """
    query = ""
    should_create_on_enter = False

    vim.command("echohl None")
    vim.command('echo ">> "')
    while True:
        raw_char = vim.eval("getchar()")
        if raw_char in ("13", "27"):
            if raw_char == "13":
                if should_create_on_enter:
                    open_pad(first_line=query)
                    vim.command("echohl None")
                else:
                    display(query, True)
            vim.command("redraw!")
            break
        else:
            try:  # if we can convert to an int, we have a regular key
                int(raw_char)  # we bring up an error on nr2char
                last_char = vim.eval("nr2char(" + raw_char + ")")
                query = query + last_char
            except:  # if we don't, we have some special key
                keycode = unicode(raw_char, errors="ignore")
                if keycode == "kb":  # backspace
                    query = query[:-len(last_char)]
        pad_files = get_filelist(query)
        if pad_files != []:
            info = ""
            vim.command("echohl None")
            should_create_on_enter = False
        else:  # we will create a new pad
            info = "[NEW] "
            vim.command("echohl WarningMsg")
            should_create_on_enter = True
        vim.command("redraw")
        vim.command('echo ">> ' + info + query + '"')
Ejemplo n.º 5
0
def global_incremental_search():  # {{{1
    """ Provides incremental search in normal mode without opening the list.
    """
    query = ""
    should_create_on_enter = False

    vim.command("echohl None")
    vim.command('echo ">> "')
    while True:
        raw_char = vim.eval("getchar()")
        if raw_char in ("13", "27"):
            if raw_char == "13":
                if should_create_on_enter:
                    open_pad(first_line=query)
                    vim.command("echohl None")
                else:
                    display(query, True)
            vim.command("redraw!")
            break
        else:
            try:   # if we can convert to an int, we have a regular key
                int(raw_char)   # we bring up an error on nr2char
                last_char = vim.eval("nr2char(" + raw_char + ")")
                query = query + last_char
            except:  # if we don't, we have some special key
                keycode = unicode(raw_char, errors="ignore")
                if keycode == "kb":  # backspace
                    query = query[:-len(last_char)]
        pad_files = get_filelist(query)
        if pad_files != []:
            info = ""
            vim.command("echohl None")
            should_create_on_enter = False
        else:  # we will create a new pad
            info = "[NEW] "
            vim.command("echohl WarningMsg")
            should_create_on_enter = True
        vim.command("redraw")
        vim.command('echo ">> ' + info + query + '"')
Ejemplo n.º 6
0
def display(query, archive): # {{{1
    """ Shows a list of notes.

    query: a string representing a regex search. Can be "".

    Builds a list of files for query and then processes it to show the list in the pad format.
    """
    if get_save_dir() == "":
        vim.command('let tmp = confirm("IMPORTANT:\n'\
                'Please set g:pad_dir to a valid path in your vimrc.", "OK", 1, "Error")')
        return
    pad_files = get_filelist(query, archive)
    if len(pad_files) > 0:
        if vim.eval("bufexists('__pad__')") == "1":
            vim.command("bw __pad__")
        if vim.eval('g:pad_position["list"]') == "right":
            vim.command("silent! rightbelow " + str(vim.eval('g:pad_window_width')) + "vnew __pad__")
        else:
            vim.command("silent! botright " + str(vim.eval("g:pad_window_height")) + "new __pad__")
        fill_list(pad_files, query != "")
        vim.command("set filetype=pad")
        vim.command("setlocal nomodifiable")
    else:
        print "no pads"