<s> import vim <EOL> from os . path import join <EOL> from . vim_interface import * <EOL> from . vim_globals import set_vim_globals <EOL> from . collator import NotesCollator <EOL> from . list import NotesListBuffer <EOL> from . pad import PadInfo <EOL> class PadPlugin ( object ) : <EOL> def __init__ ( self ) : <EOL> sources = get_setting ( '<STR_LIT>' ) <EOL> self . collator = NotesCollator ( sources ) <EOL> self . list = NotesListBuffer ( ) <EOL> set_vim_globals ( ) <EOL> @ prevent_invalid_dir <EOL> def open ( self , path = None , first_line = None , query = None ) : <EOL> """<STR_LIT>""" <EOL> if not path : <EOL> path = join ( get_save_dir ( ) , <EOL> PadInfo ( [ first_line ] ) . id + get_setting ( "<STR_LIT>" ) ) <EOL> path = path . replace ( "<STR_LIT:U+0020>" , "<STR_LIT>" ) <EOL> def split_for_pad ( ) : <EOL> if get_setting ( '<STR_LIT>' ) == '<STR_LIT:right>' : <EOL> V + ( "<STR_LIT>" + get_setting ( "<STR_LIT>" ) + "<STR_LIT>" + path ) <EOL> else : <EOL> V + ( "<STR_LIT>" + get_setting ( "<STR_LIT>" ) + "<STR_LIT>" + path ) <EOL> if get_setting ( "<STR_LIT>" , bool ) : <EOL> split_for_pad ( ) <EOL> else : <EOL> awa = int ( vim . eval ( "<STR_LIT>" ) ) <EOL> if bool ( int ( vim . eval ( "<STR_LIT>" ) ) ) : <EOL> reply = vim . eval ( '<STR_LIT>' ) <EOL> if reply == "<STR_LIT:y>" : <EOL> V + "<STR_LIT>" <EOL> V + ( "<STR_LIT>" + path ) <EOL> if awa == <NUM_LIT:0> : <EOL> V + "<STR_LIT>" <EOL> else : <EOL> V + '<STR_LIT>' <EOL> split_for_pad ( ) <EOL> V + "<STR_LIT>" <EOL> else : <EOL> V + ( "<STR_LIT>" + path ) <EOL> V + "<STR_LIT>" <EOL> if vim . eval ( '<STR_LIT>' ) in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> V + "<STR_LIT>" <EOL> else : <EOL> V + "<STR_LIT>" <EOL> if vim . eval ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> V + ( "<STR_LIT>" + get_setting ( "<STR_LIT>" ) ) <EOL> if first_line : <EOL> vim . current . buffer . append ( first_line , <NUM_LIT:0> ) <EOL> V + "<STR_LIT>" <EOL> if query not in ( '<STR_LIT>' , None ) : <EOL> if get_setting ( '<STR_LIT>' ) == '<STR_LIT:1>' : <EOL> V + ( "<STR_LIT>" + query + "<STR_LIT>" ) <EOL> if get_setting ( '<STR_LIT>' ) == '<STR_LIT:1>' : <EOL> V + ( "<STR_LIT>" + query + "<STR_LIT>" ) <EOL> def new ( self , text = None , path = None ) : <EOL> """<STR_LIT>""" <EOL> self . open ( path , text , None ) <EOL> if path : <EOL> V + ( "<STR_LIT>" "<STR_LIT>" + path + "<STR_LIT>" ) <EOL> @ prevent_invalid_dir <EOL> def display ( self , query = None , use_archive = False ) : <EOL> """<STR_LIT>""" <EOL> filelist = self . collator . get_filelist ( query , use_archive ) <EOL> self . list . show ( filelist , query != "<STR_LIT>" ) <EOL> V + ( "<STR_LIT>" + ( '<STR_LIT:1>' if use_archive else '<STR_LIT:0>' ) ) <EOL> def ls ( self , query = None , use_archive = False ) : <EOL> """<STR_LIT>""" <EOL> self . display ( query , use_archive == "<STR_LIT:!>" ) <EOL> @ prevent_invalid_dir <EOL> def search ( self , query = None , use_archive = False ) : <EOL> """<STR_LIT>""" <EOL> if not query : <EOL> query = vim . eval ( '<STR_LIT>' ) <EOL> self . display ( query , use_archive == "<STR_LIT:!>" ) <EOL> V + "<STR_LIT>" <EOL> @ prevent_invalid_dir <EOL> def global_incremental_search ( self , should_open = True ) : <EOL> """<STR_LIT>""" <EOL> query = "<STR_LIT>" <EOL> should_create_on_enter = False <EOL> V + "<STR_LIT>" <EOL> V + '<STR_LIT>' <EOL> while True : <EOL> raw_char = vim . eval ( "<STR_LIT>" ) <EOL> if raw_char in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> if raw_char == "<STR_LIT>" : <EOL> if should_create_on_enter : <EOL> if should_open == True : <EOL> self . open ( first_line = query ) <EOL> else : <EOL> path = join ( get_save_dir ( ) , PadInfo ( [ query ] ) . id + get_setting ( "<STR_LIT>" ) ) <EOL> with open ( path , '<STR_LIT:w>' ) as new_note : <EOL> new_note . write ( query ) <EOL> V + "<STR_LIT>" <EOL> else : <EOL> self . display ( query , True ) <EOL> V + "<STR_LIT>" <EOL> break <EOL> else : <EOL> try : <EOL> int ( raw_char ) <EOL> last_char = vim . eval ( "<STR_LIT>" + raw_char + "<STR_LIT:)>" ) <EOL> query = query + last_char <EOL> except : <EOL> keycode = unicode ( raw_char , errors = "<STR_LIT:ignore>" ) <EOL> if keycode == "<STR_LIT>" : <EOL> query = query [ : - len ( last_char ) ] <EOL> pad_files = self . collator . get_filelist ( query ) <EOL> if pad_files != [ ] : <EOL> info = "<STR_LIT>" <EOL> V + "<STR_LIT>" <EOL> should_create_on_enter = False <EOL> else : <EOL> info = "<STR_LIT>" <EOL> V + "<STR_LIT>" <EOL> should_create_on_enter = True <EOL> V + "<STR_LIT>" <EOL> V + ( '<STR_LIT>' + info + query + '<STR_LIT:">' ) </s>
